Commit a2a7c8093b7fb2966a40c6c6be45c4dd52683ab4

Authored by Dmitriy Zaporozhets
1 parent df9550c7

Use flash message for notification across app

app/assets/javascripts/flash.js.coffee 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +class Flash
  2 + constructor: (message, type)->
  3 + flash = $(".flash-container")
  4 + flash.html("")
  5 +
  6 + $('<div/>',
  7 + class: "flash-#{type}",
  8 + text: message
  9 + ).appendTo(".flash-container")
  10 +
  11 + flash.click -> $(@).fadeOut()
  12 + flash.show()
  13 + setTimeout (-> flash.fadeOut()), 5000
  14 +
  15 +@Flash = Flash
app/assets/javascripts/profile.js.coffee
1 $ -> 1 $ ->
2 $('.edit_user .application-theme input, .edit_user .code-preview-theme input').click -> 2 $('.edit_user .application-theme input, .edit_user .code-preview-theme input').click ->
3 - # Hide any previous submission feedback  
4 - $('.edit_user .update-feedback').hide()  
5 -  
6 # Submit the form 3 # Submit the form
7 $('.edit_user').submit() 4 $('.edit_user').submit()
8 5
9 - # Go up the hierarchy and show the corresponding submission feedback element  
10 - $(@).closest('fieldset').find('.update-feedback').show('highlight', {color: '#DFF0D8'}, 500) 6 + new Flash("Appearance settings saved", "notice")
11 7
12 $('.update-username form').on 'ajax:before', -> 8 $('.update-username form').on 'ajax:before', ->
13 $('.loading-gif').show() 9 $('.loading-gif').show()
@@ -17,6 +13,6 @@ $ -&gt; @@ -17,6 +13,6 @@ $ -&gt;
17 $('.update-username form').on 'ajax:complete', -> 13 $('.update-username form').on 'ajax:complete', ->
18 $(this).find('.btn-save').enableButton() 14 $(this).find('.btn-save').enableButton()
19 $(this).find('.loading-gif').hide() 15 $(this).find('.loading-gif').hide()
20 - 16 +
21 $('.update-notifications').on 'ajax:complete', -> 17 $('.update-notifications').on 'ajax:complete', ->
22 $(this).find('.btn-save').enableButton() 18 $(this).find('.btn-save').enableButton()
app/assets/stylesheets/sections/profile.scss
1 -.save-status-fixed {  
2 - position: fixed;  
3 - left: 20px;  
4 - bottom: 50px;  
5 -}  
6 -  
7 .update-notifications { 1 .update-notifications {
8 margin-bottom: 0; 2 margin-bottom: 0;
9 label { 3 label {
app/assets/stylesheets/sections/themes.scss
1 -.application-theme, .code-preview-theme {  
2 - .update-feedback {  
3 - color: #468847;  
4 - float: right;  
5 - }  
6 -}  
7 -  
8 .themes_opts { 1 .themes_opts {
9 padding-left: 20px; 2 padding-left: 20px;
10 3
app/views/profiles/design.html.haml
@@ -8,9 +8,6 @@ @@ -8,9 +8,6 @@
8 %fieldset.application-theme 8 %fieldset.application-theme
9 %legend 9 %legend
10 Application theme 10 Application theme
11 - .update-feedback.hide  
12 - %i.icon-ok  
13 - Saved  
14 .themes_opts 11 .themes_opts
15 = label_tag do 12 = label_tag do
16 .prev.default 13 .prev.default
@@ -42,9 +39,6 @@ @@ -42,9 +39,6 @@
42 %fieldset.code-preview-theme 39 %fieldset.code-preview-theme
43 %legend 40 %legend
44 Code preview theme 41 Code preview theme
45 - .update-feedback.hide  
46 - %i.icon-ok  
47 - Saved  
48 .code_highlight_opts 42 .code_highlight_opts
49 - color_schemes.each do |color_scheme_id, color_scheme| 43 - color_schemes.each do |color_scheme_id, color_scheme|
50 = label_tag do 44 = label_tag do
app/views/profiles/notifications/show.html.haml
@@ -56,12 +56,3 @@ @@ -56,12 +56,3 @@
56 - @users_projects.each do |users_project| 56 - @users_projects.each do |users_project|
57 - notification = Notification.new(users_project) 57 - notification = Notification.new(users_project)
58 = render 'settings', type: 'project', membership: users_project, notification: notification 58 = render 'settings', type: 'project', membership: users_project, notification: notification
59 -  
60 -  
61 -.save-status-fixed  
62 - %span.update-success.cgreen.hide  
63 - %i.icon-ok  
64 - Saved  
65 - %span.update-failed.cred.hide  
66 - %i.icon-remove  
67 - Failed  
app/views/profiles/notifications/update.js.haml
1 - if @saved 1 - if @saved
2 :plain 2 :plain
3 - $('.save-status-fixed .update-success').showAndHide(); 3 + new Flash("Notification settings saved", "notice")
4 - else 4 - else
5 :plain 5 :plain
6 - $('.save-status-fixed .update-failed').showAndHide(); 6 + new Flash("Failed to save new settings", "alert")