You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sidebar.js 5.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 = { Sidebar: function(form) {
  23. var me = this;
  24. this.form = form;
  25. this.opts = {
  26. sections: [
  27. {
  28. title: 'Actions',
  29. items: [
  30. {
  31. type: 'link',
  32. label: 'New',
  33. icon: 'icon-plus',
  34. display: function() {
  35. return in_list(profile.can_create, form.doctype)
  36. },
  37. onclick: function() { new_doc(me.form.doctype) }
  38. },
  39. {
  40. type: 'link',
  41. label: 'List',
  42. icon: 'icon-list',
  43. display: function() {
  44. return !me.form.meta.issingle;
  45. },
  46. onclick: function() { window.location.href="#!List/" + me.form.doctype }
  47. },
  48. {
  49. type: 'link',
  50. label: 'Refresh',
  51. icon: 'icon-refresh',
  52. onclick: function() { me.form.reload_doc() }
  53. },
  54. {
  55. type: 'link',
  56. label: 'Print',
  57. display: function() {
  58. return !(me.form.doc.__islocal || me.form.meta.allow_print);
  59. },
  60. icon: 'icon-print',
  61. onclick: function() { me.form.print_doc() }
  62. },
  63. {
  64. type: 'link',
  65. label: 'Email',
  66. display: function() {
  67. return !(me.form.doc.__islocal || me.form.meta.allow_email);
  68. },
  69. icon: 'icon-envelope',
  70. onclick: function() { me.form.email_doc() }
  71. },
  72. {
  73. type: 'link',
  74. label: 'Copy',
  75. display: function() {
  76. return in_list(profile.can_create, me.form.doctype) && !me.form.meta.allow_copy
  77. },
  78. icon: 'icon-file',
  79. onclick: function() { me.form.copy_doc() }
  80. },
  81. {
  82. type: 'link',
  83. label: 'Delete',
  84. display: function() {
  85. return (cint(me.form.doc.docstatus) != 1) && !me.form.doc.__islocal
  86. && wn.model.can_delete(me.form.doctype);
  87. },
  88. icon: 'icon-remove-sign',
  89. onclick: function() { me.form.savetrash() }
  90. }
  91. ]
  92. },
  93. {
  94. title: 'Assign To',
  95. render: function(wrapper) {
  96. me.form.assign_to = new wn.widgets.form.sidebar.AssignTo(wrapper, me, me.form.doctype, me.form.docname);
  97. },
  98. display: function() {
  99. if(me.form.doc.__local) return false;
  100. else return true;
  101. }
  102. },
  103. {
  104. title: 'Attachments',
  105. render: function(wrapper) {
  106. me.form.attachments = new wn.widgets.form.sidebar.Attachments(wrapper, me, me.form.doctype, me.form.docname);
  107. },
  108. display: function() { return me.form.meta.allow_attach }
  109. },
  110. {
  111. title: 'Comments',
  112. render: function(wrapper) {
  113. new wn.widgets.form.sidebar.Comments(wrapper, me, me.form.doctype, me.form.docname);
  114. },
  115. display: function() { return !me.form.doc.__islocal }
  116. },
  117. {
  118. title: 'Tags',
  119. render: function(wrapper) {
  120. me.form.taglist = new TagList(wrapper,
  121. me.form.doc._user_tags ? me.form.doc._user_tags.split(',') : [],
  122. me.form.doctype, me.form.docname, 0,
  123. function() { });
  124. },
  125. display: function() { return !me.form.doc.__islocal }
  126. },
  127. {
  128. title: 'Users',
  129. render: function(wrapper) {
  130. var doc = cur_frm.doc;
  131. var scrub_date = function(d) {
  132. if(d)t=d.split(' ');else return '';
  133. return dateutil.str_to_user(t[0]) + ' ' + t[1];
  134. }
  135. $(wrapper).html(repl('<p>Created:<br> <span class="avatar-small">\
  136. <img title="%(created_by)s" src="%(avatar_created)s" /></span> \
  137. <span class="help small">%(creation)s</span></p>\
  138. <p>Modified:<br> <span class="avatar-small">\
  139. <img title="%(modified_by)s" src="%(avatar_modified)s" /></span> \
  140. <span class="help small">%(modified)s</span></p>', {
  141. created_by: wn.user_info(doc.owner).fullname,
  142. avatar_created: wn.user_info(doc.owner).image,
  143. creation: scrub_date(doc.creation),
  144. modified_by: wn.user_info(doc.modified_by).fullname,
  145. avatar_modified: wn.user_info(doc.modified_by).image,
  146. modified: scrub_date(doc.modified)
  147. }));
  148. },
  149. display: function() { return !me.form.doc.__islocal }
  150. }
  151. ]
  152. }
  153. this.refresh = function() {
  154. var parent = this.form.page_layout.sidebar_area;
  155. if(!this.sidebar) {
  156. //$y(parent, {paddingTop:'37px'})
  157. this.sidebar = new wn.widgets.PageSidebar(parent, this.opts);
  158. } else {
  159. this.sidebar.refresh();
  160. }
  161. }
  162. }}