***************************************************************************/
(function($) {
- var dispatchType(method) {
- return function(type) {
+ var dispatchType = function(method) {
+ return function(type, id) {
var name = type + '_' + method;
if ($.isFunction(this[name])) {
- return this[name]();
+ return this[name](id);
}
return this;
};
}
var question = $("#q_edit_new").tmpl(q);
question
- .children('select')
+ .children('select[name$="[type]"]')
.change(function () {
var type = $(this).val();
var form = question.children('.q_edit_form');
+ var qid = $(this).qid();
form.empty();
if (type) {
- $("#q_edit_base").tmpl({ qid: id, type: type })
- .bindQuestion(type)
+ $("#q_edit_base").tmpl({ qid: qid, type: type })
+ .bindQuestion(type, qid)
.appendTo(form);
}
return true;
},
/* Multiple choices questions */
- multiple_bindQuestion: function() {
+ multiple_selectSubtype: function() {
+ return this.find('select[name$="[subtype]"]');
+ },
+
+ multiple_bindQuestion: function(id) {
+ var $question = this;
+ this.multiple_selectSubtype()
+ .change(function() {
+ $question.find('.q_edit_answer_box')
+ .empty()
+ .append($('<input>', {
+ type: $(this).val(),
+ disabled: "disabled"
+ }));
+ });
return this;
},
multiple_addAnswer: function() {
- var answer = $("#q_edit_multiple_answer").tmpl({ qid: this.qid() });
- this.childrenContainer().children('.add_answer').before(answer);
+ var question = this.question();
+ var answer = $("#q_edit_multiple_answer").tmpl({ qid: question.qid() });
+ question.childrenContainer().children('.add_answer').after(answer);
return answer;
}
});
<option value="text" {{if type}}{{if type == 'text'}}selected="selected"{{/if}}{{/if}}>
Texte
</option>
- <option value="multiple" {{if type}}{{if type == 'multiple'}}selection="selected"{{/if}}{{/if}}>
+ <option value="multiple" {{if type}}{{if type == 'multiple'}}selected="selected"{{/if}}{{/if}}>
Question à choix multiples
</option>
</select>
{/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="checkbox">Oui</option>
+ <option value="radio" selected="selected">Non</option>
+ </select>
+ </div>
<div>
Ajouter une case Autre ?
<select name="q_edit[${qid}][allow_other]">
- <option name="1">Oui</option>
- <option name="" selected="selected">Non</option>
+ <option value="1">Oui</option>
+ <option value="" selected="selected">Non</option>
</select>
</div>
</div>
</script>
<script id="q_edit_multiple_answer" type="text/x-jquery-tmpl">
- <div><input type="text" name="q_edit[${qid}][answer][]" /></div>
+ <div>
+ <span class="q_edit_answer_box">
+ </span>
+ Réponse : <input type="text" name="q_edit[${qid}][answer][][value]" value="${value}" />
+ </div>
</script>
{/literal}