// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
// recent document list
wn.ui.toolbar.RecentDocs = Class.extend({
init:function() {
$('.navbar .nav:first').append('
\
'+wn._("History")+'\
\
');
this.setup();
this.bind_events();
},
bind_events: function() {
// notify on rename
var me = this;
$(document).bind('rename', function(event, dt, old_name, new_name) {
me.rename_notify(dt, old_name, new_name)
});
},
rename_notify: function(dt, old, name) {
this.remove(dt, old);
this.add(dt, name, 1);
},
add: function(dt, dn, on_top) {
if(this.istable(dt)) return;
this.remove(dt, dn);
var html = repl('\
\
\
%(dn)s\
',
{dt:dt, dn:dn, icon:wn.boot.doctype_icons[dt]});
if(on_top) {
$('#toolbar-recent').prepend(html);
} else {
$('#toolbar-recent').append(html);
}
},
istable: function(dt) {
return locals.DocType[dt] && locals.DocType[dt].istable || false;
},
remove: function(dt, dn) {
$(repl('#toolbar-recent li[data-docref="%(dt)s/%(dn)s"]', {dt:dt, dn:dn})).remove();
},
setup: function() {
// add menu items
var rlist = JSON.parse(profile.recent||"[]");
var m = rlist.length;
if(m>15)m=15;
for (var i=0;i