Skip to content

Commit

Permalink
Prepare UI for notification settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaporozhets committed Mar 27, 2013
1 parent d55ade1 commit ba59912
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 19 deletions.
8 changes: 8 additions & 0 deletions app/assets/javascripts/behaviors/toggler_behavior.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
9 changes: 9 additions & 0 deletions app/assets/javascripts/extensions/jquery.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$.fn.showAndHide = ->
$(@).show().
delay(3000).
fadeOut()

$.fn.enableButton = ->
$(@).removeAttr('disabled').
removeClass('disabled')

2 changes: 2 additions & 0 deletions app/assets/javascripts/main.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions app/assets/javascripts/profile.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 3 additions & 1 deletion app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 47 additions & 5 deletions app/views/notifications/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
%h3.page_title Setup your notification level
%hr

%br

= form_tag profile_notifications_path do
%p.light
%strong Disabled
&ndash; You will not get any notifications via email
%p.light
%strong Participating
&ndash; You will receive only notifications from related resources(ex. from assigned issue or your commit)
%p.light
%strong Watch
&ndash; 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
Expand All @@ -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
7 changes: 7 additions & 0 deletions app/views/notifications/update.js.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- if @saved
:plain
$('.update-notifications .update-success').showAndHide();
- else
:plain
$('.update-notifications .update-failed').showAndHide();

11 changes: 0 additions & 11 deletions spec/requests/notifications_spec.rb

This file was deleted.

0 comments on commit ba59912

Please sign in to comment.