@@ -1,651 +1,652 | |||||
1 | /* Redmine - project management software |
|
1 | /* Redmine - project management software | |
2 | Copyright (C) 2006-2014 Jean-Philippe Lang */ |
|
2 | Copyright (C) 2006-2014 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 | case "integer": |
|
218 | case "integer": | |
218 | case "float": |
|
219 | case "float": | |
219 | tr.find('td.values').append( |
|
220 | tr.find('td.values').append( | |
220 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' + |
|
221 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' + | |
221 | ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>' |
|
222 | ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>' | |
222 | ); |
|
223 | ); | |
223 | $('#values_'+fieldId+'_1').val(values[0]); |
|
224 | $('#values_'+fieldId+'_1').val(values[0]); | |
224 | $('#values_'+fieldId+'_2').val(values[1]); |
|
225 | $('#values_'+fieldId+'_2').val(values[1]); | |
225 | break; |
|
226 | break; | |
226 | } |
|
227 | } | |
227 | } |
|
228 | } | |
228 |
|
229 | |||
229 | function toggleFilter(field) { |
|
230 | function toggleFilter(field) { | |
230 | var fieldId = field.replace('.', '_'); |
|
231 | var fieldId = field.replace('.', '_'); | |
231 | if ($('#cb_' + fieldId).is(':checked')) { |
|
232 | if ($('#cb_' + fieldId).is(':checked')) { | |
232 | $("#operators_" + fieldId).show().removeAttr('disabled'); |
|
233 | $("#operators_" + fieldId).show().removeAttr('disabled'); | |
233 | toggleOperator(field); |
|
234 | toggleOperator(field); | |
234 | } else { |
|
235 | } else { | |
235 | $("#operators_" + fieldId).hide().attr('disabled', true); |
|
236 | $("#operators_" + fieldId).hide().attr('disabled', true); | |
236 | enableValues(field, []); |
|
237 | enableValues(field, []); | |
237 | } |
|
238 | } | |
238 | } |
|
239 | } | |
239 |
|
240 | |||
240 | function enableValues(field, indexes) { |
|
241 | function enableValues(field, indexes) { | |
241 | var fieldId = field.replace('.', '_'); |
|
242 | var fieldId = field.replace('.', '_'); | |
242 | $('#tr_'+fieldId+' td.values .value').each(function(index) { |
|
243 | $('#tr_'+fieldId+' td.values .value').each(function(index) { | |
243 | if ($.inArray(index, indexes) >= 0) { |
|
244 | if ($.inArray(index, indexes) >= 0) { | |
244 | $(this).removeAttr('disabled'); |
|
245 | $(this).removeAttr('disabled'); | |
245 | $(this).parents('span').first().show(); |
|
246 | $(this).parents('span').first().show(); | |
246 | } else { |
|
247 | } else { | |
247 | $(this).val(''); |
|
248 | $(this).val(''); | |
248 | $(this).attr('disabled', true); |
|
249 | $(this).attr('disabled', true); | |
249 | $(this).parents('span').first().hide(); |
|
250 | $(this).parents('span').first().hide(); | |
250 | } |
|
251 | } | |
251 |
|
252 | |||
252 | if ($(this).hasClass('group')) { |
|
253 | if ($(this).hasClass('group')) { | |
253 | $(this).addClass('open'); |
|
254 | $(this).addClass('open'); | |
254 | } else { |
|
255 | } else { | |
255 | $(this).show(); |
|
256 | $(this).show(); | |
256 | } |
|
257 | } | |
257 | }); |
|
258 | }); | |
258 | } |
|
259 | } | |
259 |
|
260 | |||
260 | function toggleOperator(field) { |
|
261 | function toggleOperator(field) { | |
261 | var fieldId = field.replace('.', '_'); |
|
262 | var fieldId = field.replace('.', '_'); | |
262 | var operator = $("#operators_" + fieldId); |
|
263 | var operator = $("#operators_" + fieldId); | |
263 | switch (operator.val()) { |
|
264 | switch (operator.val()) { | |
264 | case "!*": |
|
265 | case "!*": | |
265 | case "*": |
|
266 | case "*": | |
266 | case "t": |
|
267 | case "t": | |
267 | case "ld": |
|
268 | case "ld": | |
268 | case "w": |
|
269 | case "w": | |
269 | case "lw": |
|
270 | case "lw": | |
270 | case "l2w": |
|
271 | case "l2w": | |
271 | case "m": |
|
272 | case "m": | |
272 | case "lm": |
|
273 | case "lm": | |
273 | case "y": |
|
274 | case "y": | |
274 | case "o": |
|
275 | case "o": | |
275 | case "c": |
|
276 | case "c": | |
276 | enableValues(field, []); |
|
277 | enableValues(field, []); | |
277 | break; |
|
278 | break; | |
278 | case "><": |
|
279 | case "><": | |
279 | enableValues(field, [0,1]); |
|
280 | enableValues(field, [0,1]); | |
280 | break; |
|
281 | break; | |
281 | case "<t+": |
|
282 | case "<t+": | |
282 | case ">t+": |
|
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 | enableValues(field, [2]); |
|
290 | enableValues(field, [2]); | |
290 | break; |
|
291 | break; | |
291 | case "=p": |
|
292 | case "=p": | |
292 | case "=!p": |
|
293 | case "=!p": | |
293 | case "!p": |
|
294 | case "!p": | |
294 | enableValues(field, [1]); |
|
295 | enableValues(field, [1]); | |
295 | break; |
|
296 | break; | |
296 | default: |
|
297 | default: | |
297 | enableValues(field, [0]); |
|
298 | enableValues(field, [0]); | |
298 | break; |
|
299 | break; | |
299 | } |
|
300 | } | |
300 | } |
|
301 | } | |
301 |
|
302 | |||
302 | function toggleMultiSelect(el) { |
|
303 | function toggleMultiSelect(el) { | |
303 | if (el.attr('multiple')) { |
|
304 | if (el.attr('multiple')) { | |
304 | el.removeAttr('multiple'); |
|
305 | el.removeAttr('multiple'); | |
305 | el.attr('size', 1); |
|
306 | el.attr('size', 1); | |
306 | } else { |
|
307 | } else { | |
307 | el.attr('multiple', true); |
|
308 | el.attr('multiple', true); | |
308 | if (el.children().length > 10) |
|
309 | if (el.children().length > 10) | |
309 | el.attr('size', 10); |
|
310 | el.attr('size', 10); | |
310 | else |
|
311 | else | |
311 | el.attr('size', 4); |
|
312 | el.attr('size', 4); | |
312 | } |
|
313 | } | |
313 | } |
|
314 | } | |
314 |
|
315 | |||
315 | function showTab(name, url) { |
|
316 | function showTab(name, url) { | |
316 | $('div#content .tab-content').hide(); |
|
317 | $('div#content .tab-content').hide(); | |
317 | $('div.tabs a').removeClass('selected'); |
|
318 | $('div.tabs a').removeClass('selected'); | |
318 | $('#tab-content-' + name).show(); |
|
319 | $('#tab-content-' + name).show(); | |
319 | $('#tab-' + name).addClass('selected'); |
|
320 | $('#tab-' + name).addClass('selected'); | |
320 | //replaces current URL with the "href" attribute of the current link |
|
321 | //replaces current URL with the "href" attribute of the current link | |
321 | //(only triggered if supported by browser) |
|
322 | //(only triggered if supported by browser) | |
322 | if ("replaceState" in window.history) { |
|
323 | if ("replaceState" in window.history) { | |
323 | window.history.replaceState(null, document.title, url); |
|
324 | window.history.replaceState(null, document.title, url); | |
324 | } |
|
325 | } | |
325 | return false; |
|
326 | return false; | |
326 | } |
|
327 | } | |
327 |
|
328 | |||
328 | function moveTabRight(el) { |
|
329 | function moveTabRight(el) { | |
329 | var lis = $(el).parents('div.tabs').first().find('ul').children(); |
|
330 | var lis = $(el).parents('div.tabs').first().find('ul').children(); | |
330 | var tabsWidth = 0; |
|
331 | var tabsWidth = 0; | |
331 | var i = 0; |
|
332 | var i = 0; | |
332 | lis.each(function() { |
|
333 | lis.each(function() { | |
333 | if ($(this).is(':visible')) { |
|
334 | if ($(this).is(':visible')) { | |
334 | tabsWidth += $(this).width() + 6; |
|
335 | tabsWidth += $(this).width() + 6; | |
335 | } |
|
336 | } | |
336 | }); |
|
337 | }); | |
337 | if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; } |
|
338 | if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; } | |
338 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } |
|
339 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } | |
339 | lis.eq(i).hide(); |
|
340 | lis.eq(i).hide(); | |
340 | } |
|
341 | } | |
341 |
|
342 | |||
342 | function moveTabLeft(el) { |
|
343 | function moveTabLeft(el) { | |
343 | var lis = $(el).parents('div.tabs').first().find('ul').children(); |
|
344 | var lis = $(el).parents('div.tabs').first().find('ul').children(); | |
344 | var i = 0; |
|
345 | var i = 0; | |
345 | while (i < lis.length && !lis.eq(i).is(':visible')) { i++; } |
|
346 | while (i < lis.length && !lis.eq(i).is(':visible')) { i++; } | |
346 | if (i > 0) { |
|
347 | if (i > 0) { | |
347 | lis.eq(i-1).show(); |
|
348 | lis.eq(i-1).show(); | |
348 | } |
|
349 | } | |
349 | } |
|
350 | } | |
350 |
|
351 | |||
351 | function displayTabsButtons() { |
|
352 | function displayTabsButtons() { | |
352 | var lis; |
|
353 | var lis; | |
353 | var tabsWidth = 0; |
|
354 | var tabsWidth = 0; | |
354 | var el; |
|
355 | var el; | |
355 | $('div.tabs').each(function() { |
|
356 | $('div.tabs').each(function() { | |
356 | el = $(this); |
|
357 | el = $(this); | |
357 | lis = el.find('ul').children(); |
|
358 | lis = el.find('ul').children(); | |
358 | lis.each(function(){ |
|
359 | lis.each(function(){ | |
359 | if ($(this).is(':visible')) { |
|
360 | if ($(this).is(':visible')) { | |
360 | tabsWidth += $(this).width() + 6; |
|
361 | tabsWidth += $(this).width() + 6; | |
361 | } |
|
362 | } | |
362 | }); |
|
363 | }); | |
363 | if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) { |
|
364 | if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) { | |
364 | el.find('div.tabs-buttons').hide(); |
|
365 | el.find('div.tabs-buttons').hide(); | |
365 | } else { |
|
366 | } else { | |
366 | el.find('div.tabs-buttons').show(); |
|
367 | el.find('div.tabs-buttons').show(); | |
367 | } |
|
368 | } | |
368 | }); |
|
369 | }); | |
369 | } |
|
370 | } | |
370 |
|
371 | |||
371 | function setPredecessorFieldsVisibility() { |
|
372 | function setPredecessorFieldsVisibility() { | |
372 | var relationType = $('#relation_relation_type'); |
|
373 | var relationType = $('#relation_relation_type'); | |
373 | if (relationType.val() == "precedes" || relationType.val() == "follows") { |
|
374 | if (relationType.val() == "precedes" || relationType.val() == "follows") { | |
374 | $('#predecessor_fields').show(); |
|
375 | $('#predecessor_fields').show(); | |
375 | } else { |
|
376 | } else { | |
376 | $('#predecessor_fields').hide(); |
|
377 | $('#predecessor_fields').hide(); | |
377 | } |
|
378 | } | |
378 | } |
|
379 | } | |
379 |
|
380 | |||
380 | function showModal(id, width) { |
|
381 | function showModal(id, width) { | |
381 | var el = $('#'+id).first(); |
|
382 | var el = $('#'+id).first(); | |
382 | if (el.length === 0 || el.is(':visible')) {return;} |
|
383 | if (el.length === 0 || el.is(':visible')) {return;} | |
383 | var title = el.find('h3.title').text(); |
|
384 | var title = el.find('h3.title').text(); | |
384 | el.dialog({ |
|
385 | el.dialog({ | |
385 | width: width, |
|
386 | width: width, | |
386 | modal: true, |
|
387 | modal: true, | |
387 | resizable: false, |
|
388 | resizable: false, | |
388 | dialogClass: 'modal', |
|
389 | dialogClass: 'modal', | |
389 | title: title |
|
390 | title: title | |
390 | }); |
|
391 | }); | |
391 | el.find("input[type=text], input[type=submit]").first().focus(); |
|
392 | el.find("input[type=text], input[type=submit]").first().focus(); | |
392 | } |
|
393 | } | |
393 |
|
394 | |||
394 | function hideModal(el) { |
|
395 | function hideModal(el) { | |
395 | var modal; |
|
396 | var modal; | |
396 | if (el) { |
|
397 | if (el) { | |
397 | modal = $(el).parents('.ui-dialog-content'); |
|
398 | modal = $(el).parents('.ui-dialog-content'); | |
398 | } else { |
|
399 | } else { | |
399 | modal = $('#ajax-modal'); |
|
400 | modal = $('#ajax-modal'); | |
400 | } |
|
401 | } | |
401 | modal.dialog("close"); |
|
402 | modal.dialog("close"); | |
402 | } |
|
403 | } | |
403 |
|
404 | |||
404 | function submitPreview(url, form, target) { |
|
405 | function submitPreview(url, form, target) { | |
405 | $.ajax({ |
|
406 | $.ajax({ | |
406 | url: url, |
|
407 | url: url, | |
407 | type: 'post', |
|
408 | type: 'post', | |
408 | data: $('#'+form).serialize(), |
|
409 | data: $('#'+form).serialize(), | |
409 | success: function(data){ |
|
410 | success: function(data){ | |
410 | $('#'+target).html(data); |
|
411 | $('#'+target).html(data); | |
411 | } |
|
412 | } | |
412 | }); |
|
413 | }); | |
413 | } |
|
414 | } | |
414 |
|
415 | |||
415 | function collapseScmEntry(id) { |
|
416 | function collapseScmEntry(id) { | |
416 | $('.'+id).each(function() { |
|
417 | $('.'+id).each(function() { | |
417 | if ($(this).hasClass('open')) { |
|
418 | if ($(this).hasClass('open')) { | |
418 | collapseScmEntry($(this).attr('id')); |
|
419 | collapseScmEntry($(this).attr('id')); | |
419 | } |
|
420 | } | |
420 | $(this).hide(); |
|
421 | $(this).hide(); | |
421 | }); |
|
422 | }); | |
422 | $('#'+id).removeClass('open'); |
|
423 | $('#'+id).removeClass('open'); | |
423 | } |
|
424 | } | |
424 |
|
425 | |||
425 | function expandScmEntry(id) { |
|
426 | function expandScmEntry(id) { | |
426 | $('.'+id).each(function() { |
|
427 | $('.'+id).each(function() { | |
427 | $(this).show(); |
|
428 | $(this).show(); | |
428 | if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) { |
|
429 | if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) { | |
429 | expandScmEntry($(this).attr('id')); |
|
430 | expandScmEntry($(this).attr('id')); | |
430 | } |
|
431 | } | |
431 | }); |
|
432 | }); | |
432 | $('#'+id).addClass('open'); |
|
433 | $('#'+id).addClass('open'); | |
433 | } |
|
434 | } | |
434 |
|
435 | |||
435 | function scmEntryClick(id, url) { |
|
436 | function scmEntryClick(id, url) { | |
436 | var el = $('#'+id); |
|
437 | var el = $('#'+id); | |
437 | if (el.hasClass('open')) { |
|
438 | if (el.hasClass('open')) { | |
438 | collapseScmEntry(id); |
|
439 | collapseScmEntry(id); | |
439 | el.addClass('collapsed'); |
|
440 | el.addClass('collapsed'); | |
440 | return false; |
|
441 | return false; | |
441 | } else if (el.hasClass('loaded')) { |
|
442 | } else if (el.hasClass('loaded')) { | |
442 | expandScmEntry(id); |
|
443 | expandScmEntry(id); | |
443 | el.removeClass('collapsed'); |
|
444 | el.removeClass('collapsed'); | |
444 | return false; |
|
445 | return false; | |
445 | } |
|
446 | } | |
446 | if (el.hasClass('loading')) { |
|
447 | if (el.hasClass('loading')) { | |
447 | return false; |
|
448 | return false; | |
448 | } |
|
449 | } | |
449 | el.addClass('loading'); |
|
450 | el.addClass('loading'); | |
450 | $.ajax({ |
|
451 | $.ajax({ | |
451 | url: url, |
|
452 | url: url, | |
452 | success: function(data) { |
|
453 | success: function(data) { | |
453 | el.after(data); |
|
454 | el.after(data); | |
454 | el.addClass('open').addClass('loaded').removeClass('loading'); |
|
455 | el.addClass('open').addClass('loaded').removeClass('loading'); | |
455 | } |
|
456 | } | |
456 | }); |
|
457 | }); | |
457 | return true; |
|
458 | return true; | |
458 | } |
|
459 | } | |
459 |
|
460 | |||
460 | function randomKey(size) { |
|
461 | function randomKey(size) { | |
461 | var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
|
462 | var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |
462 | var key = ''; |
|
463 | var key = ''; | |
463 | for (var i = 0; i < size; i++) { |
|
464 | for (var i = 0; i < size; i++) { | |
464 | key += chars.charAt(Math.floor(Math.random() * chars.length)); |
|
465 | key += chars.charAt(Math.floor(Math.random() * chars.length)); | |
465 | } |
|
466 | } | |
466 | return key; |
|
467 | return key; | |
467 | } |
|
468 | } | |
468 |
|
469 | |||
469 | function updateIssueFrom(url) { |
|
470 | function updateIssueFrom(url) { | |
470 | $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ |
|
471 | $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ | |
471 | $(this).data('valuebeforeupdate', $(this).val()); |
|
472 | $(this).data('valuebeforeupdate', $(this).val()); | |
472 | }); |
|
473 | }); | |
473 | $.ajax({ |
|
474 | $.ajax({ | |
474 | url: url, |
|
475 | url: url, | |
475 | type: 'post', |
|
476 | type: 'post', | |
476 | data: $('#issue-form').serialize() |
|
477 | data: $('#issue-form').serialize() | |
477 | }); |
|
478 | }); | |
478 | } |
|
479 | } | |
479 |
|
480 | |||
480 | function replaceIssueFormWith(html){ |
|
481 | function replaceIssueFormWith(html){ | |
481 | var replacement = $(html); |
|
482 | var replacement = $(html); | |
482 | $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ |
|
483 | $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ | |
483 | var object_id = $(this).attr('id'); |
|
484 | var object_id = $(this).attr('id'); | |
484 | if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) { |
|
485 | if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) { | |
485 | replacement.find('#'+object_id).val($(this).val()); |
|
486 | replacement.find('#'+object_id).val($(this).val()); | |
486 | } |
|
487 | } | |
487 | }); |
|
488 | }); | |
488 | $('#all_attributes').empty(); |
|
489 | $('#all_attributes').empty(); | |
489 | $('#all_attributes').prepend(replacement); |
|
490 | $('#all_attributes').prepend(replacement); | |
490 | } |
|
491 | } | |
491 |
|
492 | |||
492 | function updateBulkEditFrom(url) { |
|
493 | function updateBulkEditFrom(url) { | |
493 | $.ajax({ |
|
494 | $.ajax({ | |
494 | url: url, |
|
495 | url: url, | |
495 | type: 'post', |
|
496 | type: 'post', | |
496 | data: $('#bulk_edit_form').serialize() |
|
497 | data: $('#bulk_edit_form').serialize() | |
497 | }); |
|
498 | }); | |
498 | } |
|
499 | } | |
499 |
|
500 | |||
500 | function observeAutocompleteField(fieldId, url, options) { |
|
501 | function observeAutocompleteField(fieldId, url, options) { | |
501 | $(document).ready(function() { |
|
502 | $(document).ready(function() { | |
502 | $('#'+fieldId).autocomplete($.extend({ |
|
503 | $('#'+fieldId).autocomplete($.extend({ | |
503 | source: url, |
|
504 | source: url, | |
504 | minLength: 2, |
|
505 | minLength: 2, | |
505 | search: function(){$('#'+fieldId).addClass('ajax-loading');}, |
|
506 | search: function(){$('#'+fieldId).addClass('ajax-loading');}, | |
506 | response: function(){$('#'+fieldId).removeClass('ajax-loading');} |
|
507 | response: function(){$('#'+fieldId).removeClass('ajax-loading');} | |
507 | }, options)); |
|
508 | }, options)); | |
508 | $('#'+fieldId).addClass('autocomplete'); |
|
509 | $('#'+fieldId).addClass('autocomplete'); | |
509 | }); |
|
510 | }); | |
510 | } |
|
511 | } | |
511 |
|
512 | |||
512 | function observeSearchfield(fieldId, targetId, url) { |
|
513 | function observeSearchfield(fieldId, targetId, url) { | |
513 | $('#'+fieldId).each(function() { |
|
514 | $('#'+fieldId).each(function() { | |
514 | var $this = $(this); |
|
515 | var $this = $(this); | |
515 | $this.addClass('autocomplete'); |
|
516 | $this.addClass('autocomplete'); | |
516 | $this.attr('data-value-was', $this.val()); |
|
517 | $this.attr('data-value-was', $this.val()); | |
517 | var check = function() { |
|
518 | var check = function() { | |
518 | var val = $this.val(); |
|
519 | var val = $this.val(); | |
519 | if ($this.attr('data-value-was') != val){ |
|
520 | if ($this.attr('data-value-was') != val){ | |
520 | $this.attr('data-value-was', val); |
|
521 | $this.attr('data-value-was', val); | |
521 | $.ajax({ |
|
522 | $.ajax({ | |
522 | url: url, |
|
523 | url: url, | |
523 | type: 'get', |
|
524 | type: 'get', | |
524 | data: {q: $this.val()}, |
|
525 | data: {q: $this.val()}, | |
525 | success: function(data){ if(targetId) $('#'+targetId).html(data); }, |
|
526 | success: function(data){ if(targetId) $('#'+targetId).html(data); }, | |
526 | beforeSend: function(){ $this.addClass('ajax-loading'); }, |
|
527 | beforeSend: function(){ $this.addClass('ajax-loading'); }, | |
527 | complete: function(){ $this.removeClass('ajax-loading'); } |
|
528 | complete: function(){ $this.removeClass('ajax-loading'); } | |
528 | }); |
|
529 | }); | |
529 | } |
|
530 | } | |
530 | }; |
|
531 | }; | |
531 | var reset = function() { |
|
532 | var reset = function() { | |
532 | if (timer) { |
|
533 | if (timer) { | |
533 | clearInterval(timer); |
|
534 | clearInterval(timer); | |
534 | timer = setInterval(check, 300); |
|
535 | timer = setInterval(check, 300); | |
535 | } |
|
536 | } | |
536 | }; |
|
537 | }; | |
537 | var timer = setInterval(check, 300); |
|
538 | var timer = setInterval(check, 300); | |
538 | $this.bind('keyup click mousemove', reset); |
|
539 | $this.bind('keyup click mousemove', reset); | |
539 | }); |
|
540 | }); | |
540 | } |
|
541 | } | |
541 |
|
542 | |||
542 | function beforeShowDatePicker(input, inst) { |
|
543 | function beforeShowDatePicker(input, inst) { | |
543 | var default_date = null; |
|
544 | var default_date = null; | |
544 | switch ($(input).attr("id")) { |
|
545 | switch ($(input).attr("id")) { | |
545 | case "issue_start_date" : |
|
546 | case "issue_start_date" : | |
546 | if ($("#issue_due_date").size() > 0) { |
|
547 | if ($("#issue_due_date").size() > 0) { | |
547 | default_date = $("#issue_due_date").val(); |
|
548 | default_date = $("#issue_due_date").val(); | |
548 | } |
|
549 | } | |
549 | break; |
|
550 | break; | |
550 | case "issue_due_date" : |
|
551 | case "issue_due_date" : | |
551 | if ($("#issue_start_date").size() > 0) { |
|
552 | if ($("#issue_start_date").size() > 0) { | |
552 | default_date = $("#issue_start_date").val(); |
|
553 | default_date = $("#issue_start_date").val(); | |
553 | } |
|
554 | } | |
554 | break; |
|
555 | break; | |
555 | } |
|
556 | } | |
556 | $(input).datepicker("option", "defaultDate", default_date); |
|
557 | $(input).datepicker("option", "defaultDate", default_date); | |
557 | } |
|
558 | } | |
558 |
|
559 | |||
559 | function initMyPageSortable(list, url) { |
|
560 | function initMyPageSortable(list, url) { | |
560 | $('#list-'+list).sortable({ |
|
561 | $('#list-'+list).sortable({ | |
561 | connectWith: '.block-receiver', |
|
562 | connectWith: '.block-receiver', | |
562 | tolerance: 'pointer', |
|
563 | tolerance: 'pointer', | |
563 | update: function(){ |
|
564 | update: function(){ | |
564 | $.ajax({ |
|
565 | $.ajax({ | |
565 | url: url, |
|
566 | url: url, | |
566 | type: 'post', |
|
567 | type: 'post', | |
567 | data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})} |
|
568 | data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})} | |
568 | }); |
|
569 | }); | |
569 | } |
|
570 | } | |
570 | }); |
|
571 | }); | |
571 | $("#list-top, #list-left, #list-right").disableSelection(); |
|
572 | $("#list-top, #list-left, #list-right").disableSelection(); | |
572 | } |
|
573 | } | |
573 |
|
574 | |||
574 | var warnLeavingUnsavedMessage; |
|
575 | var warnLeavingUnsavedMessage; | |
575 | function warnLeavingUnsaved(message) { |
|
576 | function warnLeavingUnsaved(message) { | |
576 | warnLeavingUnsavedMessage = message; |
|
577 | warnLeavingUnsavedMessage = message; | |
577 | $(document).on('submit', 'form', function(){ |
|
578 | $(document).on('submit', 'form', function(){ | |
578 | $('textarea').removeData('changed'); |
|
579 | $('textarea').removeData('changed'); | |
579 | }); |
|
580 | }); | |
580 | $(document).on('change', 'textarea', function(){ |
|
581 | $(document).on('change', 'textarea', function(){ | |
581 | $(this).data('changed', 'changed'); |
|
582 | $(this).data('changed', 'changed'); | |
582 | }); |
|
583 | }); | |
583 | window.onbeforeunload = function(){ |
|
584 | window.onbeforeunload = function(){ | |
584 | var warn = false; |
|
585 | var warn = false; | |
585 | $('textarea').blur().each(function(){ |
|
586 | $('textarea').blur().each(function(){ | |
586 | if ($(this).data('changed')) { |
|
587 | if ($(this).data('changed')) { | |
587 | warn = true; |
|
588 | warn = true; | |
588 | } |
|
589 | } | |
589 | }); |
|
590 | }); | |
590 | if (warn) {return warnLeavingUnsavedMessage;} |
|
591 | if (warn) {return warnLeavingUnsavedMessage;} | |
591 | }; |
|
592 | }; | |
592 | } |
|
593 | } | |
593 |
|
594 | |||
594 | function setupAjaxIndicator() { |
|
595 | function setupAjaxIndicator() { | |
595 | $(document).bind('ajaxSend', function(event, xhr, settings) { |
|
596 | $(document).bind('ajaxSend', function(event, xhr, settings) { | |
596 | if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') { |
|
597 | if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') { | |
597 | $('#ajax-indicator').show(); |
|
598 | $('#ajax-indicator').show(); | |
598 | } |
|
599 | } | |
599 | }); |
|
600 | }); | |
600 | $(document).bind('ajaxStop', function() { |
|
601 | $(document).bind('ajaxStop', function() { | |
601 | $('#ajax-indicator').hide(); |
|
602 | $('#ajax-indicator').hide(); | |
602 | }); |
|
603 | }); | |
603 | } |
|
604 | } | |
604 |
|
605 | |||
605 | function hideOnLoad() { |
|
606 | function hideOnLoad() { | |
606 | $('.hol').hide(); |
|
607 | $('.hol').hide(); | |
607 | } |
|
608 | } | |
608 |
|
609 | |||
609 | function addFormObserversForDoubleSubmit() { |
|
610 | function addFormObserversForDoubleSubmit() { | |
610 | $('form[method=post]').each(function() { |
|
611 | $('form[method=post]').each(function() { | |
611 | if (!$(this).hasClass('multiple-submit')) { |
|
612 | if (!$(this).hasClass('multiple-submit')) { | |
612 | $(this).submit(function(form_submission) { |
|
613 | $(this).submit(function(form_submission) { | |
613 | if ($(form_submission.target).attr('data-submitted')) { |
|
614 | if ($(form_submission.target).attr('data-submitted')) { | |
614 | form_submission.preventDefault(); |
|
615 | form_submission.preventDefault(); | |
615 | } else { |
|
616 | } else { | |
616 | $(form_submission.target).attr('data-submitted', true); |
|
617 | $(form_submission.target).attr('data-submitted', true); | |
617 | } |
|
618 | } | |
618 | }); |
|
619 | }); | |
619 | } |
|
620 | } | |
620 | }); |
|
621 | }); | |
621 | } |
|
622 | } | |
622 |
|
623 | |||
623 | function defaultFocus(){ |
|
624 | function defaultFocus(){ | |
624 | if ($('#content :focus').length == 0) { |
|
625 | if ($('#content :focus').length == 0) { | |
625 | $('#content input[type=text], #content textarea').first().focus(); |
|
626 | $('#content input[type=text], #content textarea').first().focus(); | |
626 | } |
|
627 | } | |
627 | } |
|
628 | } | |
628 |
|
629 | |||
629 | function blockEventPropagation(event) { |
|
630 | function blockEventPropagation(event) { | |
630 | event.stopPropagation(); |
|
631 | event.stopPropagation(); | |
631 | event.preventDefault(); |
|
632 | event.preventDefault(); | |
632 | } |
|
633 | } | |
633 |
|
634 | |||
634 | function toggleDisabledOnChange() { |
|
635 | function toggleDisabledOnChange() { | |
635 | var checked = $(this).is(':checked'); |
|
636 | var checked = $(this).is(':checked'); | |
636 | $($(this).data('disables')).attr('disabled', checked); |
|
637 | $($(this).data('disables')).attr('disabled', checked); | |
637 | $($(this).data('enables')).attr('disabled', !checked); |
|
638 | $($(this).data('enables')).attr('disabled', !checked); | |
638 | } |
|
639 | } | |
639 | function toggleDisabledInit() { |
|
640 | function toggleDisabledInit() { | |
640 | $('input[data-disables], input[data-enables]').each(toggleDisabledOnChange); |
|
641 | $('input[data-disables], input[data-enables]').each(toggleDisabledOnChange); | |
641 | } |
|
642 | } | |
642 | $(document).ready(function(){ |
|
643 | $(document).ready(function(){ | |
643 | $('#content').on('change', 'input[data-disables], input[data-enables]', toggleDisabledOnChange); |
|
644 | $('#content').on('change', 'input[data-disables], input[data-enables]', toggleDisabledOnChange); | |
644 | toggleDisabledInit(); |
|
645 | toggleDisabledInit(); | |
645 | }); |
|
646 | }); | |
646 |
|
647 | |||
647 | $(document).ready(setupAjaxIndicator); |
|
648 | $(document).ready(setupAjaxIndicator); | |
648 | $(document).ready(hideOnLoad); |
|
649 | $(document).ready(hideOnLoad); | |
649 | $(document).ready(addFormObserversForDoubleSubmit); |
|
650 | $(document).ready(addFormObserversForDoubleSubmit); | |
650 | $(document).ready(defaultFocus); |
|
651 | $(document).ready(defaultFocus); | |
651 |
|
652 |
General Comments 0
You need to be logged in to leave comments.
Login now