Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | // ERPNext - web based ERP (http://erpnext.com) |
| 2 | // Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
Rushabh Mehta | 3a751e8 | 2012-01-27 18:00:14 +0530 | [diff] [blame] | 17 | |
| 18 | pscript.onload_blog = function(wrapper) { |
Rushabh Mehta | f81a64e | 2012-03-07 18:19:41 +0530 | [diff] [blame] | 19 | wrapper.blog_list = new wn.ui.Listing({ |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 20 | parent: $(wrapper).find('#blog-list').get(0), |
Rushabh Mehta | 03a26f2 | 2012-05-19 10:53:15 +0530 | [diff] [blame] | 21 | query: 'select tabBlog.name, title, left(content, 1000) as content, tabBlog.creation, \ |
Rushabh Mehta | 3a751e8 | 2012-01-27 18:00:14 +0530 | [diff] [blame] | 22 | ifnull(first_name, "") as first_name, ifnull(last_name, "") as last_name \ |
| 23 | from tabProfile, tabBlog\ |
Rushabh Mehta | 39c47a0 | 2012-05-01 16:15:09 +0530 | [diff] [blame] | 24 | where ifnull(published,0)=1 and tabBlog.owner = tabProfile.name \ |
Rushabh Mehta | 03a26f2 | 2012-05-19 10:53:15 +0530 | [diff] [blame] | 25 | order by tabBlog.creation desc', |
Rushabh Mehta | 3a751e8 | 2012-01-27 18:00:14 +0530 | [diff] [blame] | 26 | hide_refresh: true, |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 27 | no_toolbar: true, |
Rushabh Mehta | 3a751e8 | 2012-01-27 18:00:14 +0530 | [diff] [blame] | 28 | render_row: function(parent, data) { |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 29 | if(data.content && data.content.length==1000) data.content += '... (read on)'; |
| 30 | data.content = wn.markdown(data.content); |
| 31 | if(data.last_name) data.last_name = ' ' + data.last_name; |
Rushabh Mehta | 03a26f2 | 2012-05-19 10:53:15 +0530 | [diff] [blame] | 32 | data.date = prettyDate(data.creation); |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 33 | parent.innerHTML = repl('<h2>%(title)s</h2>\ |
| 34 | <p><div class="help">By %(first_name)s%(last_name)s, %(date)s</div></p>\ |
| 35 | <p>%(content)s</p>\ |
Rushabh Mehta | b9483d1 | 2012-05-09 11:42:52 +0530 | [diff] [blame] | 36 | <a href="%(name)s.html">Read Full Text</a><br>', data); |
Rushabh Mehta | 3a751e8 | 2012-01-27 18:00:14 +0530 | [diff] [blame] | 37 | }, |
| 38 | page_length: 10 |
| 39 | }); |
| 40 | wrapper.blog_list.run(); |
| 41 | |
| 42 | // subscribe button |
| 43 | $('#blog-subscribe').click(function() { |
| 44 | var email = $(wrapper).find('input[name="blog-subscribe"]').val(); |
| 45 | if(!validate_email(email)) { |
| 46 | msgprint('Please enter a valid email!'); |
| 47 | } |
| 48 | wn.call({ |
| 49 | module:'website', |
| 50 | page:'blog', |
| 51 | method:'subscribe', |
| 52 | args:email, |
| 53 | btn: this, |
| 54 | callback: function() { |
| 55 | $(wrapper).find('input[name="blog-subscribe"]').val(''); |
| 56 | } |
| 57 | }); |
| 58 | }) |
| 59 | } |