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.
 
 
 
 
 
 

67 line
1.7 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. // recent document list
  4. wn.ui.toolbar.RecentDocs = Class.extend({
  5. init:function() {
  6. $('.navbar .nav:first').append('<li class="dropdown">\
  7. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  8. title="'+wn._("History")+'"\
  9. onclick="return false;">'+wn._("History")+'</i></a>\
  10. <ul class="dropdown-menu" id="toolbar-recent"></ul>\
  11. </li>');
  12. this.setup();
  13. this.bind_events();
  14. },
  15. bind_events: function() {
  16. // notify on rename
  17. var me = this;
  18. $(document).bind('rename', function(event, dt, old_name, new_name) {
  19. me.rename_notify(dt, old_name, new_name)
  20. });
  21. },
  22. rename_notify: function(dt, old, name) {
  23. this.remove(dt, old);
  24. this.add(dt, name, 1);
  25. },
  26. add: function(dt, dn, on_top) {
  27. if(this.istable(dt)) return;
  28. this.remove(dt, dn);
  29. var html = repl('<li data-docref="%(dt)s/%(dn)s">\
  30. <a href="#Form/%(dt)s/%(dn)s">\
  31. <i class="icon-fixed-width %(icon)s"></i> \
  32. %(dn)s</span>\
  33. </a></li>',
  34. {dt:dt, dn:dn, icon:wn.boot.doctype_icons[dt]});
  35. if(on_top) {
  36. $('#toolbar-recent').prepend(html);
  37. } else {
  38. $('#toolbar-recent').append(html);
  39. }
  40. },
  41. istable: function(dt) {
  42. return locals.DocType[dt] && locals.DocType[dt].istable || false;
  43. },
  44. remove: function(dt, dn) {
  45. $(repl('#toolbar-recent li[data-docref="%(dt)s/%(dn)s"]', {dt:dt, dn:dn})).remove();
  46. },
  47. setup: function() {
  48. // add menu items
  49. var rlist = JSON.parse(profile.recent||"[]");
  50. var m = rlist.length;
  51. if(m>15)m=15;
  52. for (var i=0;i<m;i++) {
  53. var rd = rlist[i]
  54. if(rd[1]) {
  55. var dt = rd[0]; var dn = rd[1];
  56. try {
  57. this.add(dt, dn, 0);
  58. } catch(e) {
  59. // don't crash
  60. }
  61. }
  62. }
  63. }
  64. });