Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame^] | 1 | {% extends "page.html" %} |
| 2 | |
| 3 | {% block javascript %} |
Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 4 | // 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 Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 20 | // js inside blog page |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame^] | 21 | wn.pages['{{ name }}'].onload = function(wrapper) { |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 22 | // sidebar |
Rushabh Mehta | f81a64e | 2012-03-07 18:19:41 +0530 | [diff] [blame] | 23 | wrapper.recent_list = new wn.ui.Listing({ |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 24 | parent: $(wrapper).find('.recent-posts'), |
| 25 | no_toolbar: true, |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 26 | query: 'select name, title, left(content, 100) as content from tabBlog\ |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame^] | 27 | where ifnull(published,0)=1 and name!="{{ name }}" order by creation desc', |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 28 | hide_refresh: true, |
| 29 | render_row: function(parent, data) { |
Anand Doshi | 4b1a44f | 2012-05-10 15:44:36 +0530 | [diff] [blame] | 30 | //console.log(data); |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 31 | if(data.content && data.content.length==100) data.content += '...'; |
Rushabh Mehta | b9483d1 | 2012-05-09 11:42:52 +0530 | [diff] [blame] | 32 | parent.innerHTML = repl('<a href="%(name)s.html">%(title)s</a>\ |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 33 | <div class="comment">%(content)s</div><br>', data); |
| 34 | }, |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 35 | page_length: 5, |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 36 | }); |
| 37 | wrapper.recent_list.run(); |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame^] | 38 | |
Rushabh Mehta | f81a64e | 2012-03-07 18:19:41 +0530 | [diff] [blame] | 39 | wrapper.comment_list = new wn.ui.Listing({ |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 40 | parent: $(wrapper).find('.blog-comments').get(0), |
| 41 | no_toolbar: true, |
Rushabh Mehta | 03a26f2 | 2012-05-19 10:53:15 +0530 | [diff] [blame] | 42 | query: 'select comment, comment_by_fullname, creation\ |
Anand Doshi | fedfd89 | 2012-03-30 12:29:06 +0530 | [diff] [blame] | 43 | from `tabComment` where comment_doctype="Page"\ |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame^] | 44 | and comment_docname="{{ name }}" order by creation desc', |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 45 | no_result_message: 'Be the first one to comment', |
| 46 | render_row: function(parent, data) { |
Rushabh Mehta | 03a26f2 | 2012-05-19 10:53:15 +0530 | [diff] [blame] | 47 | data.comment_date = prettyDate(data.creation); |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 48 | $(parent).html(repl("<div style='color:#777'>\ |
Rushabh Mehta | b8d6497 | 2012-02-08 12:33:13 +0530 | [diff] [blame] | 49 | %(comment_by_fullname)s | %(comment_date)s:\ |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 50 | </div>\ |
| 51 | <p style='margin-left: 20px;'>%(comment)s</p><br>", data)) |
| 52 | }, |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame^] | 53 | hide_refresh: true, |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 54 | }); |
| 55 | wrapper.comment_list.run(); |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame^] | 56 | |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 57 | // add comment |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 58 | $(wrapper).find('.layout-main-section').append('<br><button class="btn add-comment">\ |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 59 | 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 Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame^] | 75 | args.comment_docname = '{{ name }}'; |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 76 | $(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 Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame^] | 85 | } |
| 86 | |
| 87 | {% endblock %} |