##// END OF EJS Templates
Send the CSRF token with Ajax requests (#7843)....
Jean-Philippe Lang -
r5014:36dbb3906b32
parent child
Show More
@@ -1,81 +1,82
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3 <head>
3 <head>
4 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
4 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5 <title><%=h html_title %></title>
5 <title><%=h html_title %></title>
6 <meta name="description" content="<%= Redmine::Info.app_name %>" />
6 <meta name="description" content="<%= Redmine::Info.app_name %>" />
7 <meta name="keywords" content="issue,bug,tracker" />
7 <meta name="keywords" content="issue,bug,tracker" />
8 <%= csrf_meta_tag %>
8 <%= favicon %>
9 <%= favicon %>
9 <%= stylesheet_link_tag 'application', :media => 'all' %>
10 <%= stylesheet_link_tag 'application', :media => 'all' %>
10 <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
11 <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
11 <%= javascript_heads %>
12 <%= javascript_heads %>
12 <%= heads_for_theme %>
13 <%= heads_for_theme %>
13 <%= heads_for_wiki_formatter %>
14 <%= heads_for_wiki_formatter %>
14 <!--[if IE 6]>
15 <!--[if IE 6]>
15 <style type="text/css">
16 <style type="text/css">
16 * html body{ width: expression( document.documentElement.clientWidth < 900 ? '900px' : '100%' ); }
17 * html body{ width: expression( document.documentElement.clientWidth < 900 ? '900px' : '100%' ); }
17 body {behavior: url(<%= stylesheet_path "csshover.htc" %>);}
18 body {behavior: url(<%= stylesheet_path "csshover.htc" %>);}
18 </style>
19 </style>
19 <![endif]-->
20 <![endif]-->
20 <%= call_hook :view_layouts_base_html_head %>
21 <%= call_hook :view_layouts_base_html_head %>
21 <!-- page specific tags -->
22 <!-- page specific tags -->
22 <%= yield :header_tags -%>
23 <%= yield :header_tags -%>
23 </head>
24 </head>
24 <body class="<%=h body_css_classes %>">
25 <body class="<%=h body_css_classes %>">
25 <div id="wrapper">
26 <div id="wrapper">
26 <div id="wrapper2">
27 <div id="wrapper2">
27 <div id="top-menu">
28 <div id="top-menu">
28 <div id="account">
29 <div id="account">
29 <%= render_menu :account_menu -%>
30 <%= render_menu :account_menu -%>
30 </div>
31 </div>
31 <%= content_tag('div', "#{l(:label_logged_as)} #{link_to_user(User.current, :format => :username)}", :id => 'loggedas') if User.current.logged? %>
32 <%= content_tag('div', "#{l(:label_logged_as)} #{link_to_user(User.current, :format => :username)}", :id => 'loggedas') if User.current.logged? %>
32 <%= render_menu :top_menu if User.current.logged? || !Setting.login_required? -%>
33 <%= render_menu :top_menu if User.current.logged? || !Setting.login_required? -%>
33 </div>
34 </div>
34
35
35 <div id="header">
36 <div id="header">
36 <% if User.current.logged? || !Setting.login_required? %>
37 <% if User.current.logged? || !Setting.login_required? %>
37 <div id="quick-search">
38 <div id="quick-search">
38 <% form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
39 <% form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
39 <%= hidden_field_tag(controller.default_search_scope, 1, :id => nil) if controller.default_search_scope %>
40 <%= hidden_field_tag(controller.default_search_scope, 1, :id => nil) if controller.default_search_scope %>
40 <%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project}, :accesskey => accesskey(:search) %>:
41 <%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project}, :accesskey => accesskey(:search) %>:
41 <%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %>
42 <%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %>
42 <% end %>
43 <% end %>
43 <%= render_project_jump_box %>
44 <%= render_project_jump_box %>
44 </div>
45 </div>
45 <% end %>
46 <% end %>
46
47
47 <h1><%= page_header_title %></h1>
48 <h1><%= page_header_title %></h1>
48
49
49 <% if display_main_menu?(@project) %>
50 <% if display_main_menu?(@project) %>
50 <div id="main-menu">
51 <div id="main-menu">
51 <%= render_main_menu(@project) %>
52 <%= render_main_menu(@project) %>
52 </div>
53 </div>
53 <% end %>
54 <% end %>
54 </div>
55 </div>
55
56
56 <%= tag('div', {:id => 'main', :class => (has_content?(:sidebar) ? '' : 'nosidebar')}, true) %>
57 <%= tag('div', {:id => 'main', :class => (has_content?(:sidebar) ? '' : 'nosidebar')}, true) %>
57 <div id="sidebar">
58 <div id="sidebar">
58 <%= yield :sidebar %>
59 <%= yield :sidebar %>
59 <%= call_hook :view_layouts_base_sidebar %>
60 <%= call_hook :view_layouts_base_sidebar %>
60 </div>
61 </div>
61
62
62 <div id="content">
63 <div id="content">
63 <%= render_flash_messages %>
64 <%= render_flash_messages %>
64 <%= yield %>
65 <%= yield %>
65 <%= call_hook :view_layouts_base_content %>
66 <%= call_hook :view_layouts_base_content %>
66 <div style="clear:both;"></div>
67 <div style="clear:both;"></div>
67 </div>
68 </div>
68 </div>
69 </div>
69
70
70 <div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
71 <div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
71
72
72 <div id="footer">
73 <div id="footer">
73 <div class="bgl"><div class="bgr">
74 <div class="bgl"><div class="bgr">
74 Powered by <%= link_to Redmine::Info.app_name, Redmine::Info.url %> &copy; 2006-2011 Jean-Philippe Lang
75 Powered by <%= link_to Redmine::Info.app_name, Redmine::Info.url %> &copy; 2006-2011 Jean-Philippe Lang
75 </div></div>
76 </div></div>
76 </div>
77 </div>
77 </div>
78 </div>
78 </div>
79 </div>
79 <%= call_hook :view_layouts_base_body_bottom %>
80 <%= call_hook :view_layouts_base_body_bottom %>
80 </body>
81 </body>
81 </html>
82 </html>
@@ -1,322 +1,340
1 /* redMine - project management software
1 /* redMine - project management software
2 Copyright (C) 2006-2008 Jean-Philippe Lang */
2 Copyright (C) 2006-2008 Jean-Philippe Lang */
3
3
4 function checkAll (id, checked) {
4 function checkAll (id, checked) {
5 var els = Element.descendants(id);
5 var els = Element.descendants(id);
6 for (var i = 0; i < els.length; i++) {
6 for (var i = 0; i < els.length; i++) {
7 if (els[i].disabled==false) {
7 if (els[i].disabled==false) {
8 els[i].checked = checked;
8 els[i].checked = checked;
9 }
9 }
10 }
10 }
11 }
11 }
12
12
13 function toggleCheckboxesBySelector(selector) {
13 function toggleCheckboxesBySelector(selector) {
14 boxes = $$(selector);
14 boxes = $$(selector);
15 var all_checked = true;
15 var all_checked = true;
16 for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } }
16 for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } }
17 for (i = 0; i < boxes.length; i++) { boxes[i].checked = !all_checked; }
17 for (i = 0; i < boxes.length; i++) { boxes[i].checked = !all_checked; }
18 }
18 }
19
19
20 function setCheckboxesBySelector(checked, selector) {
20 function setCheckboxesBySelector(checked, selector) {
21 var boxes = $$(selector);
21 var boxes = $$(selector);
22 boxes.each(function(ele) {
22 boxes.each(function(ele) {
23 ele.checked = checked;
23 ele.checked = checked;
24 });
24 });
25 }
25 }
26
26
27 function showAndScrollTo(id, focus) {
27 function showAndScrollTo(id, focus) {
28 Element.show(id);
28 Element.show(id);
29 if (focus!=null) { Form.Element.focus(focus); }
29 if (focus!=null) { Form.Element.focus(focus); }
30 Element.scrollTo(id);
30 Element.scrollTo(id);
31 }
31 }
32
32
33 function toggleRowGroup(el) {
33 function toggleRowGroup(el) {
34 var tr = Element.up(el, 'tr');
34 var tr = Element.up(el, 'tr');
35 var n = Element.next(tr);
35 var n = Element.next(tr);
36 tr.toggleClassName('open');
36 tr.toggleClassName('open');
37 while (n != undefined && !n.hasClassName('group')) {
37 while (n != undefined && !n.hasClassName('group')) {
38 Element.toggle(n);
38 Element.toggle(n);
39 n = Element.next(n);
39 n = Element.next(n);
40 }
40 }
41 }
41 }
42
42
43 function toggleFieldset(el) {
43 function toggleFieldset(el) {
44 var fieldset = Element.up(el, 'fieldset');
44 var fieldset = Element.up(el, 'fieldset');
45 fieldset.toggleClassName('collapsed');
45 fieldset.toggleClassName('collapsed');
46 Effect.toggle(fieldset.down('div'), 'slide', {duration:0.2});
46 Effect.toggle(fieldset.down('div'), 'slide', {duration:0.2});
47 }
47 }
48
48
49 function hideFieldset(el) {
49 function hideFieldset(el) {
50 var fieldset = Element.up(el, 'fieldset');
50 var fieldset = Element.up(el, 'fieldset');
51 fieldset.toggleClassName('collapsed');
51 fieldset.toggleClassName('collapsed');
52 fieldset.down('div').hide();
52 fieldset.down('div').hide();
53 }
53 }
54
54
55 var fileFieldCount = 1;
55 var fileFieldCount = 1;
56
56
57 function addFileField() {
57 function addFileField() {
58 if (fileFieldCount >= 10) return false
58 if (fileFieldCount >= 10) return false
59 fileFieldCount++;
59 fileFieldCount++;
60 var f = document.createElement("input");
60 var f = document.createElement("input");
61 f.type = "file";
61 f.type = "file";
62 f.name = "attachments[" + fileFieldCount + "][file]";
62 f.name = "attachments[" + fileFieldCount + "][file]";
63 f.size = 30;
63 f.size = 30;
64 var d = document.createElement("input");
64 var d = document.createElement("input");
65 d.type = "text";
65 d.type = "text";
66 d.name = "attachments[" + fileFieldCount + "][description]";
66 d.name = "attachments[" + fileFieldCount + "][description]";
67 d.size = 60;
67 d.size = 60;
68 var dLabel = new Element('label');
68 var dLabel = new Element('label');
69 dLabel.addClassName('inline');
69 dLabel.addClassName('inline');
70 // Pulls the languge value used for Optional Description
70 // Pulls the languge value used for Optional Description
71 dLabel.update($('attachment_description_label_content').innerHTML)
71 dLabel.update($('attachment_description_label_content').innerHTML)
72 p = document.getElementById("attachments_fields");
72 p = document.getElementById("attachments_fields");
73 p.appendChild(document.createElement("br"));
73 p.appendChild(document.createElement("br"));
74 p.appendChild(f);
74 p.appendChild(f);
75 p.appendChild(dLabel);
75 p.appendChild(dLabel);
76 dLabel.appendChild(d);
76 dLabel.appendChild(d);
77
77
78 }
78 }
79
79
80 function showTab(name) {
80 function showTab(name) {
81 var f = $$('div#content .tab-content');
81 var f = $$('div#content .tab-content');
82 for(var i=0; i<f.length; i++){
82 for(var i=0; i<f.length; i++){
83 Element.hide(f[i]);
83 Element.hide(f[i]);
84 }
84 }
85 var f = $$('div.tabs a');
85 var f = $$('div.tabs a');
86 for(var i=0; i<f.length; i++){
86 for(var i=0; i<f.length; i++){
87 Element.removeClassName(f[i], "selected");
87 Element.removeClassName(f[i], "selected");
88 }
88 }
89 Element.show('tab-content-' + name);
89 Element.show('tab-content-' + name);
90 Element.addClassName('tab-' + name, "selected");
90 Element.addClassName('tab-' + name, "selected");
91 return false;
91 return false;
92 }
92 }
93
93
94 function moveTabRight(el) {
94 function moveTabRight(el) {
95 var lis = Element.up(el, 'div.tabs').down('ul').childElements();
95 var lis = Element.up(el, 'div.tabs').down('ul').childElements();
96 var tabsWidth = 0;
96 var tabsWidth = 0;
97 var i;
97 var i;
98 for (i=0; i<lis.length; i++) {
98 for (i=0; i<lis.length; i++) {
99 if (lis[i].visible()) {
99 if (lis[i].visible()) {
100 tabsWidth += lis[i].getWidth() + 6;
100 tabsWidth += lis[i].getWidth() + 6;
101 }
101 }
102 }
102 }
103 if (tabsWidth < Element.up(el, 'div.tabs').getWidth() - 60) {
103 if (tabsWidth < Element.up(el, 'div.tabs').getWidth() - 60) {
104 return;
104 return;
105 }
105 }
106 i=0;
106 i=0;
107 while (i<lis.length && !lis[i].visible()) {
107 while (i<lis.length && !lis[i].visible()) {
108 i++;
108 i++;
109 }
109 }
110 lis[i].hide();
110 lis[i].hide();
111 }
111 }
112
112
113 function moveTabLeft(el) {
113 function moveTabLeft(el) {
114 var lis = Element.up(el, 'div.tabs').down('ul').childElements();
114 var lis = Element.up(el, 'div.tabs').down('ul').childElements();
115 var i = 0;
115 var i = 0;
116 while (i<lis.length && !lis[i].visible()) {
116 while (i<lis.length && !lis[i].visible()) {
117 i++;
117 i++;
118 }
118 }
119 if (i>0) {
119 if (i>0) {
120 lis[i-1].show();
120 lis[i-1].show();
121 }
121 }
122 }
122 }
123
123
124 function displayTabsButtons() {
124 function displayTabsButtons() {
125 var lis;
125 var lis;
126 var tabsWidth = 0;
126 var tabsWidth = 0;
127 var i;
127 var i;
128 $$('div.tabs').each(function(el) {
128 $$('div.tabs').each(function(el) {
129 lis = el.down('ul').childElements();
129 lis = el.down('ul').childElements();
130 for (i=0; i<lis.length; i++) {
130 for (i=0; i<lis.length; i++) {
131 if (lis[i].visible()) {
131 if (lis[i].visible()) {
132 tabsWidth += lis[i].getWidth() + 6;
132 tabsWidth += lis[i].getWidth() + 6;
133 }
133 }
134 }
134 }
135 if ((tabsWidth < el.getWidth() - 60) && (lis[0].visible())) {
135 if ((tabsWidth < el.getWidth() - 60) && (lis[0].visible())) {
136 el.down('div.tabs-buttons').hide();
136 el.down('div.tabs-buttons').hide();
137 } else {
137 } else {
138 el.down('div.tabs-buttons').show();
138 el.down('div.tabs-buttons').show();
139 }
139 }
140 });
140 });
141 }
141 }
142
142
143 function setPredecessorFieldsVisibility() {
143 function setPredecessorFieldsVisibility() {
144 relationType = $('relation_relation_type');
144 relationType = $('relation_relation_type');
145 if (relationType && (relationType.value == "precedes" || relationType.value == "follows")) {
145 if (relationType && (relationType.value == "precedes" || relationType.value == "follows")) {
146 Element.show('predecessor_fields');
146 Element.show('predecessor_fields');
147 } else {
147 } else {
148 Element.hide('predecessor_fields');
148 Element.hide('predecessor_fields');
149 }
149 }
150 }
150 }
151
151
152 function promptToRemote(text, param, url) {
152 function promptToRemote(text, param, url) {
153 value = prompt(text + ':');
153 value = prompt(text + ':');
154 if (value) {
154 if (value) {
155 new Ajax.Request(url + '?' + param + '=' + encodeURIComponent(value), {asynchronous:true, evalScripts:true});
155 new Ajax.Request(url + '?' + param + '=' + encodeURIComponent(value), {asynchronous:true, evalScripts:true});
156 return false;
156 return false;
157 }
157 }
158 }
158 }
159
159
160 function collapseScmEntry(id) {
160 function collapseScmEntry(id) {
161 var els = document.getElementsByClassName(id, 'browser');
161 var els = document.getElementsByClassName(id, 'browser');
162 for (var i = 0; i < els.length; i++) {
162 for (var i = 0; i < els.length; i++) {
163 if (els[i].hasClassName('open')) {
163 if (els[i].hasClassName('open')) {
164 collapseScmEntry(els[i].id);
164 collapseScmEntry(els[i].id);
165 }
165 }
166 Element.hide(els[i]);
166 Element.hide(els[i]);
167 }
167 }
168 $(id).removeClassName('open');
168 $(id).removeClassName('open');
169 }
169 }
170
170
171 function expandScmEntry(id) {
171 function expandScmEntry(id) {
172 var els = document.getElementsByClassName(id, 'browser');
172 var els = document.getElementsByClassName(id, 'browser');
173 for (var i = 0; i < els.length; i++) {
173 for (var i = 0; i < els.length; i++) {
174 Element.show(els[i]);
174 Element.show(els[i]);
175 if (els[i].hasClassName('loaded') && !els[i].hasClassName('collapsed')) {
175 if (els[i].hasClassName('loaded') && !els[i].hasClassName('collapsed')) {
176 expandScmEntry(els[i].id);
176 expandScmEntry(els[i].id);
177 }
177 }
178 }
178 }
179 $(id).addClassName('open');
179 $(id).addClassName('open');
180 }
180 }
181
181
182 function scmEntryClick(id) {
182 function scmEntryClick(id) {
183 el = $(id);
183 el = $(id);
184 if (el.hasClassName('open')) {
184 if (el.hasClassName('open')) {
185 collapseScmEntry(id);
185 collapseScmEntry(id);
186 el.addClassName('collapsed');
186 el.addClassName('collapsed');
187 return false;
187 return false;
188 } else if (el.hasClassName('loaded')) {
188 } else if (el.hasClassName('loaded')) {
189 expandScmEntry(id);
189 expandScmEntry(id);
190 el.removeClassName('collapsed');
190 el.removeClassName('collapsed');
191 return false;
191 return false;
192 }
192 }
193 if (el.hasClassName('loading')) {
193 if (el.hasClassName('loading')) {
194 return false;
194 return false;
195 }
195 }
196 el.addClassName('loading');
196 el.addClassName('loading');
197 return true;
197 return true;
198 }
198 }
199
199
200 function scmEntryLoaded(id) {
200 function scmEntryLoaded(id) {
201 Element.addClassName(id, 'open');
201 Element.addClassName(id, 'open');
202 Element.addClassName(id, 'loaded');
202 Element.addClassName(id, 'loaded');
203 Element.removeClassName(id, 'loading');
203 Element.removeClassName(id, 'loading');
204 }
204 }
205
205
206 function randomKey(size) {
206 function randomKey(size) {
207 var chars = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
207 var chars = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
208 var key = '';
208 var key = '';
209 for (i = 0; i < size; i++) {
209 for (i = 0; i < size; i++) {
210 key += chars[Math.floor(Math.random() * chars.length)];
210 key += chars[Math.floor(Math.random() * chars.length)];
211 }
211 }
212 return key;
212 return key;
213 }
213 }
214
214
215 function observeParentIssueField(url) {
215 function observeParentIssueField(url) {
216 new Ajax.Autocompleter('issue_parent_issue_id',
216 new Ajax.Autocompleter('issue_parent_issue_id',
217 'parent_issue_candidates',
217 'parent_issue_candidates',
218 url,
218 url,
219 { minChars: 3,
219 { minChars: 3,
220 frequency: 0.5,
220 frequency: 0.5,
221 paramName: 'q',
221 paramName: 'q',
222 updateElement: function(value) {
222 updateElement: function(value) {
223 document.getElementById('issue_parent_issue_id').value = value.id;
223 document.getElementById('issue_parent_issue_id').value = value.id;
224 }});
224 }});
225 }
225 }
226
226
227 function observeRelatedIssueField(url) {
227 function observeRelatedIssueField(url) {
228 new Ajax.Autocompleter('relation_issue_to_id',
228 new Ajax.Autocompleter('relation_issue_to_id',
229 'related_issue_candidates',
229 'related_issue_candidates',
230 url,
230 url,
231 { minChars: 3,
231 { minChars: 3,
232 frequency: 0.5,
232 frequency: 0.5,
233 paramName: 'q',
233 paramName: 'q',
234 updateElement: function(value) {
234 updateElement: function(value) {
235 document.getElementById('relation_issue_to_id').value = value.id;
235 document.getElementById('relation_issue_to_id').value = value.id;
236 },
236 },
237 parameters: 'scope=all'
237 parameters: 'scope=all'
238 });
238 });
239 }
239 }
240
240
241 function setVisible(id, visible) {
241 function setVisible(id, visible) {
242 var el = $(id);
242 var el = $(id);
243 if (el) {if (visible) {el.show();} else {el.hide();}}
243 if (el) {if (visible) {el.show();} else {el.hide();}}
244 }
244 }
245
245
246 function observeProjectModules() {
246 function observeProjectModules() {
247 var f = function() {
247 var f = function() {
248 /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */
248 /* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */
249 var c = ($('project_enabled_module_names_issue_tracking').checked == true);
249 var c = ($('project_enabled_module_names_issue_tracking').checked == true);
250 setVisible('project_trackers', c);
250 setVisible('project_trackers', c);
251 setVisible('project_issue_custom_fields', c);
251 setVisible('project_issue_custom_fields', c);
252 };
252 };
253
253
254 Event.observe(window, 'load', f);
254 Event.observe(window, 'load', f);
255 Event.observe('project_enabled_module_names_issue_tracking', 'change', f);
255 Event.observe('project_enabled_module_names_issue_tracking', 'change', f);
256 }
256 }
257
257
258 /*
258 /*
259 * Class used to warn user when leaving a page with unsaved textarea
259 * Class used to warn user when leaving a page with unsaved textarea
260 * Author: mathias.fischer@berlinonline.de
260 * Author: mathias.fischer@berlinonline.de
261 */
261 */
262
262
263 var WarnLeavingUnsaved = Class.create({
263 var WarnLeavingUnsaved = Class.create({
264 observedForms: false,
264 observedForms: false,
265 observedElements: false,
265 observedElements: false,
266 changedForms: false,
266 changedForms: false,
267 message: null,
267 message: null,
268
268
269 initialize: function(message){
269 initialize: function(message){
270 this.observedForms = $$('form');
270 this.observedForms = $$('form');
271 this.observedElements = $$('textarea');
271 this.observedElements = $$('textarea');
272 this.message = message;
272 this.message = message;
273
273
274 this.observedElements.each(this.observeChange.bind(this));
274 this.observedElements.each(this.observeChange.bind(this));
275 this.observedForms.each(this.submitAction.bind(this));
275 this.observedForms.each(this.submitAction.bind(this));
276
276
277 window.onbeforeunload = this.unload.bind(this);
277 window.onbeforeunload = this.unload.bind(this);
278 },
278 },
279
279
280 unload: function(){
280 unload: function(){
281 if(this.changedForms)
281 if(this.changedForms)
282 return this.message;
282 return this.message;
283 },
283 },
284
284
285 setChanged: function(){
285 setChanged: function(){
286 this.changedForms = true;
286 this.changedForms = true;
287 },
287 },
288
288
289 setUnchanged: function(){
289 setUnchanged: function(){
290 this.changedForms = false;
290 this.changedForms = false;
291 },
291 },
292
292
293 observeChange: function(element){
293 observeChange: function(element){
294 element.observe('change',this.setChanged.bindAsEventListener(this));
294 element.observe('change',this.setChanged.bindAsEventListener(this));
295 },
295 },
296
296
297 submitAction: function(element){
297 submitAction: function(element){
298 element.observe('submit',this.setUnchanged.bindAsEventListener(this));
298 element.observe('submit',this.setUnchanged.bindAsEventListener(this));
299 }
299 }
300 });
300 });
301
301
302 /* shows and hides ajax indicator */
302 /*
303 * 1 - registers a callback which copies the csrf token into the
304 * X-CSRF-Token header with each ajax request. Necessary to
305 * work with rails applications which have fixed
306 * CVE-2011-0447
307 * 2 - shows and hides ajax indicator
308 */
303 Ajax.Responders.register({
309 Ajax.Responders.register({
304 onCreate: function(){
310 onCreate: function(request){
311 var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
312
313 if (csrf_meta_tag) {
314 var header = 'X-CSRF-Token',
315 token = csrf_meta_tag.readAttribute('content');
316
317 if (!request.options.requestHeaders) {
318 request.options.requestHeaders = {};
319 }
320 request.options.requestHeaders[header] = token;
321 }
322
305 if ($('ajax-indicator') && Ajax.activeRequestCount > 0) {
323 if ($('ajax-indicator') && Ajax.activeRequestCount > 0) {
306 Element.show('ajax-indicator');
324 Element.show('ajax-indicator');
307 }
325 }
308 },
326 },
309 onComplete: function(){
327 onComplete: function(){
310 if ($('ajax-indicator') && Ajax.activeRequestCount == 0) {
328 if ($('ajax-indicator') && Ajax.activeRequestCount == 0) {
311 Element.hide('ajax-indicator');
329 Element.hide('ajax-indicator');
312 }
330 }
313 }
331 }
314 });
332 });
315
333
316 function hideOnLoad() {
334 function hideOnLoad() {
317 $$('.hol').each(function(el) {
335 $$('.hol').each(function(el) {
318 el.hide();
336 el.hide();
319 });
337 });
320 }
338 }
321
339
322 Event.observe(window, 'load', hideOnLoad);
340 Event.observe(window, 'load', hideOnLoad);
General Comments 0
You need to be logged in to leave comments. Login now