blob: 9e89acdca83044b7abc9937fba2769184a6432fd [file] [log] [blame]
Rushabh Mehta3a751e82012-01-27 18:00:14 +05301
2pscript.onload_blog = function(wrapper) {
3 wrapper.blog_list = new wn.widgets.Listing({
4 parent: $(wrapper).find('.web-main-section').get(0),
5 query: 'select tabBlog.name, title, left(content, 300) as content, tabBlog.modified, \
6 ifnull(first_name, "") as first_name, ifnull(last_name, "") as last_name \
7 from tabProfile, tabBlog\
8 where ifnull(published,1)=1 and tabBlog.owner = tabProfile.name',
9 hide_refresh: true,
10 render_row: function(parent, data) {
11 if(data.content.length==300) data.content += '...';
12 data.date = prettyDate(data.modified);
Rushabh Mehtab8d64972012-02-08 12:33:13 +053013 parent.innerHTML = repl('<h3><a href="#!%(name)s">%(title)s</a></h3>\
14 <p><div class="help">By %(first_name)s %(last_name)s on %(date)s</div></p>\
15 <div class="comment">%(content)s</div><br>', data);
Rushabh Mehta3a751e82012-01-27 18:00:14 +053016 },
17 page_length: 10
18 });
19 wrapper.blog_list.run();
20
21 // subscribe button
22 $('#blog-subscribe').click(function() {
23 var email = $(wrapper).find('input[name="blog-subscribe"]').val();
24 if(!validate_email(email)) {
25 msgprint('Please enter a valid email!');
26 }
27 wn.call({
28 module:'website',
29 page:'blog',
30 method:'subscribe',
31 args:email,
32 btn: this,
33 callback: function() {
34 $(wrapper).find('input[name="blog-subscribe"]').val('');
35 }
36 });
37 })
38}