blob: bc7aec44b9b99e3ab591625e74fadd32fb8d7ac2 [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301// 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 Mehta3a751e82012-01-27 18:00:14 +053017
18pscript.onload_blog = function(wrapper) {
Rushabh Mehtaf81a64e2012-03-07 18:19:41 +053019 wrapper.blog_list = new wn.ui.Listing({
Rushabh Mehta3a751e82012-01-27 18:00:14 +053020 parent: $(wrapper).find('.web-main-section').get(0),
21 query: 'select tabBlog.name, title, left(content, 300) as content, tabBlog.modified, \
22 ifnull(first_name, "") as first_name, ifnull(last_name, "") as last_name \
23 from tabProfile, tabBlog\
24 where ifnull(published,1)=1 and tabBlog.owner = tabProfile.name',
25 hide_refresh: true,
26 render_row: function(parent, data) {
27 if(data.content.length==300) data.content += '...';
28 data.date = prettyDate(data.modified);
Rushabh Mehtab8d64972012-02-08 12:33:13 +053029 parent.innerHTML = repl('<h3><a href="#!%(name)s">%(title)s</a></h3>\
30 <p><div class="help">By %(first_name)s %(last_name)s on %(date)s</div></p>\
31 <div class="comment">%(content)s</div><br>', data);
Rushabh Mehta3a751e82012-01-27 18:00:14 +053032 },
33 page_length: 10
34 });
35 wrapper.blog_list.run();
36
37 // subscribe button
38 $('#blog-subscribe').click(function() {
39 var email = $(wrapper).find('input[name="blog-subscribe"]').val();
40 if(!validate_email(email)) {
41 msgprint('Please enter a valid email!');
42 }
43 wn.call({
44 module:'website',
45 page:'blog',
46 method:'subscribe',
47 args:email,
48 btn: this,
49 callback: function() {
50 $(wrapper).find('input[name="blog-subscribe"]').val('');
51 }
52 });
53 })
54}