From a2a7c8093b7fb2966a40c6c6be45c4dd52683ab4 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 27 Aug 2013 12:18:53 +0300 Subject: [PATCH] Use flash message for notification across app --- app/assets/javascripts/flash.js.coffee | 15 +++++++++++++++ app/assets/javascripts/profile.js.coffee | 8 ++------ app/assets/stylesheets/sections/profile.scss | 6 ------ app/assets/stylesheets/sections/themes.scss | 7 ------- app/views/profiles/design.html.haml | 6 ------ app/views/profiles/notifications/show.html.haml | 9 --------- app/views/profiles/notifications/update.js.haml | 4 ++-- 7 files changed, 19 insertions(+), 36 deletions(-) create mode 100644 app/assets/javascripts/flash.js.coffee diff --git a/app/assets/javascripts/flash.js.coffee b/app/assets/javascripts/flash.js.coffee new file mode 100644 index 00000000000..f8b7789884f --- /dev/null +++ b/app/assets/javascripts/flash.js.coffee @@ -0,0 +1,15 @@ +class Flash + constructor: (message, type)-> + flash = $(".flash-container") + flash.html("") + + $('
', + class: "flash-#{type}", + text: message + ).appendTo(".flash-container") + + flash.click -> $(@).fadeOut() + flash.show() + setTimeout (-> flash.fadeOut()), 5000 + +@Flash = Flash diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile.js.coffee index 213133bc965..e7974611cbe 100644 --- a/app/assets/javascripts/profile.js.coffee +++ b/app/assets/javascripts/profile.js.coffee @@ -1,13 +1,9 @@ $ -> $('.edit_user .application-theme input, .edit_user .code-preview-theme input').click -> - # Hide any previous submission feedback - $('.edit_user .update-feedback').hide() - # Submit the form $('.edit_user').submit() - # Go up the hierarchy and show the corresponding submission feedback element - $(@).closest('fieldset').find('.update-feedback').show('highlight', {color: '#DFF0D8'}, 500) + new Flash("Appearance settings saved", "notice") $('.update-username form').on 'ajax:before', -> $('.loading-gif').show() @@ -17,6 +13,6 @@ $ -> $('.update-username form').on 'ajax:complete', -> $(this).find('.btn-save').enableButton() $(this).find('.loading-gif').hide() - + $('.update-notifications').on 'ajax:complete', -> $(this).find('.btn-save').enableButton() diff --git a/app/assets/stylesheets/sections/profile.scss b/app/assets/stylesheets/sections/profile.scss index 06a4046f916..5c7516ce6f9 100644 --- a/app/assets/stylesheets/sections/profile.scss +++ b/app/assets/stylesheets/sections/profile.scss @@ -1,9 +1,3 @@ -.save-status-fixed { - position: fixed; - left: 20px; - bottom: 50px; -} - .update-notifications { margin-bottom: 0; label { diff --git a/app/assets/stylesheets/sections/themes.scss b/app/assets/stylesheets/sections/themes.scss index c5487f9f40c..cd1aa2b011a 100644 --- a/app/assets/stylesheets/sections/themes.scss +++ b/app/assets/stylesheets/sections/themes.scss @@ -1,10 +1,3 @@ -.application-theme, .code-preview-theme { - .update-feedback { - color: #468847; - float: right; - } -} - .themes_opts { padding-left: 20px; diff --git a/app/views/profiles/design.html.haml b/app/views/profiles/design.html.haml index 75f00ab10a2..0d8075b7d43 100644 --- a/app/views/profiles/design.html.haml +++ b/app/views/profiles/design.html.haml @@ -8,9 +8,6 @@ %fieldset.application-theme %legend Application theme - .update-feedback.hide - %i.icon-ok - Saved .themes_opts = label_tag do .prev.default @@ -42,9 +39,6 @@ %fieldset.code-preview-theme %legend Code preview theme - .update-feedback.hide - %i.icon-ok - Saved .code_highlight_opts - color_schemes.each do |color_scheme_id, color_scheme| = label_tag do diff --git a/app/views/profiles/notifications/show.html.haml b/app/views/profiles/notifications/show.html.haml index 356d5499f07..8353b2f5f23 100644 --- a/app/views/profiles/notifications/show.html.haml +++ b/app/views/profiles/notifications/show.html.haml @@ -56,12 +56,3 @@ - @users_projects.each do |users_project| - notification = Notification.new(users_project) = render 'settings', type: 'project', membership: users_project, notification: notification - - -.save-status-fixed - %span.update-success.cgreen.hide - %i.icon-ok - Saved - %span.update-failed.cred.hide - %i.icon-remove - Failed diff --git a/app/views/profiles/notifications/update.js.haml b/app/views/profiles/notifications/update.js.haml index 88e74d50671..84c6ab25599 100644 --- a/app/views/profiles/notifications/update.js.haml +++ b/app/views/profiles/notifications/update.js.haml @@ -1,6 +1,6 @@ - if @saved :plain - $('.save-status-fixed .update-success').showAndHide(); + new Flash("Notification settings saved", "notice") - else :plain - $('.save-status-fixed .update-failed').showAndHide(); + new Flash("Failed to save new settings", "alert")