diff --git a/app/assets/javascripts/behaviors/toggler_behavior.coffee b/app/assets/javascripts/behaviors/toggler_behavior.coffee index 3fefbf8e121ac7e9624958f026ca2621b05e25fb..d2181e7b75967ea837bb7c376ad5726c7ae9873d 100644 --- a/app/assets/javascripts/behaviors/toggler_behavior.coffee +++ b/app/assets/javascripts/behaviors/toggler_behavior.coffee @@ -3,3 +3,11 @@ $ -> container = $(@).closest(".js-toggler-container") container.toggleClass("on") + + $("body").on "click", ".js-toggle-visibility-link", (e) -> + $(@).find('i'). + toggleClass('icon-chevron-down'). + toggleClass('icon-chevron-up') + container = $(".js-toggle-visibility-container") + container.toggleClass("hide") + e.preventDefault() diff --git a/app/assets/javascripts/extensions/jquery.js.coffee b/app/assets/javascripts/extensions/jquery.js.coffee new file mode 100644 index 0000000000000000000000000000000000000000..8a997fe318e192a623d01ab833daec01eff3854b --- /dev/null +++ b/app/assets/javascripts/extensions/jquery.js.coffee @@ -0,0 +1,9 @@ +$.fn.showAndHide = -> + $(@).show(). + delay(3000). + fadeOut() + +$.fn.enableButton = -> + $(@).removeAttr('disabled'). + removeClass('disabled') + diff --git a/app/assets/javascripts/main.js.coffee b/app/assets/javascripts/main.js.coffee index b61df846c7ab88da5e86c972ffcd5f7486f5600a..39ec86e623fd9ce992a69c58aa7008a97e7a510c 100644 --- a/app/assets/javascripts/main.js.coffee +++ b/app/assets/javascripts/main.js.coffee @@ -7,6 +7,8 @@ window.slugify = (text) -> window.ajaxGet = (url) -> $.ajax({type: "GET", url: url, dataType: "script"}) +window.showAndHide = (selector) -> + window.errorMessage = (message) -> ehtml = $("<p>") ehtml.addClass("error_message") diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile.js.coffee index 42207a390b38e7820eca9f8c8c6404f869550885..213133bc96523372763a6b09e8005c55dbda3ed7 100644 --- a/app/assets/javascripts/profile.js.coffee +++ b/app/assets/javascripts/profile.js.coffee @@ -15,6 +15,8 @@ $ -> $(this).find('.update-failed').hide() $('.update-username form').on 'ajax:complete', -> - $(this).find('.save-btn').removeAttr('disabled') - $(this).find('.save-btn').removeClass('disabled') + $(this).find('.btn-save').enableButton() $(this).find('.loading-gif').hide() + + $('.update-notifications').on 'ajax:complete', -> + $(this).find('.btn-save').enableButton() diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index d2edb6a69e85d70693b1e8da4f3de8c5715435f0..e44e0aa845e5d51bd40faeabf0fc17068e52e6bc 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -3,9 +3,11 @@ class NotificationsController < ApplicationController def show @notification = current_user.notification + @projects = current_user.authorized_projects end def update - @notification = current_user.notification + current_user.notification_level = params[:notification_level] + @saved = current_user.save end end diff --git a/app/views/notifications/show.html.haml b/app/views/notifications/show.html.haml index 7ceb1926f1d477f5c926511b53fd13b1527317e6..d8ab93b8d1fbaa8ba0a3107ce8b4a77e39175347 100644 --- a/app/views/notifications/show.html.haml +++ b/app/views/notifications/show.html.haml @@ -1,15 +1,25 @@ %h3.page_title Setup your notification level -%hr +%br -= form_tag profile_notifications_path do +%p.light + %strong Disabled + – You will not get any notifications via email +%p.light + %strong Participating + – You will receive only notifications from related resources(ex. from assigned issue or your commit) +%p.light + %strong Watch + – You will receive all notifications from projects in which you participate +%hr - %ul.unstyled += form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do + %ul.well-list %li .row - .span3 + .span4 %h5 Global - .span9 + .span7 = label_tag do = radio_button_tag :notification_level, Notification::N_DISABLED, @notification.disabled? %span Disabled @@ -22,5 +32,37 @@ = radio_button_tag :notification_level, Notification::N_WATCH, @notification.watch? %span Watch + + = link_to '#', class: 'js-toggle-visibility-link' do + %h6.btn.btn-tiny + %i.icon-chevron-down + %span Per project notifications settings + %ul.well-list.js-toggle-visibility-container.hide + - @projects.each do |project| + %li + .row + .span4 + %span + = project.name_with_namespace + .span7 + = label_tag do + = radio_button_tag :"notification_level[#{project.id}]", Notification::N_DISABLED, @notification.disabled?, disabled: true + %span Disabled + + = label_tag do + = radio_button_tag :"notification_level[#{project.id}]", Notification::N_PARTICIPATING, @notification.participating?, disabled: true + %span Participating + + = label_tag do + = radio_button_tag :"notification_level[#{project.id}]", Notification::N_WATCH, @notification.watch?, disabled: true + %span Watch + + .form-actions = submit_tag 'Save', class: 'btn btn-save' + %span.update-success.cgreen.hide + %i.icon-ok + Saved + %span.update-failed.cred.hide + %i.icon-remove + Failed diff --git a/app/views/notifications/update.js.haml b/app/views/notifications/update.js.haml new file mode 100644 index 0000000000000000000000000000000000000000..4468004a5c220ecb7f116030f683159786dee59c --- /dev/null +++ b/app/views/notifications/update.js.haml @@ -0,0 +1,7 @@ +- if @saved + :plain + $('.update-notifications .update-success').showAndHide(); +- else + :plain + $('.update-notifications .update-failed').showAndHide(); + diff --git a/spec/requests/notifications_spec.rb b/spec/requests/notifications_spec.rb deleted file mode 100644 index 07db7c059870dc1493e93e3bd43f067f335acbf1..0000000000000000000000000000000000000000 --- a/spec/requests/notifications_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -describe "Notifications" do - describe "GET /notifications" do - it "works! (now write some real specs)" do - # Run the generator again with the --webrat flag if you want to use webrat methods/matchers - get notifications_path - response.status.should be(200) - end - end -end