blob: 3836f909eee51436653ed653235207c6f687ca43 [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 Mehta702473d2012-04-26 19:01:35 +053020 parent: $(wrapper).find('#blog-list').get(0),
21 query: 'select tabBlog.name, title, left(content, 1000) as content, tabBlog.modified, \
Rushabh Mehta3a751e82012-01-27 18:00:14 +053022 ifnull(first_name, "") as first_name, ifnull(last_name, "") as last_name \
23 from tabProfile, tabBlog\
Rushabh Mehta702473d2012-04-26 19:01:35 +053024 where ifnull(published,0)=1 and tabBlog.owner = tabProfile.name',
Rushabh Mehta3a751e82012-01-27 18:00:14 +053025 hide_refresh: true,
Rushabh Mehta702473d2012-04-26 19:01:35 +053026 no_toolbar: true,
Rushabh Mehta3a751e82012-01-27 18:00:14 +053027 render_row: function(parent, data) {
Rushabh Mehta702473d2012-04-26 19:01:35 +053028 if(data.content && data.content.length==1000) data.content += '... (read on)';
29 data.content = wn.markdown(data.content);
30 if(data.last_name) data.last_name = ' ' + data.last_name;
Rushabh Mehta3a751e82012-01-27 18:00:14 +053031 data.date = prettyDate(data.modified);
Rushabh Mehta702473d2012-04-26 19:01:35 +053032 parent.innerHTML = repl('<h2>%(title)s</h2>\
33 <p><div class="help">By %(first_name)s%(last_name)s, %(date)s</div></p>\
34 <p>%(content)s</p>\
35 <a href="#!%(name)s">Read Full Text</a><br>', data);
Rushabh Mehta3a751e82012-01-27 18:00:14 +053036 },
37 page_length: 10
38 });
39 wrapper.blog_list.run();
40
41 // subscribe button
42 $('#blog-subscribe').click(function() {
43 var email = $(wrapper).find('input[name="blog-subscribe"]').val();
44 if(!validate_email(email)) {
45 msgprint('Please enter a valid email!');
46 }
47 wn.call({
48 module:'website',
49 page:'blog',
50 method:'subscribe',
51 args:email,
52 btn: this,
53 callback: function() {
54 $(wrapper).find('input[name="blog-subscribe"]').val('');
55 }
56 });
57 })
58}