1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| @(poll: Poll, pollForm: Form[Poll]))
@import helper._
@import helper.twitterBootstrap._
@choiceGroup(field: Field, className: String = "choice") = {
<div class="@className">
<input name="label" placeholder="Choice"/>
<a href="#" class="removeChoice btn btn-danger btn-mini"><i class="icon-white icon-remove-sign"></i> Remove</a>
</div>
}
@main("Add choices") {
<form method="post" action="/poll/addChoices/@poll.id">
<fieldset>
<legend>Choices</legend>
<div id="choices">
@repeat(pollForm("choices")) { choice =>
@choiceGroup(choice)
}
@** Keep an hidden block that will be used as template for Javascript copy code **@
@choiceGroup(
pollForm("choices[x]"),
className = "choice_template"
)
<div class="manage">
<a class="addChoice btn btn-inverse btn-small">Add another choice</a>
</div>
</div>
</fieldset>
<div class="actions">
<input type="submit" class="btn btn-primary" value="Create" />
<a href="/" class="btn btn-link">Cancel</a>
</div>
</form>
<script type="text/javascript" charset="utf-8">
$('.removeChoice').live('click', function(e) {
$(this).parents('.choice').remove()
renumber()
})
$('.addChoice').live('click', function(e) {
var template = $('.choice_template')
template.before('<div class="choice">' + template.html() + '</div>')
})
$('#form').submit(function() {
$('.choice_template').remove()
})
</script>
} |