blob: 3cfb2345492dce088327aa3968dc8c5fd267140d [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 Mehta676a5682013-03-07 18:51:10 +053051 if(data.exc) console.log(data.exc);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053052 blog.render(data.message);
53 }
54 });
55 },
56 render: function(data) {
57 var $wrap = $("#blog-list");
58 $.each(data, function(i, b) {
59 // comments
60 if(!b.comments) {
61 b.comment_text = 'No comments yet.'
62 } else if (b.comments===1) {
63 b.comment_text = '1 comment.'
Rushabh Mehtaaaa75492012-08-06 15:22:17 +053064 } else {
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053065 b.comment_text = b.comments + ' comments.'
Rushabh Mehtaaaa75492012-08-06 15:22:17 +053066 }
67
Rushabh Mehta676a5682013-03-07 18:51:10 +053068 $(repl('<div class="row">\
69 <div class="span1">\
70 <div class="avatar avatar-medium" style="margin-top: 6px;">\
71 <img src="%(avatar)s" />\
72 </div>\
73 </div>\
74 <div class="span11">\
75 <h4><a href="%(page_name)s">%(title)s</a></h4>\
76 <p>%(content)s</p>\
77 <p style="color: #aaa; font-size: 90%">\
78 <a href="blog?by=%(blogger)s&by_name=%(full_name)s">\
79 %(full_name)s</a> wrote this on %(published)s / %(comment_text)s</p>\
80 </div>\
81 </div><hr>', b)).appendTo($wrap);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053082 });
Rushabh Mehtae109fa42012-12-19 10:14:59 +053083 blog.start += (data.length || 0);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053084 if(!data.length) {
Rushabh Mehtae109fa42012-12-19 10:14:59 +053085 if(blog.start) {
86 $("#next-page").toggle(false)
87 .parent().append("<div class='alert'>Nothing more to show.</div>");
88 } else {
89 $("#next-page").toggle(false)
90 .parent().append("<div class='alert'>No blogs written yet.</div>");
91 }
92 } else {
93 $("#next-page").toggle(true);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053094 }
95 }
Anand Doshi51146c02012-07-12 18:41:12 +053096}