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.
 
 
 
 
 
 

141 lines
4.0 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. wn.ui.form.InfoBar = Class.extend({
  4. init: function(opts) {
  5. $.extend(this, opts);
  6. this.make();
  7. this.refresh();
  8. },
  9. make: function() {
  10. var me = this;
  11. this.appframe.iconbar.clear(2);
  12. this.$reload = this.appframe.add_icon_btn("2", "icon-refresh", wn._("Reload Page"),
  13. function() { me.frm.reload_doc(); })
  14. this.$timestamp = this.appframe.add_icon_btn("2", "icon-user", wn._("Creation / Modified By"),
  15. function() { })
  16. this.$comments = this.appframe.add_icon_btn("2", "icon-comments", wn._("Comments"), function() {
  17. me.scroll_to(".form-comments");
  18. });
  19. this.$attachments = this.appframe.add_icon_btn("2", "icon-paper-clip", wn._("Attachments"), function() {
  20. me.scroll_to(".form-attachments");
  21. });
  22. this.$assignments = this.appframe.add_icon_btn("2", "icon-flag", wn._("Assignments"), function() {
  23. me.scroll_to(".form-attachments");
  24. });
  25. this.$links = this.appframe.add_icon_btn("2", "icon-link", wn._("Linked With"),
  26. function() { me.frm.toolbar.show_linked_with(); });
  27. // link to user restrictions
  28. if(wn.model.can_restrict(me.frm.doctype, me.frm)) {
  29. this.$user_properties = this.appframe.add_icon_btn("2", "icon-shield",
  30. wn._("User Permission Restrictions"), function() {
  31. wn.route_options = {
  32. property: me.frm.doctype,
  33. restriction: me.frm.docname
  34. };
  35. wn.set_route("user-properties");
  36. });
  37. }
  38. if(wn.model.can_print(me.frm.doctype, me.frm)) {
  39. this.$print = this.appframe.add_icon_btn("2", "icon-print", wn._("Print"),
  40. function() { me.frm.print_doc(); });
  41. }
  42. if(wn.model.can_email(me.frm.doctype, me.frm)) {
  43. this.$print = this.appframe.add_icon_btn("2", "icon-envelope", wn._("Email"),
  44. function() { me.frm.email_doc(); });
  45. }
  46. if(!this.frm.meta.issingle) {
  47. this.$prev = this.appframe.add_icon_btn("2", "icon-arrow-left", wn._("Previous Record"),
  48. function() { me.go_prev_next(true); });
  49. this.$next = this.appframe.add_icon_btn("2", "icon-arrow-right", wn._("Next Record"),
  50. function() { me.go_prev_next(false); });
  51. }
  52. },
  53. refresh: function() {
  54. if(!this.frm.doc.__islocal) {
  55. this.docinfo = wn.model.docinfo[this.frm.doctype][this.frm.docname];
  56. // highlight comments
  57. this.highlight_items();
  58. }
  59. },
  60. highlight_items: function() {
  61. var me = this;
  62. this.$timestamp
  63. .popover("destroy")
  64. .popover({
  65. title: "Created and Modified By",
  66. content: "Created By: " + wn.user.full_name(me.frm.doc.owner) + "<br>" +
  67. "Created On: " + dateutil.str_to_user(me.frm.doc.creation) + "<br>" +
  68. "Last Modified By: " + wn.user.full_name(me.frm.doc.modified_by) + "<br>" +
  69. "Last Modifed On: " + dateutil.str_to_user(me.frm.doc.modified),
  70. trigger:"hover",
  71. html: true,
  72. placement: "bottom"
  73. })
  74. this.$comments
  75. .popover("destroy")
  76. if(this.docinfo.comments && this.docinfo.comments.length) {
  77. var last = this.docinfo.comments[0];
  78. this.$comments
  79. .popover({
  80. title: "Last Comment",
  81. content: last.comment
  82. + '<p class="text-muted small">By '
  83. + wn.user_info(last.comment_by).fullname
  84. + " / " + comment_when(last.creation)
  85. + '</p>',
  86. trigger:"hover",
  87. html: true,
  88. placement: "bottom"
  89. });
  90. }
  91. $.each(["comments", "attachments", "assignments"], function(i, v) {
  92. if(me.docinfo[v] && me.docinfo[v].length)
  93. me["$" + v].addClass("appframe-iconbar-active");
  94. else
  95. me["$" + v].removeClass("appframe-iconbar-active");
  96. })
  97. },
  98. scroll_to: function(cls) {
  99. $('html, body').animate({
  100. scrollTop: $(this.frm.wrapper).find(cls).offset().top
  101. }, 1000);
  102. },
  103. go_prev_next: function(prev) {
  104. var me = this;
  105. return wn.call({
  106. method: "webnotes.widgets.form.utils.get_next",
  107. args: {
  108. doctype: me.frm.doctype,
  109. name: me.frm.docname,
  110. prev: prev ? 1 : 0
  111. },
  112. callback: function(r) {
  113. if(r.message)
  114. wn.set_route("Form", me.frm.doctype, r.message);
  115. }
  116. });
  117. },
  118. })