new listing and changed wn.widgets.listing to wn.ui.listing

This commit is contained in:
Rushabh Mehta 2012-03-07 18:19:41 +05:30
parent 0dd5da2299
commit f81a64e57f
23 changed files with 202 additions and 81 deletions

View File

@ -62,6 +62,7 @@
"lib/css/legacy/dialog.css",
"lib/css/legacy/tabs.css",
"lib/css/legacy/sidebar.css",
"lib/css/ui/list.css",
"lib/css/bootstrap/headings.css",
"lib/css/bootstrap/buttons.css",
"lib/css/bootstrap/navbar.css",
@ -131,7 +132,6 @@
"lib/js/wn/ui/dialog.js",
"lib/js/legacy/widgets/dialog.js",
"lib/js/legacy/widgets/listing.js",
"lib/js/wn/ui/listing.js",
"lib/js/legacy/widgets/layout.js",
"lib/js/legacy/widgets/tabbedpage.js",
"lib/js/legacy/webpage/page_header.js",

View File

@ -239,7 +239,6 @@ div.std-footer-item {
margin-bottom: -7px;
max-width: 24px;
}
/*
* lib/css/legacy/messages.css
*/
@ -1143,6 +1142,80 @@ div.psidebar div.section-item, div.psidebar .section-link {
font-size: 11px;
color: #666;
}
/*
* lib/css/ui/list.css
*/.hide {
display: none;
}
.list-filters {
margin: 7px 0px;
}
.wnlist .img-load {
display: none;
float: left;
margin-left: 11px;
margin-top: 8px;
}
div.list-row {
border-bottom: 1px solid #eee;
padding: 3px 0px;
}
div.list-row:hover {
background-color: #eef
}
div.show_filters {
display: none;
}
div.filter_list {
padding: 13px;
}
div.show_filters.well {
margin-top: 11px;
margin-bottom: 11px;
}
div.filter_list .run_btn {
text-align: right;
}
div.filter_list .add_filter {
margin: 3px 0px;
}
div.list_filter {
margin: 7px 0px;
}
div.list_filter input, div.list_filter select {
width: 130px;
margin-right: 7px;
}
span.bar-outer {
display: inline-block;
margin: 0px 7px;
margin-top: 3px;
background-color: #fff;
border: 1px solid #aaa;
height: 10px;
}
span.bar-inner {
display: inline-block;
background-color: #bdf;
height: 100%;
margin-bottom: 2px;
}
span.bar-complete {
background-color: green;
}
/*
* lib/css/bootstrap/headings.css
*//* heading from bootstrap */

View File

@ -239,7 +239,6 @@ div.std-footer-item {
margin-bottom: -7px;
max-width: 24px;
}
/*
* lib/css/legacy/messages.css
*/

View File

