@@ -1,656 +1,657 | |||||
1 | /* Redmine - project management software |
|
1 | /* Redmine - project management software | |
2 | Copyright (C) 2006-2015 Jean-Philippe Lang */ |
|
2 | Copyright (C) 2006-2015 Jean-Philippe Lang */ | |
3 |
|
3 | |||
4 | function checkAll(id, checked) { |
|
4 | function checkAll(id, checked) { | |
5 | $('#'+id).find('input[type=checkbox]:enabled').prop('checked', checked); |
|
5 | $('#'+id).find('input[type=checkbox]:enabled').prop('checked', checked); | |
6 | } |
|
6 | } | |
7 |
|
7 | |||
8 | function toggleCheckboxesBySelector(selector) { |
|
8 | function toggleCheckboxesBySelector(selector) { | |
9 | var all_checked = true; |
|
9 | var all_checked = true; | |
10 | $(selector).each(function(index) { |
|
10 | $(selector).each(function(index) { | |
11 | if (!$(this).is(':checked')) { all_checked = false; } |
|
11 | if (!$(this).is(':checked')) { all_checked = false; } | |
12 | }); |
|
12 | }); | |
13 | $(selector).prop('checked', !all_checked); |
|
13 | $(selector).prop('checked', !all_checked); | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | function showAndScrollTo(id, focus) { |
|
16 | function showAndScrollTo(id, focus) { | |
17 | $('#'+id).show(); |
|
17 | $('#'+id).show(); | |
18 | if (focus !== null) { |
|
18 | if (focus !== null) { | |
19 | $('#'+focus).focus(); |
|
19 | $('#'+focus).focus(); | |
20 | } |
|
20 | } | |
21 | $('html, body').animate({scrollTop: $('#'+id).offset().top}, 100); |
|
21 | $('html, body').animate({scrollTop: $('#'+id).offset().top}, 100); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | function toggleRowGroup(el) { |
|
24 | function toggleRowGroup(el) { | |
25 | var tr = $(el).parents('tr').first(); |
|
25 | var tr = $(el).parents('tr').first(); | |
26 | var n = tr.next(); |
|
26 | var n = tr.next(); | |
27 | tr.toggleClass('open'); |
|
27 | tr.toggleClass('open'); | |
28 | while (n.length && !n.hasClass('group')) { |
|
28 | while (n.length && !n.hasClass('group')) { | |
29 | n.toggle(); |
|
29 | n.toggle(); | |
30 | n = n.next('tr'); |
|
30 | n = n.next('tr'); | |
31 | } |
|
31 | } | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | function collapseAllRowGroups(el) { |
|
34 | function collapseAllRowGroups(el) { | |
35 | var tbody = $(el).parents('tbody').first(); |
|
35 | var tbody = $(el).parents('tbody').first(); | |
36 | tbody.children('tr').each(function(index) { |
|
36 | tbody.children('tr').each(function(index) { | |
37 | if ($(this).hasClass('group')) { |
|
37 | if ($(this).hasClass('group')) { | |
38 | $(this).removeClass('open'); |
|
38 | $(this).removeClass('open'); | |
39 | } else { |
|
39 | } else { | |
40 | $(this).hide(); |
|
40 | $(this).hide(); | |
41 | } |
|
41 | } | |
42 | }); |
|
42 | }); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | function expandAllRowGroups(el) { |
|
45 | function expandAllRowGroups(el) { | |
46 | var tbody = $(el).parents('tbody').first(); |
|
46 | var tbody = $(el).parents('tbody').first(); | |
47 | tbody.children('tr').each(function(index) { |
|
47 | tbody.children('tr').each(function(index) { | |
48 | if ($(this).hasClass('group')) { |
|
48 | if ($(this).hasClass('group')) { | |
49 | $(this).addClass('open'); |
|
49 | $(this).addClass('open'); | |
50 | } else { |
|
50 | } else { | |
51 | $(this).show(); |
|
51 | $(this).show(); | |
52 | } |
|
52 | } | |
53 | }); |
|
53 | }); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | function toggleAllRowGroups(el) { |
|
56 | function toggleAllRowGroups(el) { | |
57 | var tr = $(el).parents('tr').first(); |
|
57 | var tr = $(el).parents('tr').first(); | |
58 | if (tr.hasClass('open')) { |
|
58 | if (tr.hasClass('open')) { | |
59 | collapseAllRowGroups(el); |
|
59 | collapseAllRowGroups(el); | |
60 | } else { |
|
60 | } else { | |
61 | expandAllRowGroups(el); |
|
61 | expandAllRowGroups(el); | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | function toggleFieldset(el) { |
|
65 | function toggleFieldset(el) { | |
66 | var fieldset = $(el).parents('fieldset').first(); |
|
66 | var fieldset = $(el).parents('fieldset').first(); | |
67 | fieldset.toggleClass('collapsed'); |
|
67 | fieldset.toggleClass('collapsed'); | |
68 | fieldset.children('div').toggle(); |
|
68 | fieldset.children('div').toggle(); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | function hideFieldset(el) { |
|
71 | function hideFieldset(el) { | |
72 | var fieldset = $(el).parents('fieldset').first(); |
|
72 | var fieldset = $(el).parents('fieldset').first(); | |
73 | fieldset.toggleClass('collapsed'); |
|
73 | fieldset.toggleClass('collapsed'); | |
74 | fieldset.children('div').hide(); |
|
74 | fieldset.children('div').hide(); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | // columns selection |
|
77 | // columns selection | |
78 | function moveOptions(theSelFrom, theSelTo) { |
|
78 | function moveOptions(theSelFrom, theSelTo) { | |
79 | $(theSelFrom).find('option:selected').detach().prop("selected", false).appendTo($(theSelTo)); |
|
79 | $(theSelFrom).find('option:selected').detach().prop("selected", false).appendTo($(theSelTo)); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | function moveOptionUp(theSel) { |
|
82 | function moveOptionUp(theSel) { | |
83 | $(theSel).find('option:selected').each(function(){ |
|
83 | $(theSel).find('option:selected').each(function(){ | |
84 | $(this).prev(':not(:selected)').detach().insertAfter($(this)); |
|
84 | $(this).prev(':not(:selected)').detach().insertAfter($(this)); | |
85 | }); |
|
85 | }); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | function moveOptionTop(theSel) { |
|
88 | function moveOptionTop(theSel) { | |
89 | $(theSel).find('option:selected').detach().prependTo($(theSel)); |
|
89 | $(theSel).find('option:selected').detach().prependTo($(theSel)); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | function moveOptionDown(theSel) { |
|
92 | function moveOptionDown(theSel) { | |
93 | $($(theSel).find('option:selected').get().reverse()).each(function(){ |
|
93 | $($(theSel).find('option:selected').get().reverse()).each(function(){ | |
94 | $(this).next(':not(:selected)').detach().insertBefore($(this)); |
|
94 | $(this).next(':not(:selected)').detach().insertBefore($(this)); | |
95 | }); |
|
95 | }); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | function moveOptionBottom(theSel) { |
|
98 | function moveOptionBottom(theSel) { | |
99 | $(theSel).find('option:selected').detach().appendTo($(theSel)); |
|
99 | $(theSel).find('option:selected').detach().appendTo($(theSel)); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | function initFilters() { |
|
102 | function initFilters() { | |
103 | $('#add_filter_select').change(function() { |
|
103 | $('#add_filter_select').change(function() { | |
104 | addFilter($(this).val(), '', []); |
|
104 | addFilter($(this).val(), '', []); | |
105 | }); |
|
105 | }); | |
106 | $('#filters-table td.field input[type=checkbox]').each(function() { |
|
106 | $('#filters-table td.field input[type=checkbox]').each(function() { | |
107 | toggleFilter($(this).val()); |
|
107 | toggleFilter($(this).val()); | |
108 | }); |
|
108 | }); | |
109 | $('#filters-table').on('click', 'td.field input[type=checkbox]', function() { |
|
109 | $('#filters-table').on('click', 'td.field input[type=checkbox]', function() { | |
110 | toggleFilter($(this).val()); |
|
110 | toggleFilter($(this).val()); | |
111 | }); |
|
111 | }); | |
112 | $('#filters-table').on('click', '.toggle-multiselect', function() { |
|
112 | $('#filters-table').on('click', '.toggle-multiselect', function() { | |
113 | toggleMultiSelect($(this).siblings('select')); |
|
113 | toggleMultiSelect($(this).siblings('select')); | |
114 | }); |
|
114 | }); | |
115 | $('#filters-table').on('keypress', 'input[type=text]', function(e) { |
|
115 | $('#filters-table').on('keypress', 'input[type=text]', function(e) { | |
116 | if (e.keyCode == 13) $(this).closest('form').submit(); |
|
116 | if (e.keyCode == 13) $(this).closest('form').submit(); | |
117 | }); |
|
117 | }); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | function addFilter(field, operator, values) { |
|
120 | function addFilter(field, operator, values) { | |
121 | var fieldId = field.replace('.', '_'); |
|
121 | var fieldId = field.replace('.', '_'); | |
122 | var tr = $('#tr_'+fieldId); |
|
122 | var tr = $('#tr_'+fieldId); | |
123 | if (tr.length > 0) { |
|
123 | if (tr.length > 0) { | |
124 | tr.show(); |
|
124 | tr.show(); | |
125 | } else { |
|
125 | } else { | |
126 | buildFilterRow(field, operator, values); |
|
126 | buildFilterRow(field, operator, values); | |
127 | } |
|
127 | } | |
128 | $('#cb_'+fieldId).prop('checked', true); |
|
128 | $('#cb_'+fieldId).prop('checked', true); | |
129 | toggleFilter(field); |
|
129 | toggleFilter(field); | |
130 | $('#add_filter_select').val('').find('option').each(function() { |
|
130 | $('#add_filter_select').val('').find('option').each(function() { | |
131 | if ($(this).attr('value') == field) { |
|
131 | if ($(this).attr('value') == field) { | |
132 | $(this).attr('disabled', true); |
|
132 | $(this).attr('disabled', true); | |
133 | } |
|
133 | } | |
134 | }); |
|
134 | }); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | function buildFilterRow(field, operator, values) { |
|
137 | function buildFilterRow(field, operator, values) { | |
138 | var fieldId = field.replace('.', '_'); |
|
138 | var fieldId = field.replace('.', '_'); | |
139 | var filterTable = $("#filters-table"); |
|
139 | var filterTable = $("#filters-table"); | |
140 | var filterOptions = availableFilters[field]; |
|
140 | var filterOptions = availableFilters[field]; | |
141 | if (!filterOptions) return; |
|
141 | if (!filterOptions) return; | |
142 | var operators = operatorByType[filterOptions['type']]; |
|
142 | var operators = operatorByType[filterOptions['type']]; | |
143 | var filterValues = filterOptions['values']; |
|
143 | var filterValues = filterOptions['values']; | |
144 | var i, select; |
|
144 | var i, select; | |
145 |
|
145 | |||
146 | var tr = $('<tr class="filter">').attr('id', 'tr_'+fieldId).html( |
|
146 | var tr = $('<tr class="filter">').attr('id', 'tr_'+fieldId).html( | |
147 | '<td class="field"><input checked="checked" id="cb_'+fieldId+'" name="f[]" value="'+field+'" type="checkbox"><label for="cb_'+fieldId+'"> '+filterOptions['name']+'</label></td>' + |
|
147 | '<td class="field"><input checked="checked" id="cb_'+fieldId+'" name="f[]" value="'+field+'" type="checkbox"><label for="cb_'+fieldId+'"> '+filterOptions['name']+'</label></td>' + | |
148 | '<td class="operator"><select id="operators_'+fieldId+'" name="op['+field+']"></td>' + |
|
148 | '<td class="operator"><select id="operators_'+fieldId+'" name="op['+field+']"></td>' + | |
149 | '<td class="values"></td>' |
|
149 | '<td class="values"></td>' | |
150 | ); |
|
150 | ); | |
151 | filterTable.append(tr); |
|
151 | filterTable.append(tr); | |
152 |
|
152 | |||
153 | select = tr.find('td.operator select'); |
|
153 | select = tr.find('td.operator select'); | |
154 | for (i = 0; i < operators.length; i++) { |
|
154 | for (i = 0; i < operators.length; i++) { | |
155 | var option = $('<option>').val(operators[i]).text(operatorLabels[operators[i]]); |
|
155 | var option = $('<option>').val(operators[i]).text(operatorLabels[operators[i]]); | |
156 | if (operators[i] == operator) { option.attr('selected', true); } |
|
156 | if (operators[i] == operator) { option.attr('selected', true); } | |
157 | select.append(option); |
|
157 | select.append(option); | |
158 | } |
|
158 | } | |
159 | select.change(function(){ toggleOperator(field); }); |
|
159 | select.change(function(){ toggleOperator(field); }); | |
160 |
|
160 | |||
161 | switch (filterOptions['type']) { |
|
161 | switch (filterOptions['type']) { | |
162 | case "list": |
|
162 | case "list": | |
163 | case "list_optional": |
|
163 | case "list_optional": | |
164 | case "list_status": |
|
164 | case "list_status": | |
165 | case "list_subprojects": |
|
165 | case "list_subprojects": | |
166 | tr.find('td.values').append( |
|
166 | tr.find('td.values').append( | |
167 | '<span style="display:none;"><select class="value" id="values_'+fieldId+'_1" name="v['+field+'][]"></select>' + |
|
167 | '<span style="display:none;"><select class="value" id="values_'+fieldId+'_1" name="v['+field+'][]"></select>' + | |
168 | ' <span class="toggle-multiselect"> </span></span>' |
|
168 | ' <span class="toggle-multiselect"> </span></span>' | |
169 | ); |
|
169 | ); | |
170 | select = tr.find('td.values select'); |
|
170 | select = tr.find('td.values select'); | |
171 | if (values.length > 1) { select.attr('multiple', true); } |
|
171 | if (values.length > 1) { select.attr('multiple', true); } | |
172 | for (i = 0; i < filterValues.length; i++) { |
|
172 | for (i = 0; i < filterValues.length; i++) { | |
173 | var filterValue = filterValues[i]; |
|
173 | var filterValue = filterValues[i]; | |
174 | var option = $('<option>'); |
|
174 | var option = $('<option>'); | |
175 | if ($.isArray(filterValue)) { |
|
175 | if ($.isArray(filterValue)) { | |
176 | option.val(filterValue[1]).text(filterValue[0]); |
|
176 | option.val(filterValue[1]).text(filterValue[0]); | |
177 | if ($.inArray(filterValue[1], values) > -1) {option.attr('selected', true);} |
|
177 | if ($.inArray(filterValue[1], values) > -1) {option.attr('selected', true);} | |
178 | } else { |
|
178 | } else { | |
179 | option.val(filterValue).text(filterValue); |
|
179 | option.val(filterValue).text(filterValue); | |
180 | if ($.inArray(filterValue, values) > -1) {option.attr('selected', true);} |
|
180 | if ($.inArray(filterValue, values) > -1) {option.attr('selected', true);} | |
181 | } |
|
181 | } | |
182 | select.append(option); |
|
182 | select.append(option); | |
183 | } |
|
183 | } | |
184 | break; |
|
184 | break; | |
185 | case "date": |
|
185 | case "date": | |
186 | case "date_past": |
|
186 | case "date_past": | |
187 | tr.find('td.values').append( |
|
187 | tr.find('td.values').append( | |
188 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="10" class="value date_value" /></span>' + |
|
188 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="10" class="value date_value" /></span>' + | |
189 | ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="10" class="value date_value" /></span>' + |
|
189 | ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="10" class="value date_value" /></span>' + | |
190 | ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="3" class="value" /> '+labelDayPlural+'</span>' |
|
190 | ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="3" class="value" /> '+labelDayPlural+'</span>' | |
191 | ); |
|
191 | ); | |
192 | $('#values_'+fieldId+'_1').val(values[0]).datepicker(datepickerOptions); |
|
192 | $('#values_'+fieldId+'_1').val(values[0]).datepicker(datepickerOptions); | |
193 | $('#values_'+fieldId+'_2').val(values[1]).datepicker(datepickerOptions); |
|
193 | $('#values_'+fieldId+'_2').val(values[1]).datepicker(datepickerOptions); | |
194 | $('#values_'+fieldId).val(values[0]); |
|
194 | $('#values_'+fieldId).val(values[0]); | |
195 | break; |
|
195 | break; | |
196 | case "string": |
|
196 | case "string": | |
197 | case "text": |
|
197 | case "text": | |
198 | tr.find('td.values').append( |
|
198 | tr.find('td.values').append( | |
199 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="30" class="value" /></span>' |
|
199 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="30" class="value" /></span>' | |
200 | ); |
|
200 | ); | |
201 | $('#values_'+fieldId).val(values[0]); |
|
201 | $('#values_'+fieldId).val(values[0]); | |
202 | break; |
|
202 | break; | |
203 | case "relation": |
|
203 | case "relation": | |
204 | tr.find('td.values').append( |
|
204 | tr.find('td.values').append( | |
205 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="6" class="value" /></span>' + |
|
205 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="6" class="value" /></span>' + | |
206 | '<span style="display:none;"><select class="value" name="v['+field+'][]" id="values_'+fieldId+'_1"></select></span>' |
|
206 | '<span style="display:none;"><select class="value" name="v['+field+'][]" id="values_'+fieldId+'_1"></select></span>' | |
207 | ); |
|
207 | ); | |
208 | $('#values_'+fieldId).val(values[0]); |
|
208 | $('#values_'+fieldId).val(values[0]); | |
209 | select = tr.find('td.values select'); |
|
209 | select = tr.find('td.values select'); | |
210 | for (i = 0; i < allProjects.length; i++) { |
|
210 | for (i = 0; i < allProjects.length; i++) { | |
211 | var filterValue = allProjects[i]; |
|
211 | var filterValue = allProjects[i]; | |
212 | var option = $('<option>'); |
|
212 | var option = $('<option>'); | |
213 | option.val(filterValue[1]).text(filterValue[0]); |
|
213 | option.val(filterValue[1]).text(filterValue[0]); | |
214 | if (values[0] == filterValue[1]) { option.attr('selected', true); } |
|
214 | if (values[0] == filterValue[1]) { option.attr('selected', true); } | |
215 | select.append(option); |
|
215 | select.append(option); | |
216 | } |
|
216 | } | |
217 | break; |
|
217 | break; | |
218 | case "integer": |
|
218 | case "integer": | |
219 | case "float": |
|
219 | case "float": | |
220 | case "tree": |
|
220 | case "tree": | |
221 | tr.find('td.values').append( |
|
221 | tr.find('td.values').append( | |
222 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' + |
|
222 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' + | |
223 | ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>' |
|
223 | ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>' | |
224 | ); |
|
224 | ); | |
225 | $('#values_'+fieldId+'_1').val(values[0]); |
|
225 | $('#values_'+fieldId+'_1').val(values[0]); | |
226 | $('#values_'+fieldId+'_2').val(values[1]); |
|
226 | $('#values_'+fieldId+'_2').val(values[1]); | |
227 | break; |
|
227 | break; | |
228 | } |
|
228 | } | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | function toggleFilter(field) { |
|
231 | function toggleFilter(field) { | |
232 | var fieldId = field.replace('.', '_'); |
|
232 | var fieldId = field.replace('.', '_'); | |
233 | if ($('#cb_' + fieldId).is(':checked')) { |
|
233 | if ($('#cb_' + fieldId).is(':checked')) { | |
234 | $("#operators_" + fieldId).show().removeAttr('disabled'); |
|
234 | $("#operators_" + fieldId).show().removeAttr('disabled'); | |
235 | toggleOperator(field); |
|
235 | toggleOperator(field); | |
236 | } else { |
|
236 | } else { | |
237 | $("#operators_" + fieldId).hide().attr('disabled', true); |
|
237 | $("#operators_" + fieldId).hide().attr('disabled', true); | |
238 | enableValues(field, []); |
|
238 | enableValues(field, []); | |
239 | } |
|
239 | } | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | function enableValues(field, indexes) { |
|
242 | function enableValues(field, indexes) { | |
243 | var fieldId = field.replace('.', '_'); |
|
243 | var fieldId = field.replace('.', '_'); | |
244 | $('#tr_'+fieldId+' td.values .value').each(function(index) { |
|
244 | $('#tr_'+fieldId+' td.values .value').each(function(index) { | |
245 | if ($.inArray(index, indexes) >= 0) { |
|
245 | if ($.inArray(index, indexes) >= 0) { | |
246 | $(this).removeAttr('disabled'); |
|
246 | $(this).removeAttr('disabled'); | |
247 | $(this).parents('span').first().show(); |
|
247 | $(this).parents('span').first().show(); | |
248 | } else { |
|
248 | } else { | |
249 | $(this).val(''); |
|
249 | $(this).val(''); | |
250 | $(this).attr('disabled', true); |
|
250 | $(this).attr('disabled', true); | |
251 | $(this).parents('span').first().hide(); |
|
251 | $(this).parents('span').first().hide(); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | if ($(this).hasClass('group')) { |
|
254 | if ($(this).hasClass('group')) { | |
255 | $(this).addClass('open'); |
|
255 | $(this).addClass('open'); | |
256 | } else { |
|
256 | } else { | |
257 | $(this).show(); |
|
257 | $(this).show(); | |
258 | } |
|
258 | } | |
259 | }); |
|
259 | }); | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | function toggleOperator(field) { |
|
262 | function toggleOperator(field) { | |
263 | var fieldId = field.replace('.', '_'); |
|
263 | var fieldId = field.replace('.', '_'); | |
264 | var operator = $("#operators_" + fieldId); |
|
264 | var operator = $("#operators_" + fieldId); | |
265 | switch (operator.val()) { |
|
265 | switch (operator.val()) { | |
266 | case "!*": |
|
266 | case "!*": | |
267 | case "*": |
|
267 | case "*": | |
268 | case "t": |
|
268 | case "t": | |
269 | case "ld": |
|
269 | case "ld": | |
270 | case "w": |
|
270 | case "w": | |
271 | case "lw": |
|
271 | case "lw": | |
272 | case "l2w": |
|
272 | case "l2w": | |
273 | case "m": |
|
273 | case "m": | |
274 | case "lm": |
|
274 | case "lm": | |
275 | case "y": |
|
275 | case "y": | |
276 | case "o": |
|
276 | case "o": | |
277 | case "c": |
|
277 | case "c": | |
278 | enableValues(field, []); |
|
278 | enableValues(field, []); | |
279 | break; |
|
279 | break; | |
280 | case "><": |
|
280 | case "><": | |
281 | enableValues(field, [0,1]); |
|
281 | enableValues(field, [0,1]); | |
282 | break; |
|
282 | break; | |
283 | case "<t+": |
|
283 | case "<t+": | |
284 | case ">t+": |
|
284 | case ">t+": | |
285 | case "><t+": |
|
285 | case "><t+": | |
286 | case "t+": |
|
286 | case "t+": | |
287 | case ">t-": |
|
287 | case ">t-": | |
288 | case "<t-": |
|
288 | case "<t-": | |
289 | case "><t-": |
|
289 | case "><t-": | |
290 | case "t-": |
|
290 | case "t-": | |
291 | enableValues(field, [2]); |
|
291 | enableValues(field, [2]); | |
292 | break; |
|
292 | break; | |
293 | case "=p": |
|
293 | case "=p": | |
294 | case "=!p": |
|
294 | case "=!p": | |
295 | case "!p": |
|
295 | case "!p": | |
296 | enableValues(field, [1]); |
|
296 | enableValues(field, [1]); | |
297 | break; |
|
297 | break; | |
298 | default: |
|
298 | default: | |
299 | enableValues(field, [0]); |
|
299 | enableValues(field, [0]); | |
300 | break; |
|
300 | break; | |
301 | } |
|
301 | } | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | function toggleMultiSelect(el) { |
|
304 | function toggleMultiSelect(el) { | |
305 | if (el.attr('multiple')) { |
|
305 | if (el.attr('multiple')) { | |
306 | el.removeAttr('multiple'); |
|
306 | el.removeAttr('multiple'); | |
307 | el.attr('size', 1); |
|
307 | el.attr('size', 1); | |
308 | } else { |
|
308 | } else { | |
309 | el.attr('multiple', true); |
|
309 | el.attr('multiple', true); | |
310 | if (el.children().length > 10) |
|
310 | if (el.children().length > 10) | |
311 | el.attr('size', 10); |
|
311 | el.attr('size', 10); | |
312 | else |
|
312 | else | |
313 | el.attr('size', 4); |
|
313 | el.attr('size', 4); | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | function showTab(name, url) { |
|
317 | function showTab(name, url) { | |
318 | $('div#content .tab-content').hide(); |
|
318 | $('div#content .tab-content').hide(); | |
319 | $('div.tabs a').removeClass('selected'); |
|
319 | $('div.tabs a').removeClass('selected'); | |
320 | $('#tab-content-' + name).show(); |
|
320 | $('#tab-content-' + name).show(); | |
321 | $('#tab-' + name).addClass('selected'); |
|
321 | $('#tab-' + name).addClass('selected'); | |
322 | //replaces current URL with the "href" attribute of the current link |
|
322 | //replaces current URL with the "href" attribute of the current link | |
323 | //(only triggered if supported by browser) |
|
323 | //(only triggered if supported by browser) | |
324 | if ("replaceState" in window.history) { |
|
324 | if ("replaceState" in window.history) { | |
325 | window.history.replaceState(null, document.title, url); |
|
325 | window.history.replaceState(null, document.title, url); | |
326 | } |
|
326 | } | |
327 | return false; |
|
327 | return false; | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | function moveTabRight(el) { |
|
330 | function moveTabRight(el) { | |
331 | var lis = $(el).parents('div.tabs').first().find('ul').children(); |
|
331 | var lis = $(el).parents('div.tabs').first().find('ul').children(); | |
332 | var tabsWidth = 0; |
|
332 | var tabsWidth = 0; | |
333 | var i = 0; |
|
333 | var i = 0; | |
334 | lis.each(function() { |
|
334 | lis.each(function() { | |
335 | if ($(this).is(':visible')) { |
|
335 | if ($(this).is(':visible')) { | |
336 | tabsWidth += $(this).width() + 6; |
|
336 | tabsWidth += $(this).width() + 6; | |
337 | } |
|
337 | } | |
338 | }); |
|
338 | }); | |
339 | if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; } |
|
339 | if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; } | |
340 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } |
|
340 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } | |
341 | lis.eq(i).hide(); |
|
341 | lis.eq(i).hide(); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | function moveTabLeft(el) { |
|
344 | function moveTabLeft(el) { | |
345 | var lis = $(el).parents('div.tabs').first().find('ul').children(); |
|
345 | var lis = $(el).parents('div.tabs').first().find('ul').children(); | |
346 | var i = 0; |
|
346 | var i = 0; | |
347 | while (i < lis.length && !lis.eq(i).is(':visible')) { i++; } |
|
347 | while (i < lis.length && !lis.eq(i).is(':visible')) { i++; } | |
348 | if (i > 0) { |
|
348 | if (i > 0) { | |
349 | lis.eq(i-1).show(); |
|
349 | lis.eq(i-1).show(); | |
350 | } |
|
350 | } | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | function displayTabsButtons() { |
|
353 | function displayTabsButtons() { | |
354 | var lis; |
|
354 | var lis; | |
355 |
var tabsWidth |
|
355 | var tabsWidth; | |
356 | var el; |
|
356 | var el; | |
357 | $('div.tabs').each(function() { |
|
357 | $('div.tabs').each(function() { | |
358 | el = $(this); |
|
358 | el = $(this); | |
359 | lis = el.find('ul').children(); |
|
359 | lis = el.find('ul').children(); | |
|
360 | tabsWidth = 0; | |||
360 | lis.each(function(){ |
|
361 | lis.each(function(){ | |
361 | if ($(this).is(':visible')) { |
|
362 | if ($(this).is(':visible')) { | |
362 | tabsWidth += $(this).width() + 6; |
|
363 | tabsWidth += $(this).width() + 6; | |
363 | } |
|
364 | } | |
364 | }); |
|
365 | }); | |
365 | if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) { |
|
366 | if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) { | |
366 | el.find('div.tabs-buttons').hide(); |
|
367 | el.find('div.tabs-buttons').hide(); | |
367 | } else { |
|
368 | } else { | |
368 | el.find('div.tabs-buttons').show(); |
|
369 | el.find('div.tabs-buttons').show(); | |
369 | } |
|
370 | } | |
370 | }); |
|
371 | }); | |
371 | } |
|
372 | } | |
372 |
|
373 | |||
373 | function setPredecessorFieldsVisibility() { |
|
374 | function setPredecessorFieldsVisibility() { | |
374 | var relationType = $('#relation_relation_type'); |
|
375 | var relationType = $('#relation_relation_type'); | |
375 | if (relationType.val() == "precedes" || relationType.val() == "follows") { |
|
376 | if (relationType.val() == "precedes" || relationType.val() == "follows") { | |
376 | $('#predecessor_fields').show(); |
|
377 | $('#predecessor_fields').show(); | |
377 | } else { |
|
378 | } else { | |
378 | $('#predecessor_fields').hide(); |
|
379 | $('#predecessor_fields').hide(); | |
379 | } |
|
380 | } | |
380 | } |
|
381 | } | |
381 |
|
382 | |||
382 | function showModal(id, width, title) { |
|
383 | function showModal(id, width, title) { | |
383 | var el = $('#'+id).first(); |
|
384 | var el = $('#'+id).first(); | |
384 | if (el.length === 0 || el.is(':visible')) {return;} |
|
385 | if (el.length === 0 || el.is(':visible')) {return;} | |
385 | if (!title) title = el.find('h3.title').text(); |
|
386 | if (!title) title = el.find('h3.title').text(); | |
386 | // moves existing modals behind the transparent background |
|
387 | // moves existing modals behind the transparent background | |
387 | $(".modal").zIndex(99); |
|
388 | $(".modal").zIndex(99); | |
388 | el.dialog({ |
|
389 | el.dialog({ | |
389 | width: width, |
|
390 | width: width, | |
390 | modal: true, |
|
391 | modal: true, | |
391 | resizable: false, |
|
392 | resizable: false, | |
392 | dialogClass: 'modal', |
|
393 | dialogClass: 'modal', | |
393 | title: title |
|
394 | title: title | |
394 | }).on('dialogclose', function(){ |
|
395 | }).on('dialogclose', function(){ | |
395 | $(".modal").zIndex(101); |
|
396 | $(".modal").zIndex(101); | |
396 | }); |
|
397 | }); | |
397 | el.find("input[type=text], input[type=submit]").first().focus(); |
|
398 | el.find("input[type=text], input[type=submit]").first().focus(); | |
398 | } |
|
399 | } | |
399 |
|
400 | |||
400 | function hideModal(el) { |
|
401 | function hideModal(el) { | |
401 | var modal; |
|
402 | var modal; | |
402 | if (el) { |
|
403 | if (el) { | |
403 | modal = $(el).parents('.ui-dialog-content'); |
|
404 | modal = $(el).parents('.ui-dialog-content'); | |
404 | } else { |
|
405 | } else { | |
405 | modal = $('#ajax-modal'); |
|
406 | modal = $('#ajax-modal'); | |
406 | } |
|
407 | } | |
407 | modal.dialog("close"); |
|
408 | modal.dialog("close"); | |
408 | } |
|
409 | } | |
409 |
|
410 | |||
410 | function submitPreview(url, form, target) { |
|
411 | function submitPreview(url, form, target) { | |
411 | $.ajax({ |
|
412 | $.ajax({ | |
412 | url: url, |
|
413 | url: url, | |
413 | type: 'post', |
|
414 | type: 'post', | |
414 | data: $('#'+form).serialize(), |
|
415 | data: $('#'+form).serialize(), | |
415 | success: function(data){ |
|
416 | success: function(data){ | |
416 | $('#'+target).html(data); |
|
417 | $('#'+target).html(data); | |
417 | } |
|
418 | } | |
418 | }); |
|
419 | }); | |
419 | } |
|
420 | } | |
420 |
|
421 | |||
421 | function collapseScmEntry(id) { |
|
422 | function collapseScmEntry(id) { | |
422 | $('.'+id).each(function() { |
|
423 | $('.'+id).each(function() { | |
423 | if ($(this).hasClass('open')) { |
|
424 | if ($(this).hasClass('open')) { | |
424 | collapseScmEntry($(this).attr('id')); |
|
425 | collapseScmEntry($(this).attr('id')); | |
425 | } |
|
426 | } | |
426 | $(this).hide(); |
|
427 | $(this).hide(); | |
427 | }); |
|
428 | }); | |
428 | $('#'+id).removeClass('open'); |
|
429 | $('#'+id).removeClass('open'); | |
429 | } |
|
430 | } | |
430 |
|
431 | |||
431 | function expandScmEntry(id) { |
|
432 | function expandScmEntry(id) { | |
432 | $('.'+id).each(function() { |
|
433 | $('.'+id).each(function() { | |
433 | $(this).show(); |
|
434 | $(this).show(); | |
434 | if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) { |
|
435 | if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) { | |
435 | expandScmEntry($(this).attr('id')); |
|
436 | expandScmEntry($(this).attr('id')); | |
436 | } |
|
437 | } | |
437 | }); |
|
438 | }); | |
438 | $('#'+id).addClass('open'); |
|
439 | $('#'+id).addClass('open'); | |
439 | } |
|
440 | } | |
440 |
|
441 | |||
441 | function scmEntryClick(id, url) { |
|
442 | function scmEntryClick(id, url) { | |
442 | var el = $('#'+id); |
|
443 | var el = $('#'+id); | |
443 | if (el.hasClass('open')) { |
|
444 | if (el.hasClass('open')) { | |
444 | collapseScmEntry(id); |
|
445 | collapseScmEntry(id); | |
445 | el.addClass('collapsed'); |
|
446 | el.addClass('collapsed'); | |
446 | return false; |
|
447 | return false; | |
447 | } else if (el.hasClass('loaded')) { |
|
448 | } else if (el.hasClass('loaded')) { | |
448 | expandScmEntry(id); |
|
449 | expandScmEntry(id); | |
449 | el.removeClass('collapsed'); |
|
450 | el.removeClass('collapsed'); | |
450 | return false; |
|
451 | return false; | |
451 | } |
|
452 | } | |
452 | if (el.hasClass('loading')) { |
|
453 | if (el.hasClass('loading')) { | |
453 | return false; |
|
454 | return false; | |
454 | } |
|
455 | } | |
455 | el.addClass('loading'); |
|
456 | el.addClass('loading'); | |
456 | $.ajax({ |
|
457 | $.ajax({ | |
457 | url: url, |
|
458 | url: url, | |
458 | success: function(data) { |
|
459 | success: function(data) { | |
459 | el.after(data); |
|
460 | el.after(data); | |
460 | el.addClass('open').addClass('loaded').removeClass('loading'); |
|
461 | el.addClass('open').addClass('loaded').removeClass('loading'); | |
461 | } |
|
462 | } | |
462 | }); |
|
463 | }); | |
463 | return true; |
|
464 | return true; | |
464 | } |
|
465 | } | |
465 |
|
466 | |||
466 | function randomKey(size) { |
|
467 | function randomKey(size) { | |
467 | var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
|
468 | var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |
468 | var key = ''; |
|
469 | var key = ''; | |
469 | for (var i = 0; i < size; i++) { |
|
470 | for (var i = 0; i < size; i++) { | |
470 | key += chars.charAt(Math.floor(Math.random() * chars.length)); |
|
471 | key += chars.charAt(Math.floor(Math.random() * chars.length)); | |
471 | } |
|
472 | } | |
472 | return key; |
|
473 | return key; | |
473 | } |
|
474 | } | |
474 |
|
475 | |||
475 | function updateIssueFrom(url) { |
|
476 | function updateIssueFrom(url) { | |
476 | $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ |
|
477 | $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ | |
477 | $(this).data('valuebeforeupdate', $(this).val()); |
|
478 | $(this).data('valuebeforeupdate', $(this).val()); | |
478 | }); |
|
479 | }); | |
479 | return $.ajax({ |
|
480 | return $.ajax({ | |
480 | url: url, |
|
481 | url: url, | |
481 | type: 'post', |
|
482 | type: 'post', | |
482 | data: $('#issue-form').serialize() |
|
483 | data: $('#issue-form').serialize() | |
483 | }); |
|
484 | }); | |
484 | } |
|
485 | } | |
485 |
|
486 | |||
486 | function replaceIssueFormWith(html){ |
|
487 | function replaceIssueFormWith(html){ | |
487 | var replacement = $(html); |
|
488 | var replacement = $(html); | |
488 | $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ |
|
489 | $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ | |
489 | var object_id = $(this).attr('id'); |
|
490 | var object_id = $(this).attr('id'); | |
490 | if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) { |
|
491 | if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) { | |
491 | replacement.find('#'+object_id).val($(this).val()); |
|
492 | replacement.find('#'+object_id).val($(this).val()); | |
492 | } |
|
493 | } | |
493 | }); |
|
494 | }); | |
494 | $('#all_attributes').empty(); |
|
495 | $('#all_attributes').empty(); | |
495 | $('#all_attributes').prepend(replacement); |
|
496 | $('#all_attributes').prepend(replacement); | |
496 | } |
|
497 | } | |
497 |
|
498 | |||
498 | function updateBulkEditFrom(url) { |
|
499 | function updateBulkEditFrom(url) { | |
499 | $.ajax({ |
|
500 | $.ajax({ | |
500 | url: url, |
|
501 | url: url, | |
501 | type: 'post', |
|
502 | type: 'post', | |
502 | data: $('#bulk_edit_form').serialize() |
|
503 | data: $('#bulk_edit_form').serialize() | |
503 | }); |
|
504 | }); | |
504 | } |
|
505 | } | |
505 |
|
506 | |||
506 | function observeAutocompleteField(fieldId, url, options) { |
|
507 | function observeAutocompleteField(fieldId, url, options) { | |
507 | $(document).ready(function() { |
|
508 | $(document).ready(function() { | |
508 | $('#'+fieldId).autocomplete($.extend({ |
|
509 | $('#'+fieldId).autocomplete($.extend({ | |
509 | source: url, |
|
510 | source: url, | |
510 | minLength: 2, |
|
511 | minLength: 2, | |
511 | search: function(){$('#'+fieldId).addClass('ajax-loading');}, |
|
512 | search: function(){$('#'+fieldId).addClass('ajax-loading');}, | |
512 | response: function(){$('#'+fieldId).removeClass('ajax-loading');} |
|
513 | response: function(){$('#'+fieldId).removeClass('ajax-loading');} | |
513 | }, options)); |
|
514 | }, options)); | |
514 | $('#'+fieldId).addClass('autocomplete'); |
|
515 | $('#'+fieldId).addClass('autocomplete'); | |
515 | }); |
|
516 | }); | |
516 | } |
|
517 | } | |
517 |
|
518 | |||
518 | function observeSearchfield(fieldId, targetId, url) { |
|
519 | function observeSearchfield(fieldId, targetId, url) { | |
519 | $('#'+fieldId).each(function() { |
|
520 | $('#'+fieldId).each(function() { | |
520 | var $this = $(this); |
|
521 | var $this = $(this); | |
521 | $this.addClass('autocomplete'); |
|
522 | $this.addClass('autocomplete'); | |
522 | $this.attr('data-value-was', $this.val()); |
|
523 | $this.attr('data-value-was', $this.val()); | |
523 | var check = function() { |
|
524 | var check = function() { | |
524 | var val = $this.val(); |
|
525 | var val = $this.val(); | |
525 | if ($this.attr('data-value-was') != val){ |
|
526 | if ($this.attr('data-value-was') != val){ | |
526 | $this.attr('data-value-was', val); |
|
527 | $this.attr('data-value-was', val); | |
527 | $.ajax({ |
|
528 | $.ajax({ | |
528 | url: url, |
|
529 | url: url, | |
529 | type: 'get', |
|
530 | type: 'get', | |
530 | data: {q: $this.val()}, |
|
531 | data: {q: $this.val()}, | |
531 | success: function(data){ if(targetId) $('#'+targetId).html(data); }, |
|
532 | success: function(data){ if(targetId) $('#'+targetId).html(data); }, | |
532 | beforeSend: function(){ $this.addClass('ajax-loading'); }, |
|
533 | beforeSend: function(){ $this.addClass('ajax-loading'); }, | |
533 | complete: function(){ $this.removeClass('ajax-loading'); } |
|
534 | complete: function(){ $this.removeClass('ajax-loading'); } | |
534 | }); |
|
535 | }); | |
535 | } |
|
536 | } | |
536 | }; |
|
537 | }; | |
537 | var reset = function() { |
|
538 | var reset = function() { | |
538 | if (timer) { |
|
539 | if (timer) { | |
539 | clearInterval(timer); |
|
540 | clearInterval(timer); | |
540 | timer = setInterval(check, 300); |
|
541 | timer = setInterval(check, 300); | |
541 | } |
|
542 | } | |
542 | }; |
|
543 | }; | |
543 | var timer = setInterval(check, 300); |
|
544 | var timer = setInterval(check, 300); | |
544 | $this.bind('keyup click mousemove', reset); |
|
545 | $this.bind('keyup click mousemove', reset); | |
545 | }); |
|
546 | }); | |
546 | } |
|
547 | } | |
547 |
|
548 | |||
548 | function beforeShowDatePicker(input, inst) { |
|
549 | function beforeShowDatePicker(input, inst) { | |
549 | var default_date = null; |
|
550 | var default_date = null; | |
550 | switch ($(input).attr("id")) { |
|
551 | switch ($(input).attr("id")) { | |
551 | case "issue_start_date" : |
|
552 | case "issue_start_date" : | |
552 | if ($("#issue_due_date").size() > 0) { |
|
553 | if ($("#issue_due_date").size() > 0) { | |
553 | default_date = $("#issue_due_date").val(); |
|
554 | default_date = $("#issue_due_date").val(); | |
554 | } |
|
555 | } | |
555 | break; |
|
556 | break; | |
556 | case "issue_due_date" : |
|
557 | case "issue_due_date" : | |
557 | if ($("#issue_start_date").size() > 0) { |
|
558 | if ($("#issue_start_date").size() > 0) { | |
558 | default_date = $("#issue_start_date").val(); |
|
559 | default_date = $("#issue_start_date").val(); | |
559 | } |
|
560 | } | |
560 | break; |
|
561 | break; | |
561 | } |
|
562 | } | |
562 | $(input).datepicker("option", "defaultDate", default_date); |
|
563 | $(input).datepicker("option", "defaultDate", default_date); | |
563 | } |
|
564 | } | |
564 |
|
565 | |||
565 | function initMyPageSortable(list, url) { |
|
566 | function initMyPageSortable(list, url) { | |
566 | $('#list-'+list).sortable({ |
|
567 | $('#list-'+list).sortable({ | |
567 | connectWith: '.block-receiver', |
|
568 | connectWith: '.block-receiver', | |
568 | tolerance: 'pointer', |
|
569 | tolerance: 'pointer', | |
569 | update: function(){ |
|
570 | update: function(){ | |
570 | $.ajax({ |
|
571 | $.ajax({ | |
571 | url: url, |
|
572 | url: url, | |
572 | type: 'post', |
|
573 | type: 'post', | |
573 | data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})} |
|
574 | data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})} | |
574 | }); |
|
575 | }); | |
575 | } |
|
576 | } | |
576 | }); |
|
577 | }); | |
577 | $("#list-top, #list-left, #list-right").disableSelection(); |
|
578 | $("#list-top, #list-left, #list-right").disableSelection(); | |
578 | } |
|
579 | } | |
579 |
|
580 | |||
580 | var warnLeavingUnsavedMessage; |
|
581 | var warnLeavingUnsavedMessage; | |
581 | function warnLeavingUnsaved(message) { |
|
582 | function warnLeavingUnsaved(message) { | |
582 | warnLeavingUnsavedMessage = message; |
|
583 | warnLeavingUnsavedMessage = message; | |
583 | $(document).on('submit', 'form', function(){ |
|
584 | $(document).on('submit', 'form', function(){ | |
584 | $('textarea').removeData('changed'); |
|
585 | $('textarea').removeData('changed'); | |
585 | }); |
|
586 | }); | |
586 | $(document).on('change', 'textarea', function(){ |
|
587 | $(document).on('change', 'textarea', function(){ | |
587 | $(this).data('changed', 'changed'); |
|
588 | $(this).data('changed', 'changed'); | |
588 | }); |
|
589 | }); | |
589 | window.onbeforeunload = function(){ |
|
590 | window.onbeforeunload = function(){ | |
590 | var warn = false; |
|
591 | var warn = false; | |
591 | $('textarea').blur().each(function(){ |
|
592 | $('textarea').blur().each(function(){ | |
592 | if ($(this).data('changed')) { |
|
593 | if ($(this).data('changed')) { | |
593 | warn = true; |
|
594 | warn = true; | |
594 | } |
|
595 | } | |
595 | }); |
|
596 | }); | |
596 | if (warn) {return warnLeavingUnsavedMessage;} |
|
597 | if (warn) {return warnLeavingUnsavedMessage;} | |
597 | }; |
|
598 | }; | |
598 | } |
|
599 | } | |
599 |
|
600 | |||
600 | function setupAjaxIndicator() { |
|
601 | function setupAjaxIndicator() { | |
601 | $(document).bind('ajaxSend', function(event, xhr, settings) { |
|
602 | $(document).bind('ajaxSend', function(event, xhr, settings) { | |
602 | if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') { |
|
603 | if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') { | |
603 | $('#ajax-indicator').show(); |
|
604 | $('#ajax-indicator').show(); | |
604 | } |
|
605 | } | |
605 | }); |
|
606 | }); | |
606 | $(document).bind('ajaxStop', function() { |
|
607 | $(document).bind('ajaxStop', function() { | |
607 | $('#ajax-indicator').hide(); |
|
608 | $('#ajax-indicator').hide(); | |
608 | }); |
|
609 | }); | |
609 | } |
|
610 | } | |
610 |
|
611 | |||
611 | function hideOnLoad() { |
|
612 | function hideOnLoad() { | |
612 | $('.hol').hide(); |
|
613 | $('.hol').hide(); | |
613 | } |
|
614 | } | |
614 |
|
615 | |||
615 | function addFormObserversForDoubleSubmit() { |
|
616 | function addFormObserversForDoubleSubmit() { | |
616 | $('form[method=post]').each(function() { |
|
617 | $('form[method=post]').each(function() { | |
617 | if (!$(this).hasClass('multiple-submit')) { |
|
618 | if (!$(this).hasClass('multiple-submit')) { | |
618 | $(this).submit(function(form_submission) { |
|
619 | $(this).submit(function(form_submission) { | |
619 | if ($(form_submission.target).attr('data-submitted')) { |
|
620 | if ($(form_submission.target).attr('data-submitted')) { | |
620 | form_submission.preventDefault(); |
|
621 | form_submission.preventDefault(); | |
621 | } else { |
|
622 | } else { | |
622 | $(form_submission.target).attr('data-submitted', true); |
|
623 | $(form_submission.target).attr('data-submitted', true); | |
623 | } |
|
624 | } | |
624 | }); |
|
625 | }); | |
625 | } |
|
626 | } | |
626 | }); |
|
627 | }); | |
627 | } |
|
628 | } | |
628 |
|
629 | |||
629 | function defaultFocus(){ |
|
630 | function defaultFocus(){ | |
630 | if (($('#content :focus').length == 0) && (window.location.hash == '')) { |
|
631 | if (($('#content :focus').length == 0) && (window.location.hash == '')) { | |
631 | $('#content input[type=text], #content textarea').first().focus(); |
|
632 | $('#content input[type=text], #content textarea').first().focus(); | |
632 | } |
|
633 | } | |
633 | } |
|
634 | } | |
634 |
|
635 | |||
635 | function blockEventPropagation(event) { |
|
636 | function blockEventPropagation(event) { | |
636 | event.stopPropagation(); |
|
637 | event.stopPropagation(); | |
637 | event.preventDefault(); |
|
638 | event.preventDefault(); | |
638 | } |
|
639 | } | |
639 |
|
640 | |||
640 | function toggleDisabledOnChange() { |
|
641 | function toggleDisabledOnChange() { | |
641 | var checked = $(this).is(':checked'); |
|
642 | var checked = $(this).is(':checked'); | |
642 | $($(this).data('disables')).attr('disabled', checked); |
|
643 | $($(this).data('disables')).attr('disabled', checked); | |
643 | $($(this).data('enables')).attr('disabled', !checked); |
|
644 | $($(this).data('enables')).attr('disabled', !checked); | |
644 | } |
|
645 | } | |
645 | function toggleDisabledInit() { |
|
646 | function toggleDisabledInit() { | |
646 | $('input[data-disables], input[data-enables]').each(toggleDisabledOnChange); |
|
647 | $('input[data-disables], input[data-enables]').each(toggleDisabledOnChange); | |
647 | } |
|
648 | } | |
648 | $(document).ready(function(){ |
|
649 | $(document).ready(function(){ | |
649 | $('#content').on('change', 'input[data-disables], input[data-enables]', toggleDisabledOnChange); |
|
650 | $('#content').on('change', 'input[data-disables], input[data-enables]', toggleDisabledOnChange); | |
650 | toggleDisabledInit(); |
|
651 | toggleDisabledInit(); | |
651 | }); |
|
652 | }); | |
652 |
|
653 | |||
653 | $(document).ready(setupAjaxIndicator); |
|
654 | $(document).ready(setupAjaxIndicator); | |
654 | $(document).ready(hideOnLoad); |
|
655 | $(document).ready(hideOnLoad); | |
655 | $(document).ready(addFormObserversForDoubleSubmit); |
|
656 | $(document).ready(addFormObserversForDoubleSubmit); | |
656 | $(document).ready(defaultFocus); |
|
657 | $(document).ready(defaultFocus); |
General Comments 0
You need to be logged in to leave comments.
Login now