2012-02-23 07:05:32 +00:00
|
|
|
// ERPNext - web based ERP (http://erpnext.com)
|
|
|
|
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-01-27 10:27:17 +00:00
|
|
|
// js inside blog page
|
2012-07-12 13:11:12 +00:00
|
|
|
|
2012-07-09 14:32:52 +00:00
|
|
|
wn.provide('erpnext.blog');
|
2012-06-22 14:31:07 +00:00
|
|
|
wn.pages['{{ name }}'].onload = function(wrapper) {
|
2012-07-09 14:32:52 +00:00
|
|
|
erpnext.blog.wrapper = wrapper;
|
|
|
|
|
2012-01-27 10:27:17 +00:00
|
|
|
// sidebar
|
2012-07-11 13:10:57 +00:00
|
|
|
erpnext.blog.render_recent_list(wrapper);
|
|
|
|
|
|
|
|
// unhide no-result if no comments found
|
|
|
|
erpnext.blog.toggle_no_result(wrapper);
|
|
|
|
|
|
|
|
// bind add comment button to comment dialog
|
|
|
|
erpnext.blog.make_comment_dialog(wrapper);
|
|
|
|
|
|
|
|
// hide add comment button after 50 comments
|
|
|
|
erpnext.blog.toggle_add_comment_btn(wrapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.blog.adjust_page_height = function(wrapper) {
|
|
|
|
if (!wrapper) { wrapper = erpnext.blog.wrapper; }
|
|
|
|
if (!wrapper) { return; }
|
|
|
|
|
|
|
|
// adjust page height based on sidebar height
|
|
|
|
var $main_page = $(wrapper).find('.layout-main-section');
|
|
|
|
var $sidebar = $(wrapper).find('.layout-side-section');
|
|
|
|
if ($sidebar.height() > $main_page.height()) {
|
|
|
|
$main_page.height($sidebar.height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.blog.render_recent_list = function(wrapper) {
|
|
|
|
if (!wrapper) { wrapper = erpnext.blog.wrapper; }
|
|
|
|
if (!wrapper) { return; }
|
|
|
|
|
2012-03-07 12:49:41 +00:00
|
|
|
wrapper.recent_list = new wn.ui.Listing({
|
2012-04-26 13:31:35 +00:00
|
|
|
parent: $(wrapper).find('.recent-posts'),
|
|
|
|
no_toolbar: true,
|
2012-07-11 13:10:57 +00:00
|
|
|
method: 'website.blog.get_recent_blog_list',
|
|
|
|
get_args: function() {
|
|
|
|
return { name: '{{ name }}' }
|
|
|
|
},
|
2012-01-27 10:27:17 +00:00
|
|
|
hide_refresh: true,
|
|
|
|
render_row: function(parent, data) {
|
2012-07-11 13:10:57 +00:00
|
|
|
if(data.content && data.content.length>=100) data.content += '...';
|
2012-07-31 13:45:01 +00:00
|
|
|
parent.innerHTML = repl('<a href="%(page_name)s.html">%(title)s</a>\
|
2012-01-27 10:27:17 +00:00
|
|
|
<div class="comment">%(content)s</div><br>', data);
|
2012-07-09 14:32:52 +00:00
|
|
|
|
|
|
|
// adjust page height depending on sidebar height
|
|
|
|
erpnext.blog.adjust_page_height(wrapper);
|
2012-01-27 10:27:17 +00:00
|
|
|
},
|
2012-04-26 13:31:35 +00:00
|
|
|
page_length: 5,
|
2012-01-27 10:27:17 +00:00
|
|
|
});
|
|
|
|
wrapper.recent_list.run();
|
2012-07-09 14:32:52 +00:00
|
|
|
}
|
2012-06-22 14:31:07 +00:00
|
|
|
|
2012-07-11 13:10:57 +00:00
|
|
|
erpnext.blog.toggle_no_result = function(wrapper) {
|
2012-07-09 14:32:52 +00:00
|
|
|
if (!wrapper) { wrapper = erpnext.blog.wrapper; }
|
|
|
|
if (!wrapper) { return; }
|
2012-07-11 13:10:57 +00:00
|
|
|
|
|
|
|
var $blog_comments = $(wrapper).find('.blog-comments');
|
|
|
|
var $comment_rows = $blog_comments.find('.comment-row');
|
|
|
|
var $no_result = $blog_comments.find('.no-result');
|
2012-07-12 13:11:12 +00:00
|
|
|
|
2012-07-11 13:10:57 +00:00
|
|
|
if ($comment_rows.length == 0) {
|
|
|
|
$no_result.removeClass('hide');
|
|
|
|
} else {
|
|
|
|
$no_result.addClass('hide');
|
|
|
|
}
|
|
|
|
}
|
2012-06-22 14:31:07 +00:00
|
|
|
|
2012-07-11 13:10:57 +00:00
|
|
|
erpnext.blog.make_comment_dialog = function(wrapper) {
|
|
|
|
if (!wrapper) { wrapper = erpnext.blog.wrapper; }
|
|
|
|
if (!wrapper) { return; }
|
|
|
|
|
|
|
|
var $comment_btn = $(wrapper).find('button.add-comment');
|
|
|
|
|
|
|
|
$comment_btn.click(function() {
|
|
|
|
if(!erpnext.blog.comment_dialog) {
|
|
|
|
var d = new wn.widgets.Dialog({
|
|
|
|
title: 'Add Comment',
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
fieldname: 'comment_by_fullname', label: 'Your Name',
|
|
|
|
reqd: 1, fieldtype: 'Data'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'comment_by', label: 'Email Id',
|
|
|
|
reqd: 1, fieldtype: 'Data'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'comment', label: 'Comment',
|
|
|
|
reqd: 1, fieldtype: 'Text'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'post_comment', label: 'Post Comment',
|
|
|
|
fieldtype: 'Button'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
erpnext.blog.comment_dialog = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.blog.comment_dialog.fields_dict.post_comment
|
|
|
|
.input.onclick = function() {
|
|
|
|
erpnext.blog.add_comment(wrapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.blog.comment_dialog.show();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.blog.add_comment = function(wrapper) {
|
|
|
|
var args = erpnext.blog.comment_dialog.get_values();
|
|
|
|
|
|
|
|
if(!args) return;
|
|
|
|
|
|
|
|
args.comment_doctype = 'Blog';
|
|
|
|
args.comment_docname = '{{ name }}';
|
|
|
|
args.page_name = '{{ page_name }}';
|
|
|
|
|
|
|
|
wn.call({
|
|
|
|
method: 'website.blog.add_comment',
|
|
|
|
args: args,
|
|
|
|
btn: this,
|
|
|
|
callback: function(r) {
|
|
|
|
if(!r.exc) {
|
|
|
|
erpnext.blog.add_comment_to_page(wrapper, r.message);
|
|
|
|
erpnext.blog.comment_dialog.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.blog.add_comment_to_page = function(wrapper, comment) {
|
|
|
|
$blog_comments = $(wrapper).find('.blog-comments');
|
|
|
|
$comment_rows = $blog_comments.find('.comment-row');
|
|
|
|
|
|
|
|
if ($comment_rows.length) {
|
2012-07-12 13:11:12 +00:00
|
|
|
$blog_comments.append(comment);
|
2012-07-11 13:10:57 +00:00
|
|
|
} else {
|
2012-07-12 13:11:12 +00:00
|
|
|
$blog_comments.append(comment);
|
2012-07-09 14:32:52 +00:00
|
|
|
}
|
2012-07-11 13:10:57 +00:00
|
|
|
|
|
|
|
erpnext.blog.toggle_no_result(wrapper);
|
|
|
|
erpnext.blog.toggle_add_comment_btn(wrapper);
|
2012-06-22 14:31:07 +00:00
|
|
|
}
|
2012-07-09 14:32:52 +00:00
|
|
|
|
2012-07-11 13:10:57 +00:00
|
|
|
erpnext.blog.toggle_add_comment_btn = function(wrapper) {
|
|
|
|
var $wrapper = $(wrapper);
|
|
|
|
if ($wrapper.find('.blog-comments .comment-row').length > 50) {
|
|
|
|
var $comment_btn = $wrapper.find('button.add-comment');
|
|
|
|
$comment_btn.addClass('hide');
|
2012-07-12 13:11:12 +00:00
|
|
|
|
|
|
|
// show comments are close
|
|
|
|
$wrapper.find('.blog-comments').append("\
|
|
|
|
<div class=\"help\"> \
|
|
|
|
<p>Comments Closed</p> \
|
|
|
|
<br /> \
|
|
|
|
</div>");
|
2012-07-11 13:10:57 +00:00
|
|
|
}
|
2012-07-12 13:11:12 +00:00
|
|
|
}
|