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