diff --git a/cgi-bin/webnotes/profile.py b/cgi-bin/webnotes/profile.py index 1c4ac13f01..963dda4090 100644 --- a/cgi-bin/webnotes/profile.py +++ b/cgi-bin/webnotes/profile.py @@ -177,21 +177,32 @@ class Profile: """ conn = webnotes.conn from webnotes.utils import cstr + import json # get list of child tables, so we know what not to add in the recent list child_tables = [t[0] for t in conn.sql('select name from tabDocType where istable = 1')] if not (dt in ['Print Format', 'Start Page', 'Event', 'ToDo Item', 'Search Criteria']) and not webnotes.is_testing and not (dt in child_tables): r = webnotes.conn.sql("select recent_documents from tabProfile where name=%s", self.name)[0][0] or '' - new_str = dt+'~~~'+dn + '\n' - if new_str in r: - r = r.replace(new_str, '') + + # clear old style (to be removed) + if '~~' in r: r = '' + + rdl = json.loads(r or '[]') + new_rd = [dt, dn] + + # clear if exists + for i in range(len(rdl)): + rd = rdl[i] + if rd==new_rd: + del rdl[i] - self.recent = new_str + r - - if len(self.recent.split('\n')) > 50: - self.recent = '\n'.join(self.recent.split('\n')[:50]) + rdl.append(new_rd) + if len(rdl) > 20: + rdl = rdl[:20] + self.recent = json.dumps(rdl) + webnotes.conn.sql("update tabProfile set recent_documents=%s where name=%s", (self.recent, self.name)) def load_profile(self): diff --git a/js/webpage/wntoolbar.js b/js/webpage/wntoolbar.js index 7fbfede1f4..b7bc287a50 100644 --- a/js/webpage/wntoolbar.js +++ b/js/webpage/wntoolbar.js @@ -104,23 +104,27 @@ function WNToolbar(parent) { if(it)$dh(it); if(pscript.on_recent_update)pscript.on_recent_update(); } - // add menu items - var rlist = profile.recent.split('\n'); - var m = rlist.length; - if(m>15)m=15; - for (var i=0;i15)m=15; + for (var i=0;i'+tdn+'' +''+get_doctype_label(dt)+'';var mi=me.menu.add_item('Recent',rec_label,fn,on_top);mi.dt=dt;mi.dn=dn;this.items[dt+'-'+dn]=mi;if(pscript.on_recent_update)pscript.on_recent_update();}} this.rdocs.remove=function(dt,dn){var it=me.rdocs.items[dt+'-'+dn];if(it)$dh(it);if(pscript.on_recent_update)pscript.on_recent_update();} -var rlist=profile.recent.split('\n');var m=rlist.length;if(m>15)m=15;for(var i=0;i15)m=15;for(var i=0;i