25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

105 lines
3.6 KiB

  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. wn.widgets.form.sidebar.Comments = function(parent, sidebar, doctype, docname) {
  23. var me = this;
  24. this.sidebar = sidebar;
  25. this.doctype = doctype; this.docname = docname;
  26. this.refresh = function() {
  27. $c('webnotes.widgets.form.comments.get_comments', {dt: me.doctype, dn: me.docname, limit: 5}, function(r, rt) {
  28. wn.widgets.form.comments.sync(me.doctype, me.docname, r);
  29. me.make_body();
  30. me.refresh_latest_comment();
  31. });
  32. }
  33. this.refresh_latest_comment = function() {
  34. var wrapper = cur_frm.page_layout.body;
  35. if(!$(wrapper).find(".latest-comment").length) {
  36. $('<div class="latest-comment alert" style="margin-top:0px;">').prependTo(wrapper);
  37. }
  38. var comment_list = wn.widgets.form.comments.comment_list[me.docname];
  39. if(comment_list) {
  40. $(wrapper).find(".latest-comment")
  41. .html(repl('<div style="width: 70%; float:left;">\
  42. Last Comment: <b>%(comment)s</b></div>\
  43. <div style="width: 25%; float:right; text-align: right; font-size: 90%">\
  44. by %(comment_by_fullname)s</div>\
  45. <div class="clear"></div>', comment_list[0]))
  46. .toggle(true);
  47. } else {
  48. $(wrapper).find(".latest-comment").toggle(false);
  49. }
  50. }
  51. this.make_body = function() {
  52. if(this.wrapper) this.wrapper.innerHTML = '';
  53. else this.wrapper = $a(parent, 'div', 'sidebar-comment-wrapper');
  54. this.input = $a_input(this.wrapper, 'text');
  55. $(this.input).keydown(function(e) {
  56. if(e.which==13) {
  57. $(me.btn).click();
  58. }
  59. })
  60. this.btn = $btn(this.wrapper, 'Post', function() { me.add_comment() }, {marginLeft:'8px'});
  61. this.render_comments()
  62. }
  63. this.render_comments = function() {
  64. var f = wn.widgets.form.comments;
  65. var cl = f.comment_list[me.docname]
  66. this.msg = $a(this.wrapper, 'div', 'help small');
  67. if(cl) {
  68. this.msg.innerHTML = cl.length + ' out of ' + f.n_comments[me.docname] + ' comments';
  69. for(var i=0; i< cl.length; i++) {
  70. this.render_one_comment(cl[i]);
  71. }
  72. } else {
  73. this.msg.innerHTML = 'Be the first one to comment.'
  74. }
  75. }
  76. //
  77. this.render_one_comment = function(det) {
  78. // comment
  79. $a(this.wrapper, 'div', 'social sidebar-comment-text', '', det.comment);
  80. // by etc
  81. $a(this.wrapper, 'div', 'sidebar-comment-info', '', comment_when(det.creation) + ' by ' + det.comment_by_fullname);
  82. }
  83. this.add_comment = function() {
  84. if(!this.input.value) return;
  85. this.btn.set_working();
  86. wn.widgets.form.comments.add(this.input, me.doctype, me.docname, function() {
  87. me.btn.done_working();
  88. me.make_body();
  89. });
  90. }
  91. this.refresh();
  92. }