Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

recent.js 2.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // recent document list
  23. wn.ui.toolbar.RecentDocs = Class.extend({
  24. init:function() {
  25. $('.navbar .nav:first').append('<li class="dropdown">\
  26. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  27. title="'+wn._("History")+'"\
  28. onclick="return false;">History</i></a>\
  29. <ul class="dropdown-menu" id="toolbar-recent"></ul>\
  30. </li>');
  31. this.setup();
  32. this.bind_events();
  33. },
  34. bind_events: function() {
  35. // notify on rename
  36. var me = this;
  37. $(document).bind('rename', function(event, dt, old_name, new_name) {
  38. me.rename_notify(dt, old_name, new_name)
  39. });
  40. },
  41. rename_notify: function(dt, old, name) {
  42. this.remove(dt, old);
  43. this.add(dt, name, 1);
  44. },
  45. add: function(dt, dn, on_top) {
  46. if(this.istable(dt)) return;
  47. this.remove(dt, dn);
  48. var html = repl('<li data-docref="%(dt)s/%(dn)s">\
  49. <a href="#Form/%(dt)s/%(dn)s">\
  50. %(dn)s <span style="font-size: 10px">(%(dt)s)</span>\
  51. </a></li>',
  52. {dt:dt, dn:dn});
  53. if(on_top) {
  54. $('#toolbar-recent').prepend(html);
  55. } else {
  56. $('#toolbar-recent').append(html);
  57. }
  58. },
  59. istable: function(dt) {
  60. return locals.DocType[dt] && locals.DocType[dt].istable || false;
  61. },
  62. remove: function(dt, dn) {
  63. $(repl('#toolbar-recent li[data-docref="%(dt)s/%(dn)s"]', {dt:dt, dn:dn})).remove();
  64. },
  65. setup: function() {
  66. // add menu items
  67. var rlist = JSON.parse(profile.recent||"[]");
  68. var m = rlist.length;
  69. if(m>15)m=15;
  70. for (var i=0;i<m;i++) {
  71. var rd = rlist[i]
  72. if(rd[1]) {
  73. var dt = rd[0]; var dn = rd[1];
  74. this.add(dt, dn, 0);
  75. }
  76. }
  77. }
  78. });