// 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.
//
// new re-factored Listing object
// uses FieldGroup for rendering filters
// removed rarely used functionality
//
// opts:
// parent
// method (method to call on server)
// args (additional args to method)
// get_args (method to return args as dict)
// show_filters [false]
// doctype
// filter_fields (if given, this list is rendered, else built from doctype)
// query or get_query (will be deprecated)
// query_max
// buttons_in_frame
// no_result_message ("No result")
// page_length (20)
// hide_refresh (False)
// no_toolbar
// new_doctype
// [function] render_row(parent, data)
// [function] onrun
// no_loading (no ajax indicator)
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) {
if(wn.boot.profile.can_read.indexOf(this.opts.new_doctype)==-1) {
this.opts.new_doctype = null;
} else {
this.opts.new_doctype = get_doctype_label(this.opts.new_doctype);
}
}
if(!this.opts.no_result_message) {
this.opts.no_result_message = 'Nothing to show'
}
},
make: function(opts) {
if(opts) {
this.opts = opts;
}
this.prepare_opts();
$.extend(this, this.opts);
$(this.parent).html(repl('\