##// END OF EJS Templates
Fixed that autocomplete results are not reset after clearing search field (#11909)....
Jean-Philippe Lang -
r10317:8cf8f5bdbfe0
parent child
Show More
@@ -1,602 +1,600
1 /* Redmine - project management software
1 /* Redmine - project management software
2 Copyright (C) 2006-2012 Jean-Philippe Lang */
2 Copyright (C) 2006-2012 Jean-Philippe Lang */
3
3
4 function checkAll(id, checked) {
4 function checkAll(id, checked) {
5 if (checked) {
5 if (checked) {
6 $('#'+id).find('input[type=checkbox]').attr('checked', true);
6 $('#'+id).find('input[type=checkbox]').attr('checked', true);
7 } else {
7 } else {
8 $('#'+id).find('input[type=checkbox]').removeAttr('checked');
8 $('#'+id).find('input[type=checkbox]').removeAttr('checked');
9 }
9 }
10 }
10 }
11
11
12 function toggleCheckboxesBySelector(selector) {
12 function toggleCheckboxesBySelector(selector) {
13 var all_checked = true;
13 var all_checked = true;
14 $(selector).each(function(index) {
14 $(selector).each(function(index) {
15 if (!$(this).is(':checked')) { all_checked = false; }
15 if (!$(this).is(':checked')) { all_checked = false; }
16 });
16 });
17 $(selector).attr('checked', !all_checked)
17 $(selector).attr('checked', !all_checked)
18 }
18 }
19
19
20 function showAndScrollTo(id, focus) {
20 function showAndScrollTo(id, focus) {
21 $('#'+id).show();
21 $('#'+id).show();
22 if (focus!=null) {
22 if (focus!=null) {
23 $('#'+focus).focus();
23 $('#'+focus).focus();
24 }
24 }
25 $('html, body').animate({scrollTop: $('#'+id).offset().top}, 100);
25 $('html, body').animate({scrollTop: $('#'+id).offset().top}, 100);
26 }
26 }
27
27
28 function toggleRowGroup(el) {
28 function toggleRowGroup(el) {
29 var tr = $(el).parents('tr').first();
29 var tr = $(el).parents('tr').first();
30 var n = tr.next();
30 var n = tr.next();
31 tr.toggleClass('open');
31 tr.toggleClass('open');
32 while (n.length && !n.hasClass('group')) {
32 while (n.length && !n.hasClass('group')) {
33 n.toggle();
33 n.toggle();
34 n = n.next('tr');
34 n = n.next('tr');
35 }
35 }
36 }
36 }
37
37
38 function collapseAllRowGroups(el) {
38 function collapseAllRowGroups(el) {
39 var tbody = $(el).parents('tbody').first();
39 var tbody = $(el).parents('tbody').first();
40 tbody.children('tr').each(function(index) {
40 tbody.children('tr').each(function(index) {
41 if ($(this).hasClass('group')) {
41 if ($(this).hasClass('group')) {
42 $(this).removeClass('open');
42 $(this).removeClass('open');
43 } else {
43 } else {
44 $(this).hide();
44 $(this).hide();
45 }
45 }
46 });
46 });
47 }
47 }
48
48
49 function expandAllRowGroups(el) {
49 function expandAllRowGroups(el) {
50 var tbody = $(el).parents('tbody').first();
50 var tbody = $(el).parents('tbody').first();
51 tbody.children('tr').each(function(index) {
51 tbody.children('tr').each(function(index) {
52 if ($(this).hasClass('group')) {
52 if ($(this).hasClass('group')) {
53 $(this).addClass('open');
53 $(this).addClass('open');
54 } else {
54 } else {
55 $(this).show();
55 $(this).show();
56 }
56 }
57 });
57 });
58 }
58 }
59
59
60 function toggleAllRowGroups(el) {
60 function toggleAllRowGroups(el) {
61 var tr = $(el).parents('tr').first();
61 var tr = $(el).parents('tr').first();
62 if (tr.hasClass('open')) {
62 if (tr.hasClass('open')) {
63 collapseAllRowGroups(el);
63 collapseAllRowGroups(el);
64 } else {
64 } else {
65 expandAllRowGroups(el);
65 expandAllRowGroups(el);
66 }
66 }
67 }
67 }
68
68
69 function toggleFieldset(el) {
69 function toggleFieldset(el) {
70 var fieldset = $(el).parents('fieldset').first();
70 var fieldset = $(el).parents('fieldset').first();
71 fieldset.toggleClass('collapsed');
71 fieldset.toggleClass('collapsed');
72 fieldset.children('div').toggle();
72 fieldset.children('div').toggle();
73 }
73 }
74
74
75 function hideFieldset(el) {
75 function hideFieldset(el) {
76 var fieldset = $(el).parents('fieldset').first();
76 var fieldset = $(el).parents('fieldset').first();
77 fieldset.toggleClass('collapsed');
77 fieldset.toggleClass('collapsed');
78 fieldset.children('div').hide();
78 fieldset.children('div').hide();
79 }
79 }
80
80
81 function initFilters(){
81 function initFilters(){
82 $('#add_filter_select').change(function(){
82 $('#add_filter_select').change(function(){
83 addFilter($(this).val(), '', []);
83 addFilter($(this).val(), '', []);
84 });
84 });
85 $('#filters-table td.field input[type=checkbox]').each(function(){
85 $('#filters-table td.field input[type=checkbox]').each(function(){
86 toggleFilter($(this).val());
86 toggleFilter($(this).val());
87 });
87 });
88 $('#filters-table td.field input[type=checkbox]').live('click',function(){
88 $('#filters-table td.field input[type=checkbox]').live('click',function(){
89 toggleFilter($(this).val());
89 toggleFilter($(this).val());
90 });
90 });
91 $('#filters-table .toggle-multiselect').live('click',function(){
91 $('#filters-table .toggle-multiselect').live('click',function(){
92 toggleMultiSelect($(this).siblings('select'));
92 toggleMultiSelect($(this).siblings('select'));
93 });
93 });
94 $('#filters-table input[type=text]').live('keypress', function(e){
94 $('#filters-table input[type=text]').live('keypress', function(e){
95 if (e.keyCode == 13) submit_query_form("query_form");
95 if (e.keyCode == 13) submit_query_form("query_form");
96 });
96 });
97 }
97 }
98
98
99 function addFilter(field, operator, values) {
99 function addFilter(field, operator, values) {
100 var fieldId = field.replace('.', '_');
100 var fieldId = field.replace('.', '_');
101 var tr = $('#tr_'+fieldId);
101 var tr = $('#tr_'+fieldId);
102 if (tr.length > 0) {
102 if (tr.length > 0) {
103 tr.show();
103 tr.show();
104 } else {
104 } else {
105 buildFilterRow(field, operator, values);
105 buildFilterRow(field, operator, values);
106 }
106 }
107 $('#cb_'+fieldId).attr('checked', true);
107 $('#cb_'+fieldId).attr('checked', true);
108 toggleFilter(field);
108 toggleFilter(field);
109 $('#add_filter_select').val('').children('option').each(function(){
109 $('#add_filter_select').val('').children('option').each(function(){
110 if ($(this).attr('value') == field) {
110 if ($(this).attr('value') == field) {
111 $(this).attr('disabled', true);
111 $(this).attr('disabled', true);
112 }
112 }
113 });
113 });
114 }
114 }
115
115
116 function buildFilterRow(field, operator, values) {
116 function buildFilterRow(field, operator, values) {
117 var fieldId = field.replace('.', '_');
117 var fieldId = field.replace('.', '_');
118 var filterTable = $("#filters-table");
118 var filterTable = $("#filters-table");
119 var filterOptions = availableFilters[field];
119 var filterOptions = availableFilters[field];
120 var operators = operatorByType[filterOptions['type']];
120 var operators = operatorByType[filterOptions['type']];
121 var filterValues = filterOptions['values'];
121 var filterValues = filterOptions['values'];
122 var i, select;
122 var i, select;
123
123
124 var tr = $('<tr class="filter">').attr('id', 'tr_'+fieldId).html(
124 var tr = $('<tr class="filter">').attr('id', 'tr_'+fieldId).html(
125 '<td class="field"><input checked="checked" id="cb_'+fieldId+'" name="f[]" value="'+field+'" type="checkbox"><label for="cb_'+fieldId+'"> '+filterOptions['name']+'</label></td>' +
125 '<td class="field"><input checked="checked" id="cb_'+fieldId+'" name="f[]" value="'+field+'" type="checkbox"><label for="cb_'+fieldId+'"> '+filterOptions['name']+'</label></td>' +
126 '<td class="operator"><select id="operators_'+fieldId+'" name="op['+field+']"></td>' +
126 '<td class="operator"><select id="operators_'+fieldId+'" name="op['+field+']"></td>' +
127 '<td class="values"></td>'
127 '<td class="values"></td>'
128 );
128 );
129 filterTable.append(tr);
129 filterTable.append(tr);
130
130
131 select = tr.find('td.operator select');
131 select = tr.find('td.operator select');
132 for (i=0;i<operators.length;i++){
132 for (i=0;i<operators.length;i++){
133 var option = $('<option>').val(operators[i]).text(operatorLabels[operators[i]]);
133 var option = $('<option>').val(operators[i]).text(operatorLabels[operators[i]]);
134 if (operators[i] == operator) {option.attr('selected', true)};
134 if (operators[i] == operator) {option.attr('selected', true)};
135 select.append(option);
135 select.append(option);
136 }
136 }
137 select.change(function(){toggleOperator(field)});
137 select.change(function(){toggleOperator(field)});
138
138
139 switch (filterOptions['type']){
139 switch (filterOptions['type']){
140 case "list":
140 case "list":
141 case "list_optional":
141 case "list_optional":
142 case "list_status":
142 case "list_status":
143 case "list_subprojects":
143 case "list_subprojects":
144 tr.find('td.values').append(
144 tr.find('td.values').append(
145 '<span style="display:none;"><select class="value" id="values_'+fieldId+'_1" name="v['+field+'][]"></select>' +
145 '<span style="display:none;"><select class="value" id="values_'+fieldId+'_1" name="v['+field+'][]"></select>' +
146 ' <span class="toggle-multiselect">&nbsp;</span></span>'
146 ' <span class="toggle-multiselect">&nbsp;</span></span>'
147 );
147 );
148 select = tr.find('td.values select');
148 select = tr.find('td.values select');
149 if (values.length > 1) {select.attr('multiple', true)};
149 if (values.length > 1) {select.attr('multiple', true)};
150 for (i=0;i<filterValues.length;i++){
150 for (i=0;i<filterValues.length;i++){
151 var filterValue = filterValues[i];
151 var filterValue = filterValues[i];
152 var option = $('<option>');
152 var option = $('<option>');
153 if ($.isArray(filterValue)) {
153 if ($.isArray(filterValue)) {
154 option.val(filterValue[1]).text(filterValue[0]);
154 option.val(filterValue[1]).text(filterValue[0]);
155 if ($.inArray(filterValue[1], values) > -1) {option.attr('selected', true);}
155 if ($.inArray(filterValue[1], values) > -1) {option.attr('selected', true);}
156 } else {
156 } else {
157 option.val(filterValue).text(filterValue);
157 option.val(filterValue).text(filterValue);
158 if ($.inArray(filterValue, values) > -1) {option.attr('selected', true);}
158 if ($.inArray(filterValue, values) > -1) {option.attr('selected', true);}
159 }
159 }
160 select.append(option);
160 select.append(option);
161 }
161 }
162 break;
162 break;
163 case "date":
163 case "date":
164 case "date_past":
164 case "date_past":
165 tr.find('td.values').append(
165 tr.find('td.values').append(
166 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="10" class="value date_value" /></span>' +
166 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="10" class="value date_value" /></span>' +
167 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="10" class="value date_value" /></span>' +
167 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="10" class="value date_value" /></span>' +
168 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="3" class="value" /> '+labelDayPlural+'</span>'
168 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="3" class="value" /> '+labelDayPlural+'</span>'
169 );
169 );
170 $('#values_'+fieldId+'_1').val(values[0]).datepicker(datepickerOptions);
170 $('#values_'+fieldId+'_1').val(values[0]).datepicker(datepickerOptions);
171 $('#values_'+fieldId+'_2').val(values[1]).datepicker(datepickerOptions);
171 $('#values_'+fieldId+'_2').val(values[1]).datepicker(datepickerOptions);
172 $('#values_'+fieldId).val(values[0]);
172 $('#values_'+fieldId).val(values[0]);
173 break;
173 break;
174 case "string":
174 case "string":
175 case "text":
175 case "text":
176 tr.find('td.values').append(
176 tr.find('td.values').append(
177 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="30" class="value" /></span>'
177 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="30" class="value" /></span>'
178 );
178 );
179 $('#values_'+fieldId).val(values[0]);
179 $('#values_'+fieldId).val(values[0]);
180 break;
180 break;
181 case "relation":
181 case "relation":
182 tr.find('td.values').append(
182 tr.find('td.values').append(
183 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="6" class="value" /></span>' +
183 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="6" class="value" /></span>' +
184 '<span style="display:none;"><select class="value" name="v['+field+'][]" id="values_'+fieldId+'_1"></select></span>'
184 '<span style="display:none;"><select class="value" name="v['+field+'][]" id="values_'+fieldId+'_1"></select></span>'
185 );
185 );
186 $('#values_'+fieldId).val(values[0]);
186 $('#values_'+fieldId).val(values[0]);
187 select = tr.find('td.values select');
187 select = tr.find('td.values select');
188 for (i=0;i<allProjects.length;i++){
188 for (i=0;i<allProjects.length;i++){
189 var filterValue = allProjects[i];
189 var filterValue = allProjects[i];
190 var option = $('<option>');
190 var option = $('<option>');
191 option.val(filterValue[1]).text(filterValue[0]);
191 option.val(filterValue[1]).text(filterValue[0]);
192 if (values[0] == filterValue[1]) {option.attr('selected', true)};
192 if (values[0] == filterValue[1]) {option.attr('selected', true)};
193 select.append(option);
193 select.append(option);
194 }
194 }
195 case "integer":
195 case "integer":
196 case "float":
196 case "float":
197 tr.find('td.values').append(
197 tr.find('td.values').append(
198 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' +
198 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' +
199 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>'
199 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>'
200 );
200 );
201 $('#values_'+fieldId+'_1').val(values[0]);
201 $('#values_'+fieldId+'_1').val(values[0]);
202 $('#values_'+fieldId+'_2').val(values[1]);
202 $('#values_'+fieldId+'_2').val(values[1]);
203 break;
203 break;
204 }
204 }
205 }
205 }
206
206
207 function toggleFilter(field) {
207 function toggleFilter(field) {
208 var fieldId = field.replace('.', '_');
208 var fieldId = field.replace('.', '_');
209 if ($('#cb_' + fieldId).is(':checked')) {
209 if ($('#cb_' + fieldId).is(':checked')) {
210 $("#operators_" + fieldId).show().removeAttr('disabled');
210 $("#operators_" + fieldId).show().removeAttr('disabled');
211 toggleOperator(field);
211 toggleOperator(field);
212 } else {
212 } else {
213 $("#operators_" + fieldId).hide().attr('disabled', true);
213 $("#operators_" + fieldId).hide().attr('disabled', true);
214 enableValues(field, []);
214 enableValues(field, []);
215 }
215 }
216 }
216 }
217
217
218 function enableValues(field, indexes) {
218 function enableValues(field, indexes) {
219 var fieldId = field.replace('.', '_');
219 var fieldId = field.replace('.', '_');
220 $('#tr_'+fieldId+' td.values .value').each(function(index) {
220 $('#tr_'+fieldId+' td.values .value').each(function(index) {
221 if ($.inArray(index, indexes) >= 0) {
221 if ($.inArray(index, indexes) >= 0) {
222 $(this).removeAttr('disabled');
222 $(this).removeAttr('disabled');
223 $(this).parents('span').first().show();
223 $(this).parents('span').first().show();
224 } else {
224 } else {
225 $(this).val('');
225 $(this).val('');
226 $(this).attr('disabled', true);
226 $(this).attr('disabled', true);
227 $(this).parents('span').first().hide();
227 $(this).parents('span').first().hide();
228 }
228 }
229
229
230 if ($(this).hasClass('group')) {
230 if ($(this).hasClass('group')) {
231 $(this).addClass('open');
231 $(this).addClass('open');
232 } else {
232 } else {
233 $(this).show();
233 $(this).show();
234 }
234 }
235 });
235 });
236 }
236 }
237
237
238 function toggleOperator(field) {
238 function toggleOperator(field) {
239 var fieldId = field.replace('.', '_');
239 var fieldId = field.replace('.', '_');
240 var operator = $("#operators_" + fieldId);
240 var operator = $("#operators_" + fieldId);
241 switch (operator.val()) {
241 switch (operator.val()) {
242 case "!*":
242 case "!*":
243 case "*":
243 case "*":
244 case "t":
244 case "t":
245 case "w":
245 case "w":
246 case "o":
246 case "o":
247 case "c":
247 case "c":
248 enableValues(field, []);
248 enableValues(field, []);
249 break;
249 break;
250 case "><":
250 case "><":
251 enableValues(field, [0,1]);
251 enableValues(field, [0,1]);
252 break;
252 break;
253 case "<t+":
253 case "<t+":
254 case ">t+":
254 case ">t+":
255 case "t+":
255 case "t+":
256 case ">t-":
256 case ">t-":
257 case "<t-":
257 case "<t-":
258 case "t-":
258 case "t-":
259 enableValues(field, [2]);
259 enableValues(field, [2]);
260 break;
260 break;
261 case "=p":
261 case "=p":
262 case "=!p":
262 case "=!p":
263 enableValues(field, [1]);
263 enableValues(field, [1]);
264 break;
264 break;
265 default:
265 default:
266 enableValues(field, [0]);
266 enableValues(field, [0]);
267 break;
267 break;
268 }
268 }
269 }
269 }
270
270
271 function toggleMultiSelect(el) {
271 function toggleMultiSelect(el) {
272 if (el.attr('multiple')) {
272 if (el.attr('multiple')) {
273 el.removeAttr('multiple');
273 el.removeAttr('multiple');
274 } else {
274 } else {
275 el.attr('multiple', true);
275 el.attr('multiple', true);
276 }
276 }
277 }
277 }
278
278
279 function submit_query_form(id) {
279 function submit_query_form(id) {
280 selectAllOptions("selected_columns");
280 selectAllOptions("selected_columns");
281 $('#'+id).submit();
281 $('#'+id).submit();
282 }
282 }
283
283
284 var fileFieldCount = 1;
284 var fileFieldCount = 1;
285 function addFileField() {
285 function addFileField() {
286 var fields = $('#attachments_fields');
286 var fields = $('#attachments_fields');
287 if (fields.children().length >= 10) return false;
287 if (fields.children().length >= 10) return false;
288 fileFieldCount++;
288 fileFieldCount++;
289 var s = fields.children('span').first().clone();
289 var s = fields.children('span').first().clone();
290 s.children('input.file').attr('name', "attachments[" + fileFieldCount + "][file]").val('');
290 s.children('input.file').attr('name', "attachments[" + fileFieldCount + "][file]").val('');
291 s.children('input.description').attr('name', "attachments[" + fileFieldCount + "][description]").val('');
291 s.children('input.description').attr('name', "attachments[" + fileFieldCount + "][description]").val('');
292 fields.append(s);
292 fields.append(s);
293 }
293 }
294
294
295 function removeFileField(el) {
295 function removeFileField(el) {
296 var fields = $('#attachments_fields');
296 var fields = $('#attachments_fields');
297 var s = $(el).parents('span').first();
297 var s = $(el).parents('span').first();
298 if (fields.children().length > 1) {
298 if (fields.children().length > 1) {
299 s.remove();
299 s.remove();
300 } else {
300 } else {
301 s.children('input.file').val('');
301 s.children('input.file').val('');
302 s.children('input.description').val('');
302 s.children('input.description').val('');
303 }
303 }
304 }
304 }
305
305
306 function checkFileSize(el, maxSize, message) {
306 function checkFileSize(el, maxSize, message) {
307 var files = el.files;
307 var files = el.files;
308 if (files) {
308 if (files) {
309 for (var i=0; i<files.length; i++) {
309 for (var i=0; i<files.length; i++) {
310 if (files[i].size > maxSize) {
310 if (files[i].size > maxSize) {
311 alert(message);
311 alert(message);
312 el.value = "";
312 el.value = "";
313 }
313 }
314 }
314 }
315 }
315 }
316 }
316 }
317
317
318 function showTab(name) {
318 function showTab(name) {
319 $('div#content .tab-content').hide();
319 $('div#content .tab-content').hide();
320 $('div.tabs a').removeClass('selected');
320 $('div.tabs a').removeClass('selected');
321 $('#tab-content-' + name).show();
321 $('#tab-content-' + name).show();
322 $('#tab-' + name).addClass('selected');
322 $('#tab-' + name).addClass('selected');
323 return false;
323 return false;
324 }
324 }
325
325
326 function moveTabRight(el) {
326 function moveTabRight(el) {
327 var lis = $(el).parents('div.tabs').first().find('ul').children();
327 var lis = $(el).parents('div.tabs').first().find('ul').children();
328 var tabsWidth = 0;
328 var tabsWidth = 0;
329 var i = 0;
329 var i = 0;
330 lis.each(function(){
330 lis.each(function(){
331 if ($(this).is(':visible')) {
331 if ($(this).is(':visible')) {
332 tabsWidth += $(this).width() + 6;
332 tabsWidth += $(this).width() + 6;
333 }
333 }
334 });
334 });
335 if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; }
335 if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; }
336 while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
336 while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
337 lis.eq(i).hide();
337 lis.eq(i).hide();
338 }
338 }
339
339
340 function moveTabLeft(el) {
340 function moveTabLeft(el) {
341 var lis = $(el).parents('div.tabs').first().find('ul').children();
341 var lis = $(el).parents('div.tabs').first().find('ul').children();
342 var i = 0;
342 var i = 0;
343 while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
343 while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
344 if (i>0) {
344 if (i>0) {
345 lis.eq(i-1).show();
345 lis.eq(i-1).show();
346 }
346 }
347 }
347 }
348
348
349 function displayTabsButtons() {
349 function displayTabsButtons() {
350 var lis;
350 var lis;
351 var tabsWidth = 0;
351 var tabsWidth = 0;
352 var el;
352 var el;
353 $('div.tabs').each(function() {
353 $('div.tabs').each(function() {
354 el = $(this);
354 el = $(this);
355 lis = el.find('ul').children();
355 lis = el.find('ul').children();
356 lis.each(function(){
356 lis.each(function(){
357 if ($(this).is(':visible')) {
357 if ($(this).is(':visible')) {
358 tabsWidth += $(this).width() + 6;
358 tabsWidth += $(this).width() + 6;
359 }
359 }
360 });
360 });
361 if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) {
361 if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) {
362 el.find('div.tabs-buttons').hide();
362 el.find('div.tabs-buttons').hide();
363 } else {
363 } else {
364 el.find('div.tabs-buttons').show();
364 el.find('div.tabs-buttons').show();
365 }
365 }
366 });
366 });
367 }
367 }
368
368
369 function setPredecessorFieldsVisibility() {
369 function setPredecessorFieldsVisibility() {
370 var relationType = $('#relation_relation_type');
370 var relationType = $('#relation_relation_type');
371 if (relationType.val() == "precedes" || relationType.val() == "follows") {
371 if (relationType.val() == "precedes" || relationType.val() == "follows") {
372 $('#predecessor_fields').show();
372 $('#predecessor_fields').show();
373 } else {
373 } else {
374 $('#predecessor_fields').hide();
374 $('#predecessor_fields').hide();
375 }
375 }
376 }
376 }
377
377
378 function showModal(id, width) {
378 function showModal(id, width) {
379 var el = $('#'+id).first();
379 var el = $('#'+id).first();
380 if (el.length == 0 || el.is(':visible')) {return;}
380 if (el.length == 0 || el.is(':visible')) {return;}
381 var title = el.find('h3.title').text();
381 var title = el.find('h3.title').text();
382 el.dialog({
382 el.dialog({
383 width: width,
383 width: width,
384 modal: true,
384 modal: true,
385 resizable: false,
385 resizable: false,
386 dialogClass: 'modal',
386 dialogClass: 'modal',
387 title: title
387 title: title
388 });
388 });
389 el.find("input[type=text], input[type=submit]").first().focus();
389 el.find("input[type=text], input[type=submit]").first().focus();
390 }
390 }
391
391
392 function hideModal(el) {
392 function hideModal(el) {
393 var modal;
393 var modal;
394 if (el) {
394 if (el) {
395 modal = $(el).parents('.ui-dialog-content');
395 modal = $(el).parents('.ui-dialog-content');
396 } else {
396 } else {
397 modal = $('#ajax-modal');
397 modal = $('#ajax-modal');
398 }
398 }
399 modal.dialog("close");
399 modal.dialog("close");
400 }
400 }
401
401
402 function submitPreview(url, form, target) {
402 function submitPreview(url, form, target) {
403 $.ajax({
403 $.ajax({
404 url: url,
404 url: url,
405 type: 'post',
405 type: 'post',
406 data: $('#'+form).serialize(),
406 data: $('#'+form).serialize(),
407 success: function(data){
407 success: function(data){
408 $('#'+target).html(data);
408 $('#'+target).html(data);
409 }
409 }
410 });
410 });
411 }
411 }
412
412
413 function collapseScmEntry(id) {
413 function collapseScmEntry(id) {
414 $('.'+id).each(function() {
414 $('.'+id).each(function() {
415 if ($(this).hasClass('open')) {
415 if ($(this).hasClass('open')) {
416 collapseScmEntry($(this).attr('id'));
416 collapseScmEntry($(this).attr('id'));
417 }
417 }
418 $(this).hide();
418 $(this).hide();
419 });
419 });
420 $('#'+id).removeClass('open');
420 $('#'+id).removeClass('open');
421 }
421 }
422
422
423 function expandScmEntry(id) {
423 function expandScmEntry(id) {
424 $('.'+id).each(function() {
424 $('.'+id).each(function() {
425 $(this).show();
425 $(this).show();
426 if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) {
426 if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) {
427 expandScmEntry($(this).attr('id'));
427 expandScmEntry($(this).attr('id'));
428 }
428 }
429 });
429 });
430 $('#'+id).addClass('open');
430 $('#'+id).addClass('open');
431 }
431 }
432
432
433 function scmEntryClick(id, url) {
433 function scmEntryClick(id, url) {
434 el = $('#'+id);
434 el = $('#'+id);
435 if (el.hasClass('open')) {
435 if (el.hasClass('open')) {
436 collapseScmEntry(id);
436 collapseScmEntry(id);
437 el.addClass('collapsed');
437 el.addClass('collapsed');
438 return false;
438 return false;
439 } else if (el.hasClass('loaded')) {
439 } else if (el.hasClass('loaded')) {
440 expandScmEntry(id);
440 expandScmEntry(id);
441 el.removeClass('collapsed');
441 el.removeClass('collapsed');
442 return false;
442 return false;
443 }
443 }
444 if (el.hasClass('loading')) {
444 if (el.hasClass('loading')) {
445 return false;
445 return false;
446 }
446 }
447 el.addClass('loading');
447 el.addClass('loading');
448 $.ajax({
448 $.ajax({
449 url: url,
449 url: url,
450 success: function(data){
450 success: function(data){
451 el.after(data);
451 el.after(data);
452 el.addClass('open').addClass('loaded').removeClass('loading');
452 el.addClass('open').addClass('loaded').removeClass('loading');
453 }
453 }
454 });
454 });
455 return true;
455 return true;
456 }
456 }
457
457
458 function randomKey(size) {
458 function randomKey(size) {
459 var chars = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
459 var chars = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
460 var key = '';
460 var key = '';
461 for (i = 0; i < size; i++) {
461 for (i = 0; i < size; i++) {
462 key += chars[Math.floor(Math.random() * chars.length)];
462 key += chars[Math.floor(Math.random() * chars.length)];
463 }
463 }
464 return key;
464 return key;
465 }
465 }
466
466
467 // Can't use Rails' remote select because we need the form data
467 // Can't use Rails' remote select because we need the form data
468 function updateIssueFrom(url) {
468 function updateIssueFrom(url) {
469 $.ajax({
469 $.ajax({
470 url: url,
470 url: url,
471 type: 'post',
471 type: 'post',
472 data: $('#issue-form').serialize()
472 data: $('#issue-form').serialize()
473 });
473 });
474 }
474 }
475
475
476 function updateBulkEditFrom(url) {
476 function updateBulkEditFrom(url) {
477 $.ajax({
477 $.ajax({
478 url: url,
478 url: url,
479 type: 'post',
479 type: 'post',
480 data: $('#bulk_edit_form').serialize()
480 data: $('#bulk_edit_form').serialize()
481 });
481 });
482 }
482 }
483
483
484 function observeAutocompleteField(fieldId, url) {
484 function observeAutocompleteField(fieldId, url) {
485 $('#'+fieldId).autocomplete({
485 $('#'+fieldId).autocomplete({
486 source: url,
486 source: url,
487 minLength: 2,
487 minLength: 2,
488 });
488 });
489 }
489 }
490
490
491 function observeSearchfield(fieldId, targetId, url) {
491 function observeSearchfield(fieldId, targetId, url) {
492 $('#'+fieldId).each(function() {
492 $('#'+fieldId).each(function() {
493 var $this = $(this);
493 var $this = $(this);
494 $this.attr('data-value-was', $this.val());
494 $this.attr('data-value-was', $this.val());
495 var check = function() {
495 var check = function() {
496 var val = $this.val();
496 var val = $this.val();
497 if ($this.attr('data-value-was') != val){
497 if ($this.attr('data-value-was') != val){
498 $this.attr('data-value-was', val);
498 $this.attr('data-value-was', val);
499 if (val != '') {
499 $.ajax({
500 $.ajax({
500 url: url,
501 url: url,
501 type: 'get',
502 type: 'get',
502 data: {q: $this.val()},
503 data: {q: $this.val()},
503 success: function(data){ $('#'+targetId).html(data); },
504 success: function(data){ $('#'+targetId).html(data); },
504 beforeSend: function(){ $this.addClass('ajax-loading'); },
505 beforeSend: function(){ $this.addClass('ajax-loading'); },
505 complete: function(){ $this.removeClass('ajax-loading'); }
506 complete: function(){ $this.removeClass('ajax-loading'); }
506 });
507 });
508 }
509 }
507 }
510 };
508 };
511 var reset = function() {
509 var reset = function() {
512 if (timer) {
510 if (timer) {
513 clearInterval(timer);
511 clearInterval(timer);
514 timer = setInterval(check, 300);
512 timer = setInterval(check, 300);
515 }
513 }
516 };
514 };
517 var timer = setInterval(check, 300);
515 var timer = setInterval(check, 300);
518 $this.bind('keyup click mousemove', reset);
516 $this.bind('keyup click mousemove', reset);
519 });
517 });
520 }
518 }
521
519
522 function observeProjectModules() {
520 function observeProjectModules() {
523 var f = function() {
521 var f = function() {
524 /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */
522 /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */
525 if ($('#project_enabled_module_names_issue_tracking').attr('checked')) {
523 if ($('#project_enabled_module_names_issue_tracking').attr('checked')) {
526 $('#project_trackers').show();
524 $('#project_trackers').show();
527 }else{
525 }else{
528 $('#project_trackers').hide();
526 $('#project_trackers').hide();
529 }
527 }
530 };
528 };
531
529
532 $(window).load(f);
530 $(window).load(f);
533 $('#project_enabled_module_names_issue_tracking').change(f);
531 $('#project_enabled_module_names_issue_tracking').change(f);
534 }
532 }
535
533
536 function initMyPageSortable(list, url) {
534 function initMyPageSortable(list, url) {
537 $('#list-'+list).sortable({
535 $('#list-'+list).sortable({
538 connectWith: '.block-receiver',
536 connectWith: '.block-receiver',
539 tolerance: 'pointer',
537 tolerance: 'pointer',
540 update: function(){
538 update: function(){
541 $.ajax({
539 $.ajax({
542 url: url,
540 url: url,
543 type: 'post',
541 type: 'post',
544 data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})}
542 data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})}
545 });
543 });
546 }
544 }
547 });
545 });
548 $("#list-top, #list-left, #list-right").disableSelection();
546 $("#list-top, #list-left, #list-right").disableSelection();
549 }
547 }
550
548
551 var warnLeavingUnsavedMessage;
549 var warnLeavingUnsavedMessage;
552 function warnLeavingUnsaved(message) {
550 function warnLeavingUnsaved(message) {
553 warnLeavingUnsavedMessage = message;
551 warnLeavingUnsavedMessage = message;
554
552
555 $('form').submit(function(){
553 $('form').submit(function(){
556 $('textarea').removeData('changed');
554 $('textarea').removeData('changed');
557 });
555 });
558 $('textarea').change(function(){
556 $('textarea').change(function(){
559 $(this).data('changed', 'changed');
557 $(this).data('changed', 'changed');
560 });
558 });
561 window.onbeforeunload = function(){
559 window.onbeforeunload = function(){
562 var warn = false;
560 var warn = false;
563 $('textarea').blur().each(function(){
561 $('textarea').blur().each(function(){
564 if ($(this).data('changed')) {
562 if ($(this).data('changed')) {
565 warn = true;
563 warn = true;
566 }
564 }
567 });
565 });
568 if (warn) {return warnLeavingUnsavedMessage;}
566 if (warn) {return warnLeavingUnsavedMessage;}
569 };
567 };
570 };
568 };
571
569
572 $(document).ready(function(){
570 $(document).ready(function(){
573 $('#ajax-indicator').bind('ajaxSend', function(){
571 $('#ajax-indicator').bind('ajaxSend', function(){
574 if ($('.ajax-loading').length == 0) {
572 if ($('.ajax-loading').length == 0) {
575 $('#ajax-indicator').show();
573 $('#ajax-indicator').show();
576 }
574 }
577 });
575 });
578 $('#ajax-indicator').bind('ajaxStop', function(){
576 $('#ajax-indicator').bind('ajaxStop', function(){
579 $('#ajax-indicator').hide();
577 $('#ajax-indicator').hide();
580 });
578 });
581 });
579 });
582
580
583 function hideOnLoad() {
581 function hideOnLoad() {
584 $('.hol').hide();
582 $('.hol').hide();
585 }
583 }
586
584
587 function addFormObserversForDoubleSubmit() {
585 function addFormObserversForDoubleSubmit() {
588 $('form[method=post]').each(function() {
586 $('form[method=post]').each(function() {
589 if (!$(this).hasClass('multiple-submit')) {
587 if (!$(this).hasClass('multiple-submit')) {
590 $(this).submit(function(form_submission) {
588 $(this).submit(function(form_submission) {
591 if ($(form_submission.target).attr('data-submitted')) {
589 if ($(form_submission.target).attr('data-submitted')) {
592 form_submission.preventDefault();
590 form_submission.preventDefault();
593 } else {
591 } else {
594 $(form_submission.target).attr('data-submitted', true);
592 $(form_submission.target).attr('data-submitted', true);
595 }
593 }
596 });
594 });
597 }
595 }
598 });
596 });
599 }
597 }
600
598
601 $(document).ready(hideOnLoad);
599 $(document).ready(hideOnLoad);
602 $(document).ready(addFormObserversForDoubleSubmit);
600 $(document).ready(addFormObserversForDoubleSubmit);
General Comments 0
You need to be logged in to leave comments. Login now