Anand Doshi | 10bcf5e | 2012-06-26 18:54:10 +0530 | [diff] [blame] | 1 | // 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 | |
| 17 | // js inside blog page |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 18 | |
| 19 | $(document).ready(function() { |
| 20 | // make list of blogs |
| 21 | blog.get_list(); |
| 22 | |
| 23 | $("#next-page").click(function() { |
| 24 | blog.get_list(); |
| 25 | }) |
| 26 | }); |
| 27 | |
| 28 | var blog = { |
| 29 | start: 0, |
| 30 | get_list: function() { |
| 31 | $.ajax({ |
| 32 | method: "GET", |
| 33 | url: "server.py", |
| 34 | data: { |
| 35 | cmd: "website.helpers.blog.get_blog_list", |
| 36 | start: blog.start |
| 37 | }, |
| 38 | dataType: "json", |
| 39 | success: function(data) { |
| 40 | blog.render(data.message); |
| 41 | } |
| 42 | }); |
| 43 | }, |
| 44 | render: function(data) { |
| 45 | var $wrap = $("#blog-list"); |
| 46 | $.each(data, function(i, b) { |
| 47 | // comments |
| 48 | if(!b.comments) { |
| 49 | b.comment_text = 'No comments yet.' |
| 50 | } else if (b.comments===1) { |
| 51 | b.comment_text = '1 comment.' |
Rushabh Mehta | aaa7549 | 2012-08-06 15:22:17 +0530 | [diff] [blame] | 52 | } else { |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 53 | b.comment_text = b.comments + ' comments.' |
Rushabh Mehta | aaa7549 | 2012-08-06 15:22:17 +0530 | [diff] [blame] | 54 | } |
| 55 | |
Rushabh Mehta | 5f18398 | 2013-01-01 10:55:58 +0530 | [diff] [blame] | 56 | $(repl('<h2><a href="%(page_name)s">%(title)s</a></h2>\ |
Rushabh Mehta | aaa7549 | 2012-08-06 15:22:17 +0530 | [diff] [blame] | 57 | <div class="help">%(comment_text)s</div>\ |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 58 | %(content)s<br />\ |
| 59 | <p><a href="%(page_name)s">Read with comments...</a></p>\ |
| 60 | <hr /><br />', b)).appendTo($wrap); |
| 61 | }); |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 62 | blog.start += (data.length || 0); |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 63 | if(!data.length) { |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 64 | if(blog.start) { |
| 65 | $("#next-page").toggle(false) |
| 66 | .parent().append("<div class='alert'>Nothing more to show.</div>"); |
| 67 | } else { |
| 68 | $("#next-page").toggle(false) |
| 69 | .parent().append("<div class='alert'>No blogs written yet.</div>"); |
| 70 | } |
| 71 | } else { |
| 72 | $("#next-page").toggle(true); |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 73 | } |
| 74 | } |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 75 | } |