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 79 insertions and 11 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/notifications.py
Show inline comments
 
@@ -13,146 +13,158 @@
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import logging
 
import traceback
 

	
 
from pylons import request
 
from pylons import tmpl_context as c, url
 
from pylons.controllers.util import redirect
 

	
 
from webhelpers.paginate import Page
 

	
 
from rhodecode.lib.base import BaseController, render
 
from rhodecode.model.db import Notification
 

	
 
from rhodecode.model.notification import NotificationModel
 
from rhodecode.lib.auth import LoginRequired, NotAnonymous
 
from rhodecode.lib import helpers as h
 
from rhodecode.model.meta import Session
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class NotificationsController(BaseController):
 
    """REST Controller styled on the Atom Publishing Protocol"""
 
    # To properly map this controller, ensure your config/routing.py
 
    # file has a resource setup:
 
    #     map.resource('notification', 'notifications', controller='_admin/notifications',
 
    #         path_prefix='/_admin', name_prefix='_admin_')
 

	
 
    @LoginRequired()
 
    @NotAnonymous()
 
    def __before__(self):
 
        super(NotificationsController, self).__before__()
 

	
 
    def index(self, format='html'):
 
        """GET /_admin/notifications: All items in the collection"""
 
        # url('notifications')
 
        c.user = self.rhodecode_user
 
        notif = NotificationModel().get_for_user(self.rhodecode_user.user_id,
 
                                            filter_=request.GET.getall('type'))
 
        p = int(request.params.get('page', 1))
 
        c.notifications = Page(notif, page=p, items_per_page=10)
 
        c.pull_request_type = Notification.TYPE_PULL_REQUEST
 
        c.comment_type = [Notification.TYPE_CHANGESET_COMMENT,
 
                          Notification.TYPE_PULL_REQUEST_COMMENT]
 

	
 
        _current_filter = request.GET.getall('type')
 
        c.current_filter = 'all'
 
        if _current_filter == [c.pull_request_type]:
 
            c.current_filter = 'pull_request'
 
        elif _current_filter == c.comment_type:
 
            c.current_filter = 'comment'
 

	
 
        return render('admin/notifications/notifications.html')
 

	
 
    def mark_all_read(self):
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
 
            nm = NotificationModel()
 
            # mark all read
 
            nm.mark_all_read_for_user(self.rhodecode_user.user_id,
 
                                      filter_=request.GET.getall('type'))
 
            Session.commit()
 
            c.user = self.rhodecode_user
 
            notif = nm.get_for_user(self.rhodecode_user.user_id,
 
                                    filter_=request.GET.getall('type'))
 
            c.notifications = Page(notif, page=1, items_per_page=10)
 
            return render('admin/notifications/notifications_data.html')
 

	
 
    def create(self):
 
        """POST /_admin/notifications: Create a new item"""
 
        # url('notifications')
 

	
 
    def new(self, format='html'):
 
        """GET /_admin/notifications/new: Form to create a new item"""
 
        # url('new_notification')
 

	
 
    def update(self, notification_id):
 
        """PUT /_admin/notifications/id: Update an existing item"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="PUT" />
 
        # Or using helpers:
 
        #    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"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="DELETE" />
 
        # Or using helpers:
 
        #    h.form(url('notification', notification_id=ID),
 
        #           method='delete')
 
        # 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', 'repository.admin')() or owner:
 
            if h.HasPermissionAny('hg.admin')() or owner:
 
                    NotificationModel().delete(c.rhodecode_user.user_id, no)
 
                    Session.commit()
 
                    return 'ok'
 
        except Exception:
 
            Session.rollback()
 
            log.error(traceback.format_exc())
 
        return 'fail'
 

	
 
    def show(self, notification_id, format='html'):
 
        """GET /_admin/notifications/id: Show a specific item"""
 
        # url('notification', notification_id=ID)
 
        c.user = self.rhodecode_user
 
        no = Notification.get(notification_id)
 

	
 
        owner = lambda: (no.notifications_to_users.user.user_id
 
                         == c.user.user_id)
 
        if no and (h.HasPermissionAny('hg.admin', 'repository.admin')() or owner):
 
            unotification = NotificationModel()\
 
                            .get_user_notification(c.user.user_id, no)
 

	
 
            # if this association to user is not valid, we don't want to show
 
            # this message
 
            if unotification:
 
                if unotification.read is False:
 
                    unotification.mark_as_read()
 
                    Session.commit()
 
                c.notification = no
 

	
 
                return render('admin/notifications/show_notification.html')
 

	
 
        return redirect(url('notifications'))
 

	
 
    def edit(self, notification_id, format='html'):
 
        """GET /_admin/notifications/id/edit: Form to edit an existing item"""
 
        # url('edit_notification', notification_id=ID)
rhodecode/model/notification.py
Show inline comments
 
@@ -63,192 +63,209 @@ class NotificationModel(BaseModel):
 
            notification
 
        :param subject:
 
        :param body:
 
        :param recipients: list of int, str or User objects, when None
 
            is given send to all admins
 
        :param type_: type of notification
 
        :param with_email: send email with this notification
 
        :param email_kwargs: additional dict to pass as args to email template
 
        """
 
        from rhodecode.lib.celerylib import tasks, run_task
 

	
 
        if recipients and not getattr(recipients, '__iter__', False):
 
            raise Exception('recipients must be a list of iterable')
 

	
 
        created_by_obj = self._get_user(created_by)
 

	
 
        if recipients:
 
            recipients_objs = []
 
            for u in recipients:
 
                obj = self._get_user(u)
 
                if obj:
 
                    recipients_objs.append(obj)
 
            recipients_objs = set(recipients_objs)
 
            log.debug('sending notifications %s to %s' % (
 
                type_, recipients_objs)
 
            )
 
        else:
 
            # empty recipients means to all admins
 
            recipients_objs = User.query().filter(User.admin == True).all()
 
            log.debug('sending notifications %s to admins: %s' % (
 
                type_, recipients_objs)
 
            )
 
        notif = Notification.create(
 
            created_by=created_by_obj, subject=subject,
 
            body=body, recipients=recipients_objs, type_=type_
 
        )
 

	
 
        if with_email is False:
 
            return notif
 

	
 
        #don't send email to person who created this comment
 
        rec_objs = set(recipients_objs).difference(set([created_by_obj]))
 

	
 
        # send email with notification to all other participants
 
        for rec in rec_objs:
 
            email_subject = NotificationModel().make_description(notif, False)
 
            type_ = type_
 
            email_body = body
 
            ## this is passed into template
 
            kwargs = {'subject': subject, 'body': h.rst_w_mentions(body)}
 
            kwargs.update(email_kwargs)
 
            email_body_html = EmailNotificationModel()\
 
                                .get_email_tmpl(type_, **kwargs)
 

	
 
            run_task(tasks.send_email, rec.email, email_subject, email_body,
 
                     email_body_html)
 

	
 
        return notif
 

	
 
    def delete(self, user, notification):
 
        # we don't want to remove actual notification just the assignment
 
        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()
 
                self.sa.delete(obj)
 
                return True
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            raise
 

	
 
    def get_for_user(self, user, filter_=None):
 
        """
 
        Get mentions for given user, filter them if filter dict is given
 

	
 
        :param user:
 
        :type user:
 
        :param filter:
 
        """
 
        user = self._get_user(user)
 

	
 
        q = UserNotification.query()\
 
            .filter(UserNotification.user == user)\
 
            .join((Notification, UserNotification.notification_id ==
 
                                 Notification.notification_id))
 

	
 
        if filter_:
 
            q = q.filter(Notification.type_.in_(filter_))
 

	
 
        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()\
 
            .filter(UserNotification.user == user)\
 
            .filter(UserNotification.read == False)\
 
            .join((Notification, UserNotification.notification_id ==
 
                                 Notification.notification_id))
 
        if filter_:
 
            q = q.filter(Notification.type_.in_(filter_))
 

	
 
        # this is a little inefficient but sqlalchemy doesn't support
 
        # update on joined tables :(
 
        for obj in q.all():
 
            obj.read = True
 
            self.sa.add(obj)
 

	
 
    def get_unread_cnt_for_user(self, user):
 
        user = self._get_user(user)
 
        return UserNotification.query()\
 
                .filter(UserNotification.read == False)\
 
                .filter(UserNotification.user == user).count()
 

	
 
    def get_unread_for_user(self, user):
 
        user = self._get_user(user)
 
        return [x.notification for x in UserNotification.query()\
 
                .filter(UserNotification.read == False)\
 
                .filter(UserNotification.user == user).all()]
 

	
 
    def get_user_notification(self, user, notification):
 
        user = self._get_user(user)
 
        notification = self.__get_notification(notification)
 

	
 
        return UserNotification.query()\
 
            .filter(UserNotification.notification == notification)\
 
            .filter(UserNotification.user == user).scalar()
 

	
 
    def make_description(self, notification, show_age=True):
 
        """
 
        Creates a human readable description based on properties
 
        of notification object
 
        """
 
        #alias
 
        _n = notification
 
        _map = {
 
            _n.TYPE_CHANGESET_COMMENT: _('commented on commit'),
 
            _n.TYPE_MESSAGE: _('sent message'),
 
            _n.TYPE_MENTION: _('mentioned you'),
 
            _n.TYPE_REGISTRATION: _('registered in RhodeCode'),
 
            _n.TYPE_PULL_REQUEST: _('opened new pull request'),
 
            _n.TYPE_PULL_REQUEST_COMMENT: _('commented on pull request')
 
        }
 

	
 
        # action == _map string
 
        tmpl = "%(user)s %(action)s at %(when)s"
 
        if show_age:
 
            when = h.age(notification.created_on)
 
        else:
 
            when = h.fmt_date(notification.created_on)
 

	
 
        data = dict(
 
            user=notification.created_by_user.username,
 
            action=_map[notification.type_], when=when,
 
        )
 
        return tmpl % data
 

	
 

	
 
