// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
//
// MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
wn.provide('wn.views.doclistview');
wn.provide('wn.doclistviews');
wn.views.doclistview.show = function(doctype) {
var page_name = wn.get_route_str();
if(wn.pages[page_name]) {
wn.container.change_to(wn.pages[page_name]);
} else {
var route = wn.get_route();
if(route[1]) {
wn.model.with_doctype(route[1], function(r) {
if(r && r['403']) {
return;
}
new wn.views.DocListView(route[1]);
});
}
}
}
wn.views.DocListView = wn.ui.Listing.extend({
init: function(doctype) {
this.doctype = doctype;
this.label = get_doctype_label(doctype);
this.label = (this.label.toLowerCase().substr(-4) == 'list') ?
this.label : (this.label + ' List');
this.make_page();
this.setup();
},
make_page: function() {
var me = this;
var page_name = wn.get_route_str();
var page = wn.container.add_page(page_name);
wn.container.change_to(page_name);
this.$page = $(page);
this.$page.html('
\
\
\
Loading...
\
\
\
\
Show
\
Drafts
\
Submitted
\
Cancelled
\
\
\
\
');
this.appframe = new wn.ui.AppFrame(this.$page.find('.appframe-area'));
wn.views.breadcrumbs(this.appframe, locals.DocType[this.doctype].module, this.doctype);
},
setup: function() {
var me = this;
me.can_delete = wn.model.can_delete(me.doctype);
me.meta = locals.DocType[me.doctype];
me.$page.find('.wnlist-area').empty(),
me.setup_docstatus_filter();
me.setup_listview();
me.init_list();
me.init_stats();
me.make_report_button();
me.add_delete_option();
},
make_report_button: function() {
var me = this;
if(wn.boot.profile.can_get_report.indexOf(this.doctype)!=-1) {
this.appframe.add_button('Build Report', function() {
wn.set_route('Report2', me.doctype);
}, 'icon-th')
}
},
setup_docstatus_filter: function() {
var me = this;
this.can_submit = $.map(locals.DocPerm, function(d) {
if(d.parent==me.meta.name && d.submit) return 1
else return null;
}).length;
if(this.can_submit) {
this.$page.find('.show-docstatus').removeClass('hide');
this.$page.find('.show-docstatus input').click(function() {
me.run();
})
}
},
setup_listview: function() {
if(this.meta.__listjs) {
eval(this.meta.__listjs);
this.listview = new wn.doclistviews[this.doctype](this);
} else {
this.listview = new wn.views.ListView(this);
}
this.listview.parent = this;
this.wrapper = this.$page.find('.wnlist-area');
this.page_length = 20;
this.allow_delete = true;
},
init_list: function(auto_run) {
var me = this;
// init list
this.make({
method: 'webnotes.widgets.doclistview.get',
get_args: this.get_args,
parent: this.wrapper,
start: 0,
page_length: this.page_length,
show_filters: true,
show_grid: true,
new_doctype: this.doctype,
allow_delete: this.allow_delete,
no_result_message: this.make_no_result(),
columns: this.listview.fields
});
// make_new_doc can be overridden so that default values can be prefilled
// for example - communication list in customer
$(this.wrapper).find('button[list_view_doc="'+me.doctype+'"]').click(function(){
me.make_new_doc(me.doctype);
});
if((auto_run !== false) && (auto_run !== 0)) this.run();
},
make_no_result: function() {
var no_result_message = repl('