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.
 
 
 
 
 
 

129 line
3.5 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", "Reload Page",
  13. function() { me.frm.reload_doc(); })
  14. this.$timestamp = this.appframe.add_icon_btn("2", "icon-user", "Creation / Modified By",
  15. function() { })
  16. this.$comments = this.appframe.add_icon_btn("2", "icon-comments", "Comments", function() {
  17. me.scroll_to(".form-comments");
  18. });
  19. this.$attachments = this.appframe.add_icon_btn("2", "icon-paper-clip", "Attachments", function() {
  20. me.scroll_to(".form-attachments");
  21. });
  22. this.$assignments = this.appframe.add_icon_btn("2", "icon-flag", "Assignments", function() {
  23. me.scroll_to(".form-attachments");
  24. });
  25. this.$links = this.appframe.add_icon_btn("2", "icon-link", "Linked With",
  26. function() { me.frm.toolbar.show_linked_with(); });
  27. if(!me.frm.meta.allow_print) {
  28. this.$print = this.appframe.add_icon_btn("2", "icon-print", "Print",
  29. function() { me.frm.print_doc(); });
  30. }
  31. if(!me.frm.meta.allow_email) {
  32. this.$print = this.appframe.add_icon_btn("2", "icon-envelope", "Email",
  33. function() { me.frm.email_doc(); });
  34. }
  35. if(!this.frm.meta.issingle) {
  36. this.$prev = this.appframe.add_icon_btn("2", "icon-arrow-left", "Previous Record",
  37. function() { me.go_prev_next(true); });
  38. this.$next = this.appframe.add_icon_btn("2", "icon-arrow-right", "Next Record",
  39. function() { me.go_prev_next(false); });
  40. }
  41. },
  42. refresh: function() {
  43. if(!this.frm.doc.__islocal) {
  44. this.docinfo = wn.model.docinfo[this.frm.doctype][this.frm.docname];
  45. // highlight comments
  46. this.highlight_items();
  47. }
  48. },
  49. highlight_items: function() {
  50. var me = this;
  51. this.$timestamp
  52. .popover("destroy")
  53. .popover({
  54. title: "Created and Modified By",
  55. content: "Created By: " + wn.user.full_name(me.frm.doc.owner) + "<br>" +
  56. "Created On: " + dateutil.str_to_user(me.frm.doc.creation) + "<br>" +
  57. "Last Modified By: " + wn.user.full_name(me.frm.doc.modified_by) + "<br>" +
  58. "Last Modifed On: " + dateutil.str_to_user(me.frm.doc.modified),
  59. trigger:"hover",
  60. html: true,
  61. placement: "bottom"
  62. })
  63. this.$comments
  64. .popover("destroy")
  65. if(this.docinfo.comments.length) {
  66. var last = this.docinfo.comments[0];
  67. this.$comments
  68. .popover({
  69. title: "Last Comment",
  70. content: last.comment
  71. + '<p class="text-muted small">By '
  72. + wn.user_info(last.comment_by).fullname
  73. + " / " + comment_when(last.creation)
  74. + '</p>',
  75. trigger:"hover",
  76. html: true,
  77. placement: "bottom"
  78. });
  79. }
  80. $.each(["comments", "attachments", "assignments"], function(i, v) {
  81. if(me.docinfo[v].length)
  82. me["$" + v].addClass("appframe-iconbar-active");
  83. else
  84. me["$" + v].removeClass("appframe-iconbar-active");
  85. })
  86. },
  87. scroll_to: function(cls) {
  88. $('html, body').animate({
  89. scrollTop: $(this.frm.wrapper).find(cls).offset().top
  90. }, 1000);
  91. },
  92. go_prev_next: function(prev) {
  93. var me = this;
  94. return wn.call({
  95. method: "webnotes.widgets.form.utils.get_next",
  96. args: {
  97. doctype: me.frm.doctype,
  98. name: me.frm.docname,
  99. prev: prev ? 1 : 0
  100. },
  101. callback: function(r) {
  102. if(r.message)
  103. wn.set_route("Form", me.frm.doctype, r.message);
  104. }
  105. });
  106. },
  107. })