moved mark as seen to ruby function

This commit is contained in:
Johannes Nickel 2015-01-12 23:13:50 +01:00
parent c67048131c
commit 20084057cf
4 changed files with 33 additions and 19 deletions

View file

@ -43,10 +43,18 @@ class App.OnlineNotificationWidget extends App.Controller
else
@el.find('.logo').append('<div class="activity-counter">' + count.toString() + '</div>')
markAllAsSeen: (items) =>
for item in items
if !item.seen
App.OnlineNotification.seen( 'Ticket', item.id )
markAllAsSeen: () =>
@ajax(
id: 'markAllAsSeen'
type: 'POST'
url: @apiPath + '/online_notifications/markAllAsSeen'
data: JSON.stringify( '' )
processData: true
success: (data, status, xhr) =>
if data.result is 'ok'
else
fail: =>
)
stop: =>
@counterUpdate(0)
@ -81,7 +89,7 @@ class App.OnlineNotificationWidget extends App.Controller
# show frontend times
$('#markAllAsSeen').bind('click', (e) =>
e.preventDefault()
@markAllAsSeen(items)
@markAllAsSeen()
);
@frontendTimeUpdate()
).on('hide.bs.popover', =>

View file

@ -88,4 +88,12 @@ curl http://localhost/api/v1/online_notifications -v -u #{login}:#{password} -H
model_update_render(OnlineNotification, params)
end
def markAllAsSeen
notifications = OnlineNotification.list(current_user,100)
notifications.each do |notification|
OnlineNotification.seen({:id => notification['id']})
end
render :json => {data:'all cool'}
end
end

View file

@ -47,23 +47,20 @@ add a new online notification for this user
=begin
add a new online notification for this user
mark online notification as seen
OnlineNotification.add(
:type => 'Assigned to you',
:object => 'Ticket',
:o_id => ticket.id,
:seen => 1,
:created_by_id => 1,
:user_id => 2,
OnlineNotification.seen(
:id => 2,
:user => UserObject, #optional, if passed all
#notfications for the given user are marked as seen
)
=end
def self.seen(data)
notification = OnlineNotification.find(data[:id])
notification.seen = true
notification.save
notification = OnlineNotification.find(data[:id])
notification.seen = true
notification.save
end
=begin
@ -86,7 +83,7 @@ remove whole online notifications of an object
return all online notifications of an user
notifications = OnlineNotification.list( user )
notifications = OnlineNotification.list( user, limit )
=end

View file

@ -2,7 +2,8 @@ Zammad::Application.routes.draw do
api_path = Rails.configuration.api_path
# groups
match api_path + '/online_notifications', :to => 'online_notifications#index', :via => :get
match api_path + '/online_notifications/:id', :to => 'online_notifications#update', :via => :put
match api_path + '/online_notifications', :to => 'online_notifications#index', :via => :get
match api_path + '/online_notifications/:id', :to => 'online_notifications#update', :via => :put
match api_path + '/online_notifications/markAllAsSeen', :to => 'online_notifications#markAllAsSeen', :via => :post
end