From 3a751e8f82fbec8501a0dfb127a9aecabae5c86f Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 27 Jan 2012 18:00:14 +0530 Subject: [PATCH] added blog subscriber, unsubscribe --- erpnext/home/page/dashboard/dashboard.js | 1 - erpnext/patches/jan_mar_2012/website.py | 4 ++ .../page/sales_dashboard/sales_dashboard.js | 9 ++-- erpnext/startup/event_handlers.py | 2 +- .../doctype/blog_subscriber/__init__.py | 0 .../blog_subscriber/blog_subscriber.txt | 29 +++++++++++++ erpnext/website/js/topbar.js | 2 +- erpnext/website/page/blog/blog.html | 14 ++++++ erpnext/website/page/blog/blog.js | 39 +++++++++++++++++ erpnext/website/page/blog/blog.py | 11 +++++ erpnext/website/page/unsubscribe/__init__.py | 0 .../website/page/unsubscribe/unsubscribe.html | 13 ++++++ .../website/page/unsubscribe/unsubscribe.js | 21 +++++++++ .../website/page/unsubscribe/unsubscribe.py | 8 ++++ .../website/page/unsubscribe/unsubscribe.txt | 43 +++++++++++++++++++ index.html | 2 +- version.num | 2 +- 17 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 erpnext/website/doctype/blog_subscriber/__init__.py create mode 100644 erpnext/website/doctype/blog_subscriber/blog_subscriber.txt create mode 100644 erpnext/website/page/blog/blog.html create mode 100644 erpnext/website/page/blog/blog.js create mode 100644 erpnext/website/page/blog/blog.py create mode 100644 erpnext/website/page/unsubscribe/__init__.py create mode 100644 erpnext/website/page/unsubscribe/unsubscribe.html create mode 100644 erpnext/website/page/unsubscribe/unsubscribe.js create mode 100644 erpnext/website/page/unsubscribe/unsubscribe.py create mode 100644 erpnext/website/page/unsubscribe/unsubscribe.txt diff --git a/erpnext/home/page/dashboard/dashboard.js b/erpnext/home/page/dashboard/dashboard.js index 8ef2ffb0c5..e8f2992208 100644 --- a/erpnext/home/page/dashboard/dashboard.js +++ b/erpnext/home/page/dashboard/dashboard.js @@ -1,6 +1,5 @@ pscript.onload_dashboard = function() { // load jqplot - $.scriptPath = 'js/' wn.require('lib/css/jqpot.css'); wn.require('lib/js/legacy/jquery/jquery.jqplot.min.js'); wn.require('lib/js/legacy/jquery/jqplot-plugins/jqplot.barRenderer.js'); diff --git a/erpnext/patches/jan_mar_2012/website.py b/erpnext/patches/jan_mar_2012/website.py index dfa0a3d5f1..777e0ef06d 100644 --- a/erpnext/patches/jan_mar_2012/website.py +++ b/erpnext/patches/jan_mar_2012/website.py @@ -16,10 +16,14 @@ def execute(): reload_doc('website', 'doctype', 'top_bar_item') reload_doc('website', 'doctype', 'contact_us_settings') reload_doc('website', 'doctype', 'about_us_settings') + reload_doc('website', 'doctype', 'blog') + reload_doc('website', 'doctype', 'blog_subscriber') reload_doc('website', 'page', 'home') reload_doc('website', 'page', 'contact') reload_doc('website', 'page', 'about') + reload_doc('website', 'page', 'blog') + reload_doc('website', 'page', 'unsubscribe') def add_website_manager(): """add website manager to system manager""" diff --git a/erpnext/selling/page/sales_dashboard/sales_dashboard.js b/erpnext/selling/page/sales_dashboard/sales_dashboard.js index cdb5c7cf52..d15c602333 100644 --- a/erpnext/selling/page/sales_dashboard/sales_dashboard.js +++ b/erpnext/selling/page/sales_dashboard/sales_dashboard.js @@ -5,11 +5,10 @@ pscript['onload_Sales Dashboard'] = function() { $dh(pscript.mnt_div); $dh(pscript.mnt_div1); //pscript.dx_axis = []; - - if($.jqplot) pscript.all_onchnge(); - else - // import the library - $c_js('jquery/jquery.jqplot.min.js', pscript.all_onchnge); + + wn.require('lib/css/jqpot.css'); + wn.require('lib/js/legacy/jquery/jquery.jqplot.min.js'); + pscript.all_onchnge(); } //======================================================================= pscript.make_filters = function(){ diff --git a/erpnext/startup/event_handlers.py b/erpnext/startup/event_handlers.py index 8b1a7cfe8d..603d8f33f8 100644 --- a/erpnext/startup/event_handlers.py +++ b/erpnext/startup/event_handlers.py @@ -42,7 +42,7 @@ def boot_session(bootinfo): if webnotes.session['user']=='Guest': bootinfo['topbar'] = webnotes.model.doc.getsingle('Top Bar Settings') bootinfo['topbaritems'] = webnotes.conn.sql("""select label, std_page, custom_page, parent_label - from `tabTop Bar Item`""", as_dict=1) + from `tabTop Bar Item` where parent='Top Bar Settings' order by idx asc""", as_dict=1) else: bootinfo['letter_heads'] = get_letter_heads() diff --git a/erpnext/website/doctype/blog_subscriber/__init__.py b/erpnext/website/doctype/blog_subscriber/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/website/doctype/blog_subscriber/blog_subscriber.txt b/erpnext/website/doctype/blog_subscriber/blog_subscriber.txt new file mode 100644 index 0000000000..1b4a987205 --- /dev/null +++ b/erpnext/website/doctype/blog_subscriber/blog_subscriber.txt @@ -0,0 +1,29 @@ +# DocType, Blog Subscriber +[ + + # These values are common in all dictionaries + { + 'creation': '2012-01-27 17:18:33', + 'docstatus': 0, + 'modified': '2012-01-27 17:18:33', + 'modified_by': 'Administrator', + 'owner': 'Administrator' + }, + + # These values are common for all DocType + { + 'colour': 'White:FFF', + 'doctype': 'DocType', + 'module': 'Website', + 'name': '__common__', + 'section_style': 'Simple', + 'show_in_menu': 0, + 'version': 1 + }, + + # DocType, Blog Subscriber + { + 'doctype': 'DocType', + 'name': 'Blog Subscriber' + } +] \ No newline at end of file diff --git a/erpnext/website/js/topbar.js b/erpnext/website/js/topbar.js index 85d975bdb4..788ed62f6c 100644 --- a/erpnext/website/js/topbar.js +++ b/erpnext/website/js/topbar.js @@ -20,7 +20,7 @@ erpnext.topbar.TopBar = Class.extend({ $('header').append('
\
\
\ - [brand]\ + [brand]\ \ \ diff --git a/erpnext/website/page/blog/blog.html b/erpnext/website/page/blog/blog.html new file mode 100644 index 0000000000..f271e030e5 --- /dev/null +++ b/erpnext/website/page/blog/blog.html @@ -0,0 +1,14 @@ +
+
+

Blog

+
+
+
+
+

Get Updates

+ + +
+
+
+
\ No newline at end of file diff --git a/erpnext/website/page/blog/blog.js b/erpnext/website/page/blog/blog.js new file mode 100644 index 0000000000..f86e98d252 --- /dev/null +++ b/erpnext/website/page/blog/blog.js @@ -0,0 +1,39 @@ +wn.require('lib/js/lib/prettydate.js') + +pscript.onload_blog = function(wrapper) { + wrapper.blog_list = new wn.widgets.Listing({ + parent: $(wrapper).find('.web-main-section').get(0), + query: 'select tabBlog.name, title, left(content, 300) as content, tabBlog.modified, \ + ifnull(first_name, "") as first_name, ifnull(last_name, "") as last_name \ + from tabProfile, tabBlog\ + where ifnull(published,1)=1 and tabBlog.owner = tabProfile.name', + hide_refresh: true, + render_row: function(parent, data) { + if(data.content.length==300) data.content += '...'; + data.date = prettyDate(data.modified); + parent.innerHTML = repl('

%(title)s

\ +
By %(first_name)s %(last_name)s on %(date)s
\ +

%(content)s


', data); + }, + page_length: 10 + }); + wrapper.blog_list.run(); + + // subscribe button + $('#blog-subscribe').click(function() { + var email = $(wrapper).find('input[name="blog-subscribe"]').val(); + if(!validate_email(email)) { + msgprint('Please enter a valid email!'); + } + wn.call({ + module:'website', + page:'blog', + method:'subscribe', + args:email, + btn: this, + callback: function() { + $(wrapper).find('input[name="blog-subscribe"]').val(''); + } + }); + }) +} \ No newline at end of file diff --git a/erpnext/website/page/blog/blog.py b/erpnext/website/page/blog/blog.py new file mode 100644 index 0000000000..6e7a62e6aa --- /dev/null +++ b/erpnext/website/page/blog/blog.py @@ -0,0 +1,11 @@ +import webnotes +def subscribe(arg): + """subscribe to blog (blog_subscriber)""" + if webnotes.conn.sql("""select name from `tabBlog Subscriber` where name=%s""", arg): + webnotes.msgprint("Already a subscriber. Thanks!") + else: + from webnotes.model.doc import Document + d = Document('Blog Subscriber') + d.name = arg + d.save() + webnotes.msgprint("Thank you for subscribing!") \ No newline at end of file diff --git a/erpnext/website/page/unsubscribe/__init__.py b/erpnext/website/page/unsubscribe/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/website/page/unsubscribe/unsubscribe.html b/erpnext/website/page/unsubscribe/unsubscribe.html new file mode 100644 index 0000000000..7b2b68ee9c --- /dev/null +++ b/erpnext/website/page/unsubscribe/unsubscribe.html @@ -0,0 +1,13 @@ +
+
+

Unsubscribe

+
+
+ + +
+
+
+
+
+
\ No newline at end of file diff --git a/erpnext/website/page/unsubscribe/unsubscribe.js b/erpnext/website/page/unsubscribe/unsubscribe.js new file mode 100644 index 0000000000..7cbed37f4a --- /dev/null +++ b/erpnext/website/page/unsubscribe/unsubscribe.js @@ -0,0 +1,21 @@ +pscript.onload_unsubscribe = function(wrapper) { + var email = window.location.hash.split('/').splice(-1); + $(wrapper).find('input[name="unsubscribe"]').val(email) + + $('#btn-unsubscribe').click(function() { + var email = $(wrapper).find('input[name="unsubscribe"]').val(); + if(email) { + var btn = this; + wn.call({ + module:'website', + page:'unsubscribe', + method:'unsubscribe', + args:email, + btn: this, + callback: function() { + $(wrapper).find('input[name="unsubscribe"]').val(''); + } + }); + } + }); +} \ No newline at end of file diff --git a/erpnext/website/page/unsubscribe/unsubscribe.py b/erpnext/website/page/unsubscribe/unsubscribe.py new file mode 100644 index 0000000000..57d1d47f86 --- /dev/null +++ b/erpnext/website/page/unsubscribe/unsubscribe.py @@ -0,0 +1,8 @@ +def unsubscribe(arg): + """unsubscribe from lists""" + import webnotes + lists = [['Blog Subscriber', 'name']] + for l in lists: + webnotes.conn.sql("""delete from `tab%s` where %s=%s""" % (l[0], l[1], '%s'), arg) + + webnotes.msgprint('Unsubscribed!') \ No newline at end of file diff --git a/erpnext/website/page/unsubscribe/unsubscribe.txt b/erpnext/website/page/unsubscribe/unsubscribe.txt new file mode 100644 index 0000000000..2cc3b58a35 --- /dev/null +++ b/erpnext/website/page/unsubscribe/unsubscribe.txt @@ -0,0 +1,43 @@ +# Page, unsubscribe +[ + + # These values are common in all dictionaries + { + 'creation': '2012-01-27 17:19:02', + 'docstatus': 0, + 'modified': '2012-01-27 17:19:02', + 'modified_by': 'Administrator', + 'owner': 'Administrator' + }, + + # These values are common for all Page + { + 'doctype': 'Page', + 'module': 'Website', + 'name': '__common__', + 'page_name': 'unsubscribe', + 'standard': 'Yes', + 'title': 'Unsubscribe' + }, + + # These values are common for all Page Role + { + 'doctype': 'Page Role', + 'name': '__common__', + 'parent': 'unsubscribe', + 'parentfield': 'roles', + 'parenttype': 'Page', + 'role': 'Guest' + }, + + # Page, unsubscribe + { + 'doctype': 'Page', + 'name': 'unsubscribe' + }, + + # Page Role + { + 'doctype': 'Page Role' + } +] \ No newline at end of file diff --git a/index.html b/index.html index 9d2726d130..6ab3b03b8a 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ ERPNext -