(function($) {
var dispatchType = function(method) {
- return function(type, id) {
+ return function(type) {
var name = type + '_' + method;
+ var args = Array.prototype.slice.call(arguments, 1);
if ($.isFunction(this[name])) {
- return this[name](id);
+ return this[name].apply(this, args);
}
return this;
};
}
var question = $("#q_edit_new").tmpl(q);
var type = question
- .children('select[name$="[type]"]')
+ .find('select[name$="[type]"]')
.change(function () {
var type = $(this).val();
var form = question.children('.q_edit_form');
});
if (type.val()) {
question.children('.q_edit_form')
- .bindQuestion(type.val(), q.qid);
+ .bindQuestion(type.val(), q.qid, q.parameters)
}
this.childrenContainer().children('.add_question').before(question);
$.renumberQuestions();
return this.find('select[name$="[subtype]"]');
},
- multiple_bindQuestion: function(id) {
+ multiple_bindQuestion: function(id, parameters) {
var $question = this;
+ var answer;
+ var value;
this.multiple_selectSubtype()
+ .assertLength(1)
.change(function() {
$question.find('.q_edit_answer_box')
.empty()
type: $(this).val(),
disabled: "disabled"
}));
- })
- .change();
+ });
+ if (parameters) {
+ for (answer = 0; answer < parameters.answers.length; answer++) {
+ this.multiple_addAnswer(parameters.answers[answer]);
+ }
+ }
return this;
},
- multiple_addAnswer: function() {
+ multiple_addAnswer: function(value) {
var question = this.question();
- var answer = $("#q_edit_multiple_answer").tmpl({ qid: question.qid() });
- question.childrenContainer().children('.add_answer').after(answer);
+ var answer = $("#q_edit_multiple_answer").tmpl({ qid: question.qid(), value: value });
+ question.childrenContainer().children('.add_answer').before(answer);
question.multiple_selectSubtype().change();
return answer;
+ },
+
+ multiple_removeAnswer: function() {
+ return this.parent().remove();
}
});
}(jQuery));
{literal}
<script id="q_edit_new" type="text/x-jquery-tmpl">
- <div style="clear: both; padding-top: 1em" class="q_edit" id="q_edit[${qid}]">
- <div>
+ <fieldset style="clear: both; padding-top: 1em; background: inherit; color: inherit"
+ class="q_edit" id="q_edit[${qid}]">
+ <legend>
<span class="q_edit_label" style="font-weight: bold">Question ${qid + 1}</span>
+ <input type="text" name="q_edit[${qid}][label]" value="{{if label}}${label}{{/if}}" />
(<a onclick="$(this).removeQuestion()" style="text-decoration: none">
{/literal}{icon name="delete"}{literal} Supprimer
- </a>)
- </div>
- Titre : <input type="text" name="q_edit[${qid}][label]"
- value="{{if label}}${label}{{/if}}" /><br />
- Type de question : <select name="q_edit[${qid}][type]">
- <option value=""></option>
- <option value="section" {{if type}}{{if type == 'section'}}selected="selected"{{/if}}{{/if}}>
- Section
- </option>
- <option value="text" {{if type}}{{if type == 'text'}}selected="selected"{{/if}}{{/if}}>
- Texte
- </option>
- <option value="multiple" {{if type}}{{if type == 'multiple'}}selected="selected"{{/if}}{{/if}}>
- Question à choix multiples
- </option>
- </select>
+ </a>)<br />
+ Type de question : <select name="q_edit[${qid}][type]">
+ <option value=""></option>
+ <option value="section" {{if type}}{{if type == 'section'}}selected="selected"{{/if}}{{/if}}>
+ Section
+ </option>
+ <option value="text" {{if type}}{{if type == 'text'}}selected="selected"{{/if}}{{/if}}>
+ Texte
+ </option>
+ <option value="multiple" {{if type}}{{if type == 'multiple'}}selected="selected"{{/if}}{{/if}}>
+ Question à choix multiples
+ </option>
+ </select>
+ </legend>
<div class="q_edit_form">
{{tmpl "#q_edit_base"}}
</div>
- </div>
+ </fieldset>
</script>
<script id="q_edit_base" type="text/x-jquery-tmpl">
</script>
<script id="q_edit_section" type="text/x-jquery-tmpl">
- <div id="q_edit[${qid}][section]" style="padding-left: 4ex; border-left: 1px solid white">
+ <div id="q_edit[${qid}][section]">
<div class="add_question">
<a onclick="$(this).addQuestion()" style="text-decoration: none">
{/literal}{icon name="add"}{literal} Ajouter une question
<script id="q_edit_multiple" type="text/x-jquery-tmpl">
<div id="q_edit[${qid}][answers]">
- <div class="add_answer">
- <a onclick="$(this).multiple_addAnswer()">
- {/literal}{icon name="add"}{literal} Ajouter une réponse
- </a>
- </div>
- {{if parameters}}{{if parameters.answer}}
- {{tmpl(parameters.answer) "#q_edit_multiple_answer"}}
- {{/if}}{{/if}}
<div>
Permettre la sélection de plusieurs réponses ?
<select name="q_edit[${qid}][subtype]">
<option value="radio" selected="selected">Non</option>
</select>
</div>
+ <div class="add_answer">
+ <a onclick="$(this).multiple_addAnswer()">
+ {/literal}{icon name="add"}{literal} Ajouter une réponse
+ </a>
+ </div>
<div>
Ajouter une case Autre ?
<select name="q_edit[${qid}][allow_other]">
<script id="q_edit_multiple_answer" type="text/x-jquery-tmpl">
<div>
<span class="q_edit_answer_box"></span>
- Réponse : <input type="text" name="q_edit[${qid}][answer][][value]" value="${value}" />
+ <input type="text" name="q_edit[${qid}][answers][]" value="${value}" />
+ <a onclick="$(this).multiple_removeAnswer()">{/literal}{icon name="delete"}{literal}</a>
</div>
</script>