blob: 70df99c34ae4b7bf21cbc366e12ce3c534d17761 [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"));
29 $("#blog-link").toggle(true);
30 }
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053031});
32
33var blog = {
34 start: 0,
35 get_list: function() {
36 $.ajax({
37 method: "GET",
38 url: "server.py",
39 data: {
40 cmd: "website.helpers.blog.get_blog_list",
Rushabh Mehta676a5682013-03-07 18:51:10 +053041 start: blog.start,
42 by: get_url_arg("by")
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053043 },
44 dataType: "json",
45 success: function(data) {
Rushabh Mehta676a5682013-03-07 18:51:10 +053046 if(data.exc) console.log(data.exc);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053047 blog.render(data.message);
48 }
49 });
50 },
51 render: function(data) {
52 var $wrap = $("#blog-list");
53 $.each(data, function(i, b) {
54 // comments
55 if(!b.comments) {
56 b.comment_text = 'No comments yet.'
57 } else if (b.comments===1) {
58 b.comment_text = '1 comment.'
Rushabh Mehtaaaa75492012-08-06 15:22:17 +053059 } else {
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053060 b.comment_text = b.comments + ' comments.'
Rushabh Mehtaaaa75492012-08-06 15:22:17 +053061 }
62
Rushabh Mehta676a5682013-03-07 18:51:10 +053063 $(repl('<div class="row">\
64 <div class="span1">\
65 <div class="avatar avatar-medium" style="margin-top: 6px;">\
66 <img src="%(avatar)s" />\
67 </div>\
68 </div>\
69 <div class="span11">\
70 <h4><a href="%(page_name)s">%(title)s</a></h4>\
71 <p>%(content)s</p>\
72 <p style="color: #aaa; font-size: 90%">\
73 <a href="blog?by=%(blogger)s&by_name=%(full_name)s">\
74 %(full_name)s</a> wrote this on %(published)s / %(comment_text)s</p>\
75 </div>\
76 </div><hr>', b)).appendTo($wrap);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053077 });
Rushabh Mehtae109fa42012-12-19 10:14:59 +053078 blog.start += (data.length || 0);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053079 if(!data.length) {
Rushabh Mehtae109fa42012-12-19 10:14:59 +053080 if(blog.start) {
81 $("#next-page").toggle(false)
82 .parent().append("<div class='alert'>Nothing more to show.</div>");
83 } else {
84 $("#next-page").toggle(false)
85 .parent().append("<div class='alert'>No blogs written yet.</div>");
86 }
87 } else {
88 $("#next-page").toggle(true);
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053089 }
90 }
Anand Doshi51146c02012-07-12 18:41:12 +053091}