|
1 /* Copyright 2009 the Melange authors. |
|
2 * |
|
3 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 * you may not use this file except in compliance with the License. |
|
5 * You may obtain a copy of the License at |
|
6 * |
|
7 * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 * |
|
9 * Unless required by applicable law or agreed to in writing, software |
|
10 * distributed under the License is distributed on an "AS IS" BASIS, |
|
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 * See the License for the specific language governing permissions and |
|
13 * limitations under the License. |
|
14 */ |
|
15 |
|
16 /* |
|
17 * |
|
18 * @author <a href="mailto:ajaksu@gmail.com">Daniel Diniz</a> |
|
19 * @author <a href="mailto:jamesalexanderlevy@gmail.com">James Levy</a> |
|
20 */ |
|
21 |
|
22 (function ($) { |
|
23 |
|
24 var DEFAULT_LONG_ANSWER_TEXT = 'Write a Custom Prompt For This Question...'; |
|
25 var DEFAULT_SHORT_ANSWER_TEXT = 'Write a Custom Prompt...'; |
|
26 |
|
27 $(function () { |
|
28 /* |
|
29 * == Set Selectors == |
|
30 * |
|
31 */ |
|
32 var widget = $('div#survey_widget'); |
|
33 |
|
34 widget.parents('td.formfieldvalue:first').css({ |
|
35 'float': 'left', |
|
36 'width': 200 |
|
37 }); |
|
38 |
|
39 /* |
|
40 * == Setup for existing surveys == |
|
41 * |
|
42 */ |
|
43 |
|
44 if ($('input#id_title').val() === '' && $('.formfielderror').length < 1) { |
|
45 widget.find('tr').remove(); |
|
46 } |
|
47 |
|
48 widget.find('table:first').show(); |
|
49 |
|
50 /* |
|
51 * Restore survey content html from editPost |
|
52 * if POST fails |
|
53 */ |
|
54 |
|
55 var SURVEY_PREFIX = 'survey__'; |
|
56 var del_el = ["<a class='delete'><img '", |
|
57 "src='/soc/content/images/minus.gif'/></a>"].join(""); |
|
58 var del_li = ["<a class='delete_item' id='del_", |
|
59 "' ><img src='/soc/content/images/minus.gif'/></a> "]; |
|
60 |
|
61 var survey_html = $('form').find("#id_survey_html").attr('value'); |
|
62 |
|
63 function renderHTML() { |
|
64 // render existing survey forms |
|
65 widget.find('td > label').prepend(del_el).end(); |
|
66 |
|
67 $('ol').find('li').each( |
|
68 function () { |
|
69 $(this).prepend(del_li.join($(this).attr('id'))).end(); |
|
70 } |
|
71 ); |
|
72 widget.find('.short_answer').each( |
|
73 function () { |
|
74 $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() + |
|
75 'short_answer__' + $(this).attr('name')); |
|
76 } |
|
77 ); |
|
78 |
|
79 widget.find('.long_answer').each( |
|
80 function () { |
|
81 $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() + |
|
82 'long_answer__' + $(this).attr('name')) |
|
83 .attr('overflow', 'auto'); |
|
84 // TODO: replace scrollbar with jquery autogrow |
|
85 } |
|
86 ); |
|
87 } |
|
88 |
|
89 if (survey_html && survey_html.length > 1) { |
|
90 widget.html(survey_html); // we don't need to re-render HTML |
|
91 |
|
92 widget.find('.long_answer,input').each( |
|
93 function () { |
|
94 $(this).val($(this).attr('val')); |
|
95 } |
|
96 ); |
|
97 } |
|
98 else { |
|
99 renderHTML(); |
|
100 } |
|
101 |
|
102 var survey = widget.find('tbody:first'); |
|
103 var options = widget.find('#survey_options'); |
|
104 |
|
105 /* |
|
106 * == Handle Enter key on dialogs == |
|
107 */ |
|
108 $('form input, form button, form select').keypress( |
|
109 function (e) { |
|
110 if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) { |
|
111 $(this).parents('.ui-dialog:first').find(":button:first").click(); |
|
112 return false; |
|
113 } |
|
114 } |
|
115 ); |
|
116 |
|
117 /* |
|
118 * == Display survey answers inline == |
|
119 */ |
|
120 $('a.fetch_answers').click( |
|
121 function () { |
|
122 var user = this.id.replace('results_for_', ''); |
|
123 var path = window.location.pathname; |
|
124 path = path.replace('/edit/', '/show/').replace('/results/', '/show/'); |
|
125 |
|
126 // TODO(ajaksu) add Date().getTime() to query arg if needed |
|
127 var query = '?read_only=true&user_results=' + user; |
|
128 var scrollable = ['<div style="overflow-y: auto; ', |
|
129 'margin-bottom: 100px;"></div>'].join(""); |
|
130 $(scrollable).load(path + query + ' #survey_widget').dialog({ |
|
131 title: user, |
|
132 height: 500, |
|
133 width: 700 |
|
134 }); |
|
135 } |
|
136 ); |
|
137 |
|
138 /* |
|
139 * == Initiation == |
|
140 * |
|
141 * Runs on PageLoad and Each Time Field is Added to Survey |
|
142 * |
|
143 */ |
|
144 |
|
145 survey.bind('init', |
|
146 function () { |
|
147 // TODO(jamslevy) unnecessarily redundant |
|
148 // TODO(jamslevy) This should be refactored as a jQuery function that |
|
149 // acts on only a single field and it should be merged with renderHTML |
|
150 // since they have comparable functionality. |
|
151 |
|
152 widget.find('input').each( |
|
153 function () { |
|
154 if (($(this).val().length < 1 || |
|
155 $(this).val() === DEFAULT_SHORT_ANSWER_TEXT) && |
|
156 ($(this).attr('type') !== 'hidden')) { |
|
157 $(this).preserveDefaultText(DEFAULT_SHORT_ANSWER_TEXT); |
|
158 } |
|
159 } |
|
160 ); |
|
161 |
|
162 widget.find('.long_answer').each( |
|
163 function () { |
|
164 if ($(this).val().length < 1 || |
|
165 $(this).val() === DEFAULT_LONG_ANSWER_TEXT) { |
|
166 $(this).preserveDefaultText(DEFAULT_LONG_ANSWER_TEXT); |
|
167 } |
|
168 $(this).growfield(); |
|
169 } |
|
170 ); |
|
171 |
|
172 widget.find('a.delete img').click( |
|
173 function () { |
|
174 // delete a field |
|
175 var this_field = $(this).parents('tr:first'); |
|
176 var deleted_id = $(this_field).find('label').attr('for'); |
|
177 var delete_this = confirm(["Deleting this field will remove all ", |
|
178 "answers submitted for this field. ", |
|
179 "Continue?"].join("")); |
|
180 if (delete_this) { |
|
181 var edit_form = $('#EditForm'); |
|
182 var deleted_field = $('#__deleted__'); |
|
183 if (deleted_field.val()) { |
|
184 deleted_field.val(deleted_field.val() + ',' + |
|
185 deleted_id.replace('id_', '')).end(); |
|
186 } |
|
187 else { |
|
188 var deleted_input = $("<input type='hidden' value='" + |
|
189 deleted_id.replace('id_', '') + "' />"); |
|
190 deleted_input.attr({'id': '__deleted__'}).attr({ |
|
191 'name': '__deleted__' |
|
192 }); |
|
193 edit_form.append(deleted_input); |
|
194 } |
|
195 this_field.remove(); |
|
196 } |
|
197 } |
|
198 ); |
|
199 |
|
200 // Add list/choice-field item to survey |
|
201 $('[name=create-option-button]').each( |
|
202 function () { |
|
203 $(this).click( |
|
204 function () { |
|
205 var new_option_val = $('#new_item_field_ul_id'); |
|
206 var new_option_dialog = $("#new_item_dialog"); |
|
207 |
|
208 new_option_val.val($(this).parents('fieldset').children('ol') |
|
209 .attr('id')); |
|
210 |
|
211 new_option_dialog.dialog('open').find('input:first').focus(); |
|
212 } |
|
213 ) |
|
214 .hover( |
|
215 function () { |
|
216 $(this).addClass("ui-state-hover"); |
|
217 }, |
|
218 function () { |
|
219 $(this).removeClass("ui-state-hover"); |
|
220 } |
|
221 ) |
|
222 .mousedown( |
|
223 function () { |
|
224 $(this).addClass("ui-state-active"); |
|
225 } |
|
226 ) |
|
227 .mouseup( |
|
228 function () { |
|
229 $(this).removeClass("ui-state-active"); |
|
230 } |
|
231 ); |
|
232 } |
|
233 ); |
|
234 |
|
235 options.find('.AddQuestion').click( |
|
236 function (e) { |
|
237 // Choose a field type |
|
238 $("#new_question_button_id").val($(this).attr('id')); |
|
239 var question_options_div = $('#question_options_div'); |
|
240 if ($(this).attr('id') === 'choice') { |
|
241 question_options_div.show(); |
|
242 } |
|
243 else { |
|
244 question_options_div.hide(); |
|
245 } |
|
246 |
|
247 $("#new_question_dialog").dialog('open').find('input:first') |
|
248 .focus(); |
|
249 } |
|
250 ); |
|
251 }).trigger('init') |
|
252 .bind('option_init', |
|
253 function () { |
|
254 |
|
255 // Delete list/choice-field item from survey |
|
256 widget.find('a.delete_item').click( |
|
257 function () { |
|
258 var to_delete = this.id.replace('del_', ''); |
|
259 $('#delete_item_field').val(to_delete); |
|
260 $('#delete_item_dialog').dialog('open'); |
|
261 } |
|
262 ).end(); |
|
263 |
|
264 } |
|
265 ).trigger('option_init'); |
|
266 |
|
267 |
|
268 /* GSOC ROLE-SPECIFIC FIELD PLUGIN |
|
269 * Choice between student/mentor renders required GSOC specific fields |
|
270 */ |
|
271 |
|
272 var taking_access_field = $('select#id_taking_access'); |
|
273 |
|
274 var addRoleFields = function (role_type) { |
|
275 // these should ideally be generated with django forms |
|
276 // TODO: apply info tooltips |
|
277 var CHOOSE_A_PROJECT_FIELD = [ |
|
278 '<tr class="role-specific"><th><label>Choose Project:</label></th>', |
|
279 '<td> <select disabled=TRUE id="id_survey__NA__selection__project"', |
|
280 ' name="survey__1__selection__see"><option>Survey Taker\'s Projects', |
|
281 'For This Program</option></select> </td></tr>' |
|
282 ].join(""); |
|
283 |
|
284 var CHOOSE_A_GRADE_FIELD = [ |
|
285 '<tr class="role-specific"><th><label>Assign Grade:</label></th><td>', |
|
286 '<select disabled=TRUE id="id_survey__NA__selection__grade"', |
|
287 'name="survey__1__selection__see"><option>Pass/Fail</option></select>', |
|
288 '</td></tr>' |
|
289 ].join(""); |
|
290 |
|
291 // flush existing role-specific fields |
|
292 var role_specific_fields = survey.find('tr.role-specific'); |
|
293 role_specific_fields.remove(); |
|
294 |
|
295 switch (role_type) { |
|
296 case "mentor evaluation": |
|
297 survey.prepend(CHOOSE_A_PROJECT_FIELD); |
|
298 survey.append(CHOOSE_A_GRADE_FIELD); |
|
299 break; |
|
300 |
|
301 case "student evaluation": |
|
302 survey.prepend(CHOOSE_A_PROJECT_FIELD); |
|
303 break; |
|
304 } |
|
305 }; |
|
306 |
|
307 taking_access_field.change( |
|
308 function () { |
|
309 var role_type = $(this).val(); |
|
310 addRoleFields(role_type); |
|
311 } |
|
312 ); |
|
313 |
|
314 addRoleFields(taking_access_field.val()); |
|
315 |
|
316 /* |
|
317 * == Survey Submission Handler == |
|
318 */ |
|
319 // Bind submit |
|
320 $('form').bind('submit', |
|
321 function () { |
|
322 |
|
323 /* |
|
324 * get rid of role-specific fields |
|
325 */ |
|
326 survey.find('tr.role-specific').remove(); |
|
327 |
|
328 /* |
|
329 * Save survey content html from editPost |
|
330 * if POST fails |
|
331 */ |
|
332 |
|
333 // save field vals |
|
334 widget.find('.long_answer,input').each( |
|
335 function () { |
|
336 $(this).attr('val', $(this).val()); |
|
337 } |
|
338 ); |
|
339 |
|
340 $(this).find("#id_survey_html").attr('value', widget.html()); |
|
341 |
|
342 // don't save default value |
|
343 widget.find('input').each( |
|
344 function () { |
|
345 if ($(this).val() === DEFAULT_SHORT_ANSWER_TEXT) { |
|
346 $(this).val(''); |
|
347 } |
|
348 } |
|
349 ); |
|
350 |
|
351 // don't save default value |
|
352 widget.find('.long_answer').each( |
|
353 function () { |
|
354 if ($(this).val() === DEFAULT_LONG_ANSWER_TEXT) { |
|
355 $(this).val(''); |
|
356 } |
|
357 } |
|
358 ); |
|
359 |
|
360 // get rid of the options |
|
361 $('input#id_s_html') |
|
362 .val( |
|
363 widget |
|
364 .find( |
|
365 'div#survey_options' |
|
366 ) |
|
367 .remove() |
|
368 .end() |
|
369 .html() |
|
370 ); |
|
371 // only needed for HTML |
|
372 |
|
373 // Get option order per field |
|
374 survey.find('.sortable').each( |
|
375 function () { |
|
376 $('#order_for_' + this.id) |
|
377 .val( |
|
378 $(this).sortable( |
|
379 'serialize' |
|
380 ) |
|
381 ); |
|
382 } |
|
383 ); |
|
384 } |
|
385 ); |
|
386 }); |
|
387 }(jQuery)); |
|
388 |
|
389 |
|
390 (function ($) { |
|
391 /* |
|
392 * == Utils == |
|
393 * |
|
394 */ |
|
395 jQuery.fn.extend({ |
|
396 |
|
397 // get position of survey field |
|
398 getPosition: function () { |
|
399 var this_row = $(this).parents('tr:first'); |
|
400 var this_table = this_row.parents('table:first'); |
|
401 var position = this_table.find('tr').index(this_row) + '__'; |
|
402 return position; |
|
403 } |
|
404 }); |
|
405 }(jQuery)); |
|
406 |
|
407 |
|
408 (function ($) { |
|
409 /* |
|
410 * == Sortable options == |
|
411 */ |
|
412 $(function () { |
|
413 $(".sortable").each( |
|
414 function (i, domEle) { |
|
415 $(domEle).sortable().disableSelection().end(); |
|
416 } |
|
417 ); |
|
418 }); |
|
419 }(jQuery)); |
|
420 |
|
421 |
|
422 (function ($) { |
|
423 /* |
|
424 * == Editable options == |
|
425 */ |
|
426 $(function () { |
|
427 function onSubmitEditable(content) { |
|
428 var id_ = $(this).parent().attr('id').replace('-li-', '_'); |
|
429 id_ = id_ + '__field'; |
|
430 $('#' + id_).val(content.current); |
|
431 } |
|
432 $('.editable_option').editable({ |
|
433 editBy: 'dblclick', |
|
434 submit: 'change', |
|
435 cancel: 'cancel', |
|
436 onSubmit: onSubmitEditable |
|
437 }); |
|
438 }); |
|
439 }(jQuery)); |
|
440 |
|
441 |
|
442 (function ($) { |
|
443 $(function () { |
|
444 var del_li = ["<a class='delete_item' id='del_", |
|
445 "' ><img src='/soc/content/images/minus.gif'/></a> "]; |
|
446 |
|
447 // Confirmation dialog for deleting list/choice-field item from survey |
|
448 $("#delete_item_dialog").dialog({ |
|
449 autoOpen: false, |
|
450 bgiframe: true, |
|
451 resizable: false, |
|
452 height: 300, |
|
453 modal: true, |
|
454 overlay: { |
|
455 backgroundColor: '#000', |
|
456 opacity: 0.5 |
|
457 }, |
|
458 buttons: { |
|
459 'Delete this item': function () { |
|
460 $('#' + $('#delete_item_field').val()).remove(); |
|
461 $('#delete_item_field').val(''); |
|
462 $(this).dialog('close'); |
|
463 }, |
|
464 Cancel: function () { |
|
465 $('#delete_item_field').val(''); |
|
466 $(this).dialog('close'); |
|
467 } |
|
468 } |
|
469 }); |
|
470 |
|
471 |
|
472 // Dialog for adding list/choice-field item to survey |
|
473 $("#new_item_dialog").dialog({ |
|
474 bgiframe: true, |
|
475 autoOpen: false, |
|
476 height: 300, |
|
477 modal: true, |
|
478 buttons: { |
|
479 'Add option': function () { |
|
480 var ol_id = $('#new_item_field_ul_id').val(); |
|
481 var ol = $('#' + ol_id); |
|
482 var name = $('#new_item_name').val(); |
|
483 var i = ol.find('li').length; |
|
484 var id_ = 'id_' + ol_id + '_' + i; |
|
485 var option_html = $([ |
|
486 '<li id="id-li-', ol_id, '_', i, |
|
487 '" class="ui-state-defaolt sortable_li">', |
|
488 '<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>', |
|
489 '<span id="', id_, '" class="editable_option" name="', id_, |
|
490 '__field">', name, '</span>', '<input type="hidden" id="', id_, |
|
491 '__field" name="', id_, '__field" value="', name, '" >', '</li>' |
|
492 ].join("")); |
|
493 |
|
494 ol.append( |
|
495 option_html |
|
496 .prepend( |
|
497 del_li.join( |
|
498 option_html.attr('id') |
|
499 ) |
|
500 ) |
|
501 ); |
|
502 ol.sortable().disableSelection(); |
|
503 $('#new_item_name').val(''); |
|
504 $('#new_item_field_ol_id').val(''); |
|
505 $(this).dialog('close'); |
|
506 }, |
|
507 Cancel: function () { |
|
508 $('#new_item_name').val(''); |
|
509 $('#new_item_field_ul_id').val(''); |
|
510 $(this).dialog('close'); |
|
511 } |
|
512 } |
|
513 }); |
|
514 }); |
|
515 }(jQuery)); |
|
516 |
|
517 |
|
518 (function ($) { |
|
519 $(function () { |
|
520 // Dialog for adding new question to survey |
|
521 var SURVEY_PREFIX = 'survey__'; |
|
522 var del_el = ["<a class='delete'><img '", |
|
523 "src='/soc/content/images/minus.gif'/></a>"].join(""); |
|
524 var del_li = ["<a class='delete_item' id='del_", |
|
525 "' ><img src='/soc/content/images/minus.gif'/></a> "]; |
|
526 |
|
527 |
|
528 var widget = $('div#survey_widget'); |
|
529 var survey = widget.find('tbody:first'); |
|
530 |
|
531 $("#new_question_dialog").dialog({ |
|
532 bgiframe: true, |
|
533 autoOpen: false, |
|
534 height: 400, |
|
535 modal: true, |
|
536 buttons: { |
|
537 'Add question': function () { |
|
538 var button_id = $("#new_question_button_id").val(); |
|
539 var survey_table = $('div#survey_widget').find('tbody:first'); |
|
540 $("#new_question_button_id").val(''); |
|
541 |
|
542 var field_template = $(["<tr><th><label>", del_el, |
|
543 "</label></th><td> </td></tr>"].join("")); |
|
544 |
|
545 var field_name = $("#new_question_name").val(); |
|
546 var question_content = $("#new_question_content").val(); |
|
547 var question_options = $("#new_question_options").val(); |
|
548 |
|
549 if (field_name !== '') { |
|
550 $("#new_question_name").val(''); |
|
551 $("#new_question_content").val(''); |
|
552 $("#new_question_options").val(''); |
|
553 |
|
554 var new_field = false; |
|
555 var type = button_id + "__"; |
|
556 var field_count = survey_table.find('tr').length; |
|
557 var new_field_count = field_count + 1 + '__'; |
|
558 |
|
559 var MIN_ROWS = 10; |
|
560 var MAX_ROWS = MIN_ROWS * 2; |
|
561 var DEFAULT_OPTION_TEXT = 'Add A New Option...'; |
|
562 var default_option = ["<option>", DEFAULT_OPTION_TEXT, |
|
563 "</option>"].join(""); |
|
564 |
|
565 // create the HTML for the field |
|
566 switch (button_id) { |
|
567 case "short_answer": |
|
568 new_field = "<input type='text'/ class='short_answer'>"; |
|
569 break; |
|
570 case "long_answer": |
|
571 new_field = ["<textarea cols='40' rows='", MIN_ROWS, |
|
572 "' class='long_answer'/>"].join(""); |
|
573 break; |
|
574 case "selection": |
|
575 new_field = ["<select><option></option>", default_option, |
|
576 "</select>"].join(""); |
|
577 break; |
|
578 case "pick_multi": |
|
579 new_field = ["<fieldset class='fieldset'><input type='button'", |
|
580 "value='", DEFAULT_OPTION_TEXT, "' /></fieldset>"] |
|
581 .join(""); |
|
582 break; |
|
583 case "choice": |
|
584 new_field = ["<fieldset class='fieldset'><input type='button'", |
|
585 "value='", DEFAULT_OPTION_TEXT, "' /></fieldset>"] |
|
586 .join(""); |
|
587 break; |
|
588 } |
|
589 |
|
590 if (new_field) { |
|
591 var question_for = [ |
|
592 '\n <input type="hidden" name="NEW_', field_name, |
|
593 '" id="NEW_', field_name, '" value="', question_content, |
|
594 '"/>' |
|
595 ].join(""); |
|
596 |
|
597 field_count = survey_table.find('tr').length; |
|
598 new_field_count = field_count + 1 + '__'; |
|
599 var formatted_name = (SURVEY_PREFIX + new_field_count + type + |
|
600 field_name); |
|
601 if (button_id === 'choice') { |
|
602 var name = (field_name); |
|
603 new_field = $([ |
|
604 '<fieldset>\n <label for="render_for_', name, |
|
605 '">Render as</label>', '\n <select id="render_for_', name, |
|
606 '" name="render_for_', name, '">', '\n <option', |
|
607 'selected="selected" value="select">select</option>', |
|
608 '\n <option value="checkboxes">checkboxes</option>', |
|
609 '\n <option value="radio_buttons">radio_buttons</option>', |
|
610 '\n </select>', '\n <input type="hidden" id="order_for_', |
|
611 name, '\n " name="order_for_', name, '" value=""/>', |
|
612 '\n <input type="hidden" id="index_for_', name, |
|
613 '\n " name="index_for_', name, '" value="', |
|
614 (field_count + 1), '"/>\n <ol id="', name, |
|
615 '" class="sortable"></ol>', |
|
616 question_for, '\n <button name="create-option-button"', |
|
617 'id="create-option-button__', name, |
|
618 '" class="ui-button ui-state-default ui-corner-all" value="', |
|
619 name, '" onClick="return false;">Create new option', |
|
620 '</button>\n</fieldset>' |
|
621 ].join("")); |
|
622 |
|
623 $(new_field).attr({ |
|
624 'id': 'id_' + formatted_name, |
|
625 'name': formatted_name |
|
626 }); |
|
627 field_template |
|
628 .find( |
|
629 'label' |
|
630 ) |
|
631 .attr( |
|
632 'for', |
|
633 'NEW_' + name |
|
634 ) |
|
635 .append(question_content).end() |
|
636 .find( |
|
637 'td' |
|
638 ) |
|
639 .append(new_field); |
|
640 survey_table.append(field_template).end(); |
|
641 |
|
642 if (question_options) { |
|
643 |
|
644 var options_array = question_options.split('\n'); |
|
645 var ol = $('#' + name); |
|
646 var length = options_array.length; |
|
647 var oname = ''; |
|
648 var id_ = ''; |
|
649 var option_html = ''; |
|
650 |
|
651 for (var i = 0; i < length; i = i + 1) { |
|
652 id_ = 'id_' + name + '_' + i; |
|
653 oname = options_array[i]; |
|
654 option_html = $([ |
|
655 '<li id="id-li-', name, '_', i, |
|
656 '" class="ui-state-defaolt sortable_li">', |
|
657 '<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>', |
|
658 '<span id="' + id_ + '" class="editable_option" name="', |
|
659 id_, '__field">', oname, '</span>', '<input ', |
|
660 'type="hidden" id="', id_, '__field" name="', id_, |
|
661 '__field" value="', oname, '" >', '</li>' |
|
662 ].join("")); |
|
663 ol.append(option_html.prepend( |
|
664 del_li.join(option_html.attr('id')))); |
|
665 ol.sortable().disableSelection(); |
|
666 } |
|
667 |
|
668 survey.trigger('option_init'); |
|
669 } |
|
670 } |
|
671 |
|
672 else { |
|
673 new_field = $(new_field); |
|
674 // maybe the name should be serialized in a more common format |
|
675 $(new_field).attr({ |
|
676 'id': 'id_' + formatted_name, |
|
677 'name': formatted_name |
|
678 }); |
|
679 field_template.find( |
|
680 'label' |
|
681 ) |
|
682 .attr( |
|
683 'for', |
|
684 'id_' + formatted_name |
|
685 ) |
|
686 .append(question_content + ":").end() |
|
687 .find( |
|
688 'td' |
|
689 ) |
|
690 .append(new_field).append($(question_for)); |
|
691 |
|
692 survey_table.append(field_template); |
|
693 } |
|
694 |
|
695 survey.trigger('init'); |
|
696 |
|
697 } |
|
698 } |
|
699 $("#new_question_name").val(''); |
|
700 $("#new_question_content").val(''); |
|
701 $("#new_question_options").val(''); |
|
702 $(this).dialog('close'); |
|
703 }, |
|
704 |
|
705 Cancel: function () { |
|
706 $('#new_question_name').val(''); |
|
707 $("#new_question_button_id").val(''); |
|
708 $("#new_question_content").val(''); |
|
709 $("#new_question_options").val(''); |
|
710 $(this).dialog('close'); |
|
711 } |
|
712 } |
|
713 }); |
|
714 }); |
|
715 }(jQuery)); |