@@ -1,500 +1,499 | |||||
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 add_filter() { |
|
81 | function add_filter() { | |
82 | var select = $('#add_filter_select'); |
|
82 | var select = $('#add_filter_select'); | |
83 | var field = select.val(); |
|
83 | var field = select.val(); | |
84 | $('#tr_'+field).show(); |
|
84 | $('#tr_'+field).show(); | |
85 | var check_box = $('#cb_' + field); |
|
85 | var check_box = $('#cb_' + field); | |
86 | check_box.attr('checked', true); |
|
86 | check_box.attr('checked', true); | |
87 | toggle_filter(field); |
|
87 | toggle_filter(field); | |
88 | select.val(''); |
|
88 | select.val(''); | |
89 |
|
89 | |||
90 | select.children('option').each(function(index) { |
|
90 | select.children('option').each(function(index) { | |
91 | if ($(this).attr('value') == field) { |
|
91 | if ($(this).attr('value') == field) { | |
92 | $(this).attr('disabled', true); |
|
92 | $(this).attr('disabled', true); | |
93 | } |
|
93 | } | |
94 | }); |
|
94 | }); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | function toggle_filter(field) { |
|
97 | function toggle_filter(field) { | |
98 | check_box = $('#cb_' + field); |
|
98 | check_box = $('#cb_' + field); | |
99 | if (check_box.is(':checked')) { |
|
99 | if (check_box.is(':checked')) { | |
100 | $("#operators_" + field).show().removeAttr('disabled'); |
|
100 | $("#operators_" + field).show().removeAttr('disabled'); | |
101 | toggle_operator(field); |
|
101 | toggle_operator(field); | |
102 | } else { |
|
102 | } else { | |
103 | $("#operators_" + field).hide().attr('disabled', true); |
|
103 | $("#operators_" + field).hide().attr('disabled', true); | |
104 | enableValues(field, []); |
|
104 | enableValues(field, []); | |
105 | } |
|
105 | } | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | function enableValues(field, indexes) { |
|
108 | function enableValues(field, indexes) { | |
109 | $(".values_" + field).each(function(index) { |
|
109 | $(".values_" + field).each(function(index) { | |
110 | if (indexes.indexOf(index) >= 0) { |
|
110 | if (indexes.indexOf(index) >= 0) { | |
111 | $(this).removeAttr('disabled'); |
|
111 | $(this).removeAttr('disabled'); | |
112 | $(this).parents('span').first().show(); |
|
112 | $(this).parents('span').first().show(); | |
113 | } else { |
|
113 | } else { | |
114 | $(this).val(''); |
|
114 | $(this).val(''); | |
115 | $(this).attr('disabled', true); |
|
115 | $(this).attr('disabled', true); | |
116 | $(this).parents('span').first().hide(); |
|
116 | $(this).parents('span').first().hide(); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | if ($(this).hasClass('group')) { |
|
119 | if ($(this).hasClass('group')) { | |
120 | $(this).addClass('open'); |
|
120 | $(this).addClass('open'); | |
121 | } else { |
|
121 | } else { | |
122 | $(this).show(); |
|
122 | $(this).show(); | |
123 | } |
|
123 | } | |
124 | }); |
|
124 | }); | |
125 |
|
125 | |||
126 | if (indexes.length > 0) { |
|
126 | if (indexes.length > 0) { | |
127 | $("#div_values_" + field).show(); |
|
127 | $("#div_values_" + field).show(); | |
128 | } else { |
|
128 | } else { | |
129 | $("#div_values_" + field).hide(); |
|
129 | $("#div_values_" + field).hide(); | |
130 | } |
|
130 | } | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | function toggle_operator(field) { |
|
133 | function toggle_operator(field) { | |
134 | operator = $("#operators_" + field); |
|
134 | operator = $("#operators_" + field); | |
135 | switch (operator.val()) { |
|
135 | switch (operator.val()) { | |
136 | case "!*": |
|
136 | case "!*": | |
137 | case "*": |
|
137 | case "*": | |
138 | case "t": |
|
138 | case "t": | |
139 | case "w": |
|
139 | case "w": | |
140 | case "o": |
|
140 | case "o": | |
141 | case "c": |
|
141 | case "c": | |
142 | enableValues(field, []); |
|
142 | enableValues(field, []); | |
143 | break; |
|
143 | break; | |
144 | case "><": |
|
144 | case "><": | |
145 | enableValues(field, [0,1]); |
|
145 | enableValues(field, [0,1]); | |
146 | break; |
|
146 | break; | |
147 | case "<t+": |
|
147 | case "<t+": | |
148 | case ">t+": |
|
148 | case ">t+": | |
149 | case "t+": |
|
149 | case "t+": | |
150 | case ">t-": |
|
150 | case ">t-": | |
151 | case "<t-": |
|
151 | case "<t-": | |
152 | case "t-": |
|
152 | case "t-": | |
153 | enableValues(field, [2]); |
|
153 | enableValues(field, [2]); | |
154 | break; |
|
154 | break; | |
155 | default: |
|
155 | default: | |
156 | enableValues(field, [0]); |
|
156 | enableValues(field, [0]); | |
157 | break; |
|
157 | break; | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | function toggle_multi_select(id) { |
|
161 | function toggle_multi_select(id) { | |
162 | var select = $('#'+id); |
|
162 | var select = $('#'+id); | |
163 | if (select.attr('multiple')) { |
|
163 | if (select.attr('multiple')) { | |
164 | select.removeAttr('multiple'); |
|
164 | select.removeAttr('multiple'); | |
165 | } else { |
|
165 | } else { | |
166 | select.attr('multiple', true); |
|
166 | select.attr('multiple', true); | |
167 | } |
|
167 | } | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | function submit_query_form(id) { |
|
170 | function submit_query_form(id) { | |
171 | selectAllOptions("selected_columns"); |
|
171 | selectAllOptions("selected_columns"); | |
172 | $('#'+id).submit(); |
|
172 | $('#'+id).submit(); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | function observeIssueFilters() { |
|
175 | function observeIssueFilters() { | |
176 | $('#query_form input[type=text]').keypress(function(e){ |
|
176 | $('#query_form input[type=text]').keypress(function(e){ | |
177 | if (e.keyCode == 13) submit_query_form("query_form"); |
|
177 | if (e.keyCode == 13) submit_query_form("query_form"); | |
178 | }); |
|
178 | }); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | var fileFieldCount = 1; |
|
181 | var fileFieldCount = 1; | |
182 | function addFileField() { |
|
182 | function addFileField() { | |
183 | var fields = $('#attachments_fields'); |
|
183 | var fields = $('#attachments_fields'); | |
184 | if (fields.children().length >= 10) return false; |
|
184 | if (fields.children().length >= 10) return false; | |
185 | fileFieldCount++; |
|
185 | fileFieldCount++; | |
186 | var s = fields.children('span').first().clone(); |
|
186 | var s = fields.children('span').first().clone(); | |
187 | s.children('input.file').attr('name', "attachments[" + fileFieldCount + "][file]").val(''); |
|
187 | s.children('input.file').attr('name', "attachments[" + fileFieldCount + "][file]").val(''); | |
188 | s.children('input.description').attr('name', "attachments[" + fileFieldCount + "][description]").val(''); |
|
188 | s.children('input.description').attr('name', "attachments[" + fileFieldCount + "][description]").val(''); | |
189 | fields.append(s); |
|
189 | fields.append(s); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | function removeFileField(el) { |
|
192 | function removeFileField(el) { | |
193 | var fields = $('#attachments_fields'); |
|
193 | var fields = $('#attachments_fields'); | |
194 | var s = $(el).parents('span').first(); |
|
194 | var s = $(el).parents('span').first(); | |
195 | if (fields.children().length > 1) { |
|
195 | if (fields.children().length > 1) { | |
196 | s.remove(); |
|
196 | s.remove(); | |
197 | } else { |
|
197 | } else { | |
198 | s.children('input.file').val(''); |
|
198 | s.children('input.file').val(''); | |
199 | s.children('input.description').val(''); |
|
199 | s.children('input.description').val(''); | |
200 | } |
|
200 | } | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | function checkFileSize(el, maxSize, message) { |
|
203 | function checkFileSize(el, maxSize, message) { | |
204 | var files = el.files; |
|
204 | var files = el.files; | |
205 | if (files) { |
|
205 | if (files) { | |
206 | for (var i=0; i<files.length; i++) { |
|
206 | for (var i=0; i<files.length; i++) { | |
207 | if (files[i].size > maxSize) { |
|
207 | if (files[i].size > maxSize) { | |
208 | alert(message); |
|
208 | alert(message); | |
209 | el.value = ""; |
|
209 | el.value = ""; | |
210 | } |
|
210 | } | |
211 | } |
|
211 | } | |
212 | } |
|
212 | } | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | function showTab(name) { |
|
215 | function showTab(name) { | |
216 | $('div#content .tab-content').hide(); |
|
216 | $('div#content .tab-content').hide(); | |
217 | $('div.tabs a').removeClass('selected'); |
|
217 | $('div.tabs a').removeClass('selected'); | |
218 | $('#tab-content-' + name).show(); |
|
218 | $('#tab-content-' + name).show(); | |
219 | $('#tab-' + name).addClass('selected'); |
|
219 | $('#tab-' + name).addClass('selected'); | |
220 | return false; |
|
220 | return false; | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | function moveTabRight(el) { |
|
223 | function moveTabRight(el) { | |
224 | var lis = $(el).parents('div.tabs').first().find('ul').children(); |
|
224 | var lis = $(el).parents('div.tabs').first().find('ul').children(); | |
225 | var tabsWidth = 0; |
|
225 | var tabsWidth = 0; | |
226 | var i = 0; |
|
226 | var i = 0; | |
227 | lis.each(function(){ |
|
227 | lis.each(function(){ | |
228 | if ($(this).is(':visible')) { |
|
228 | if ($(this).is(':visible')) { | |
229 | tabsWidth += $(this).width() + 6; |
|
229 | tabsWidth += $(this).width() + 6; | |
230 | } |
|
230 | } | |
231 | }); |
|
231 | }); | |
232 | if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; } |
|
232 | if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; } | |
233 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } |
|
233 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } | |
234 | lis.eq(i).hide(); |
|
234 | lis.eq(i).hide(); | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | function moveTabLeft(el) { |
|
237 | function moveTabLeft(el) { | |
238 | var lis = $(el).parents('div.tabs').first().find('ul').children(); |
|
238 | var lis = $(el).parents('div.tabs').first().find('ul').children(); | |
239 | var i = 0; |
|
239 | var i = 0; | |
240 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } |
|
240 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } | |
241 | if (i>0) { |
|
241 | if (i>0) { | |
242 | lis.eq(i-1).show(); |
|
242 | lis.eq(i-1).show(); | |
243 | } |
|
243 | } | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | function displayTabsButtons() { |
|
246 | function displayTabsButtons() { | |
247 | var lis; |
|
247 | var lis; | |
248 | var tabsWidth = 0; |
|
248 | var tabsWidth = 0; | |
249 | var el; |
|
249 | var el; | |
250 | $('div.tabs').each(function() { |
|
250 | $('div.tabs').each(function() { | |
251 | el = $(this); |
|
251 | el = $(this); | |
252 | lis = el.find('ul').children(); |
|
252 | lis = el.find('ul').children(); | |
253 | lis.each(function(){ |
|
253 | lis.each(function(){ | |
254 | if ($(this).is(':visible')) { |
|
254 | if ($(this).is(':visible')) { | |
255 | tabsWidth += $(this).width() + 6; |
|
255 | tabsWidth += $(this).width() + 6; | |
256 | } |
|
256 | } | |
257 | }); |
|
257 | }); | |
258 | if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) { |
|
258 | if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) { | |
259 | el.find('div.tabs-buttons').hide(); |
|
259 | el.find('div.tabs-buttons').hide(); | |
260 | } else { |
|
260 | } else { | |
261 | el.find('div.tabs-buttons').show(); |
|
261 | el.find('div.tabs-buttons').show(); | |
262 | } |
|
262 | } | |
263 | }); |
|
263 | }); | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | function setPredecessorFieldsVisibility() { |
|
266 | function setPredecessorFieldsVisibility() { | |
267 | var relationType = $('#relation_relation_type'); |
|
267 | var relationType = $('#relation_relation_type'); | |
268 | if (relationType.val() == "precedes" || relationType.val() == "follows") { |
|
268 | if (relationType.val() == "precedes" || relationType.val() == "follows") { | |
269 | $('#predecessor_fields').show(); |
|
269 | $('#predecessor_fields').show(); | |
270 | } else { |
|
270 | } else { | |
271 | $('#predecessor_fields').hide(); |
|
271 | $('#predecessor_fields').hide(); | |
272 | } |
|
272 | } | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | function showModal(id, width) { |
|
275 | function showModal(id, width) { | |
276 | var el = $('#'+id).first(); |
|
276 | var el = $('#'+id).first(); | |
277 | if (el.length == 0 || el.is(':visible')) {return;} |
|
277 | if (el.length == 0 || el.is(':visible')) {return;} | |
278 | var title = el.find('h3.title').text(); |
|
278 | var title = el.find('h3.title').text(); | |
279 | el.dialog({ |
|
279 | el.dialog({ | |
280 | width: width, |
|
280 | width: width, | |
281 | modal: true, |
|
281 | modal: true, | |
282 | resizable: false, |
|
282 | resizable: false, | |
283 | dialogClass: 'modal', |
|
283 | dialogClass: 'modal', | |
284 | title: title |
|
284 | title: title | |
285 | }); |
|
285 | }); | |
286 | el.find("input[type=text], input[type=submit]").first().focus(); |
|
286 | el.find("input[type=text], input[type=submit]").first().focus(); | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | function hideModal(el) { |
|
289 | function hideModal(el) { | |
290 | var modal; |
|
290 | var modal; | |
291 | if (el) { |
|
291 | if (el) { | |
292 | modal = $(el).parents('.ui-dialog-content'); |
|
292 | modal = $(el).parents('.ui-dialog-content'); | |
293 | } else { |
|
293 | } else { | |
294 | modal = $('#ajax-modal'); |
|
294 | modal = $('#ajax-modal'); | |
295 | } |
|
295 | } | |
296 | modal.dialog("close"); |
|
296 | modal.dialog("close"); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | function submitPreview(url, form, target) { |
|
299 | function submitPreview(url, form, target) { | |
300 | $.ajax({ |
|
300 | $.ajax({ | |
301 | url: url, |
|
301 | url: url, | |
302 | type: 'post', |
|
302 | type: 'post', | |
303 | data: $('#'+form).serialize(), |
|
303 | data: $('#'+form).serialize(), | |
304 | success: function(data){ |
|
304 | success: function(data){ | |
305 | $('#'+target).html(data); |
|
305 | $('#'+target).html(data); | |
306 | $('html, body').animate({scrollTop: $('#'+target).offset().top}, 100); |
|
|||
307 | } |
|
306 | } | |
308 | }); |
|
307 | }); | |
309 | } |
|
308 | } | |
310 |
|
309 | |||
311 | function collapseScmEntry(id) { |
|
310 | function collapseScmEntry(id) { | |
312 | $('.'+id).each(function() { |
|
311 | $('.'+id).each(function() { | |
313 | if ($(this).hasClass('open')) { |
|
312 | if ($(this).hasClass('open')) { | |
314 | collapseScmEntry($(this).attr('id')); |
|
313 | collapseScmEntry($(this).attr('id')); | |
315 | } |
|
314 | } | |
316 | $(this).hide(); |
|
315 | $(this).hide(); | |
317 | }); |
|
316 | }); | |
318 | $('#'+id).removeClass('open'); |
|
317 | $('#'+id).removeClass('open'); | |
319 | } |
|
318 | } | |
320 |
|
319 | |||
321 | function expandScmEntry(id) { |
|
320 | function expandScmEntry(id) { | |
322 | $('.'+id).each(function() { |
|
321 | $('.'+id).each(function() { | |
323 | $(this).show(); |
|
322 | $(this).show(); | |
324 | if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) { |
|
323 | if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) { | |
325 | expandScmEntry($(this).attr('id')); |
|
324 | expandScmEntry($(this).attr('id')); | |
326 | } |
|
325 | } | |
327 | }); |
|
326 | }); | |
328 | $('#'+id).addClass('open'); |
|
327 | $('#'+id).addClass('open'); | |
329 | } |
|
328 | } | |
330 |
|
329 | |||
331 | function scmEntryClick(id, url) { |
|
330 | function scmEntryClick(id, url) { | |
332 | el = $('#'+id); |
|
331 | el = $('#'+id); | |
333 | if (el.hasClass('open')) { |
|
332 | if (el.hasClass('open')) { | |
334 | collapseScmEntry(id); |
|
333 | collapseScmEntry(id); | |
335 | el.addClass('collapsed'); |
|
334 | el.addClass('collapsed'); | |
336 | return false; |
|
335 | return false; | |
337 | } else if (el.hasClass('loaded')) { |
|
336 | } else if (el.hasClass('loaded')) { | |
338 | expandScmEntry(id); |
|
337 | expandScmEntry(id); | |
339 | el.removeClass('collapsed'); |
|
338 | el.removeClass('collapsed'); | |
340 | return false; |
|
339 | return false; | |
341 | } |
|
340 | } | |
342 | if (el.hasClass('loading')) { |
|
341 | if (el.hasClass('loading')) { | |
343 | return false; |
|
342 | return false; | |
344 | } |
|
343 | } | |
345 | el.addClass('loading'); |
|
344 | el.addClass('loading'); | |
346 | $.ajax({ |
|
345 | $.ajax({ | |
347 | url: url, |
|
346 | url: url, | |
348 | success: function(data){ |
|
347 | success: function(data){ | |
349 | el.after(data); |
|
348 | el.after(data); | |
350 | el.addClass('open').addClass('loaded').removeClass('loading'); |
|
349 | el.addClass('open').addClass('loaded').removeClass('loading'); | |
351 | } |
|
350 | } | |
352 | }); |
|
351 | }); | |
353 | return true; |
|
352 | return true; | |
354 | } |
|
353 | } | |
355 |
|
354 | |||
356 | function randomKey(size) { |
|
355 | function randomKey(size) { | |
357 | 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'); |
|
356 | 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'); | |
358 | var key = ''; |
|
357 | var key = ''; | |
359 | for (i = 0; i < size; i++) { |
|
358 | for (i = 0; i < size; i++) { | |
360 | key += chars[Math.floor(Math.random() * chars.length)]; |
|
359 | key += chars[Math.floor(Math.random() * chars.length)]; | |
361 | } |
|
360 | } | |
362 | return key; |
|
361 | return key; | |
363 | } |
|
362 | } | |
364 |
|
363 | |||
365 | // Can't use Rails' remote select because we need the form data |
|
364 | // Can't use Rails' remote select because we need the form data | |
366 | function updateIssueFrom(url) { |
|
365 | function updateIssueFrom(url) { | |
367 | $.ajax({ |
|
366 | $.ajax({ | |
368 | url: url, |
|
367 | url: url, | |
369 | type: 'post', |
|
368 | type: 'post', | |
370 | data: $('#issue-form').serialize() |
|
369 | data: $('#issue-form').serialize() | |
371 | }); |
|
370 | }); | |
372 | } |
|
371 | } | |
373 |
|
372 | |||
374 | function updateBulkEditFrom(url) { |
|
373 | function updateBulkEditFrom(url) { | |
375 | $.ajax({ |
|
374 | $.ajax({ | |
376 | url: url, |
|
375 | url: url, | |
377 | type: 'post', |
|
376 | type: 'post', | |
378 | data: $('#bulk_edit_form').serialize() |
|
377 | data: $('#bulk_edit_form').serialize() | |
379 | }); |
|
378 | }); | |
380 | } |
|
379 | } | |
381 |
|
380 | |||
382 | function observeAutocompleteField(fieldId, url) { |
|
381 | function observeAutocompleteField(fieldId, url) { | |
383 | $('#'+fieldId).autocomplete({ |
|
382 | $('#'+fieldId).autocomplete({ | |
384 | source: url, |
|
383 | source: url, | |
385 | minLength: 2, |
|
384 | minLength: 2, | |
386 | }); |
|
385 | }); | |
387 | } |
|
386 | } | |
388 |
|
387 | |||
389 | function observeSearchfield(fieldId, targetId, url) { |
|
388 | function observeSearchfield(fieldId, targetId, url) { | |
390 | $('#'+fieldId).each(function() { |
|
389 | $('#'+fieldId).each(function() { | |
391 | var $this = $(this); |
|
390 | var $this = $(this); | |
392 | $this.attr('data-value-was', $this.val()); |
|
391 | $this.attr('data-value-was', $this.val()); | |
393 | var check = function() { |
|
392 | var check = function() { | |
394 | var val = $this.val(); |
|
393 | var val = $this.val(); | |
395 | if ($this.attr('data-value-was') != val){ |
|
394 | if ($this.attr('data-value-was') != val){ | |
396 | $this.attr('data-value-was', val); |
|
395 | $this.attr('data-value-was', val); | |
397 | if (val != '') { |
|
396 | if (val != '') { | |
398 | $.ajax({ |
|
397 | $.ajax({ | |
399 | url: url, |
|
398 | url: url, | |
400 | type: 'get', |
|
399 | type: 'get', | |
401 | data: {q: $this.val()}, |
|
400 | data: {q: $this.val()}, | |
402 | success: function(data){ $('#'+targetId).html(data); }, |
|
401 | success: function(data){ $('#'+targetId).html(data); }, | |
403 | beforeSend: function(){ $this.addClass('ajax-loading'); }, |
|
402 | beforeSend: function(){ $this.addClass('ajax-loading'); }, | |
404 | complete: function(){ $this.removeClass('ajax-loading'); } |
|
403 | complete: function(){ $this.removeClass('ajax-loading'); } | |
405 | }); |
|
404 | }); | |
406 | } |
|
405 | } | |
407 | } |
|
406 | } | |
408 | }; |
|
407 | }; | |
409 | var reset = function() { |
|
408 | var reset = function() { | |
410 | if (timer) { |
|
409 | if (timer) { | |
411 | clearInterval(timer); |
|
410 | clearInterval(timer); | |
412 | timer = setInterval(check, 300); |
|
411 | timer = setInterval(check, 300); | |
413 | } |
|
412 | } | |
414 | }; |
|
413 | }; | |
415 | var timer = setInterval(check, 300); |
|
414 | var timer = setInterval(check, 300); | |
416 | $this.bind('keyup click mousemove', reset); |
|
415 | $this.bind('keyup click mousemove', reset); | |
417 | }); |
|
416 | }); | |
418 | } |
|
417 | } | |
419 |
|
418 | |||
420 | function observeProjectModules() { |
|
419 | function observeProjectModules() { | |
421 | var f = function() { |
|
420 | var f = function() { | |
422 | /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */ |
|
421 | /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */ | |
423 | if ($('#project_enabled_module_names_issue_tracking').attr('checked')) { |
|
422 | if ($('#project_enabled_module_names_issue_tracking').attr('checked')) { | |
424 | $('#project_trackers').show(); |
|
423 | $('#project_trackers').show(); | |
425 | }else{ |
|
424 | }else{ | |
426 | $('#project_trackers').hide(); |
|
425 | $('#project_trackers').hide(); | |
427 | } |
|
426 | } | |
428 | }; |
|
427 | }; | |
429 |
|
428 | |||
430 | $(window).load(f); |
|
429 | $(window).load(f); | |
431 | $('#project_enabled_module_names_issue_tracking').change(f); |
|
430 | $('#project_enabled_module_names_issue_tracking').change(f); | |
432 | } |
|
431 | } | |
433 |
|
432 | |||
434 | function initMyPageSortable(list, url) { |
|
433 | function initMyPageSortable(list, url) { | |
435 | $('#list-'+list).sortable({ |
|
434 | $('#list-'+list).sortable({ | |
436 | connectWith: '.block-receiver', |
|
435 | connectWith: '.block-receiver', | |
437 | tolerance: 'pointer', |
|
436 | tolerance: 'pointer', | |
438 | update: function(){ |
|
437 | update: function(){ | |
439 | $.ajax({ |
|
438 | $.ajax({ | |
440 | url: url, |
|
439 | url: url, | |
441 | type: 'post', |
|
440 | type: 'post', | |
442 | data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})} |
|
441 | data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})} | |
443 | }); |
|
442 | }); | |
444 | } |
|
443 | } | |
445 | }); |
|
444 | }); | |
446 | $("#list-top, #list-left, #list-right").disableSelection(); |
|
445 | $("#list-top, #list-left, #list-right").disableSelection(); | |
447 | } |
|
446 | } | |
448 |
|
447 | |||
449 | var warnLeavingUnsavedMessage; |
|
448 | var warnLeavingUnsavedMessage; | |
450 | function warnLeavingUnsaved(message) { |
|
449 | function warnLeavingUnsaved(message) { | |
451 | warnLeavingUnsavedMessage = message; |
|
450 | warnLeavingUnsavedMessage = message; | |
452 |
|
451 | |||
453 | $('form').submit(function(){ |
|
452 | $('form').submit(function(){ | |
454 | $('textarea').removeData('changed'); |
|
453 | $('textarea').removeData('changed'); | |
455 | }); |
|
454 | }); | |
456 | $('textarea').change(function(){ |
|
455 | $('textarea').change(function(){ | |
457 | $(this).data('changed', 'changed'); |
|
456 | $(this).data('changed', 'changed'); | |
458 | }); |
|
457 | }); | |
459 | window.onbeforeunload = function(){ |
|
458 | window.onbeforeunload = function(){ | |
460 | var warn = false; |
|
459 | var warn = false; | |
461 | $('textarea').blur().each(function(){ |
|
460 | $('textarea').blur().each(function(){ | |
462 | if ($(this).data('changed')) { |
|
461 | if ($(this).data('changed')) { | |
463 | warn = true; |
|
462 | warn = true; | |
464 | } |
|
463 | } | |
465 | }); |
|
464 | }); | |
466 | if (warn) {return warnLeavingUnsavedMessage;} |
|
465 | if (warn) {return warnLeavingUnsavedMessage;} | |
467 | }; |
|
466 | }; | |
468 | }; |
|
467 | }; | |
469 |
|
468 | |||
470 | $(document).ready(function(){ |
|
469 | $(document).ready(function(){ | |
471 | $('#ajax-indicator').bind('ajaxSend', function(){ |
|
470 | $('#ajax-indicator').bind('ajaxSend', function(){ | |
472 | if ($('.ajax-loading').length == 0) { |
|
471 | if ($('.ajax-loading').length == 0) { | |
473 | $('#ajax-indicator').show(); |
|
472 | $('#ajax-indicator').show(); | |
474 | } |
|
473 | } | |
475 | }); |
|
474 | }); | |
476 | $('#ajax-indicator').bind('ajaxStop', function(){ |
|
475 | $('#ajax-indicator').bind('ajaxStop', function(){ | |
477 | $('#ajax-indicator').hide(); |
|
476 | $('#ajax-indicator').hide(); | |
478 | }); |
|
477 | }); | |
479 | }); |
|
478 | }); | |
480 |
|
479 | |||
481 | function hideOnLoad() { |
|
480 | function hideOnLoad() { | |
482 | $('.hol').hide(); |
|
481 | $('.hol').hide(); | |
483 | } |
|
482 | } | |
484 |
|
483 | |||
485 | function addFormObserversForDoubleSubmit() { |
|
484 | function addFormObserversForDoubleSubmit() { | |
486 | $('form[method=post]').each(function() { |
|
485 | $('form[method=post]').each(function() { | |
487 | if (!$(this).hasClass('multiple-submit')) { |
|
486 | if (!$(this).hasClass('multiple-submit')) { | |
488 | $(this).submit(function(form_submission) { |
|
487 | $(this).submit(function(form_submission) { | |
489 | if ($(form_submission.target).attr('data-submitted')) { |
|
488 | if ($(form_submission.target).attr('data-submitted')) { | |
490 | form_submission.preventDefault(); |
|
489 | form_submission.preventDefault(); | |
491 | } else { |
|
490 | } else { | |
492 | $(form_submission.target).attr('data-submitted', true); |
|
491 | $(form_submission.target).attr('data-submitted', true); | |
493 | } |
|
492 | } | |
494 | }); |
|
493 | }); | |
495 | } |
|
494 | } | |
496 | }); |
|
495 | }); | |
497 | } |
|
496 | } | |
498 |
|
497 | |||
499 | $(document).ready(hideOnLoad); |
|
498 | $(document).ready(hideOnLoad); | |
500 | $(document).ready(addFormObserversForDoubleSubmit); |
|
499 | $(document).ready(addFormObserversForDoubleSubmit); |
General Comments 0
You need to be logged in to leave comments.
Login now