class EmailNotificationModel(BaseModel):
 

	
 
    TYPE_CHANGESET_COMMENT = Notification.TYPE_CHANGESET_COMMENT
 
    TYPE_PASSWORD_RESET = 'passoword_link'
 
    TYPE_REGISTRATION = Notification.TYPE_REGISTRATION
 
    TYPE_PULL_REQUEST = Notification.TYPE_PULL_REQUEST
 
    TYPE_DEFAULT = 'default'
 

	
 
    def __init__(self):
 
        self._template_root = rhodecode.CONFIG['pylons.paths']['templates'][0]
 
        self._tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
 

	
 
        self.email_types = {
 
         self.TYPE_CHANGESET_COMMENT: 'email_templates/changeset_comment.html',
 
         self.TYPE_PASSWORD_RESET: 'email_templates/password_reset.html',
 
         self.TYPE_REGISTRATION: 'email_templates/registration.html',
 
         self.TYPE_DEFAULT: 'email_templates/default.html'
 
        }
 

	
 
    def get_email_tmpl(self, type_, **kwargs):
 
        """
 
        return generated template for email based on given type
 

	
 
        :param type_:
 
        """
 

	
 
        base = self.email_types.get(type_, self.email_types[self.TYPE_DEFAULT])
 
        email_template = self._tmpl_lookup.get_template(base)
 
        # translator inject
 
        _kwargs = {'_': _}
