##// END OF EJS Templates
added mark as read for single notifications
marcink -
r2610:3fdf7c3b beta
parent child Browse files
Show More
@@ -106,6 +106,18 b' class NotificationsController(BaseContro'
106 # h.form(url('notification', notification_id=ID),
106 # h.form(url('notification', notification_id=ID),
107 # method='put')
107 # method='put')
108 # url('notification', notification_id=ID)
108 # url('notification', notification_id=ID)
109 try:
110 no = Notification.get(notification_id)
111 owner = lambda: (no.notifications_to_users.user.user_id
112 == c.rhodecode_user.user_id)
113 if h.HasPermissionAny('hg.admin')() or owner:
114 NotificationModel().mark_read(c.rhodecode_user.user_id, no)
115 Session.commit()
116 return 'ok'
117 except Exception:
118 Session.rollback()
119 log.error(traceback.format_exc())
120 return 'fail'
109
121
110 def delete(self, notification_id):
122 def delete(self, notification_id):
111 """DELETE /_admin/notifications/id: Delete an existing item"""
123 """DELETE /_admin/notifications/id: Delete an existing item"""
@@ -120,7 +132,7 b' class NotificationsController(BaseContro'
120 no = Notification.get(notification_id)
132 no = Notification.get(notification_id)
121 owner = lambda: (no.notifications_to_users.user.user_id
133 owner = lambda: (no.notifications_to_users.user.user_id
122 == c.rhodecode_user.user_id)
134 == c.rhodecode_user.user_id)
123 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
135 if h.HasPermissionAny('hg.admin')() or owner:
124 NotificationModel().delete(c.rhodecode_user.user_id, no)
136 NotificationModel().delete(c.rhodecode_user.user_id, no)
125 Session.commit()
137 Session.commit()
126 return 'ok'
138 return 'ok'
@@ -156,6 +156,23 b' class NotificationModel(BaseModel):'
156
156
157 return q.all()
157 return q.all()
158
158
159 def mark_read(self, user, notification):
160 try:
161 notification = self.__get_notification(notification)
162 user = self._get_user(user)
163 if notification and user:
164 obj = UserNotification.query()\
165 .filter(UserNotification.user == user)\
166 .filter(UserNotification.notification
167 == notification)\
168 .one()
169 obj.read = True
170 self.sa.add(obj)
171 return True
172 except Exception:
173 log.error(traceback.format_exc())
174 raise
175
159 def mark_all_read_for_user(self, user, filter_=None):
176 def mark_all_read_for_user(self, user, filter_=None):
160 user = self._get_user(user)
177 user = self._get_user(user)
161 q = UserNotification.query()\
178 q = UserNotification.query()\
@@ -3002,6 +3002,13 b' table.code-browser .submodule-dir {'
3002 text-align: left;
3002 text-align: left;
3003 }
3003 }
3004
3004
3005 .accept_icon {
3006 background: url("../images/icons/accept.png") no-repeat scroll 3px;
3007 padding-left: 20px;
3008 padding-top: 0px;
3009 text-align: left;
3010 }
3011
3005 .edit_icon {
3012 .edit_icon {
3006 background: url("../images/icons/folder_edit.png") no-repeat scroll 3px;
3013 background: url("../images/icons/folder_edit.png") no-repeat scroll 3px;
3007 padding-left: 20px;
3014 padding-left: 20px;
@@ -4280,7 +4287,7 b' form.comment-inline-form {'
4280 background: none repeat scroll 0 0 transparent;
4287 background: none repeat scroll 0 0 transparent;
4281 padding: 0px 0px 0px 8px;
4288 padding: 0px 0px 0px 8px;
4282 }
4289 }
4283 .notification-header .desc.unread{
4290 .notification-list .container .notification-header .desc{
4284 font-weight: bold;
4291 font-weight: bold;
4285 font-size: 17px;
4292 font-size: 17px;
4286 }
4293 }
@@ -4297,6 +4304,11 b' form.comment-inline-form {'
4297 padding-top: 8px;
4304 padding-top: 8px;
4298 cursor: pointer;
4305 cursor: pointer;
4299 }
4306 }
4307 .notification-header .read-notifications{
4308 float: right;
4309 padding-top: 8px;
4310 cursor: pointer;
4311 }
4300 .notification-subject{
4312 .notification-subject{
4301 clear:both;
4313 clear:both;
4302 border-bottom: 1px solid #eee;
4314 border-bottom: 1px solid #eee;
@@ -839,6 +839,27 b' var deleteNotification = function(url, n'
839 callback, postData);
839 callback, postData);
840 };
840 };
841
841
842 var readNotification = function(url, notification_id,callbacks){
843 var callback = {
844 success:function(o){
845 var obj = YUD.get(String("notification_"+notification_id));
846 YUD.removeClass(obj, 'unread');
847 var r_button = obj.children[0].getElementsByClassName('read-notification')[0]
848
849 if(r_button.parentNode !== undefined){
850 r_button.parentNode.removeChild(r_button);
851 }
852 _run_callbacks(callbacks);
853 },
854 failure:function(o){
855 alert("error");
856 },
857 };
858 var postData = '_method=put';
859 var sUrl = url.replace('__NOTIFICATION_ID__',notification_id);
860 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl,
861 callback, postData);
862 };
842
863
843 /** MEMBERS AUTOCOMPLETE WIDGET **/
864 /** MEMBERS AUTOCOMPLETE WIDGET **/
844
865
@@ -40,25 +40,26 b''
40 </div>
40 </div>
41 </div>
41 </div>
42 <script type="text/javascript">
42 <script type="text/javascript">
43 var url_del = "${url('notification', notification_id='__NOTIFICATION_ID__')}";
43 var url_action = "${url('notification', notification_id='__NOTIFICATION_ID__')}";
44 YUE.on(YUQ('.delete-notification'),'click',function(e){
44 var run = function(){
45 var notification_id = e.currentTarget.id;
45 YUE.on(YUQ('.delete-notification'),'click',function(e){
46 deleteNotification(url_del,notification_id)
46 var notification_id = e.currentTarget.id;
47 })
47 deleteNotification(url_action,notification_id)
48 })
49 YUE.on(YUQ('.read-notification'),'click',function(e){
50 var notification_id = e.currentTarget.id;
51 readNotification(url_action,notification_id)
52 })
53 }
54 run()
48 YUE.on('mark_all_read','click',function(e){
55 YUE.on('mark_all_read','click',function(e){
49 var url = "${h.url('notifications_mark_all_read', **request.GET.mixed())}";
56 var url = "${h.url('notifications_mark_all_read', **request.GET.mixed())}";
50 ypjax(url,'notification_data',function(){
57 ypjax(url,'notification_data',function(){run()});
51 YUE.on(YUQ('.delete-notification'),'click',function(e){
52 var notification_id = e.currentTarget.id;
53 deleteNotification(url_del,notification_id)
54 })
55 });
56 })
58 })
57
59
58 var current_filter = "${c.current_filter}";
60 var current_filter = "${c.current_filter}";
59 if (YUD.get(current_filter)){
61 if (YUD.get(current_filter)){
60 YUD.addClass(current_filter, 'active');
62 YUD.addClass(current_filter, 'active');
61 }
63 }
62 console.log(current_filter);
63 </script>
64 </script>
64 </%def>
65 </%def>
@@ -18,6 +18,11 b" unread = lambda n:{False:'unread'}.get(n"
18 <div class="delete-notifications">
18 <div class="delete-notifications">
19 <span id="${notification.notification.notification_id}" class="delete-notification delete_icon action"></span>
19 <span id="${notification.notification.notification_id}" class="delete-notification delete_icon action"></span>
20 </div>
20 </div>
21 %if not notification.read:
22 <div class="read-notifications">
23 <span id="${notification.notification.notification_id}" class="read-notification accept_icon action"></span>
24 </div>
25 %endif
21 </div>
26 </div>
22 <div class="notification-subject">${h.literal(notification.notification.subject)}</div>
27 <div class="notification-subject">${h.literal(notification.notification.subject)}</div>
23 </div>
28 </div>
General Comments 0
You need to be logged in to leave comments. Login now