blob: 43b2d70a962c6d3d8bf084a47e3359449d7d5330 [file] [log] [blame]
Anand Doshi10bcf5e2012-06-26 18:54:10 +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
17// js inside blog page
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053018
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
28var 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 Mehtaaaa75492012-08-06 15:22:17 +053052 } else {
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053053 b.comment_text = b.comments + ' comments.'
Rushabh Mehtaaaa75492012-08-06 15:22:17 +053054 }
55
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053056 $(repl('<h2><a href="%(page_name)s.html">%(title)s</a></h2>\
Rushabh Mehtaaaa75492012-08-06 15:22:17 +053057 <div class="help">%(comment_text)s</div>\
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053058 %(content)s<br />\
59 <p><a href="%(page_name)s">Read with comments...</a></p>\
60 <hr /><br />', b)).appendTo($wrap);
61 });
62 blog.start += data.length;
63 if(!data.length) {
64 $("#next-page").toggle(false)
65 .parent().append("<div class='alert'>Nothing more to show.</div>");
66 }
67 }
Anand Doshi51146c02012-07-12 18:41:12 +053068}