Changeset - 3fdf7c3be2c9
[Not reviewed]
beta
0 6 0
Marcin Kuzminski - 13 years ago 2012-07-15 04:02:58
marcin@python-works.com
added mark as read for single notifications
6 files changed with 82 insertions and 14 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/notifications.py
Show inline comments
 
@@ -106,6 +106,18 @@ class NotificationsController(BaseContro
 
        #    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 @@ class NotificationsController(BaseContro
 
            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'
rhodecode/model/notification.py
Show inline comments
 
@@ -156,6 +156,23 @@ class NotificationModel(BaseModel):
 

	
 
        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()\
rhodecode/public/css/style.css
Show inline comments
 
@@ -3002,6 +3002,13 @@ table.code-browser .submodule-dir {
 
	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 @@ form.comment-inline-form {
 
    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 @@ form.comment-inline-form {
 
    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;
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -839,6 +839,27 @@ var deleteNotification = function(url, n
 
    											  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 **/
 

	
rhodecode/templates/admin/notifications/notifications.html
Show inline comments
 
@@ -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>
rhodecode/templates/admin/notifications/notifications_data.html
Show inline comments
 
@@ -18,6 +18,11 @@ unread = lambda n:{False:'unread'}.get(n
 
      <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>
0 comments (0 inline, 0 general)