[newsletter] show send progess [issue] webnotes/erpnext#531
This commit is contained in:
parent
d5b06f78a5
commit
220b597b06
@ -1,6 +1,17 @@
|
|||||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
cur_frm.cscript.onload = function(doc) {
|
||||||
|
return wn.call({
|
||||||
|
method: "support.doctype.newsletter.newsletter.get_lead_options",
|
||||||
|
type: "GET",
|
||||||
|
callback: function(r) {
|
||||||
|
set_field_options("lead_source", r.message.sources.join("\n"))
|
||||||
|
set_field_options("lead_status", r.message.statuses.join("\n"))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
cur_frm.cscript.refresh = function(doc) {
|
cur_frm.cscript.refresh = function(doc) {
|
||||||
erpnext.hide_naming_series();
|
erpnext.hide_naming_series();
|
||||||
if(!doc.__islocal && !cint(doc.email_sent) && !doc.__unsaved
|
if(!doc.__islocal && !cint(doc.email_sent) && !doc.__unsaved
|
||||||
@ -12,17 +23,41 @@ cur_frm.cscript.refresh = function(doc) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur_frm.cscript.setup_dashboard();
|
||||||
|
|
||||||
if(doc.__islocal && !doc.send_from) {
|
if(doc.__islocal && !doc.send_from) {
|
||||||
cur_frm.set_value("send_from",
|
cur_frm.set_value("send_from",
|
||||||
repl("%(fullname)s <%(email)s>", wn.user_info(doc.owner)));
|
repl("%(fullname)s <%(email)s>", wn.user_info(doc.owner)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return wn.call({
|
|
||||||
method: "support.doctype.newsletter.newsletter.get_lead_options",
|
cur_frm.cscript.setup_dashboard = function() {
|
||||||
type: "GET",
|
cur_frm.dashboard.reset();
|
||||||
callback: function(r) {
|
if(!cur_frm.doc.__islocal && cint(cur_frm.doc.email_sent) && cur_frm.doc.__status_count) {
|
||||||
set_field_options("lead_source", r.message.sources.join("\n"))
|
var stat = cur_frm.doc.__status_count;
|
||||||
set_field_options("lead_status", r.message.statuses.join("\n"))
|
var total = wn.utils.sum($.map(stat, function(v) { return v; }));
|
||||||
}
|
if(total) {
|
||||||
})
|
$.each(stat, function(k, v) {
|
||||||
|
stat[k] = flt(v * 100 / total, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
cur_frm.dashboard.add_progress("Status", [
|
||||||
|
{
|
||||||
|
title: stat["Sent"] + "% Sent",
|
||||||
|
width: stat["Sent"],
|
||||||
|
progress_class: "progress-bar-success"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: stat["Sending"] + "% Sending",
|
||||||
|
width: stat["Sending"],
|
||||||
|
progress_class: "progress-bar-warning"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: stat["Error"] + "% Error",
|
||||||
|
width: stat["Error"],
|
||||||
|
progress_class: "progress-bar-danger"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -12,6 +12,12 @@ class DocType():
|
|||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
|
|
||||||
|
def onload(self):
|
||||||
|
if self.doc.email_sent:
|
||||||
|
self.doc.fields["__status_count"] = dict(webnotes.conn.sql("""select status, count(*)
|
||||||
|
from `tabBulk Email` where ref_doctype=%s and ref_docname=%s
|
||||||
|
group by status""", (self.doc.doctype, self.doc.name))) or None
|
||||||
|
|
||||||
def test_send(self, doctype="Lead"):
|
def test_send(self, doctype="Lead"):
|
||||||
self.recipients = self.doc.test_email_id.split(",")
|
self.recipients = self.doc.test_email_id.split(",")
|
||||||
self.send_to_doctype = "Lead"
|
self.send_to_doctype = "Lead"
|
||||||
@ -74,7 +80,8 @@ class DocType():
|
|||||||
|
|
||||||
send(recipients = self.recipients, sender = sender,
|
send(recipients = self.recipients, sender = sender,
|
||||||
subject = self.doc.subject, message = self.doc.message,
|
subject = self.doc.subject, message = self.doc.message,
|
||||||
doctype = self.send_to_doctype, email_field = "email_id")
|
doctype = self.send_to_doctype, email_field = "email_id",
|
||||||
|
ref_doctype = self.doc.doctype, ref_docname = self.doc.name)
|
||||||
|
|
||||||
webnotes.conn.auto_commit_on_many_writes = False
|
webnotes.conn.auto_commit_on_many_writes = False
|
||||||
|
|
||||||
@ -91,8 +98,10 @@ class DocType():
|
|||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def get_lead_options():
|
def get_lead_options():
|
||||||
return {
|
return {
|
||||||
"sources": ["All"] + webnotes.conn.sql_list("""select distinct source from tabLead"""),
|
"sources": ["All"] + filter(None,
|
||||||
"statuses": ["All"]+ webnotes.conn.sql_list("""select distinct status from tabLead""")
|
webnotes.conn.sql_list("""select distinct source from tabLead""")),
|
||||||
|
"statuses": ["All"] + filter(None,
|
||||||
|
webnotes.conn.sql_list("""select distinct status from tabLead"""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ def get_blog_list(start=0, by=None, category=None):
|
|||||||
import webnotes.utils
|
import webnotes.utils
|
||||||
|
|
||||||
for res in result:
|
for res in result:
|
||||||
from webnotes.utils import global_date_format, get_fullname
|
from webnotes.utils import global_date_format
|
||||||
res['published'] = global_date_format(res['creation'])
|
res['published'] = global_date_format(res['creation'])
|
||||||
if not res['content']:
|
if not res['content']:
|
||||||
res['content'] = webnotes.webutils.get_html(res['page_name'])
|
res['content'] = webnotes.webutils.get_html(res['page_name'])
|
||||||
@ -101,28 +101,11 @@ def add_comment(args=None):
|
|||||||
doctype='Comment',
|
doctype='Comment',
|
||||||
email_field='comment_by',
|
email_field='comment_by',
|
||||||
subject='New Comment on Blog: ' + blog.title,
|
subject='New Comment on Blog: ' + blog.title,
|
||||||
message='%(comment)s<p>By %(comment_by_fullname)s</p>' % args)
|
message='%(comment)s<p>By %(comment_by_fullname)s</p>' % args,
|
||||||
|
ref_doctype='Blog Post', ref_docname=blog.name)
|
||||||
|
|
||||||
return comment_html.replace("\n", "")
|
return comment_html.replace("\n", "")
|
||||||
|
|
||||||
@webnotes.whitelist(allow_guest=True)
|
|
||||||
def add_subscriber(name, email_id):
|
|
||||||
"""add blog subscriber to lead"""
|
|
||||||
name = webnotes.conn.sql("""select name from tabLead where email_id=%s""", email)
|
|
||||||
|
|
||||||
from webnotes.model.doc import Document
|
|
||||||
if name:
|
|
||||||
lead = Document('Lead', name[0][0])
|
|
||||||
else:
|
|
||||||
lead = Document('Lead')
|
|
||||||
|
|
||||||
if not lead.source: lead.source = 'Blog'
|
|
||||||
lead.unsubscribed = 0
|
|
||||||
lead.blog_subscriber = 1
|
|
||||||
lead.lead_name = name
|
|
||||||
lead.email_id = email
|
|
||||||
lead.save()
|
|
||||||
|
|
||||||
def get_blog_content(blog_page_name):
|
def get_blog_content(blog_page_name):
|
||||||
import webnotes.webutils
|
import webnotes.webutils
|
||||||
content = webnotes.webutils.get_html(blog_page_name)
|
content = webnotes.webutils.get_html(blog_page_name)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user