rhodecode/public/css/style.css
Show inline comments
 
@@ -2909,192 +2909,199 @@ table.code-browser .submodule-dir {
 
	width: 100%;
 
}
 
 
.ac .yui-ac-container {
 
	position: absolute;
 
	top: 1.6em;
 
	width: auto;
 
}
 
 
.ac .yui-ac-content {
 
	position: absolute;
 
	border: 1px solid gray;
 
	background: #fff;
 
	z-index: 9050;
 
	
 
}
 
 
.ac .yui-ac-shadow {
 
	position: absolute;
 
	width: 100%;
 
	background: #000;
 
	-moz-opacity: 0.1px;
 
	opacity: .10;
 
	filter: alpha(opacity = 10);
 
	z-index: 9049;
 
	margin: .3em;
 
}
 
 
.ac .yui-ac-content ul {
 
	width: 100%;
 
	margin: 0;
 
	padding: 0;
 
	z-index: 9050;
 
}
 
 
.ac .yui-ac-content li {
 
	cursor: default;
 
	white-space: nowrap;
 
	margin: 0;
 
	padding: 2px 5px;
 
	height: 18px;
 
	z-index: 9050;
 
	display: block;
 
	width: auto !important;
 
}
 
 
.ac .yui-ac-content li .ac-container-wrap{
 
    width: auto;
 
}
 
 
.ac .yui-ac-content li.yui-ac-prehighlight {
 
	background: #B3D4FF;
 
	z-index: 9050;
 
}
 
 
.ac .yui-ac-content li.yui-ac-highlight {
 
	background: #556CB5;
 
	color: #FFF;
 
	z-index: 9050;
 
}
 
