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