blob: 5a10998c6f83228d410e3ed29a20f6375adb5fd1 [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),
Rushabh Mehta03a26f22012-05-19 10:53:15 +053021 query: 'select tabBlog.name, title, left(content, 1000) as content, tabBlog.creation, \
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 Mehta39c47a02012-05-01 16:15:09 +053024 where ifnull(published,0)=1 and tabBlog.owner = tabProfile.name \
Rushabh Mehta03a26f22012-05-19 10:53:15 +053025 order by tabBlog.creation desc',
Rushabh Mehta3a751e82012-01-27 18:00:14 +053026 hide_refresh: true,
Rushabh Mehta702473d2012-04-26 19:01:35 +053027 no_toolbar: true,
Rushabh Mehta3a751e82012-01-27 18:00:14 +053028 render_row: function(parent, data) {
Rushabh Mehta702473d2012-04-26 19:01:35 +053029 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 Mehta03a26f22012-05-19 10:53:15 +053032 data.date = prettyDate(data.creation);
Rushabh Mehta702473d2012-04-26 19:01:35 +053033 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 Mehtab9483d12012-05-09 11:42:52 +053036 <a href="%(name)s.html">Read Full Text</a><br>', data);
Rushabh Mehta3a751e82012-01-27 18:00:14 +053037 },
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}