.ac .yui-ac-bd{
 
	z-index: 9050;
 
}
 
 
.follow {
 
	background: url("../images/icons/heart_add.png") no-repeat scroll 3px;
 
	height: 16px;
 
	width: 20px;
 
	cursor: pointer;
 
	display: block;
 
	float: right;
 
	margin-top: 2px;
 
}
 
 
.following {
 
	background: url("../images/icons/heart_delete.png") no-repeat scroll 3px;
 
	height: 16px;
 
	width: 20px;
 
	cursor: pointer;
 
	display: block;
 
	float: right;
 
	margin-top: 2px;
 
}
 
 
.currently_following {
 
	padding-left: 10px;
 
	padding-bottom: 5px;
 
}
 
 
.add_icon {
 
	background: url("../images/icons/add.png") no-repeat scroll 3px;
 
	padding-left: 20px;
 
	padding-top: 0px;
 
	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;
 
	padding-top: 0px;
 
	text-align: left;
 
}
 
 
.delete_icon {
 
	background: url("../images/icons/delete.png") no-repeat scroll 3px;
 
	padding-left: 20px;
 
	padding-top: 0px;
 
	text-align: left;
 
}
 
 
.refresh_icon {
 
	background: url("../images/icons/arrow_refresh.png") no-repeat scroll
 
		3px;
 
	padding-left: 20px;
 
	padding-top: 0px;
 
	text-align: left;
 
}
 
 
.pull_icon {
 
	background: url("../images/icons/connect.png") no-repeat scroll 3px;
 
	padding-left: 20px;
 
	padding-top: 0px;
 
	text-align: left;
 
}
 
 
.rss_icon {
 
	background: url("../images/icons/rss_16.png") no-repeat scroll 3px;
 
	padding-left: 20px;
 
	padding-top: 4px;
 
	text-align: left;
 
	font-size: 8px
 
}
 
 
.atom_icon {
 
	background: url("../images/icons/atom.png") no-repeat scroll 3px;
 
	padding-left: 20px;
 
	padding-top: 4px;
 
	text-align: left;
 
	font-size: 8px
 
}
 
 
.archive_icon {
 
	background: url("../images/icons/compress.png") no-repeat scroll 3px;
 
	padding-left: 20px;
 
	text-align: left;
 
	padding-top: 1px;
 
}
 
 
.start_following_icon {
 
	background: url("../images/icons/heart_add.png") no-repeat scroll 3px;
 
	padding-left: 20px;
 
	text-align: left;
 
	padding-top: 0px;
 
}
 
 
.stop_following_icon {
 
	background: url("../images/icons/heart_delete.png") no-repeat scroll 3px;
 
	padding-left: 20px;
 
	text-align: left;
 
	padding-top: 0px;
 
}
 
 
.action_button {
 
	border: 0;
 
	display: inline;
 
}
 
 
.action_button:hover {
 
	border: 0;
 
	text-decoration: underline;
 
	cursor: pointer;
 
}
 
 
#switch_repos {
 
	position: absolute;
 
	height: 25px;
 
	z-index: 1;
 
}
 
 
#switch_repos select {
 
	min-width: 150px;
 
	max-height: 250px;
 
	z-index: 1;
 
}
 
 
.breadcrumbs {
 
	border: medium none;
 
	color: #FFF;
 
	float: left;
 
	text-transform: uppercase;
 
	font-weight: 700;
 
	font-size: 14px;
 
@@ -4187,209 +4194,214 @@ form.comment-inline-form {
 
.inline-comments .comment {
 
    border: 1px solid #ddd;
 
    -webkit-border-radius: 4px;
 
    -moz-border-radius: 4px;
 
    border-radius: 4px;
 
    margin: 3px 3px 5px 5px;
 
    background-color: #FAFAFA;
 
}
 
.inline-comments .add-comment {
 
	padding: 2px 4px 8px 5px;
 
}
 
 
.inline-comments .comment-wrapp{
 
	padding:1px;
 
}
 
.inline-comments .comment .meta {
 
    background: #f8f8f8;
 
    padding: 4px;
 
    border-bottom: 1px solid #ddd;
 
    height: 20px;
 
}
 
 
.inline-comments .comment .meta img {
 
    vertical-align: middle;
 
}
 
 
.inline-comments .comment .meta .user {
 
    font-weight: bold;
 
    float:left;
 
    padding: 3px;
 
}
 
 
.inline-comments .comment .meta .date {
 
    float:left;
 
    padding: 3px;
 
}
 
 
.inline-comments .comment .text {
 
    background-color: #FAFAFA;
 
}
 
 
.inline-comments .comments-number{
 
    padding:0px 0px 10px 0px;
 
    font-weight: bold;
 
    color: #666;
 
    font-size: 16px;
 
}
 
.inline-comments-button .add-comment{
 
	margin:2px 0px 8px 5px !important
 
}
 
 
 
.notification-paginator{
 
    padding: 0px 0px 4px 16px;
 
    float: left;    	
 
}
 
 
.notifications{
 
    border-radius: 4px 4px 4px 4px;
 
    -webkit-border-radius: 4px;
 
    -moz-border-radius: 4px;    
 
    float: right;
 
    margin: 20px 0px 0px 0px;
 
    position: absolute;
 
    text-align: center;
 
    width: 26px;
 
    z-index: 1000;
 
}
 
.notifications a{
 
	color:#888 !important;
 
	display: block;
 
	font-size: 10px;
 
	background-color: #DEDEDE !important;
 
    border-radius: 2px !important;
 
    -webkit-border-radius: 2px !important;
 
    -moz-border-radius: 2px !important;  	
 
}
 
.notifications a:hover{
 
	text-decoration: none !important;
 
	background-color: #EEEFFF !important;
 
}
 
.notification-header{
 
	padding-top:6px;
 
}
 
.notification-header .desc{
 
	font-size: 16px;
 
    height: 24px;
 
    float: left
 
}
 
.notification-list .container.unread{
 
	background: none repeat scroll 0 0 rgba(255, 255, 180, 0.6);
 
}
 
.notification-header .gravatar{
 
    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;
 
}
 
.notification-table{
 
	border: 1px solid #ccc;
 
    -webkit-border-radius: 6px 6px 6px 6px;
 
    -moz-border-radius: 6px 6px 6px 6px;
 
    border-radius: 6px 6px 6px 6px;
 
    clear: both;
 
    margin: 0px 20px 0px 20px;
 
}
 
.notification-header .delete-notifications{
 
    float: right;
 
    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;
 
    padding:5px 0px 5px 38px;
 
}
 
 
.notification-body{
 
	clear:both;
 
	margin: 34px 2px 2px 8px
 
}
 
 
/****
 
  PERMS
 
*****/
 
#perms .perms_section_head {
 
   padding:10px 10px 10px 0px;
 
   font-size:16px;
 
   font-weight: bold;
 
}
 
 
#perms .perm_tag{
 
  padding: 1px 3px 1px 3px;
 
  font-size: 10px;
 
  font-weight: bold;
 
  text-transform: uppercase;
 
  white-space: nowrap;
 
  -webkit-border-radius: 3px;
 
  -moz-border-radius: 3px;
 
  border-radius: 3px;
 
}
 
 
#perms .perm_tag.admin{
 
  background-color: #B94A48;
 
  color: #ffffff;
 
}
 
 
#perms .perm_tag.write{
 
  background-color: #B94A48;
 
  color: #ffffff;    
 
}
 
 
#perms .perm_tag.read{
 
  background-color: #468847;
 
  color: #ffffff;    
 
}
 
 
#perms .perm_tag.none{
 
  background-color: #bfbfbf;
 
  color: #ffffff;    
 
}
 
 
.perm-gravatar{
 
	vertical-align:middle;
 
	padding:2px;
 
}
 
