[star] notify starrers and star in form

This commit is contained in:
Rushabh Mehta 2015-03-23 11:24:49 +05:30
parent dd6be5c7e8
commit 1ef2c8de17
11 changed files with 80 additions and 26 deletions

View file

@ -110,6 +110,7 @@ class Communication(Document):
recipients += self.get_commentors()
recipients += [s.strip() for s in self.recipients.split(",")]
recipients += self.get_assignees()
recipients += self.get_starrers()
recipients = filter(lambda e: e and e!="Administrator", list(set(recipients)))
# remove unsubscribed recipients
@ -118,6 +119,10 @@ class Communication(Document):
return recipients
def get_starrers(self):
"""Return list of users who have starred this document."""
return self.get_parent_doc().get_starred_by()
def get_earlier_participants(self):
return frappe.db.sql("""
select distinct sender

View file

@ -8,7 +8,7 @@ from frappe.utils import flt, cint, cstr, now, get_datetime_str
from frappe.model.base_document import BaseDocument, get_controller
from frappe.model.naming import set_new_name
from werkzeug.exceptions import NotFound, Forbidden
import hashlib
import hashlib, json
# once_only validation
# methods
@ -662,3 +662,10 @@ class Document(BaseDocument):
def get_signature(self):
"""Returns signature (hash) for private URL."""
return hashlib.sha224(get_datetime_str(self.creation)).hexdigest()
def get_starred_by(self):
starred_by = getattr(self, "_starred_by", None)
if starred_by:
return json.dumps(starred_by)
else:
return []

View file

@ -197,3 +197,13 @@ a.badge-hover:active .badge {
#freeze.in {
opacity: 0.5;
}
a.no-decoration {
text-decoration: none;
color: inherit;
}
a.no-decoration:hover,
a.no-decoration:focus,
a.no-decoration:active {
text-decoration: none;
color: inherit;
}

View file

@ -197,6 +197,16 @@ a.badge-hover:active .badge {
#freeze.in {
opacity: 0.5;
}
a.no-decoration {
text-decoration: none;
color: inherit;
}
a.no-decoration:hover,
a.no-decoration:focus,
a.no-decoration:active {
text-decoration: none;
color: inherit;
}
.nav-pills a,
.nav-pills a:hover {
border-bottom: none;

View file

@ -197,6 +197,16 @@ a.badge-hover:active .badge {
#freeze.in {
opacity: 0.5;
}
a.no-decoration {
text-decoration: none;
color: inherit;
}
a.no-decoration:hover,
a.no-decoration:focus,
a.no-decoration:active {
text-decoration: none;
color: inherit;
}
html {
min-height: 100%;
}
@ -594,16 +604,6 @@ textarea {
.post-content img {
margin: 10px 0px;
}
a.no-decoration {
text-decoration: none;
color: inherit;
}
a.no-decoration:hover,
a.no-decoration:focus,
a.no-decoration:active {
text-decoration: none;
color: inherit;
}
a.active {
pointer-events: none;
cursor: default;

View file

@ -14,6 +14,7 @@ frappe.ui.form.Toolbar = Class.extend({
this.page.clear_user_actions();
this.show_title_as_dirty();
this.set_primary_action();
this.refresh_star();
if(this.frm.meta.hide_toolbar) {
this.page.hide_menu();
@ -21,9 +22,11 @@ frappe.ui.form.Toolbar = Class.extend({
if(this.frm.doc.__islocal) {
this.page.hide_menu();
this.print_icon && this.print_icon.addClass("hide");
this.star_icon.addClass("hide");
} else {
this.page.show_menu();
this.print_icon && this.print_icon.removeClass("hide");
this.star_icon.removeClass("hide");
}
}
},
@ -56,6 +59,10 @@ frappe.ui.form.Toolbar = Class.extend({
this.page.clear_indicator();
}
},
refresh_star: function() {
this.star_icon.toggleClass("text-extra-muted not-starred", !frappe.ui.is_starred(this.frm.doc))
.attr("data-doctype", this.frm.doctype).attr("data-name", this.frm.doc.name);
},
make_menu: function() {
var me = this;
var p = this.frm.perm[0];
@ -69,6 +76,11 @@ frappe.ui.form.Toolbar = Class.extend({
me.frm.print_doc();});
}
// star
this.star_icon = this.page.add_action_icon("icon-star", function() {
frappe.ui.toggle_star(me.star_icon, me.frm.doctype, me.frm.doc.name);
}).removeClass("text-muted").find(".icon-star").addClass("star-action");
// email
if(frappe.model.can_email(null, me.frm)) {
this.page.add_menu_item(__("Email"), function() {

View file

@ -3,7 +3,7 @@
{% } %}
<i class="icon-star {% if (_starred_by.indexOf(_user)===-1) {
%}text-extra-muted not-starred{% } else { %}{% }%}
icon-fixed-width star-action" data-name="{%= _name %}">
icon-fixed-width star-action" data-name="{%= _name %}" data-doctype="{%= doctype %}">
</i>
<a class="grey list-id" style="margin-right: 7px;"
href="#Form/{%= _doctype_encoded %}/{%= _name_encoded %}" title="{%= _full_title %}">{%= _title %}</a>

View file

@ -93,7 +93,7 @@ frappe.ui.Page = Class.extend({
},
add_action_icon: function(icon, click) {
return $('<a class="text-muted"><i class="'+icon+'"></i></a>')
return $('<a class="text-muted no-decoration"><i class="'+icon+'"></i></a>')
.appendTo(this.icon_group.removeClass("hide"))
.click(click);
},

View file

@ -1,6 +1,15 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
frappe.ui.is_starred = function(doc) {
var starred = doc._starred_by;
if(starred) {
starred = JSON.parse(starred);
return starred.indexOf(user)===-1 ? false : true;
}
return false;
}
frappe.ui.toggle_star = function($btn, doctype, name) {
var add = $btn.hasClass("not-starred") ? "Yes" : "No";
frappe.call({
@ -14,7 +23,8 @@ frappe.ui.toggle_star = function($btn, doctype, name) {
callback: function(r) {
if(!r.exc) {
// update in all local-buttons
var action_buttons = $(".star-action[data-name='"+ name.replace(/"/g, '\"') +"']");
var action_buttons = $('.star-action[data-name="'+ name.replace(/"/g, '\"')
+'"][data-doctype="'+ doctype.replace(/"/g, '\"')+'"]');
if(add==="Yes") {
action_buttons.removeClass("not-starred").removeClass("text-extra-muted");

View file

@ -209,3 +209,15 @@ a.badge-hover& {
#freeze.in {
opacity: 0.5;
}
a.no-decoration& {
text-decoration: none;
color: inherit;
&:hover,
&:focus,
&:active {
text-decoration: none;
color: inherit;
}
}

View file

@ -301,18 +301,6 @@ textarea {
margin: 10px 0px;
}
a.no-decoration& {
text-decoration: none;
color: inherit;
&:hover,
&:focus,
&:active {
text-decoration: none;
color: inherit;
}
}
a.active {
pointer-events: none;
cursor: default;