##// END OF EJS Templates
Merged r10714 from trunk....
Jean-Philippe Lang -
r10511:0f219b973aa2
parent child
Show More
@@ -1,582 +1,582
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 "integer":
181 case "integer":
182 case "float":
182 case "float":
183 tr.find('td.values').append(
183 tr.find('td.values').append(
184 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' +
184 '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' +
185 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>'
185 ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>'
186 );
186 );
187 $('#values_'+fieldId+'_1').val(values[0]);
187 $('#values_'+fieldId+'_1').val(values[0]);
188 $('#values_'+fieldId+'_2').val(values[1]);
188 $('#values_'+fieldId+'_2').val(values[1]);
189 break;
189 break;
190 }
190 }
191 }
191 }
192
192
193 function toggleFilter(field) {
193 function toggleFilter(field) {
194 var fieldId = field.replace('.', '_');
194 var fieldId = field.replace('.', '_');
195 if ($('#cb_' + fieldId).is(':checked')) {
195 if ($('#cb_' + fieldId).is(':checked')) {
196 $("#operators_" + fieldId).show().removeAttr('disabled');
196 $("#operators_" + fieldId).show().removeAttr('disabled');
197 toggleOperator(field);
197 toggleOperator(field);
198 } else {
198 } else {
199 $("#operators_" + fieldId).hide().attr('disabled', true);
199 $("#operators_" + fieldId).hide().attr('disabled', true);
200 enableValues(field, []);
200 enableValues(field, []);
201 }
201 }
202 }
202 }
203
203
204 function enableValues(field, indexes) {
204 function enableValues(field, indexes) {
205 var fieldId = field.replace('.', '_');
205 var fieldId = field.replace('.', '_');
206 $('#tr_'+fieldId+' td.values .value').each(function(index) {
206 $('#tr_'+fieldId+' td.values .value').each(function(index) {
207 if ($.inArray(index, indexes) >= 0) {
207 if ($.inArray(index, indexes) >= 0) {
208 $(this).removeAttr('disabled');
208 $(this).removeAttr('disabled');
209 $(this).parents('span').first().show();
209 $(this).parents('span').first().show();
210 } else {
210 } else {
211 $(this).val('');
211 $(this).val('');
212 $(this).attr('disabled', true);
212 $(this).attr('disabled', true);
213 $(this).parents('span').first().hide();
213 $(this).parents('span').first().hide();
214 }
214 }
215
215
216 if ($(this).hasClass('group')) {
216 if ($(this).hasClass('group')) {
217 $(this).addClass('open');
217 $(this).addClass('open');
218 } else {
218 } else {
219 $(this).show();
219 $(this).show();
220 }
220 }
221 });
221 });
222 }
222 }
223
223
224 function toggleOperator(field) {
224 function toggleOperator(field) {
225 var fieldId = field.replace('.', '_');
225 var fieldId = field.replace('.', '_');
226 var operator = $("#operators_" + fieldId);
226 var operator = $("#operators_" + fieldId);
227 switch (operator.val()) {
227 switch (operator.val()) {
228 case "!*":
228 case "!*":
229 case "*":
229 case "*":
230 case "t":
230 case "t":
231 case "w":
231 case "w":
232 case "o":
232 case "o":
233 case "c":
233 case "c":
234 enableValues(field, []);
234 enableValues(field, []);
235 break;
235 break;
236 case "><":
236 case "><":
237 enableValues(field, [0,1]);
237 enableValues(field, [0,1]);
238 break;
238 break;
239 case "<t+":
239 case "<t+":
240 case ">t+":
240 case ">t+":
241 case "t+":
241 case "t+":
242 case ">t-":
242 case ">t-":
243 case "<t-":
243 case "<t-":
244 case "t-":
244 case "t-":
245 enableValues(field, [2]);
245 enableValues(field, [2]);
246 break;
246 break;
247 default:
247 default:
248 enableValues(field, [0]);
248 enableValues(field, [0]);
249 break;
249 break;
250 }
250 }
251 }
251 }
252
252
253 function toggleMultiSelect(el) {
253 function toggleMultiSelect(el) {
254 if (el.attr('multiple')) {
254 if (el.attr('multiple')) {
255 el.removeAttr('multiple');
255 el.removeAttr('multiple');
256 } else {
256 } else {
257 el.attr('multiple', true);
257 el.attr('multiple', true);
258 }
258 }
259 }
259 }
260
260
261 function submit_query_form(id) {
261 function submit_query_form(id) {
262 selectAllOptions("selected_columns");
262 selectAllOptions("selected_columns");
263 $('#'+id).submit();
263 $('#'+id).submit();
264 }
264 }
265
265
266 var fileFieldCount = 1;
266 var fileFieldCount = 1;
267 function addFileField() {
267 function addFileField() {
268 var fields = $('#attachments_fields');
268 var fields = $('#attachments_fields');
269 if (fields.children().length >= 10) return false;
269 if (fields.children().length >= 10) return false;
270 fileFieldCount++;
270 fileFieldCount++;
271 var s = fields.children('span').first().clone();
271 var s = fields.children('span').first().clone();
272 s.children('input.file').attr('name', "attachments[" + fileFieldCount + "][file]").val('');
272 s.children('input.file').attr('name', "attachments[" + fileFieldCount + "][file]").val('');
273 s.children('input.description').attr('name', "attachments[" + fileFieldCount + "][description]").val('');
273 s.children('input.description').attr('name', "attachments[" + fileFieldCount + "][description]").val('');
274 fields.append(s);
274 fields.append(s);
275 }
275 }
276
276
277 function removeFileField(el) {
277 function removeFileField(el) {
278 var fields = $('#attachments_fields');
278 var fields = $('#attachments_fields');
279 var s = $(el).parents('span').first();
279 var s = $(el).parents('span').first();
280 if (fields.children().length > 1) {
280 if (fields.children().length > 1) {
281 s.remove();
281 s.remove();
282 } else {
282 } else {
283 s.children('input.file').val('');
283 s.children('input.file').val('');
284 s.children('input.description').val('');
284 s.children('input.description').val('');
285 }
285 }
286 }
286 }
287
287
288 function checkFileSize(el, maxSize, message) {
288 function checkFileSize(el, maxSize, message) {
289 var files = el.files;
289 var files = el.files;
290 if (files) {
290 if (files) {
291 for (var i=0; i<files.length; i++) {
291 for (var i=0; i<files.length; i++) {
292 if (files[i].size > maxSize) {
292 if (files[i].size > maxSize) {
293 alert(message);
293 alert(message);
294 el.value = "";
294 el.value = "";
295 }
295 }
296 }
296 }
297 }
297 }
298 }
298 }
299
299
300 function showTab(name) {
300 function showTab(name) {
301 $('div#content .tab-content').hide();
301 $('div#content .tab-content').hide();
302 $('div.tabs a').removeClass('selected');
302 $('div.tabs a').removeClass('selected');
303 $('#tab-content-' + name).show();
303 $('#tab-content-' + name).show();
304 $('#tab-' + name).addClass('selected');
304 $('#tab-' + name).addClass('selected');
305 return false;
305 return false;
306 }
306 }
307
307
308 function moveTabRight(el) {
308 function moveTabRight(el) {
309 var lis = $(el).parents('div.tabs').first().find('ul').children();
309 var lis = $(el).parents('div.tabs').first().find('ul').children();
310 var tabsWidth = 0;
310 var tabsWidth = 0;
311 var i = 0;
311 var i = 0;
312 lis.each(function(){
312 lis.each(function(){
313 if ($(this).is(':visible')) {
313 if ($(this).is(':visible')) {
314 tabsWidth += $(this).width() + 6;
314 tabsWidth += $(this).width() + 6;
315 }
315 }
316 });
316 });
317 if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; }
317 if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; }
318 while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
318 while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
319 lis.eq(i).hide();
319 lis.eq(i).hide();
320 }
320 }
321
321
322 function moveTabLeft(el) {
322 function moveTabLeft(el) {
323 var lis = $(el).parents('div.tabs').first().find('ul').children();
323 var lis = $(el).parents('div.tabs').first().find('ul').children();
324 var i = 0;
324 var i = 0;
325 while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
325 while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
326 if (i>0) {
326 if (i>0) {
327 lis.eq(i-1).show();
327 lis.eq(i-1).show();
328 }
328 }
329 }
329 }
330
330
331 function displayTabsButtons() {
331 function displayTabsButtons() {
332 var lis;
332 var lis;
333 var tabsWidth = 0;
333 var tabsWidth = 0;
334 var el;
334 var el;
335 $('div.tabs').each(function() {
335 $('div.tabs').each(function() {
336 el = $(this);
336 el = $(this);
337 lis = el.find('ul').children();
337 lis = el.find('ul').children();
338 lis.each(function(){
338 lis.each(function(){
339 if ($(this).is(':visible')) {
339 if ($(this).is(':visible')) {
340 tabsWidth += $(this).width() + 6;
340 tabsWidth += $(this).width() + 6;
341 }
341 }
342 });
342 });
343 if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) {
343 if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) {
344 el.find('div.tabs-buttons').hide();
344 el.find('div.tabs-buttons').hide();
345 } else {
345 } else {
346 el.find('div.tabs-buttons').show();
346 el.find('div.tabs-buttons').show();
347 }
347 }
348 });
348 });
349 }
349 }
350
350
351 function setPredecessorFieldsVisibility() {
351 function setPredecessorFieldsVisibility() {
352 var relationType = $('#relation_relation_type');
352 var relationType = $('#relation_relation_type');
353 if (relationType.val() == "precedes" || relationType.val() == "follows") {
353 if (relationType.val() == "precedes" || relationType.val() == "follows") {
354 $('#predecessor_fields').show();
354 $('#predecessor_fields').show();
355 } else {
355 } else {
356 $('#predecessor_fields').hide();
356 $('#predecessor_fields').hide();
357 }
357 }
358 }
358 }
359
359
360 function showModal(id, width) {
360 function showModal(id, width) {
361 var el = $('#'+id).first();
361 var el = $('#'+id).first();
362 if (el.length == 0 || el.is(':visible')) {return;}
362 if (el.length == 0 || el.is(':visible')) {return;}
363 var title = el.find('h3.title').text();
363 var title = el.find('h3.title').text();
364 el.dialog({
364 el.dialog({
365 width: width,
365 width: width,
366 modal: true,
366 modal: true,
367 resizable: false,
367 resizable: false,
368 dialogClass: 'modal',
368 dialogClass: 'modal',
369 title: title
369 title: title
370 });
370 });
371 el.find("input[type=text], input[type=submit]").first().focus();
371 el.find("input[type=text], input[type=submit]").first().focus();
372 }
372 }
373
373
374 function hideModal(el) {
374 function hideModal(el) {
375 var modal;
375 var modal;
376 if (el) {
376 if (el) {
377 modal = $(el).parents('.ui-dialog-content');
377 modal = $(el).parents('.ui-dialog-content');
378 } else {
378 } else {
379 modal = $('#ajax-modal');
379 modal = $('#ajax-modal');
380 }
380 }
381 modal.dialog("close");
381 modal.dialog("close");
382 }
382 }
383
383
384 function submitPreview(url, form, target) {
384 function submitPreview(url, form, target) {
385 $.ajax({
385 $.ajax({
386 url: url,
386 url: url,
387 type: 'post',
387 type: 'post',
388 data: $('#'+form).serialize(),
388 data: $('#'+form).serialize(),
389 success: function(data){
389 success: function(data){
390 $('#'+target).html(data);
390 $('#'+target).html(data);
391 }
391 }
392 });
392 });
393 }
393 }
394
394
395 function collapseScmEntry(id) {
395 function collapseScmEntry(id) {
396 $('.'+id).each(function() {
396 $('.'+id).each(function() {
397 if ($(this).hasClass('open')) {
397 if ($(this).hasClass('open')) {
398 collapseScmEntry($(this).attr('id'));
398 collapseScmEntry($(this).attr('id'));
399 }
399 }
400 $(this).hide();
400 $(this).hide();
401 });
401 });
402 $('#'+id).removeClass('open');
402 $('#'+id).removeClass('open');
403 }
403 }
404
404
405 function expandScmEntry(id) {
405 function expandScmEntry(id) {
406 $('.'+id).each(function() {
406 $('.'+id).each(function() {
407 $(this).show();
407 $(this).show();
408 if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) {
408 if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) {
409 expandScmEntry($(this).attr('id'));
409 expandScmEntry($(this).attr('id'));
410 }
410 }
411 });
411 });
412 $('#'+id).addClass('open');
412 $('#'+id).addClass('open');
413 }
413 }
414
414
415 function scmEntryClick(id, url) {
415 function scmEntryClick(id, url) {
416 el = $('#'+id);
416 el = $('#'+id);
417 if (el.hasClass('open')) {
417 if (el.hasClass('open')) {
418 collapseScmEntry(id);
418 collapseScmEntry(id);
419 el.addClass('collapsed');
419 el.addClass('collapsed');
420 return false;
420 return false;
421 } else if (el.hasClass('loaded')) {
421 } else if (el.hasClass('loaded')) {
422 expandScmEntry(id);
422 expandScmEntry(id);
423 el.removeClass('collapsed');
423 el.removeClass('collapsed');
424 return false;
424 return false;
425 }
425 }
426 if (el.hasClass('loading')) {
426 if (el.hasClass('loading')) {
427 return false;
427 return false;
428 }
428 }
429 el.addClass('loading');
429 el.addClass('loading');
430 $.ajax({
430 $.ajax({
431 url: url,
431 url: url,
432 success: function(data){
432 success: function(data){
433 el.after(data);
433 el.after(data);
434 el.addClass('open').addClass('loaded').removeClass('loading');
434 el.addClass('open').addClass('loaded').removeClass('loading');
435 }
435 }
436 });
436 });
437 return true;
437 return true;
438 }
438 }
439
439
440 function randomKey(size) {
440 function randomKey(size) {
441 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');
441 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');
442 var key = '';
442 var key = '';
443 for (i = 0; i < size; i++) {
443 for (i = 0; i < size; i++) {
444 key += chars[Math.floor(Math.random() * chars.length)];
444 key += chars[Math.floor(Math.random() * chars.length)];
445 }
445 }
446 return key;
446 return key;
447 }
447 }
448
448
449 // Can't use Rails' remote select because we need the form data
449 // Can't use Rails' remote select because we need the form data
450 function updateIssueFrom(url) {
450 function updateIssueFrom(url) {
451 $.ajax({
451 $.ajax({
452 url: url,
452 url: url,
453 type: 'post',
453 type: 'post',
454 data: $('#issue-form').serialize()
454 data: $('#issue-form').serialize()
455 });
455 });
456 }
456 }
457
457
458 function updateBulkEditFrom(url) {
458 function updateBulkEditFrom(url) {
459 $.ajax({
459 $.ajax({
460 url: url,
460 url: url,
461 type: 'post',
461 type: 'post',
462 data: $('#bulk_edit_form').serialize()
462 data: $('#bulk_edit_form').serialize()
463 });
463 });
464 }
464 }
465
465
466 function observeAutocompleteField(fieldId, url) {
466 function observeAutocompleteField(fieldId, url) {
467 $('#'+fieldId).autocomplete({
467 $('#'+fieldId).autocomplete({
468 source: url,
468 source: url,
469 minLength: 2,
469 minLength: 2
470 });
470 });
471 }
471 }
472
472
473 function observeSearchfield(fieldId, targetId, url) {
473 function observeSearchfield(fieldId, targetId, url) {
474 $('#'+fieldId).each(function() {
474 $('#'+fieldId).each(function() {
475 var $this = $(this);
475 var $this = $(this);
476 $this.attr('data-value-was', $this.val());
476 $this.attr('data-value-was', $this.val());
477 var check = function() {
477 var check = function() {
478 var val = $this.val();
478 var val = $this.val();
479 if ($this.attr('data-value-was') != val){
479 if ($this.attr('data-value-was') != val){
480 $this.attr('data-value-was', val);
480 $this.attr('data-value-was', val);
481 $.ajax({
481 $.ajax({
482 url: url,
482 url: url,
483 type: 'get',
483 type: 'get',
484 data: {q: $this.val()},
484 data: {q: $this.val()},
485 success: function(data){ $('#'+targetId).html(data); },
485 success: function(data){ $('#'+targetId).html(data); },
486 beforeSend: function(){ $this.addClass('ajax-loading'); },
486 beforeSend: function(){ $this.addClass('ajax-loading'); },
487 complete: function(){ $this.removeClass('ajax-loading'); }
487 complete: function(){ $this.removeClass('ajax-loading'); }
488 });
488 });
489 }
489 }
490 };
490 };
491 var reset = function() {
491 var reset = function() {
492 if (timer) {
492 if (timer) {
493 clearInterval(timer);
493 clearInterval(timer);
494 timer = setInterval(check, 300);
494 timer = setInterval(check, 300);
495 }
495 }
496 };
496 };
497 var timer = setInterval(check, 300);
497 var timer = setInterval(check, 300);
498 $this.bind('keyup click mousemove', reset);
498 $this.bind('keyup click mousemove', reset);
499 });
499 });
500 }
500 }
501
501
502 function observeProjectModules() {
502 function observeProjectModules() {
503 var f = function() {
503 var f = function() {
504 /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */
504 /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */
505 if ($('#project_enabled_module_names_issue_tracking').attr('checked')) {
505 if ($('#project_enabled_module_names_issue_tracking').attr('checked')) {
506 $('#project_trackers').show();
506 $('#project_trackers').show();
507 }else{
507 }else{
508 $('#project_trackers').hide();
508 $('#project_trackers').hide();
509 }
509 }
510 };
510 };
511
511
512 $(window).load(f);
512 $(window).load(f);
513 $('#project_enabled_module_names_issue_tracking').change(f);
513 $('#project_enabled_module_names_issue_tracking').change(f);
514 }
514 }
515
515
516 function initMyPageSortable(list, url) {
516 function initMyPageSortable(list, url) {
517 $('#list-'+list).sortable({
517 $('#list-'+list).sortable({
518 connectWith: '.block-receiver',
518 connectWith: '.block-receiver',
519 tolerance: 'pointer',
519 tolerance: 'pointer',
520 update: function(){
520 update: function(){
521 $.ajax({
521 $.ajax({
522 url: url,
522 url: url,
523 type: 'post',
523 type: 'post',
524 data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})}
524 data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})}
525 });
525 });
526 }
526 }
527 });
527 });
528 $("#list-top, #list-left, #list-right").disableSelection();
528 $("#list-top, #list-left, #list-right").disableSelection();
529 }
529 }
530
530
531 var warnLeavingUnsavedMessage;
531 var warnLeavingUnsavedMessage;
532 function warnLeavingUnsaved(message) {
532 function warnLeavingUnsaved(message) {
533 warnLeavingUnsavedMessage = message;
533 warnLeavingUnsavedMessage = message;
534
534
535 $('form').submit(function(){
535 $('form').submit(function(){
536 $('textarea').removeData('changed');
536 $('textarea').removeData('changed');
537 });
537 });
538 $('textarea').change(function(){
538 $('textarea').change(function(){
539 $(this).data('changed', 'changed');
539 $(this).data('changed', 'changed');
540 });
540 });
541 window.onbeforeunload = function(){
541 window.onbeforeunload = function(){
542 var warn = false;
542 var warn = false;
543 $('textarea').blur().each(function(){
543 $('textarea').blur().each(function(){
544 if ($(this).data('changed')) {
544 if ($(this).data('changed')) {
545 warn = true;
545 warn = true;
546 }
546 }
547 });
547 });
548 if (warn) {return warnLeavingUnsavedMessage;}
548 if (warn) {return warnLeavingUnsavedMessage;}
549 };
549 };
550 };
550 };
551
551
552 $(document).ready(function(){
552 $(document).ready(function(){
553 $('#ajax-indicator').bind('ajaxSend', function(){
553 $('#ajax-indicator').bind('ajaxSend', function(){
554 if ($('.ajax-loading').length == 0) {
554 if ($('.ajax-loading').length == 0) {
555 $('#ajax-indicator').show();
555 $('#ajax-indicator').show();
556 }
556 }
557 });
557 });
558 $('#ajax-indicator').bind('ajaxStop', function(){
558 $('#ajax-indicator').bind('ajaxStop', function(){
559 $('#ajax-indicator').hide();
559 $('#ajax-indicator').hide();
560 });
560 });
561 });
561 });
562
562
563 function hideOnLoad() {
563 function hideOnLoad() {
564 $('.hol').hide();
564 $('.hol').hide();
565 }
565 }
566
566
567 function addFormObserversForDoubleSubmit() {
567 function addFormObserversForDoubleSubmit() {
568 $('form[method=post]').each(function() {
568 $('form[method=post]').each(function() {
569 if (!$(this).hasClass('multiple-submit')) {
569 if (!$(this).hasClass('multiple-submit')) {
570 $(this).submit(function(form_submission) {
570 $(this).submit(function(form_submission) {
571 if ($(form_submission.target).attr('data-submitted')) {
571 if ($(form_submission.target).attr('data-submitted')) {
572 form_submission.preventDefault();
572 form_submission.preventDefault();
573 } else {
573 } else {
574 $(form_submission.target).attr('data-submitted', true);
574 $(form_submission.target).attr('data-submitted', true);
575 }
575 }
576 });
576 });
577 }
577 }
578 });
578 });
579 }
579 }
580
580
581 $(document).ready(hideOnLoad);
581 $(document).ready(hideOnLoad);
582 $(document).ready(addFormObserversForDoubleSubmit);
582 $(document).ready(addFormObserversForDoubleSubmit);
General Comments 0
You need to be logged in to leave comments. Login now