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