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 | }) |
Rushabh Mehta | 676a568 | 2013-03-07 18:51:10 +0530 | [diff] [blame] | 26 | |
| 27 | if(get_url_arg("by_name")) { |
Rushabh Mehta | b33693d | 2013-03-11 17:57:57 +0530 | [diff] [blame] | 28 | $("#blot-subtitle").html("Posts by " + get_url_arg("by_name")).toggle(true); |
Rushabh Mehta | 676a568 | 2013-03-07 18:51:10 +0530 | [diff] [blame] | 29 | } |
Rushabh Mehta | a2deb68 | 2013-03-08 10:44:25 +0530 | [diff] [blame] | 30 | |
| 31 | if(get_url_arg("category")) { |
Rushabh Mehta | b33693d | 2013-03-11 17:57:57 +0530 | [diff] [blame] | 32 | $("#blot-subtitle").html("Posts filed under " + get_url_arg("category")).toggle(true); |
Rushabh Mehta | a2deb68 | 2013-03-08 10:44:25 +0530 | [diff] [blame] | 33 | } |
| 34 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 35 | }); |
| 36 | |
| 37 | var blog = { |
| 38 | start: 0, |
| 39 | get_list: function() { |
| 40 | $.ajax({ |
| 41 | method: "GET", |
| 42 | url: "server.py", |
| 43 | data: { |
| 44 | cmd: "website.helpers.blog.get_blog_list", |
Rushabh Mehta | 676a568 | 2013-03-07 18:51:10 +0530 | [diff] [blame] | 45 | start: blog.start, |
Rushabh Mehta | a2deb68 | 2013-03-08 10:44:25 +0530 | [diff] [blame] | 46 | by: get_url_arg("by"), |
| 47 | category: get_url_arg("category") |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 48 | }, |
| 49 | dataType: "json", |
| 50 | success: function(data) { |
Rushabh Mehta | bbbceb6 | 2013-03-11 16:12:56 +0530 | [diff] [blame] | 51 | $(".progress").toggle(false); |
Rushabh Mehta | 676a568 | 2013-03-07 18:51:10 +0530 | [diff] [blame] | 52 | if(data.exc) console.log(data.exc); |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 53 | blog.render(data.message); |
| 54 | } |
| 55 | }); |
| 56 | }, |
| 57 | render: function(data) { |
| 58 | var $wrap = $("#blog-list"); |
| 59 | $.each(data, function(i, b) { |
| 60 | // comments |
| 61 | if(!b.comments) { |
| 62 | b.comment_text = 'No comments yet.' |
| 63 | } else if (b.comments===1) { |
| 64 | b.comment_text = '1 comment.' |
Rushabh Mehta | aaa7549 | 2012-08-06 15:22:17 +0530 | [diff] [blame] | 65 | } else { |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 66 | b.comment_text = b.comments + ' comments.' |
Anand Doshi | 643236a | 2013-03-12 20:26:33 +0530 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | b.page_name = encodeURIComponent(b.page_name); |
Rushabh Mehta | aaa7549 | 2012-08-06 15:22:17 +0530 | [diff] [blame] | 70 | |
Rushabh Mehta | 676a568 | 2013-03-07 18:51:10 +0530 | [diff] [blame] | 71 | $(repl('<div class="row">\ |
Rushabh Mehta | 4a2f0f8 | 2013-05-22 11:57:05 +0530 | [diff] [blame] | 72 | <div class="col col-lg-1">\ |
Rushabh Mehta | 676a568 | 2013-03-07 18:51:10 +0530 | [diff] [blame] | 73 | <div class="avatar avatar-medium" style="margin-top: 6px;">\ |
| 74 | <img src="%(avatar)s" />\ |
| 75 | </div>\ |
| 76 | </div>\ |
Rushabh Mehta | 4a2f0f8 | 2013-05-22 11:57:05 +0530 | [diff] [blame] | 77 | <div class="col col-lg-11">\ |
Rushabh Mehta | 676a568 | 2013-03-07 18:51:10 +0530 | [diff] [blame] | 78 | <h4><a href="%(page_name)s">%(title)s</a></h4>\ |
| 79 | <p>%(content)s</p>\ |
| 80 | <p style="color: #aaa; font-size: 90%">\ |
| 81 | <a href="blog?by=%(blogger)s&by_name=%(full_name)s">\ |
| 82 | %(full_name)s</a> wrote this on %(published)s / %(comment_text)s</p>\ |
| 83 | </div>\ |
| 84 | </div><hr>', b)).appendTo($wrap); |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 85 | }); |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 86 | blog.start += (data.length || 0); |
Rushabh Mehta | bbbceb6 | 2013-03-11 16:12:56 +0530 | [diff] [blame] | 87 | if(!data.length || data.length < 20) { |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 88 | if(blog.start) { |
| 89 | $("#next-page").toggle(false) |
Rushabh Mehta | 74560b3 | 2013-05-27 14:47:56 +0530 | [diff] [blame] | 90 | .parent().append("<div class='text-muted'>Nothing more to show.</div>"); |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 91 | } else { |
| 92 | $("#next-page").toggle(false) |
| 93 | .parent().append("<div class='alert'>No blogs written yet.</div>"); |
| 94 | } |
| 95 | } else { |
| 96 | $("#next-page").toggle(true); |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 97 | } |
| 98 | } |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 99 | } |