@ -54,7 +54,7 @@ cur_frm.cscript.refresh = function(doc,dt,dn) {
cur_frm.cscript.make_address = function() {
if(!cur_frm.address_list) {
cur_frm.address_list = new wn.widgets.Listing({
cur_frm.address_list = new wn.ui.Listing({
parent: cur_frm.fields_dict['Address HTML'].wrapper,
page_length: 2,
new_doctype: "Address",
@ -96,7 +96,7 @@ cur_frm.cscript.make_address = function() {
cur_frm.cscript.make_contact = function() {
if(!cur_frm.contact_list) {
cur_frm.contact_list = new wn.widgets.Listing({
cur_frm.contact_list = new wn.ui.Listing({
parent: cur_frm.fields_dict['Contact HTML'].wrapper,
page_length: 2,
new_doctype: "Contact",

View File

@ -1,5 +1,5 @@
wn.pages['activity'].onload = function(wrapper) {
var list = new wn.widgets.Listing({
var list = new wn.ui.Listing({
method: 'home.page.activity.activity.get_feed',
parent: $('#activity-list'),
render_row: function(row, data) {

View File

@ -470,7 +470,7 @@ FeedList.prototype.make_list = function() {
var me = this;
this.list_area = $a(this.wrapper,'div')
this.list = new wn.widgets.Listing({
this.list = new wn.ui.Listing({
parent: this.list_area,
query: repl('select \
distinct t1.name, t1.feed_type, t1.doc_type, t1.doc_name, t1.subject, t1.modified_by, \

View File

@ -179,7 +179,7 @@ MemberList.prototype.make_list = function() {
var me = this;
this.lst_area = $a(this.list_wrapper, 'div');
this.lst = new wn.widgets.Listing({
this.lst = new wn.ui.Listing({
parent: this.lst_area,
as_dict: 1,
get_query: function() {
@ -692,7 +692,7 @@ MemberConversation = function(parent, uid, fullname) {
this.my_messages_box = $a(this.lst_area, 'div', 'my-company-conversation-head', {marginBottom:'7px'}, 'Messages by everyone to me<br>To send a message, click on the user on the left')
}
this.lst = new wn.widgets.Listing({
this.lst = new wn.ui.Listing({
parent: this.lst_area,
as_dict: 1,
no_result_message: (user==uid

View File

@ -131,7 +131,7 @@ KBAnswerList = function(args) {
this.make_list = function() {
this.list = new wn.widgets.Listing({
this.list = new wn.ui.Listing({
parent: me.parent,
as_dict: 1,
no_result_message: 'No answers yet, be the first one to answer!',

View File

@ -107,7 +107,7 @@ function KnowledgeBase(w) {
this.list_area = $a(w, 'div', '', {marginRight:'13px'})
this.no_result = $a(w, 'div','help_box',{display:'none'},'No questions asked yet! Be the first one to ask')
this.list = new wn.widgets.Listing({
this.list = new wn.ui.Listing({
parent: this.list_area,
no_results_message: 'No questions found. Ask a new question!',
as_dict: 1,

View File

@ -68,7 +68,7 @@ cur_frm.cscript.refresh = function(doc,dt,dn) {
cur_frm.cscript.make_address = function() {
if(!cur_frm.address_list) {
cur_frm.address_list = new wn.widgets.Listing({
cur_frm.address_list = new wn.ui.Listing({
parent: cur_frm.fields_dict['Address HTML'].wrapper,
page_length: 2,
new_doctype: "Address",
@ -110,7 +110,7 @@ cur_frm.cscript.make_address = function() {
cur_frm.cscript.make_contact = function() {
if(!cur_frm.contact_list) {
cur_frm.contact_list = new wn.widgets.Listing({
cur_frm.contact_list = new wn.ui.Listing({
parent: cur_frm.fields_dict['Contact HTML'].wrapper,
page_length: 2,
new_doctype: "Contact",

View File

@ -1,10 +1,19 @@
// render
wn.doclistviews['Sales Order'] = {
fields: ["name", "owner", "modified", "customer_name",
"ifnull(per_delivered,0) as per_delivered",
"ifnull(per_billed,0) as per_billed", "currency",
"ifnull(grand_total_export,0) as grand_total_export",
"docstatus"],
fields: [
{ field: "name", name: "ID"},
{ field: "owner", name: "Created By"},
{ field: "modified", name: "Last Updated"},
{ field: "customer_name", name: "Customer", width:300},
{ field: "per_delivered", name: "% Delivered",
query: "ifnull(per_delivered,0) as per_delivered"},
{ field: "per_billed", name: "% Billed",
query: "ifnull(per_billed,0) as per_billed"},
{ field: "currency", name: "Currency"},
{ field: "grand_total_export", name: "Grand Total",
query:"ifnull(grand_total_export,0) as grand_total_export"},
{ field: "docstatus", name: "Status"}
],
render: function(row, data, listobj) {
data.modified_date = dateutil.str_to_user(data.modified).split(' ')[0];

View File

@ -48,7 +48,7 @@ cur_frm.cscript.refresh = function(doc,dt,dn){
cur_frm.cscript.make_address = function() {
if(!cur_frm.address_list) {
cur_frm.address_list = new wn.widgets.Listing({
cur_frm.address_list = new wn.ui.Listing({
parent: cur_frm.fields_dict['Address HTML'].wrapper,
page_length: 2,
new_doctype: "Address",
@ -80,7 +80,7 @@ cur_frm.cscript.make_address = function() {
cur_frm.cscript.make_contact = function() {
if(!cur_frm.contact_list) {
cur_frm.contact_list = new wn.widgets.Listing({
cur_frm.contact_list = new wn.ui.Listing({
parent: cur_frm.fields_dict['Contact HTML'].wrapper,
page_length: 2,
new_doctype: "Contact",

View File

@ -61,7 +61,7 @@ erpnext.module_page.hide_links = function(wrapper) {
erpnext.module_page.make_list = function(module, wrapper) {
// make project listing
wrapper.list = new wn.widgets.Listing({
wrapper.list = new wn.ui.Listing({
parent: $(wrapper).find('.reports-list').get(0),
method: 'utilities.get_report_list',
render_row: function(row, data) {

View File

@ -81,7 +81,7 @@ $.extend(cur_frm.cscript, {
}, null, -1)
// render thread
cs.thread_list = new wn.widgets.Listing({
cs.thread_list = new wn.ui.Listing({
parent: cur_frm.fields_dict['Thread HTML'].wrapper,
no_result_message: 'No responses yet',
get_query: function() {

View File

@ -91,7 +91,7 @@ erpnext.messages = {
return user;
},
make_list: function() {
erpnext.messages.list = new wn.widgets.Listing({
erpnext.messages.list = new wn.ui.Listing({
parent: $('#message-list').get(0),
method: 'utilities.page.messages.messages.get_list',
args: {

View File

@ -21,7 +21,7 @@ pscript['onload_{{ doc.name }}'] = function(wrapper) {
var side = $(wrapper).find('.web-side-section')
.append('<h4>Recent Posts</h4>').get(0);
wrapper.recent_list = new wn.widgets.Listing({
wrapper.recent_list = new wn.ui.Listing({
parent: side,
query: 'select name, title, left(content, 100) as content from tabBlog\
where ifnull(published,1)=1',
@ -39,7 +39,7 @@ pscript['onload_{{ doc.name }}'] = function(wrapper) {
// comments
$(wrapper).find('.web-main-section').append('<hr><h3>Comments</h3>');
wrapper.comment_list = new wn.widgets.Listing({
wrapper.comment_list = new wn.ui.Listing({
parent: $(wrapper).find('.web-main-section').get(0),
query: 'select comment, comment_by_fullname, modified\
from `tabComment Widget Record` where comment_doctype="Page"\

View File

@ -30,7 +30,7 @@ pscript["onload_{{ doc.page_name }}"] = function(wrapper) {
});
// similar products
wrapper.similar = new wn.widgets.Listing({
wrapper.similar = new wn.ui.Listing({
parent: $(wrapper).find('.similar-products').get(0),
hide_refresh: true,
page_length: 5,

View File

@ -18,7 +18,7 @@
erpnext.product_item_group = {}
erpnext.make_product_categories = function(wrapper) {
wrapper.category_list = new wn.widgets.Listing({
wrapper.category_list = new wn.ui.Listing({
parent: $(wrapper).find('.more-categories').get(0),
query: 'select label, count(t2.name) as items, t1.item_group \
from `tabProduct Group` t1, `tabProduct` t2, tabItem t3\

View File

@ -16,7 +16,7 @@
pscript.onload_blog = function(wrapper) {
wrapper.blog_list = new wn.widgets.Listing({
wrapper.blog_list = new wn.ui.Listing({
parent: $(wrapper).find('.web-main-section').get(0),
query: 'select tabBlog.name, title, left(content, 300) as content, tabBlog.modified, \
ifnull(first_name, "") as first_name, ifnull(last_name, "") as last_name \

View File

@ -57,7 +57,7 @@ erpnext.products.get_group = function() {
}
erpnext.products.make_product_list = function(wrapper) {
wrapper.mainlist = new wn.widgets.Listing({
wrapper.mainlist = new wn.ui.Listing({
parent: $(wrapper).find('.web-main-section').get(0),
run_btn: $(wrapper).find('.products-search .btn').get(0),
hide_refresh: true,

View File

@ -832,33 +832,6 @@ if((this.start+nr)==this.max_len||(!this.max_len&&nr<this.page_len)){}else if(nr
$di(this.more_btn);}}
Listing.prototype.make_headings=function(t,nr,nc){for(var ci=0;ci<nc;ci++){var tmp=make_table($td(t,0,ci),1,2,'100%',['','0px'],this.opts.head_style);$y(tmp,{tableLayout:'fixed',borderCollapse:'collapse'});$y($td(t,0,ci),this.opts.head_main_style);$td(t,0,ci).sort_cell=$td(tmp,0,1);$td(t,0,ci).label_cell=$td(tmp,0,0);$td(tmp,0,1).style.padding='0px';$td(tmp,0,0).innerHTML=this.colnames[ci]?this.colnames[ci]:'&nbsp;';if(this.sort_list[ci])this.set_sort($td(t,0,ci),ci,this.sort_list[ci]);var div=$a($td(t,0,ci),'div');$td(t,0,ci).style.borderBottom='1px solid #CCC';if(this.coltypes&&this.coltypes[ci]&&in_list(['Currency','Float','Int'],this.coltypes[ci]))$y($td(t,0,ci).label_cell,{textAlign:'right'})}}
Listing.prototype.std_cell=function(cell,ri,ci,d){var has_headrow=this.colnames?1:0;cell.div=$a(cell,'div');$s(cell.div,d[ri][ci],this.coltypes?this.coltypes[ci+(this.no_index?0:1)]:null,this.coloptions?this.coloptions[ci+(this.no_index?0:1)]:null);}
/*
* lib/js/wn/ui/listing.js
*/
wn.widgets.Listing=function(opts){this.opts=opts;this.page_length=20;this.btns={};this.start=0;var me=this;this.make=function(opts){if(this.opts.parent.jquery)
this.opts.parent=this.opts.parent.get(0);this.wrapper=$a(this.opts.parent,'div');this.filters_area=$a(this.wrapper,'div','listing-filters');this.toolbar_area=$a(this.wrapper,'div','listing-toolbar');this.results_area=$a(this.wrapper,'div','listing-results');this.more_button_area=$a(this.wrapper,'div','listing-more');this.no_results_area=$a(this.wrapper,'div','help_box',{display:'none'},(this.opts.no_result_message?this.opts.no_result_message:'No results'));if(opts)this.opts=opts;this.page_length=this.opts.page_length?this.opts.page_length:this.page_length;this.make_toolbar();this.make_filters();this.make_more_button();}
this.make_filters=function(){if(this.opts.filters){$ds(this.filters_area);this.filters=new wn.widgets.FieldGroup(this.filters_area,this.opts.fields);}}
this.make_toolbar=function(){if(!(this.opts.hide_refresh||this.opts.no_refresh)){if(this.opts.title){$a(this.toolbar_area,'h3','',{display:'inline-block',marginRight:'15px'},this.opts.title);}
this.ref_img=$a(this.toolbar_area,'span','link_type',{color:'#888'},'[refresh]');this.ref_img.onclick=function(){me.run();}
this.loading_img=$a(this.toolbar_area,'img','lib/images/ui/button-load.gif',{display:'none',marginLeft:'3px',marginBottom:'-2px'});}
if(this.opts.new_doctype){this.new_btn=$btn(this.toolbar_area,'New '+get_doctype_label(this.opts.new_doctype),function(){newdoc(me.opts.new_doctype,me.opts.new_doc_onload,me.opts.new_doc_indialog,me.opts.new_doc_onsave);},{marginLeft:'7px'});}}
this.make_more_button=function(){this.more_btn=$btn(this.more_button_area,'More...',function(){me.more_btn.set_working();me.run(function(){me.more_btn.done_working();},1);},'',0,1);$y(this.more_btn.loading_img,{marginBottom:'0px'});}
this.clear=function(){this.results_area.innerHTML='';this.table=null;$ds(this.results_area);$dh(this.no_results_area);}
this.make_results=function(r,rt){if(this.start==0)this.clear();$dh(this.more_button_area);if(this.loading_img)$dh(this.loading_img)
if(r.message)r.values=r.message;if(r.values&&r.values.length){this.values=r.values;var m=Math.min(r.values.length,this.page_length);for(var i=0;i<m;i++){var row=this.add_row();this.opts.render_row(row,r.values[i],this,i);}
this.start+=m;if(r.values.length>=this.page_length)$ds(this.more_button_area);}else{if(this.start==0){$dh(this.results_area);$ds(this.no_results_area);}}
if(this.onrun)this.onrun();if(this.opts.onrun)this.opts.onrun();if(this.opts.callback)this.opts.callback(r);}
this.add_row=function(){return $a(this.results_area,'div','',(opts.cell_style?opts.cell_style:{padding:'3px 0px'}));}
this.run=function(callback,append){if(callback)
this.onrun=callback;if(!append)
this.start=0;if(!this.opts.method){this.query=this.opts.get_query?this.opts.get_query():this.opts.query;this.add_limits();var args={query_max:this.query_max||this.opts.query_max||'',as_dict:1}
args.simple_query=this.query;}else{var args={limit_start:this.start,limit_page_length:this.page_length}}
if(this.opts.args)
$.extend(args,this.opts.args)
if(this.opts.get_args){$.extend(args,this.opts.get_args());}
if(this.loading_img)$di(this.loading_img);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:args,callback:function(r,rt){me.make_results(r,rt)},no_spinner:this.opts.no_loading,btn:this.opts.run_btn});}
this.refresh=this.run;this.add_limits=function(){this.query+=' LIMIT '+this.start+','+(this.page_length+1);}
if(opts)this.make();}
/*
* lib/js/legacy/widgets/layout.js
*/
@ -2191,7 +2164,7 @@ $(document).bind('startup',function(){erpnext.startup.start();});
*/
wn.provide('erpnext.module_page');erpnext.module_page.setup_page=function(module,wrapper){erpnext.module_page.hide_links(wrapper);erpnext.module_page.make_list(module,wrapper);$(wrapper).find("a[title]").tooltip({delay:{show:500,hide:100}});}
erpnext.module_page.hide_links=function(wrapper){$(wrapper).find('[href*="List/"]').each(function(){var href=$(this).attr('href');var dt=href.split('/')[1];if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1){var txt=$(this).text();$(this).parent().css('color','#999').html(txt);}});$(wrapper).find('[data-doctype]').each(function(){var dt=$(this).attr('data-doctype');if(wn.boot.profile.all_read.indexOf(dt)==-1){var txt=$(this).text();$(this).parent().css('color','#999').html(txt);}});$(wrapper).find('[href*="Form/"]').each(function(){var href=$(this).attr('href');var dt=href.split('/')[1];if(wn.boot.profile.all_read.indexOf(get_label_doctype(dt))==-1){var txt=$(this).text();$(this).parent().css('color','#999').html(txt);}});}
erpnext.module_page.make_list=function(module,wrapper){wrapper.list=new wn.widgets.Listing({parent:$(wrapper).find('.reports-list').get(0),method:'utilities.get_report_list',render_row:function(row,data){if(!data.parent_doc_type)data.parent_doc_type=data.doc_type;$(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
erpnext.module_page.make_list=function(module,wrapper){wrapper.list=new wn.ui.Listing({parent:$(wrapper).find('.reports-list').get(0),method:'utilities.get_report_list',render_row:function(row,data){if(!data.parent_doc_type)data.parent_doc_type=data.doc_type;$(row).html(repl('<a href="#!Report/%(doc_type)s/%(criteria_name)s" \
data-doctype="%(parent_doc_type)s">\
%(criteria_name)s</a>',data))},args:{module:module},no_refresh:true,callback:function(r){erpnext.module_page.hide_links(wrapper)}});wrapper.list.run();}
/*

View File

@ -670,30 +670,97 @@ this.widgets[d[1]]=b;}}
/*
* lib/js/wn/ui/listing.js
*/
wn.widgets.Listing=function(opts){this.opts=opts;this.page_length=20;this.btns={};this.start=0;var me=this;this.make=function(opts){if(this.opts.parent.jquery)
this.opts.parent=this.opts.parent.get(0);this.wrapper=$a(this.opts.parent,'div');this.filters_area=$a(this.wrapper,'div','listing-filters');this.toolbar_area=$a(this.wrapper,'div','listing-toolbar');this.results_area=$a(this.wrapper,'div','listing-results');this.more_button_area=$a(this.wrapper,'div','listing-more');this.no_results_area=$a(this.wrapper,'div','help_box',{display:'none'},(this.opts.no_result_message?this.opts.no_result_message:'No results'));if(opts)this.opts=opts;this.page_length=this.opts.page_length?this.opts.page_length:this.page_length;this.make_toolbar();this.make_filters();this.make_more_button();}
this.make_filters=function(){if(this.opts.filters){$ds(this.filters_area);this.filters=new wn.widgets.FieldGroup(this.filters_area,this.opts.fields);}}
this.make_toolbar=function(){if(!(this.opts.hide_refresh||this.opts.no_refresh)){if(this.opts.title){$a(this.toolbar_area,'h3','',{display:'inline-block',marginRight:'15px'},this.opts.title);}
this.ref_img=$a(this.toolbar_area,'span','link_type',{color:'#888'},'[refresh]');this.ref_img.onclick=function(){me.run();}
this.loading_img=$a(this.toolbar_area,'img','lib/images/ui/button-load.gif',{display:'none',marginLeft:'3px',marginBottom:'-2px'});}
if(this.opts.new_doctype){this.new_btn=$btn(this.toolbar_area,'New '+get_doctype_label(this.opts.new_doctype),function(){newdoc(me.opts.new_doctype,me.opts.new_doc_onload,me.opts.new_doc_indialog,me.opts.new_doc_onsave);},{marginLeft:'7px'});}}
this.make_more_button=function(){this.more_btn=$btn(this.more_button_area,'More...',function(){me.more_btn.set_working();me.run(function(){me.more_btn.done_working();},1);},'',0,1);$y(this.more_btn.loading_img,{marginBottom:'0px'});}
this.clear=function(){this.results_area.innerHTML='';this.table=null;$ds(this.results_area);$dh(this.no_results_area);}
this.make_results=function(r,rt){if(this.start==0)this.clear();$dh(this.more_button_area);if(this.loading_img)$dh(this.loading_img)
if(r.message)r.values=r.message;if(r.values&&r.values.length){this.values=r.values;var m=Math.min(r.values.length,this.page_length);for(var i=0;i<m;i++){var row=this.add_row();this.opts.render_row(row,r.values[i],this,i);}
this.start+=m;if(r.values.length>=this.page_length)$ds(this.more_button_area);}else{if(this.start==0){$dh(this.results_area);$ds(this.no_results_area);}}
if(this.onrun)this.onrun();if(this.opts.onrun)this.opts.onrun();if(this.opts.callback)this.opts.callback(r);}
this.add_row=function(){return $a(this.results_area,'div','',(opts.cell_style?opts.cell_style:{padding:'3px 0px'}));}
this.run=function(callback,append){if(callback)
this.onrun=callback;if(!append)
this.start=0;if(!this.opts.method){this.query=this.opts.get_query?this.opts.get_query():this.opts.query;this.add_limits();var args={query_max:this.query_max||this.opts.query_max||'',as_dict:1}
wn.provide('wn.ui');wn.ui.Listing=Class.extend({init:function(opts){this.opts=opts||{};this.page_length=20;this.start=0;this.data=[];if(opts){this.make();}},prepare_opts:function(){if(this.opts.new_doctype)
this.opts.new_doctype=get_doctype_label(this.opts.new_doctype);},make:function(opts){if(opts){this.opts=opts;}
$.extend(this,this.opts);this.prepare_opts();$(this.parent).html(repl('\
<div class="wnlist">\
<div class="btn-group hide select-view" style="float: right;">\
<a class="btn btn-small btn-info btn-list">\
<i class="icon-list icon-white"></i> List</a>\
<a class="btn btn-small btn-grid">\
<i class="icon-th"></i> Grid</a>\
</div>\
\
<h3 class="title hide">%(title)s</h3>\
<div style="height: 30px;">\
<div class="btn-group" style="float: left;">\
<a class="btn btn-small btn-refresh">\
<i class="icon-refresh"></i> Refresh</a>\
<a class="btn btn-small btn-new">\
<i class="icon-plus"></i> New %(new_doctype)s</a>\
<a class="btn btn-small btn-filter">\
<i class="icon-search"></i> Filter</a>\
</div>\
<img src="lib/images/ui/button-load.gif" \
class="img-load"/>\
</div>\
\
<div style="clear: both; height: 11px;"></div>\
<div class="list-filters hide">\
<div class="show_filters well">\
<div class="filter_area"></div>\
<div>\
<button class="btn btn-small add-filter-btn">\
<i class="icon-plus"></i> Add Filter</button>\
</div>\
</div>\
</div>\
\
<div class="no-result help hide">\
%(no_result_message)s\
</div>\
\
<div class="result">\
<div class="result-list"></div>\
<div class="result-grid"></div>\
</div>\
\
<div class="paging-button hide">\
<button class="btn btn-small btn-more">More...</div>\
</div>\
</div>\
',this.opts));this.$w=$(this.parent).find('.wnlist');this.set_events();this.make_filters();},show_view:function($btn,$div,$btn_unsel,$div_unsel){$btn_unsel.removeClass('btn-info');$btn_unsel.find('i').removeClass('icon-white');$div_unsel.toggle(false);$btn.addClass('btn-info');$btn.find('i').addClass('icon-white');$div.toggle(true);},set_events:function(){var me=this;this.$w.find('.btn-refresh').click(function(){me.run();});this.$w.find('.btn-more').click(function(){me.run({append:true});});this.$w.find('.btn-list').click(function(){me.show_view($(this),me.$w.find('.result-list'),me.$w.find('.btn-grid'),me.$w.find('.result-grid'))});this.$w.find('.btn-grid').click(function(){me.show_view($(this),me.$w.find('.result-grid'),me.$w.find('.btn-list'),me.$w.find('.result-list'))});if(this.title){this.$w.find('h3').html(this.title).toggle(true);}
if(this.new_doctype){this.$w.find('.btn-new').toggle(true).click(function(){newdoc(me.new_doctype);})}else{this.$w.find('.btn-new').toggle(false);}
if(!me.show_filters){this.$w.find('.btn-filter').toggle(false);}
if(this.hide_refresh||this.no_refresh){this.$w.find('.btn-refresh').toggle(false);}
if(this.show_grid){this.$w.find('.select-view').toggle(true);}},make_filters:function(){this.filter_list=new wn.ui.FilterList({listobj:this,$parent:this.$w.find('.list-filters').toggle(true),doctype:this.doctype,filter_fields:this.filter_fields});},clear:function(){this.data=[];this.$w.find('.result-list').empty();this.$w.find('.result').toggle(true);this.$w.find('.no-result').toggle(false);this.start=0;},run:function(){var me=this;var a0=arguments[0];var a1=arguments[1];if(a0&&typeof a0=='function')
this.onrun=a0;if(a0&&a0.callback)
this.onrun=a0.callback;if(!a1||(a0&&a0.append))
this.start=0;me.$w.find('.img-load').toggle(true);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:this.get_call_args(),callback:function(r){me.$w.find('.img-load').toggle(false);me.render_results(r)},no_spinner:this.opts.no_loading,btn:this.run_btn});},get_call_args:function(){if(!this.method){this.query=this.get_query?this.get_query():this.query;this.add_limits();var args={query_max:this.query_max,as_dict:1}
args.simple_query=this.query;}else{var args={limit_start:this.start,limit_page_length:this.page_length}}
if(this.opts.args)
$.extend(args,this.opts.args)
if(this.opts.get_args){$.extend(args,this.opts.get_args());}
if(this.loading_img)$di(this.loading_img);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:args,callback:function(r,rt){me.make_results(r,rt)},no_spinner:this.opts.no_loading,btn:this.opts.run_btn});}
this.refresh=this.run;this.add_limits=function(){this.query+=' LIMIT '+this.start+','+(this.page_length+1);}
if(opts)this.make();}
if(this.args)
$.extend(args,this.args)
if(this.get_args){$.extend(args,this.get_args());}
return args;},render_results:function(r){if(this.start==0)this.clear();this.$w.find('.btn-more').toggle(false);if(r.message)r.values=r.message;if(r.values&&r.values.length){this.data=this.data.concat(r.values);this.render_list(r.values);if(this.show_grid){this.render_grid();}}else{if(this.start==0){this.$w.find('.result').toggle(false);this.$w.find('.no-result').toggle(true);}}
if(this.onrun)this.onrun();if(this.callback)this.callback(r);},render_grid:function(){$.each(this.columns,function(i,c){if(!c.id)c.id=c.field;})
wn.require('lib/js/lib/slickgrid/slick.grid.css');wn.require('lib/js/lib/slickgrid/slick-default-theme.css');wn.require('lib/js/lib/slickgrid/jquery.event.drag.min.js');wn.require('lib/js/lib/slickgrid/slick.core.js');wn.require('lib/js/lib/slickgrid/slick.grid.js');var options={enableCellNavigation:true,enableColumnReorder:false};grid=new Slick.Grid(this.$w.find('.result-grid').css('border','1px solid grey').css('height','500px').get(0),this.data,this.columns,options);},render_list:function(values){var m=Math.min(values.length,this.page_length);for(var i=0;i<m;i++){this.render_row(this.add_row(),values[i],this,i);}
this.start+=m;if(values.length>=this.page_length)
this.$w.find('.btn-more').toggle(true);},add_row:function(){return this.$w.find('.result-list').append('<div class="list-row">').find('.list-row:last').get(0);},refresh:function(){this.run();},add_limits:function(){this.query+=' LIMIT '+this.start+','+(this.page_length+1);}});wn.ui.FilterList=Class.extend({init:function(opts){$.extend(this,opts);this.filters=[];this.$w=this.$parent;this.set_events();},set_events:function(){var me=this;this.listobj.$w.find('.btn-filter').bind('click',function(){me.$w.find('.show_filters').slideToggle();if(!me.filters.length)
me.add_filter();});this.$w.find('.add-filter-btn').bind('click',function(){me.add_filter();});},add_filter:function(fieldname,condition,value){this.filters.push(new wn.ui.Filter({flist:this,fieldname:fieldname,condition:condition,value:value}));},get_filters:function(){var values=[];$.each(this.filters,function(i,f){if(f.filter_field)
values.push(f.get_value());})
return values;},update_filters:function(){var fl=[];$.each(this.filters,function(i,f){if(f.filter_field)fl.push(f);})
this.filters=fl;}});wn.ui.Filter=Class.extend({init:function(opts){$.extend(this,opts);this.doctype=this.flist.doctype;this.fields_by_name={};this.make();this.make_options();this.set_events();},make:function(){this.flist.$w.find('.filter_area').append('<div class="list_filter">\
<select class="fieldname_select"></select>\
<select class="condition">\
<option value="=">Equals</option>\
<option value="like">Like</option>\
<option value=">=">Greater or equals</option>\
<option value=">=">Less or equals</option>\
<option value=">">Greater than</option>\
<option value="<">Less than</option>\
<option value="!=">Not equals</option>\
</select>\
<span class="filter_field"></span>\
<a class="close">&times;</a>\
</div>');this.$w=this.flist.$w.find('.list_filter:last-child');this.$select=this.$w.find('.fieldname_select');},make_options:function(){if(this.filter_fields){for(var i in this.filter_fields)
this.add_field_option(this.filter_fields[i])}else{this.render_field_select();}},set_events:function(){var me=this;this.$w.find('.fieldname_select').bind('change',function(){me.set_field(this.value);});this.$w.find('a.close').bind('click',function(){me.$w.css('display','none');var value=me.filter_field.get_value();me.filter_field=null;if(!me.flist.get_filters().length){me.flist.$w.find('.set_filters').toggle(true);me.flist.$w.find('.show_filters').toggle(false);}
if(value){me.flist.listobj.run();}
me.flist.update_filters();return false;});if(me.fieldname){me.set_field(me.fieldname);if(me.condition)me.$w.find('.condition').val(me.condition)
if(me.value)me.filter_field.set_input(me.value)}else{me.set_field('name');}},render_field_select:function(){var me=this;me.table_fields=[];var std_filters=[{fieldname:'name',fieldtype:'Data',label:'ID',parent:me.doctype},{fieldname:'modified',fieldtype:'Date',label:'Last Modified',parent:me.doctype},{fieldname:'owner',fieldtype:'Data',label:'Created By',parent:me.doctype},{fieldname:'_user_tags',fieldtype:'Data',label:'Tags',parent:me.doctype}];$.each(std_filters.concat(fields_list[me.doctype]),function(i,df){me.add_field_option(df);});$.each(me.table_fields,function(i,table_df){if(table_df.options){$.each(fields_list[table_df.options],function(i,df){me.add_field_option(df);});}})},add_field_option:function(df){var me=this;if(me.doctype&&df.parent==me.doctype){var label=df.label;var table=get_label_doctype(me.doctype);if(df.fieldtype=='Table')me.table_fields.push(df);}else{var label=df.label+' ('+df.parent+')';var table=df.parent;}
if(wn.model.no_value_type.indexOf(df.fieldtype)==-1&&!me.fields_by_name[df.fieldname]){this.$select.append($('<option>',{value:df.fieldname,table:table}).text(label));me.fields_by_name[df.fieldname]=df;}},set_field:function(fieldname){var me=this;me.$w.find('.fieldname_select').val(fieldname);wn.require('lib/js/legacy/widgets/form/fields.js');var field_area=me.$w.find('.filter_field').empty().get(0);var df=me.fields_by_name[fieldname];df.original_type=df.fieldtype;df.description='';if(df.fieldtype=='Check'){df.fieldtype='Select';df.options='No\nYes';}else if(['Text','Text Editor','Code','Link'].indexOf(df.fieldtype)!=-1){df.fieldtype='Data';}
f=make_field(me.fields_by_name[fieldname],null,field_area,null,0,1);f.df.single_select=1;f.not_in_form=1;f.with_label=0;f.refresh();me.filter_field=f;if(df.fieldtype=='Data'){me.$w.find('.condition').val('like');}else{me.$w.find('.condition').val('=');}},get_value:function(){var me=this;var val=me.filter_field.get_value();var cond=me.$w.find('.condition').val();if(me.filter_field.df.original_type=='Check'){val=(val=='Yes'?1:0);}
if(cond=='like'){val=val+'%';}
return[me.$w.find('.fieldname_select option:selected').attr('table'),me.filter_field.df.fieldname,me.$w.find('.condition').val(),val];}});
/*
* lib/js/legacy/widgets/layout.js
*/

View File

@ -1 +1 @@
881
892