@@ -895,6 +895,15 module ApplicationHelper | |||||
895 | end |
|
895 | end | |
896 | end |
|
896 | end | |
897 |
|
897 | |||
|
898 | # Returns the javascript tags that are included in the html layout head | |||
|
899 | def javascript_heads | |||
|
900 | tags = javascript_include_tag(:defaults) | |||
|
901 | unless User.current.pref.warn_on_leaving_unsaved == '0' | |||
|
902 | tags << "\n" + javascript_tag("Event.observe(window, 'load', function(){ new WarnLeavingUnsaved('#{escape_javascript( l(:text_warn_on_leaving_unsaved) )}'); });") | |||
|
903 | end | |||
|
904 | tags | |||
|
905 | end | |||
|
906 | ||||
898 | def favicon |
|
907 | def favicon | |
899 | "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />" |
|
908 | "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />" | |
900 | end |
|
909 | end |
@@ -51,4 +51,7 class UserPreference < ActiveRecord::Base | |||||
51 |
|
51 | |||
52 | def comments_sorting; self[:comments_sorting] end |
|
52 | def comments_sorting; self[:comments_sorting] end | |
53 | def comments_sorting=(order); self[:comments_sorting]=order end |
|
53 | def comments_sorting=(order); self[:comments_sorting]=order end | |
|
54 | ||||
|
55 | def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end | |||
|
56 | def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end | |||
54 | end |
|
57 | end |
@@ -8,7 +8,7 | |||||
8 | <%= favicon %> |
|
8 | <%= favicon %> | |
9 | <%= stylesheet_link_tag 'application', :media => 'all' %> |
|
9 | <%= stylesheet_link_tag 'application', :media => 'all' %> | |
10 | <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> |
|
10 | <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> | |
11 |
<%= javascript_ |
|
11 | <%= javascript_heads %> | |
12 | <%= heads_for_theme %> |
|
12 | <%= heads_for_theme %> | |
13 | <%= heads_for_wiki_formatter %> |
|
13 | <%= heads_for_wiki_formatter %> | |
14 | <!--[if IE 6]> |
|
14 | <!--[if IE 6]> |
@@ -2,5 +2,6 | |||||
2 | <p><%= pref_fields.check_box :hide_mail %></p> |
|
2 | <p><%= pref_fields.check_box :hide_mail %></p> | |
3 | <p><%= pref_fields.select :time_zone, ActiveSupport::TimeZone.all.collect {|z| [ z.to_s, z.name ]}, :include_blank => true %></p> |
|
3 | <p><%= pref_fields.select :time_zone, ActiveSupport::TimeZone.all.collect {|z| [ z.to_s, z.name ]}, :include_blank => true %></p> | |
4 | <p><%= pref_fields.select :comments_sorting, [[l(:label_chronological_order), 'asc'], [l(:label_reverse_chronological_order), 'desc']] %></p> |
|
4 | <p><%= pref_fields.select :comments_sorting, [[l(:label_chronological_order), 'asc'], [l(:label_reverse_chronological_order), 'desc']] %></p> | |
|
5 | <p><%= pref_fields.check_box :warn_on_leaving_unsaved %></p> | |||
5 | <% end %> |
|
6 | <% end %> | |
6 |
|
7 |
@@ -303,6 +303,7 en: | |||||
303 | field_assigned_to_role: "Assignee's role" |
|
303 | field_assigned_to_role: "Assignee's role" | |
304 | field_text: Text field |
|
304 | field_text: Text field | |
305 | field_visible: Visible |
|
305 | field_visible: Visible | |
|
306 | field_warn_on_leaving_unsaved: "Warn me when leaving a page with unsaved text" | |||
306 |
|
307 | |||
307 | setting_app_title: Application title |
|
308 | setting_app_title: Application title | |
308 | setting_app_subtitle: Application subtitle |
|
309 | setting_app_subtitle: Application subtitle | |
@@ -908,6 +909,7 en: | |||||
908 | text_own_membership_delete_confirmation: "You are about to remove some or all of your permissions and may no longer be able to edit this project after that.\nAre you sure you want to continue?" |
|
909 | text_own_membership_delete_confirmation: "You are about to remove some or all of your permissions and may no longer be able to edit this project after that.\nAre you sure you want to continue?" | |
909 | text_zoom_in: Zoom in |
|
910 | text_zoom_in: Zoom in | |
910 | text_zoom_out: Zoom out |
|
911 | text_zoom_out: Zoom out | |
|
912 | text_warn_on_leaving_unsaved: "The current page contains unsaved text that will be lost if you leave this page." | |||
911 |
|
913 | |||
912 | default_role_manager: Manager |
|
914 | default_role_manager: Manager | |
913 | default_role_developer: Developer |
|
915 | default_role_developer: Developer |
@@ -307,6 +307,7 fr: | |||||
307 | field_active: Actif |
|
307 | field_active: Actif | |
308 | field_parent_issue: Tâche parente |
|
308 | field_parent_issue: Tâche parente | |
309 | field_visible: Visible |
|
309 | field_visible: Visible | |
|
310 | field_warn_on_leaving_unsaved: "M'avertir lorsque je quitte une page contenant du texte non sauvegardé" | |||
310 |
|
311 | |||
311 | setting_app_title: Titre de l'application |
|
312 | setting_app_title: Titre de l'application | |
312 | setting_app_subtitle: Sous-titre de l'application |
|
313 | setting_app_subtitle: Sous-titre de l'application | |
@@ -889,6 +890,7 fr: | |||||
889 | text_wiki_page_destroy_children: "Supprimer les sous-pages et toutes leurs descedantes" |
|
890 | text_wiki_page_destroy_children: "Supprimer les sous-pages et toutes leurs descedantes" | |
890 | text_wiki_page_reassign_children: "Réaffecter les sous-pages à cette page" |
|
891 | text_wiki_page_reassign_children: "Réaffecter les sous-pages à cette page" | |
891 | text_own_membership_delete_confirmation: "Vous allez supprimer tout ou partie de vos permissions sur ce projet et ne serez peut-être plus autorisé à modifier ce projet.\nEtes-vous sûr de vouloir continuer ?" |
|
892 | text_own_membership_delete_confirmation: "Vous allez supprimer tout ou partie de vos permissions sur ce projet et ne serez peut-être plus autorisé à modifier ce projet.\nEtes-vous sûr de vouloir continuer ?" | |
|
893 | text_warn_on_leaving_unsaved: "Cette page contient du texte non sauvegardé qui sera perdu si vous quittez la page." | |||
892 |
|
894 | |||
893 | default_role_manager: "Manager " |
|
895 | default_role_manager: "Manager " | |
894 | default_role_developer: "Développeur " |
|
896 | default_role_developer: "Développeur " |
@@ -255,6 +255,49 function observeProjectModules() { | |||||
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 | /* | |||
|
259 | * Class used to warn user when leaving a page with unsaved textarea | |||
|
260 | * Author: mathias.fischer@berlinonline.de | |||
|
261 | */ | |||
|
262 | ||||
|
263 | var WarnLeavingUnsaved = Class.create({ | |||
|
264 | observedForms: false, | |||
|
265 | observedElements: false, | |||
|
266 | changedForms: false, | |||
|
267 | message: null, | |||
|
268 | ||||
|
269 | initialize: function(message){ | |||
|
270 | this.observedForms = $$('form'); | |||
|
271 | this.observedElements = $$('textarea'); | |||
|
272 | this.message = message; | |||
|
273 | ||||
|
274 | this.observedElements.each(this.observeChange.bind(this)); | |||
|
275 | this.observedForms.each(this.submitAction.bind(this)); | |||
|
276 | ||||
|
277 | window.onbeforeunload = this.unload.bind(this); | |||
|
278 | }, | |||
|
279 | ||||
|
280 | unload: function(){ | |||
|
281 | if(this.changedForms) | |||
|
282 | return this.message; | |||
|
283 | }, | |||
|
284 | ||||
|
285 | setChanged: function(){ | |||
|
286 | this.changedForms = true; | |||
|
287 | }, | |||
|
288 | ||||
|
289 | setUnchanged: function(){ | |||
|
290 | this.changedForms = false; | |||
|
291 | }, | |||
|
292 | ||||
|
293 | observeChange: function(element){ | |||
|
294 | element.observe('change',this.setChanged.bindAsEventListener(this)); | |||
|
295 | }, | |||
|
296 | ||||
|
297 | submitAction: function(element){ | |||
|
298 | element.observe('submit',this.setUnchanged.bindAsEventListener(this)); | |||
|
299 | } | |||
|
300 | }); | |||
258 |
|
301 | |||
259 |
|
|
302 | /* shows and hides ajax indicator */ | |
260 | Ajax.Responders.register({ |
|
303 | Ajax.Responders.register({ |
@@ -67,4 +67,28 class WelcomeControllerTest < ActionController::TestCase | |||||
67 | assert_equal 'text/plain', @response.content_type |
|
67 | assert_equal 'text/plain', @response.content_type | |
68 | assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$}) |
|
68 | assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$}) | |
69 | end |
|
69 | end | |
|
70 | ||||
|
71 | def test_warn_on_leaving_unsaved_turn_on | |||
|
72 | user = User.find(2) | |||
|
73 | user.pref.warn_on_leaving_unsaved = '1' | |||
|
74 | user.pref.save! | |||
|
75 | @request.session[:user_id] = 2 | |||
|
76 | ||||
|
77 | get :index | |||
|
78 | assert_tag 'script', | |||
|
79 | :attributes => {:type => "text/javascript"}, | |||
|
80 | :content => %r{new WarnLeavingUnsaved} | |||
|
81 | end | |||
|
82 | ||||
|
83 | def test_warn_on_leaving_unsaved_turn_off | |||
|
84 | user = User.find(2) | |||
|
85 | user.pref.warn_on_leaving_unsaved = '0' | |||
|
86 | user.pref.save! | |||
|
87 | @request.session[:user_id] = 2 | |||
|
88 | ||||
|
89 | get :index | |||
|
90 | assert_no_tag 'script', | |||
|
91 | :attributes => {:type => "text/javascript"}, | |||
|
92 | :content => %r{new WarnLeavingUnsaved} | |||
|
93 | end | |||
70 | end |
|
94 | end |
General Comments 0
You need to be logged in to leave comments.
Login now