diff --git a/app/assets/javascripts/app/controllers/widget/online_notification.js.coffee b/app/assets/javascripts/app/controllers/widget/online_notification.js.coffee
index f3a0689eb..a998599f5 100644
--- a/app/assets/javascripts/app/controllers/widget/online_notification.js.coffee
+++ b/app/assets/javascripts/app/controllers/widget/online_notification.js.coffee
@@ -43,10 +43,18 @@ class App.OnlineNotificationWidget extends App.Controller
else
@el.find('.logo').append('
' + count.toString() + '
')
- 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', =>
diff --git a/app/controllers/online_notifications_controller.rb b/app/controllers/online_notifications_controller.rb
index 20a60efb1..bb8ffac35 100644
--- a/app/controllers/online_notifications_controller.rb
+++ b/app/controllers/online_notifications_controller.rb
@@ -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:'ok'}
+ end
+
end
diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb
index dadbf5588..0b4112d31 100644
--- a/app/models/online_notification.rb
+++ b/app/models/online_notification.rb
@@ -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
diff --git a/config/routes/online_notification.rb b/config/routes/online_notification.rb
index 5ecfe3303..66ec56527 100644
--- a/config/routes/online_notification.rb
+++ b/config/routes/online_notification.rb
@@ -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
\ No newline at end of file