blob: 80cb813f95651e5bb87ce6fc1901b63d1bfdcd2c [file] [log] [blame]
Anand Doshi72c945b2012-06-22 20:01:07 +05301{% extends "page.html" %}
2
3{% block javascript %}
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05304// ERPNext - web based ERP (http://erpnext.com)
5// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
6//
7// This program is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053020// js inside blog page
Anand Doshi72c945b2012-06-22 20:01:07 +053021wn.pages['{{ name }}'].onload = function(wrapper) {
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053022 // sidebar
Rushabh Mehtaf81a64e2012-03-07 18:19:41 +053023 wrapper.recent_list = new wn.ui.Listing({
Rushabh Mehta702473d2012-04-26 19:01:35 +053024 parent: $(wrapper).find('.recent-posts'),
25 no_toolbar: true,
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053026 query: 'select name, title, left(content, 100) as content from tabBlog\
Anand Doshi72c945b2012-06-22 20:01:07 +053027 where ifnull(published,0)=1 and name!="{{ name }}" order by creation desc',
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053028 hide_refresh: true,
29 render_row: function(parent, data) {
Anand Doshi4b1a44f2012-05-10 15:44:36 +053030 //console.log(data);
Rushabh Mehta702473d2012-04-26 19:01:35 +053031 if(data.content && data.content.length==100) data.content += '...';
Rushabh Mehtab9483d12012-05-09 11:42:52 +053032 parent.innerHTML = repl('<a href="%(name)s.html">%(title)s</a>\
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053033 <div class="comment">%(content)s</div><br>', data);
34 },
Rushabh Mehta702473d2012-04-26 19:01:35 +053035 page_length: 5,
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053036 });
37 wrapper.recent_list.run();
Anand Doshi72c945b2012-06-22 20:01:07 +053038
Rushabh Mehtaf81a64e2012-03-07 18:19:41 +053039 wrapper.comment_list = new wn.ui.Listing({
Rushabh Mehta702473d2012-04-26 19:01:35 +053040 parent: $(wrapper).find('.blog-comments').get(0),
41 no_toolbar: true,
Rushabh Mehta03a26f22012-05-19 10:53:15 +053042 query: 'select comment, comment_by_fullname, creation\
Anand Doshifedfd892012-03-30 12:29:06 +053043 from `tabComment` where comment_doctype="Page"\
Anand Doshi72c945b2012-06-22 20:01:07 +053044 and comment_docname="{{ name }}" order by creation desc',
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053045 no_result_message: 'Be the first one to comment',
46 render_row: function(parent, data) {
Rushabh Mehta03a26f22012-05-19 10:53:15 +053047 data.comment_date = prettyDate(data.creation);
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053048 $(parent).html(repl("<div style='color:#777'>\
Rushabh Mehtab8d64972012-02-08 12:33:13 +053049 %(comment_by_fullname)s | %(comment_date)s:\
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053050 </div>\
51 <p style='margin-left: 20px;'>%(comment)s</p><br>", data))
52 },
Anand Doshi72c945b2012-06-22 20:01:07 +053053 hide_refresh: true,
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053054 });
55 wrapper.comment_list.run();
Anand Doshi72c945b2012-06-22 20:01:07 +053056
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053057 // add comment
Rushabh Mehta702473d2012-04-26 19:01:35 +053058 $(wrapper).find('.layout-main-section').append('<br><button class="btn add-comment">\
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053059 Add Comment</button>');
60 $(wrapper).find('button.add-comment').click(function(){
61 d = new wn.widgets.Dialog({
62 title: 'Add Comment',
63 fields: [
64 {fieldname:'comment_by_fullname', label:'Your Name', reqd:1, fieldtype:'Data'},
65 {fieldname:'comment_by', label:'Email Id', reqd:1, fieldtype:'Data'},
66 {fieldname:'comment', label:'Comment', reqd:1, fieldtype:'Text'},
67 {fieldname:'post', label:'Post', fieldtype:'Button'}
68 ]
69 });
70 d.fields_dict.post.input.onclick = function() {
71 var btn = this;
72 var args = d.get_values();
73 if(!args) return;
74 args.comment_doctype = 'Page';
Anand Doshi72c945b2012-06-22 20:01:07 +053075 args.comment_docname = '{{ name }}';
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053076 $(btn).set_working();
77 $c('webnotes.widgets.form.comments.add_comment', args, function(r) {
78 $(btn).done_working();
79 d.hide();
80 wrapper.comment_list.refresh();
81 })
82 }
83 d.show();
84 })
Anand Doshi72c945b2012-06-22 20:01:07 +053085}
86
87{% endblock %}