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