From 237d0e55620dc50229ac6a081f3807f06b6b52d8 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 28 Mar 2012 17:49:25 +0530 Subject: [PATCH] listview --- css/ui/list.css | 4 +++- js/core.min.js | 14 +++++++------- js/legacy/utils/datatype.js | 4 ++-- js/wn/request.js | 2 +- js/wn/views/doclistview.js | 19 +++++++++++++------ py/webnotes/widgets/doclistview.py | 2 +- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/css/ui/list.css b/css/ui/list.css index 7a8a704953..a6b6542d1b 100644 --- a/css/ui/list.css +++ b/css/ui/list.css @@ -33,10 +33,12 @@ div.list-row table { div.list-row table td { overflow: hidden; - padding-right: 3px; + /*padding-right: 3px;*/ + padding: 0px 3px; vertical-align: middle; height: 24px; max-height: 24px; + word-wrap: break-word; } div.paging-button { diff --git a/js/core.min.js b/js/core.min.js index 87f5e81bbf..68b8184689 100644 --- a/js/core.min.js +++ b/js/core.min.js @@ -250,7 +250,7 @@ this.listview.parent=this;},init_list:function(){this.make({method:'webnotes.wid Delete',function(){me.delete_items();},'.btn-filter')}},delete_items:function(){var me=this;var dl=$.map(me.$page.find('.list-delete:checked'),function(e){return $(e).data('name');});if(!dl.length) return;if(!confirm('This is PERMANENT action and you cannot undo. Continue?')){return;} me.set_working(true);wn.call({method:'webnotes.widgets.doclistview.delete_items',args:{items:dl,doctype:me.doctype},callback:function(){me.set_working(false);me.refresh();}})},init_stats:function(){var me=this -wn.call({method:'webnotes.widgets.doclistview.get_stats',args:{stats:me.listview.stats,doctype:me.doctype},callback:function(r){$.each(r.message,function(field,stat){me.render_stat(field,stat);});}});},render_stat:function(field,stat){var me=this;if(!stat||!stat.length){if(field=='_user_tags'){this.$page.find('.layout-side-section').append('

Tags

\ +wn.call({method:'webnotes.widgets.doclistview.get_stats',args:{stats:me.listview.stats,doctype:me.doctype},callback:function(r){$.each(me.listview.stats,function(i,v){me.render_stat(v,r.message[v]);});}});},render_stat:function(field,stat){var me=this;if(!stat||!stat.length){if(field=='_user_tags'){this.$page.find('.layout-side-section').append('

Tags

\
No records tagged.

\ To add a tag, open the document and click on \ "Add Tag" on the sidebar
');} @@ -271,16 +271,16 @@ args.label=v[0];args.width=flt(v[1])/max*100;args.count=v[1];args.field=field;$i this.run();}});wn.views.ListView=Class.extend({init:function(doclistview){this.doclistview=doclistview;this.doctype=doclistview.doctype;var t="`tab"+this.doctype+"`.";this.fields=[t+'name',t+'owner',t+'docstatus',t+'_user_tags',t+'modified'];this.stats=['_user_tags'];if(!this.doclistview.can_delete){this.columns=$.map(this.columns,function(v,i){if(v.content!='check')return v});}},columns:[{width:'3%',content:'check'},{width:'4%',content:'avatar'},{width:'3%',content:'docstatus',css:{"text-align":"center"}},{width:'35%',content:'name'},{width:'40%',content:'tags',css:{'color':'#aaa'}},{width:'15%',content:'modified',css:{'text-align':'right','color':'#777'}}],render_column:function(data,parent,opts){var me=this;if(opts.css){$.each(opts.css,function(k,v){$(parent).css(k,v)});} if(opts.content.indexOf&&opts.content.indexOf('+')!=-1){$.map(opts.content.split('+'),function(v){me.render_column(data,parent,{content:v});});return;} if(typeof opts.content=='function'){opts.content(parent,data);} -else if(opts.content=='name'){$(parent).html(repl('%(name)s',data));} -else if(opts.content=='avatar'){$(parent).html(repl('%(name)s',data));} +else if(opts.content=='avatar'){$(parent).append(repl('',data));} -else if(opts.content=='check'){$(parent).html('');$(parent).find('input').data('name',data.name);} -else if(opts.content=='docstatus'){$(parent).html(repl('');$(parent).find('input').data('name',data.name);} +else if(opts.content=='docstatus'){$(parent).append(repl('',data));} else if(opts.content=='tags'){this.add_user_tags(parent,data);} else if(opts.content=='modified'){$(parent).append(data.when);} else if(opts.type=='bar-graph'){args={percent:data[opts.content],fully_delivered:(data[opts.content]>99?'bar-complete':''),label:opts.label} -$(parent).html(repl('\ \ @@ -318,7 +318,7 @@ throw"Incomplete Request";}} wn.request.cleanup=function(opts,r){if(opts.btn)$(opts.btn).done_working();if(opts.show_spinner)hide_loading();if(opts.freeze)unfreeze();if(wn.boot.sid&&wn.get_cookie('sid')!=wn.boot.sid){msgprint('Session expired');setTimeout('redirect_to_login()',3000);return;} if(r.server_messages)msgprint(r.server_messages) if(r.exc){errprint(r.exc);console.log(r.exc);};if(r.docs)LocalDB.sync(r.docs);} -wn.request.call=function(opts){wn.request.prepare(opts);$.ajax({url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});msgprint('Unable to complete request: '+textStatus) +wn.request.call=function(opts){wn.request.prepare(opts);$.ajax({url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus) if(opts.error)opts.error(xhr)}})} wn.call=function(opts){var args=$.extend({},opts.args) if(opts.module&&opts.page){args.cmd=opts.module+'.page.'+opts.page+'.'+opts.page+'.'+opts.method}else if(opts.method){args.cmd=opts.method;} diff --git a/js/legacy/utils/datatype.js b/js/legacy/utils/datatype.js index de4d4ce885..e9ad1c7fe7 100644 --- a/js/legacy/utils/datatype.js +++ b/js/legacy/utils/datatype.js @@ -200,8 +200,8 @@ var rstrip = function(s, chars) { if(!chars) chars = ['\n', '\t', ' ']; var last_char = s.substr(s.length-1); while(in_list(chars, last_char)) { - var s = s.substr(0, this.length-1); - last_char = s.substr(this.length-1); + var s = s.substr(0, s.length-1); + last_char = s.substr(s.length-1); } return s; } diff --git a/js/wn/request.js b/js/wn/request.js index 69de7e11d9..edfe401559 100644 --- a/js/wn/request.js +++ b/js/wn/request.js @@ -83,7 +83,7 @@ wn.request.call = function(opts) { }, error: function(xhr, textStatus) { wn.request.cleanup(opts, {}); - msgprint('Unable to complete request: ' + textStatus) + show_alert('Unable to complete request: ' + textStatus) if(opts.error)opts.error(xhr) } }) diff --git a/js/wn/views/doclistview.js b/js/wn/views/doclistview.js index 3b54a4c0ba..7e4752c1e4 100644 --- a/js/wn/views/doclistview.js +++ b/js/wn/views/doclistview.js @@ -195,9 +195,16 @@ wn.views.DocListView = wn.ui.Listing.extend({ doctype: me.doctype }, callback: function(r) { + // This gives a predictable stats order + $.each(me.listview.stats, function(i, v) { + me.render_stat(v, r.message[v]); + }); + + // This doesn't give a predictable stats order + /* $.each(r.message, function(field, stat) { me.render_stat(field, stat); - }); + });*/ } }); }, @@ -338,19 +345,19 @@ wn.views.ListView = Class.extend({ opts.content(parent, data); } else if(opts.content=='name') { - $(parent).html(repl('%(name)s', data)); + $(parent).append(repl('%(name)s', data)); } else if(opts.content=='avatar') { - $(parent).html(repl('', data)); } else if(opts.content=='check') { - $(parent).html(''); + $(parent).append(''); $(parent).find('input').data('name', data.name); } else if(opts.content=='docstatus') { - $(parent).html(repl('', data)); } else if(opts.content=='tags') { @@ -365,7 +372,7 @@ wn.views.ListView = Class.extend({ fully_delivered: (data[opts.content] > 99 ? 'bar-complete' : ''), label: opts.label } - $(parent).html(repl('\ \ diff --git a/py/webnotes/widgets/doclistview.py b/py/webnotes/widgets/doclistview.py index 8b7e4980e4..ffad86459f 100644 --- a/py/webnotes/widgets/doclistview.py +++ b/py/webnotes/widgets/doclistview.py @@ -134,4 +134,4 @@ def scrub_user_tags(tagcount): - \ No newline at end of file +