From 2f5bc8b73fc37bb7a80e4479d5a51f6b9948b8f5 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 5 Sep 2013 12:18:59 +0530 Subject: [PATCH] [feature] [customer login] send links in email for portal access of Sales Order, Sales Invoice, Delivery Note and Suppor Ticket --- public/js/wn/views/communication.js | 41 ++++++++++++++++++++++++----- templates/js/login.js | 3 ++- webnotes/boot.py | 4 +++ webnotes/webutils.py | 15 +++++++---- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/public/js/wn/views/communication.js b/public/js/wn/views/communication.js index a0b7b4729f..34d2fe74da 100644 --- a/public/js/wn/views/communication.js +++ b/public/js/wn/views/communication.js @@ -288,7 +288,8 @@ wn.views.CommunicationComposer = Class.extend({ ? cur_frm.communication_view.list : []; var signature = wn.boot.profile.email_signature || ""; - + var portal_link = this.setup_portal_link(); + if(!wn.utils.is_html(signature)) { signature = signature.replace(/\n/g, "
"); } @@ -297,17 +298,43 @@ wn.views.CommunicationComposer = Class.extend({ this.message = '

'+wn._('Dear') +' ' + this.real_name + ",

" + (this.message || ""); } + var reply = (this.message || "") + + "

" + signature + + "

" + portal_link; + if(comm_list.length > 0) { - fields.content.set_input((this.message || "") + - "

" - + signature - +"

" + fields.content.set_input(reply + + "

" +"-----"+wn._("In response to")+"-----

" + comm_list[0].content); } else { - fields.content.set_input((this.message || "") - + "

" + signature) + fields.content.set_input(reply); + } + }, + setup_portal_link: function() { + var me = this; + var portal_link = ""; + var show_portal_link = wn.boot.portal_links[this.doc.doctype] && + !(wn.boot.website_settings && cint(wn.boot.website_settings.disable_signup)); + if(show_portal_link) { + var portal_args = wn.boot.portal_links[this.doc.doctype]; + var valid = true; + if(portal_args.conditions) { + $.each(portal_args.conditions, function(k, v) { + if(me.doc[k] !== v) valid = false; + }); + } + if(valid) { + // set portal link + portal_link = repl("%(location)s/%(page)s?name=%(name)s", { + location: window.location.origin, + page: portal_args["page"], + name: encodeURIComponent(this.doc.name) + }); + portal_link = '--
View this on our website'; + } } + return portal_link; }, setup_autosuggest: function() { var me = this; diff --git a/templates/js/login.js b/templates/js/login.js index 23fd4fa1a5..1ef976a7b8 100644 --- a/templates/js/login.js +++ b/templates/js/login.js @@ -62,8 +62,9 @@ login.do_login = function(){ window.location.href = "app.html"; } else if(data.message=="No App") { if(localStorage) { - window.location.href = localStorage.getItem("last_visited") || "index"; + var last_visited = localStorage.getItem("last_visited") || "index"; localStorage.removeItem("last_visited"); + window.location.href = last_visited; } else { window.location.href = "index"; } diff --git a/webnotes/boot.py b/webnotes/boot.py index ac7f8251ca..5001bcf9a7 100644 --- a/webnotes/boot.py +++ b/webnotes/boot.py @@ -11,6 +11,7 @@ import webnotes.defaults import webnotes.model.doc import webnotes.widgets.page import json +import webnotes.webutils def get_bootinfo(): """build and return boot info""" @@ -42,6 +43,9 @@ def get_bootinfo(): tabDocType where ifnull(icon,'')!=''""")) bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from tabPage where ifnull(icon,'')!=''"""))) + + # portal links for sending in email + bootinfo.portal_links = webnotes.webutils.get_portal_links() add_home_page(bootinfo, doclist) add_allowed_pages(bootinfo) diff --git a/webnotes/webutils.py b/webnotes/webutils.py index a68a0a6e0b..4cc5a36198 100644 --- a/webnotes/webutils.py +++ b/webnotes/webutils.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals -import os import conf import webnotes import webnotes.utils @@ -113,9 +112,6 @@ def build_html(args): return html -def get_standard_pages(): - return webnotes.get_config()["web"]["pages"].keys() - def prepare_args(page_name): has_app = True @@ -240,4 +236,13 @@ def get_generators(): def get_page_settings(): return webnotes.get_config()["web"]["pages"] - +def get_portal_links(): + portal_args = {} + for page, opts in webnotes.get_config()["web"]["pages"].items(): + if opts.get("portal"): + portal_args[opts["portal"]["doctype"]] = { + "page": page, + "conditions": opts["portal"].get("conditions") + } + + return portal_args \ No newline at end of file