.perm-gravatar-ac{
 
    vertical-align:middle;
 
    padding:2px;
 
    width: 14px;
 
    height: 14px;	
 
}
 
 
/*****************************************************************************
 
                                  DIFFS CSS
 
******************************************************************************/
 
 
div.diffblock {
 
    overflow: auto;
 
    padding: 0px;
 
    border: 1px solid #ccc;
 
    background: #f8f8f8;
 
    font-size: 100%;
 
    line-height: 100%;
 
    /* new */
 
    line-height: 125%;
 
    -webkit-border-radius: 6px 6px 0px 0px;
 
    -moz-border-radius: 6px 6px 0px 0px;
 
    border-radius: 6px 6px 0px 0px;     
 
}
 
div.diffblock.margined{
 
    margin: 0px 20px 0px 20px;
 
}
 
div.diffblock .code-header{
 
    border-bottom: 1px solid #CCCCCC;
 
    background: #EEEEEE;
 
    padding:10px 0 10px 0;
 
    height: 14px;
 
}
 
div.diffblock .code-header.cv{
 
    height: 34px;
 
}
 
div.diffblock .code-header-title{
 
	padding: 0px 0px 10px 5px !important;
 
	margin: 0 !important;
 
}
 
div.diffblock .code-header .hash{
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -746,192 +746,213 @@ var initCodeMirror = function(textAreadI
 
    
 
    YUE.on('upload_file_enable','click',function(){
 
        YUD.setStyle('editor_container','display','none');
 
        YUD.setStyle('upload_file_container','display','');
 
        YUD.setStyle('filename_container','display','none');
 
    });	
 
};
 

	
 

	
 

	
 
var getIdentNode = function(n){
 
	//iterate thru nodes untill matched interesting node !
 
	
 
	if (typeof n == 'undefined'){
 
		return -1
 
	}
 
	
 
	if(typeof n.id != "undefined" && n.id.match('L[0-9]+')){
 
			return n
 
		}
 
	else{
 
		return getIdentNode(n.parentNode);
 
	}
 
};
 

	
 
var  getSelectionLink = function(selection_link_label) {
 
	return function(){
 
	    //get selection from start/to nodes    	
 
	    if (typeof window.getSelection != "undefined") {
 
	    	s = window.getSelection();
 
	
 
	       	from = getIdentNode(s.anchorNode);
 
	       	till = getIdentNode(s.focusNode);
 
	        
 
	        f_int = parseInt(from.id.replace('L',''));
 
	        t_int = parseInt(till.id.replace('L',''));
 
	        
 
	        if (f_int > t_int){
 
	        	//highlight from bottom 
 
	        	offset = -35;
 
	        	ranges = [t_int,f_int];
 
	        	
 
	        }
 
	        else{
 
	        	//highligth from top 
 
	        	offset = 35;
 
	        	ranges = [f_int,t_int];
 
	        }
 
	        
 
	        if (ranges[0] != ranges[1]){
 
	            if(YUD.get('linktt') == null){
 
	                hl_div = document.createElement('div');
 
	                hl_div.id = 'linktt';
 
	            }
 
	            anchor = '#L'+ranges[0]+'-'+ranges[1];
 
	            hl_div.innerHTML = '';
 
	            l = document.createElement('a');
 
	            l.href = location.href.substring(0,location.href.indexOf('#'))+anchor;
 
	            l.innerHTML = selection_link_label;
 
	            hl_div.appendChild(l);
 
	            
 
	            YUD.get('body').appendChild(hl_div);
 
	            
 
	            xy = YUD.getXY(till.id);
 
	            
 
	            YUD.addClass('linktt','yui-tt');
 
	            YUD.setStyle('linktt','top',xy[1]+offset+'px');
 
	            YUD.setStyle('linktt','left',xy[0]+'px');
 
	            YUD.setStyle('linktt','visibility','visible');
 
	        }
 
	        else{
 
	        	YUD.setStyle('linktt','visibility','hidden');
 
	        }
 
	    }
 
	}
 
};
 

	
 
var deleteNotification = function(url, notification_id,callbacks){
 
    var callback = { 
 
		success:function(o){
 
		    var obj = YUD.get(String("notification_"+notification_id));
 
		    if(obj.parentNode !== undefined){
 
				obj.parentNode.removeChild(obj);
 
			}
 
			_run_callbacks(callbacks);
 
		},
 
	    failure:function(o){
 
	        alert("error");
 
	    },
 
	};
 
    var postData = '_method=delete';
 
    var sUrl = url.replace('__NOTIFICATION_ID__',notification_id);
 
    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, 
 
    											  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 **/
 

	
 
var MembersAutoComplete = function (users_list, groups_list) {
 
    var myUsers = users_list;
 
    var myGroups = groups_list;
 

	
 
    // Define a custom search function for the DataSource of users
 
    var matchUsers = function (sQuery) {
 
            // Case insensitive matching
 
            var query = sQuery.toLowerCase();
 
            var i = 0;
 
            var l = myUsers.length;
 
            var matches = [];
 

	
 
            // Match against each name of each contact
 
            for (; i < l; i++) {
 
                contact = myUsers[i];
 
                if (((contact.fname+"").toLowerCase().indexOf(query) > -1) || 
 
                   	 ((contact.lname+"").toLowerCase().indexOf(query) > -1) || 
 
                   	 ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) {
 
                       matches[matches.length] = contact;
 
                   }
 
            }
 
            return matches;
 
        };
 

	
 
    // Define a custom search function for the DataSource of usersGroups
 
    var matchGroups = function (sQuery) {
 
            // Case insensitive matching
 
            var query = sQuery.toLowerCase();
 
            var i = 0;
 
            var l = myGroups.length;
 
            var matches = [];
 

	
 
            // Match against each name of each contact
 
            for (; i < l; i++) {
 
                matched_group = myGroups[i];
 
                if (matched_group.grname.toLowerCase().indexOf(query) > -1) {
 
                    matches[matches.length] = matched_group;
 
                }
 
            }
 
            return matches;
 
        };
 

	
 
    //match all
 
    var matchAll = function (sQuery) {
 
            u = matchUsers(sQuery);
 
            g = matchGroups(sQuery);
 
            return u.concat(g);
 
        };
 

	
 
    // DataScheme for members
 
    var memberDS = new YAHOO.util.FunctionDataSource(matchAll);
 
    memberDS.responseSchema = {
 
        fields: ["id", "fname", "lname", "nname", "grname", "grmembers", "gravatar_lnk"]
 
    };
 

	
 
    // DataScheme for owner
 
    var ownerDS = new YAHOO.util.FunctionDataSource(matchUsers);
 
    ownerDS.responseSchema = {
 
        fields: ["id", "fname", "lname", "nname", "gravatar_lnk"]
 
    };
 

	
 
    // Instantiate AutoComplete for perms
 
    var membersAC = new YAHOO.widget.AutoComplete("perm_new_member_name", "perm_container", memberDS);
 
    membersAC.useShadow = false;
 
    membersAC.resultTypeList = false;
 

	
 
    // Instantiate AutoComplete for owner
 
    var ownerAC = new YAHOO.widget.AutoComplete("user", "owner_container", ownerDS);
 
    ownerAC.useShadow = false;
 
    ownerAC.resultTypeList = false;
 

	
 

	
 
    // Helper highlight function for the formatter
 
    var highlightMatch = function (full, snippet, matchindex) {
 
            return full.substring(0, matchindex) 
 
            + "<span class='match'>" 
 
            + full.substr(matchindex, snippet.length) 
 
            + "</span>" + full.substring(matchindex + snippet.length);
 
        };
 

	
 
    // Custom formatter to highlight the matching letters
 
    var custom_formatter = function (oResultData, sQuery, sResultMatch) {
 
            var query = sQuery.toLowerCase();
 
            var _gravatar = function(res, em, group){
 
            	if (group !== undefined){
 
            		em = '/images/icons/group.png'
 
            	}
 
            	tmpl = '<div class="ac-container-wrap"><img class="perm-gravatar-ac" src="{0}"/>{1}</div>'
 
            	return tmpl.format(em,res)
 
            }
 
            // group
 
            if (oResultData.grname != undefined) {
 
                var grname = oResultData.grname;
rhodecode/templates/admin/notifications/notifications.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('My Notifications')} ${c.rhodecode_user.username} - ${c.rhodecode_name}
 
</%def>
 

	
 
<%def name="breadcrumbs_links()">
 
    ${_('My Notifications')}
 
</%def>
 

	
 
<%def name="page_nav()">
 
	${self.menu('admin')}
 
</%def>
 

	
 
<%def name="main()">
 
<div class="box">
 
    <!-- box / title -->
 
    <div class="title">
 
        ${self.breadcrumbs()}
 
        ##<ul class="links">
 
        ##    <li>
 
        ##      <span style="text-transform: uppercase;"><a href="#">${_('Compose message')}</a></span>
 
        ##    </li>
 
        ##</ul>
 
    </div>
 
    
 
      <div style="padding:14px 18px;text-align: right;float:left">
 
      <span id='all' class="ui-btn"><a href="${h.url.current()}">${_('All')}</a></span>
 
      <span id='comment' class="ui-btn"><a href="${h.url.current(type=c.comment_type)}">${_('Comments')}</a></span>
 
      <span id='pull_request' class="ui-btn"><a href="${h.url.current(type=c.pull_request_type)}">${_('Pull requests')}</a></span>
 
      </div>
 
      %if c.notifications:
 
      <div style="padding:14px 18px;text-align: right;float:right">
 
      <span id='mark_all_read' class="ui-btn">${_('Mark all read')}</span>
 
      </div>
 
      %endif
 
  <div id='notification_data'>
 
    <%include file='notifications_data.html'/>
 
  </div>
 
</div>
 
<script type="text/javascript">
 
var url_del = "${url('notification', notification_id='__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_del,notification_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
 

	
 
%if c.notifications:
 
<%
 
unread = lambda n:{False:'unread'}.get(n)
 
%>
 

	
 

	
 
<div class="notification-list  notification-table">
 
%for notification in c.notifications:
 
  <div id="notification_${notification.notification.notification_id}" class="container ${unread(notification.read)}">
 
    <div class="notification-header">
 
      <div class="gravatar">
 
          <img alt="gravatar" src="${h.gravatar_url(h.email(notification.notification.created_by_user.email),24)}"/>
 
      </div>
 
      <div class="desc ${unread(notification.read)}">
 
      <a href="${url('notification', notification_id=notification.notification.notification_id)}">${notification.notification.description}</a>
 
      </div>
 
      <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>
 
%endfor
 
</div>
 

	
 
<div class="notification-paginator">
 
  <div class="pagination-wh pagination-left">
 
  ${c.notifications.pager('$link_previous ~2~ $link_next',**request.GET.mixed())}
 
  </div>
 
</div>
 

	
 
%else:
 
    <div class="table">${_('No notifications here yet')}</div>
 
%endif
0 comments (0 inline, 0 general)