blob: 91d3ead65ab6c7861485a9da46f7b331f3380077 [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 })
Rushabh Mehta676a5682013-03-07 18:51:10 +053026
27 if(get_url_arg("by_name")) {
28 $("#blog-title").html("Posts by " + get_url_arg("by_name"));
Rushabh Mehta676a5682013-03-07 18:51:10 +053029 }
Rushabh Mehtaa2deb682013-03-08 10:44:25 +053030
31 if(get_url_arg("category")) {
32 $("#blog-title").html("Posts filed under " + get_url_arg("category"));
33 }
34
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053035});
36
37var 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 Mehta676a5682013-03-07 18:51:10 +053045 start: blog.start,
Rushabh Mehtaa2deb682013-03-08 10:44:25 +053046 by: get_url_arg("by"),
47 category: get_url_arg("category")
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053048 },
49 dataType: "json",
50 success: function(data) {
Rushabh Mehtabbbceb62013-03-11 16:12:56 +053051 $(".progress").toggle(false);
Rushabh Mehta676a5682013-03-07 18:51:10 +053052 if(data.exc) console.log(data.exc);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053053 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 Mehtaaaa75492012-08-06 15:22:17 +053065 } else {
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053066 b.comment_text = b.comments + ' comments.'
Rushabh Mehtaaaa75492012-08-06 15:22:17 +053067 }
68
Rushabh Mehta676a5682013-03-07 18:51:10 +053069 $(repl('<div class="row">\
70 <div class="span1">\
71 <div class="avatar avatar-medium" style="margin-top: 6px;">\
72 <img src="%(avatar)s" />\
73 </div>\
74 </div>\
75 <div class="span11">\
76 <h4><a href="%(page_name)s">%(title)s</a></h4>\
77 <p>%(content)s</p>\
78 <p style="color: #aaa; font-size: 90%">\
79 <a href="blog?by=%(blogger)s&by_name=%(full_name)s">\
80 %(full_name)s</a> wrote this on %(published)s / %(comment_text)s</p>\
81 </div>\
82 </div><hr>', b)).appendTo($wrap);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053083 });
Rushabh Mehtae109fa42012-12-19 10:14:59 +053084 blog.start += (data.length || 0);
Rushabh Mehtabbbceb62013-03-11 16:12:56 +053085 if(!data.length || data.length < 20) {
Rushabh Mehtae109fa42012-12-19 10:14:59 +053086 if(blog.start) {
87 $("#next-page").toggle(false)
Rushabh Mehtabbbceb62013-03-11 16:12:56 +053088 .parent().append("<div class='alert alert-info'>Nothing more to show.</div>");
Rushabh Mehtae109fa42012-12-19 10:14:59 +053089 } else {
90 $("#next-page").toggle(false)
91 .parent().append("<div class='alert'>No blogs written yet.</div>");
92 }
93 } else {
94 $("#next-page").toggle(true);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053095 }
96 }
Anand Doshi51146c02012-07-12 18:41:12 +053097}