834b9e5ac91fa4f05dbec62a81130b6179822486
1 /***************************************************************************
2 * Copyright (C) 2003-2011 Polytechnique.org *
3 * http://opensource.polytechnique.org/ *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
23 questions
: function() {
24 return $('.q_edit:not(#questions)');
27 lastQuestion
: function() {
28 return $.questions().last();
31 renumberQuestions
: function() {
32 var q
= $.questions();
33 q
.each(function(idx
) {
35 var old_id
= elt
.attr('id');
36 var new_id
= 'q_edit[' + idx
+ ']';
37 if (old_id
== new_id
) {
41 var children
= elt
.children(':not(.q_edit)');
42 while (children
.length
> 0) {
43 children
.filter('.q_edit_label').text('Question ' + (idx
+ 1));
44 children
.children('[name*="' + old_id
+ '"]').each(function() {
45 function replace(attr
) {
46 var cid
= $(this).attr(attr
);
47 if (cid
.substr(0, id
.length
) == old_id
) {
48 $(this).attr(attr
, new_id
+ cid
.substring(old_id
.length
, cid
.length
));
54 children
= children
.children(':not(.q_edit)');
56 elt
.attr('id', new_id
);
60 debugPrintQuestions
: function() {
61 var q
= $.questions();
64 str
+= $(this).attr('id') + '\n';
71 showQuestions
: function(questions
) {
72 var data
= $('#question_base').tmpl(questions
);
73 this.children().remove();
79 isQuestion
: function() {
80 return this.hasClass('q_edit');
83 isRootSection
: function() {
84 return this.attr('id') == 'questions';
87 question
: function() {
88 return this.isQuestion() ? this : this.parentQuestion();
92 var question
= this.question();
93 if (question
.get(0) == undefined
) {
96 var id
= question
.attr('id');
97 if (id
.substr(0, 7) != 'q_edit[') {
100 if (id
.charAt(id
.length
- 1) != ']') {
103 id
= id
.substr(7, id
.length
- 8);
107 parentQuestion
: function() {
108 return this.closest('.q_edit');
111 childrenContainer
: function() {
112 var question
= this.question();
113 return question
.isRootSection() ? question
: question
.children('.q_edit_form').children();
116 childrenQuestion
: function() {
117 return this.childrenContainer().children('.q_edit');
120 addQuestion
: function() {
121 var id
= $.lastQuestion().qid();
122 if (id
== undefined
) {
127 var question
= $("#q_edit_new").tmpl([{ qid
: id
} ]);
130 .change(function () {
131 var type
= $(this).val();
132 var form
= question
.children('.q_edit_form');
134 $("#q_edit_base").tmpl([ { qid
: id
, type
: type
} ]).appendTo(form
);
137 var dest
= this.question();
138 var res
= this.childrenContainer().children('.add_question').before(question
);
139 $.renumberQuestions();
143 removeQuestion
: function(force
) {
144 var question
= this.parentQuestion();
145 if (!force
&& question
.children('.q_edit_form').children().children('.q_edit').length
> 0) {
146 if (!alert('Vous avez demander la suppression d\'une section contenant des questions. '
147 + 'Ces questions seront supprimées. Etes-vous sur de vouloir continuer ?')) {
152 if (question
.isRootSection()) {
153 res
= question
.empty();
155 res
= question
.remove();
157 $.renumberQuestions();
165 $(".datepicker").datepicker({
166 hideIfNoPrevNext
: true,
172 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: