您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

107 行
3.7 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 alert-info" style="margin-top:20px; display: none;">')
  37. .prependTo(wrapper);
  38. }
  39. var comment_list = wn.widgets.form.comments.comment_list[me.docname];
  40. if(comment_list) {
  41. $(wrapper).find(".latest-comment")
  42. .html(repl('<div style="width: 70%; float:left;">\
  43. Last Comment: <b>%(comment)s</b></div>\
  44. <div style="width: 25%; float:right; text-align: right; font-size: 90%">\
  45. by %(comment_by_fullname)s</div>\
  46. <div class="clear"></div>', comment_list[0]))
  47. .toggle(true);
  48. } else {
  49. $(wrapper).find(".latest-comment").toggle(false);
  50. }
  51. }
  52. this.make_body = function() {
  53. if(this.wrapper) this.wrapper.innerHTML = '';
  54. else this.wrapper = $a(parent, 'div', 'sidebar-comment-wrapper');
  55. this.input = $a_input(this.wrapper, 'text');
  56. $(this.input).keydown(function(e) {
  57. if(e.which==13) {
  58. $(me.btn).click();
  59. }
  60. })
  61. this.btn = $btn(this.wrapper, 'Post', function() { me.add_comment() }, {marginLeft:'8px'});
  62. this.render_comments()
  63. }
  64. this.render_comments = function() {
  65. var f = wn.widgets.form.comments;
  66. var cl = f.comment_list[me.docname]
  67. this.msg = $a(this.wrapper, 'div', 'help small');
  68. if(cl) {
  69. this.msg.innerHTML = cl.length + ' out of ' + f.n_comments[me.docname] + ' comments';
  70. for(var i=0; i< cl.length; i++) {
  71. this.render_one_comment(cl[i]);
  72. }
  73. } else {
  74. this.msg.innerHTML = 'Be the first one to comment.'
  75. }
  76. }
  77. //
  78. this.render_one_comment = function(det) {
  79. // comment
  80. $a(this.wrapper, 'div', 'social sidebar-comment-text', '', det.comment);
  81. // by etc
  82. $a(this.wrapper, 'div', 'sidebar-comment-info', '', comment_when(det.creation) + ' by ' + det.comment_by_fullname);
  83. }
  84. this.add_comment = function() {
  85. if(!this.input.value) return;
  86. this.btn.set_working();
  87. wn.widgets.form.comments.add(this.input, me.doctype, me.docname, function() {
  88. me.btn.done_working();
  89. me.make_body();
  90. me.refresh_latest_comment();
  91. });
  92. }
  93. this.refresh();
  94. }