changeset 2610:3fdf7c3be2c9 beta

added mark as read for single notifications
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 15 Jul 2012 04:02:58 +0200
parents 200a5b747e69
children e83be26bb8d8
files rhodecode/controllers/admin/notifications.py rhodecode/model/notification.py rhodecode/public/css/style.css rhodecode/public/js/rhodecode.js rhodecode/templates/admin/notifications/notifications.html rhodecode/templates/admin/notifications/notifications_data.html
diffstat 6 files changed, 82 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/admin/notifications.py	Sun Jul 15 03:15:43 2012 +0200
+++ b/rhodecode/controllers/admin/notifications.py	Sun Jul 15 04:02:58 2012 +0200
@@ -106,6 +106,18 @@
         #    h.form(url('notification', notification_id=ID),
         #           method='put')
         # url('notification', notification_id=ID)
+        try:
+            no = Notification.get(notification_id)
+            owner = lambda: (no.notifications_to_users.user.user_id
+                             == c.rhodecode_user.user_id)
+            if h.HasPermissionAny('hg.admin')() or owner:
+                    NotificationModel().mark_read(c.rhodecode_user.user_id, no)
+                    Session.commit()
+                    return 'ok'
+        except Exception:
+            Session.rollback()
+            log.error(traceback.format_exc())
+        return 'fail'
 
     def delete(self, notification_id):
         """DELETE /_admin/notifications/id: Delete an existing item"""
@@ -120,7 +132,7 @@
             no = Notification.get(notification_id)
             owner = lambda: (no.notifications_to_users.user.user_id
                              == c.rhodecode_user.user_id)
-            if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
+            if h.HasPermissionAny('hg.admin')() or owner:
                     NotificationModel().delete(c.rhodecode_user.user_id, no)
                     Session.commit()
                     return 'ok'
--- a/rhodecode/model/notification.py	Sun Jul 15 03:15:43 2012 +0200
+++ b/rhodecode/model/notification.py	Sun Jul 15 04:02:58 2012 +0200
@@ -156,6 +156,23 @@
 
         return q.all()
 
+    def mark_read(self, user, notification):
+        try:
+            notification = self.__get_notification(notification)
+            user = self._get_user(user)
+            if notification and user:
+                obj = UserNotification.query()\
+                        .filter(UserNotification.user == user)\
+                        .filter(UserNotification.notification
+                                == notification)\
+                        .one()
+                obj.read = True
+                self.sa.add(obj)
+                return True
+        except Exception:
+            log.error(traceback.format_exc())
+            raise
+
     def mark_all_read_for_user(self, user, filter_=None):
         user = self._get_user(user)
         q = UserNotification.query()\
--- a/rhodecode/public/css/style.css	Sun Jul 15 03:15:43 2012 +0200
+++ b/rhodecode/public/css/style.css	Sun Jul 15 04:02:58 2012 +0200
@@ -3002,6 +3002,13 @@
 	text-align: left;
 }
 
+.accept_icon {
+    background: url("../images/icons/accept.png") no-repeat scroll 3px;
+    padding-left: 20px;
+    padding-top: 0px;
+    text-align: left;
+}
+
 .edit_icon {
 	background: url("../images/icons/folder_edit.png") no-repeat scroll 3px;
 	padding-left: 20px;
@@ -4280,7 +4287,7 @@
     background: none repeat scroll 0 0 transparent;
     padding: 0px 0px 0px 8px;	
 }
-.notification-header .desc.unread{
+.notification-list .container .notification-header .desc{
     font-weight: bold;
     font-size: 17px;
 }
@@ -4297,6 +4304,11 @@
     padding-top: 8px;
     cursor: pointer;
 }
+.notification-header .read-notifications{
+    float: right;
+    padding-top: 8px;
+    cursor: pointer;
+}
 .notification-subject{
     clear:both;
     border-bottom: 1px solid #eee;
--- a/rhodecode/public/js/rhodecode.js	Sun Jul 15 03:15:43 2012 +0200
+++ b/rhodecode/public/js/rhodecode.js	Sun Jul 15 04:02:58 2012 +0200
@@ -839,6 +839,27 @@
     											  callback, postData);
 };	
 
+var readNotification = function(url, notification_id,callbacks){
+    var callback = { 
+		success:function(o){
+		    var obj = YUD.get(String("notification_"+notification_id));
+		    YUD.removeClass(obj, 'unread');
+		    var r_button = obj.children[0].getElementsByClassName('read-notification')[0]
+		    
+		    if(r_button.parentNode !== undefined){
+		    	r_button.parentNode.removeChild(r_button);
+			}		    
+			_run_callbacks(callbacks);
+		},
+	    failure:function(o){
+	        alert("error");
+	    },
+	};
+    var postData = '_method=put';
+    var sUrl = url.replace('__NOTIFICATION_ID__',notification_id);
+    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, 
+    											  callback, postData);
+};	
 
 /** MEMBERS AUTOCOMPLETE WIDGET **/
 
--- a/rhodecode/templates/admin/notifications/notifications.html	Sun Jul 15 03:15:43 2012 +0200
+++ b/rhodecode/templates/admin/notifications/notifications.html	Sun Jul 15 04:02:58 2012 +0200
@@ -40,25 +40,26 @@
   </div>
 </div>
 <script type="text/javascript">
-var url_del = "${url('notification', notification_id='__NOTIFICATION_ID__')}";
-YUE.on(YUQ('.delete-notification'),'click',function(e){
- var notification_id = e.currentTarget.id;
- deleteNotification(url_del,notification_id)
-})
+var url_action = "${url('notification', notification_id='__NOTIFICATION_ID__')}";
+var run = function(){
+  YUE.on(YUQ('.delete-notification'),'click',function(e){
+   var notification_id = e.currentTarget.id;
+   deleteNotification(url_action,notification_id)
+  })
+  YUE.on(YUQ('.read-notification'),'click',function(e){
+     var notification_id = e.currentTarget.id;
+     readNotification(url_action,notification_id)
+  })
+}
+run()
 YUE.on('mark_all_read','click',function(e){
     var url = "${h.url('notifications_mark_all_read', **request.GET.mixed())}";
-    ypjax(url,'notification_data',function(){
-    	YUE.on(YUQ('.delete-notification'),'click',function(e){
-    		 var notification_id = e.currentTarget.id;
-    		 deleteNotification(url_del,notification_id)
-    	})
-    });
+    ypjax(url,'notification_data',function(){run()});
 })
 
 var current_filter = "${c.current_filter}";
 if (YUD.get(current_filter)){
 	YUD.addClass(current_filter, 'active');
 }
-console.log(current_filter);
 </script>
 </%def>
--- a/rhodecode/templates/admin/notifications/notifications_data.html	Sun Jul 15 03:15:43 2012 +0200
+++ b/rhodecode/templates/admin/notifications/notifications_data.html	Sun Jul 15 04:02:58 2012 +0200
@@ -18,6 +18,11 @@
       <div class="delete-notifications">
         <span id="${notification.notification.notification_id}" class="delete-notification delete_icon action"></span>
       </div>
+      %if not notification.read:
+      <div class="read-notifications">
+        <span id="${notification.notification.notification_id}" class="read-notification accept_icon action"></span>
+      </div>      
+      %endif
     </div>
     <div class="notification-subject">${h.literal(notification.notification.subject)}</div>
   </div>