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

form_comments.js 2.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.comments = {
  23. n_comments: {},
  24. comment_list: {},
  25. sync: function(dt, dn, r) {
  26. var f = wn.widgets.form.comments;
  27. f.n_comments[dn] = r.n_comments;
  28. f.comment_list[dn] = r.comment_list;
  29. },
  30. add: function(input, dt, dn, callback) {
  31. $c('webnotes.widgets.form.comments.add_comment', wn.widgets.form.comments.get_args(input, dt, dn),
  32. function(r,rt) {
  33. // update the comments
  34. wn.widgets.form.comments.update_comment_list(input, dt, dn);
  35. // clean up the text area
  36. input.value = '';
  37. callback(input, dt, dn);
  38. }
  39. );
  40. },
  41. remove: function(dt, dn, comment_id, callback) {
  42. $c('webnotes.widgets.form.comments.remove_comment',{
  43. id:comment_id,
  44. dt:dt,
  45. dn:dn
  46. }, callback
  47. );
  48. },
  49. get_args: function(input, dt, dn) {
  50. return {
  51. comment: input.value,
  52. comment_by: user,
  53. comment_by_fullname: user_fullname,
  54. comment_doctype: dt,
  55. comment_docname: dn
  56. }
  57. },
  58. update_comment_list: function(input, dt, dn) {
  59. var f = wn.widgets.form.comments;
  60. // update no of comments
  61. f.n_comments[dn] = cint(f.n_comments[dn]) + 1;
  62. // update comment list
  63. f.comment_list[dn] = add_lists(
  64. [f.get_args(input, dt, dn)],
  65. f.comment_list[dn]
  66. );
  67. }
  68. }