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