diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 549b1d351f..ea7d87b986 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -50,6 +50,7 @@ class DocType(Document): self.permissions = [] self.scrub_field_names() + self.set_default_in_list_view() self.validate_series() self.validate_document_type() validate_fields(self) @@ -72,6 +73,16 @@ class DocType(Document): if self.default_print_format and not self.custom: frappe.throw(_('Standard DocType cannot have default print format, use Customize Form')) + def set_default_in_list_view(self): + '''Set default in-list-view for first 4 mandatory fields''' + if not [d.fieldname for d in self.fields if d.in_list_view]: + cnt = 0 + for d in self.fields: + if d.reqd and not d.hidden: + d.in_list_view = 1 + cnt += 1 + if cnt == 4: break + def check_developer_mode(self): """Throw exception if not developer mode or via patch""" if frappe.flags.in_patch or frappe.flags.in_test: diff --git a/frappe/core/doctype/module_def/module_def.json b/frappe/core/doctype/module_def/module_def.json index 643e64d781..1a94f7f391 100644 --- a/frappe/core/doctype/module_def/module_def.json +++ b/frappe/core/doctype/module_def/module_def.json @@ -1,5 +1,6 @@ { "allow_copy": 0, + "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 1, "autoname": "field:module_name", @@ -12,6 +13,7 @@ "engine": "InnoDB", "fields": [ { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -36,12 +38,13 @@ "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, - "reqd": 0, + "reqd": 1, "search_index": 0, "set_only_once": 0, "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -70,18 +73,18 @@ "unique": 0 } ], + "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 0, "icon": "fa fa-sitemap", "idx": 1, "image_view": 0, "in_create": 0, - "in_dialog": 0, "is_submittable": 0, "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-02-17 16:41:14.342061", + "modified": "2017-06-20 14:35:17.407968", "modified_by": "Administrator", "module": "Core", "name": "Module Def", diff --git a/frappe/public/js/frappe/ui/base_list.js b/frappe/public/js/frappe/ui/base_list.js index 720144350b..6547c4baa7 100644 --- a/frappe/public/js/frappe/ui/base_list.js +++ b/frappe/public/js/frappe/ui/base_list.js @@ -185,9 +185,11 @@ frappe.ui.BaseList = Class.extend({ this.onreset && this.onreset(); }, - set_filters_from_route_options: function () { + set_filters_from_route_options: function ({clear_filters=true} = {}) { var me = this; - this.filter_list.clear_filters(); + if(clear_filters) { + this.filter_list.clear_filters(); + } for(var field in frappe.route_options) { var value = frappe.route_options[field]; diff --git a/frappe/public/js/frappe/ui/listing.js b/frappe/public/js/frappe/ui/listing.js deleted file mode 100644 index 39ec149ca6..0000000000 --- a/frappe/public/js/frappe/ui/listing.js +++ /dev/null @@ -1,469 +0,0 @@ -// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -// MIT License. See license.txt - -// new re-factored Listing object -// 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) - -frappe.provide('frappe.ui'); -frappe.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(frappe.boot.user.can_create.indexOf(this.opts.new_doctype)==-1) { - this.opts.new_doctype = null; - } else { - this.opts.new_doctype = this.opts.new_doctype; - } - } - if(!this.opts.no_result_message) { - this.opts.no_result_message = __('Nothing to show'); - } - if(!this.opts.page_length) { - this.opts.page_length = this.list_settings ? (this.list_settings.limit || 20) : 20; - } - this.opts._more = __("More"); - }, - make: function(opts) { - if(opts) { - this.opts = opts; - } - this.prepare_opts(); - $.extend(this, this.opts); - - $(this.parent).html(frappe.render_template("listing", this.opts)); - this.wrapper = $(this.parent).find('.frappe-list'); - this.set_events(); - - if(this.page) { - this.wrapper.find('.list-toolbar-wrapper').toggle(false); - } - - if(this.show_filters) { - this.make_filters(); - } - }, - add_button: function(label, click, icon) { - if(this.page) { - return this.page.add_menu_item(label, click, icon) - } else { - this.wrapper.find('.list-toolbar-wrapper').removeClass("hide"); - var $button = $('') - .appendTo(this.wrapper.find('.list-toolbar')) - .html((icon ? (" ") : "") + label) - .click(click); - return $button - } - }, - set_events: function() { - var me = this; - - // next page - this.wrapper.find('.btn-more').click(function() { - me.run(true); - }); - - this.wrapper.find(".btn-group-paging .btn").click(function() { - me.page_length = cint($(this).attr("data-value")); - me.wrapper.find(".btn-group-paging .btn-info").removeClass("btn-info"); - $(this).addClass("btn-info"); - - // always reset when changing list page length - me.run(); - }); - - // select the correct page length - if(this.opts.page_length != 20) { - this.wrapper.find(".btn-group-paging .btn-info").removeClass("btn-info"); - this.wrapper.find(".btn-group-paging .btn[data-value='"+ this.opts.page_length +"']").addClass('btn-info'); - } - - // title - if(this.title) { - this.wrapper.find('h3').html(this.title).toggle(true); - } - - // new - this.set_primary_action(); - - if(me.no_toolbar || me.hide_toolbar) { - me.wrapper.find('.list-toolbar-wrapper').toggle(false); - } - }, - - set_primary_action: function() { - var me = this; - if(this.new_doctype) { - if(this.listview.settings.set_primary_action){ - this.listview.settings.set_primary_action(this); - } else { - this.page.set_primary_action(__("New"), function() { - me.make_new_doc(me.new_doctype); }, "octicon octicon-plus"); - } - } else { - this.page.clear_primary_action(); - } - }, - - make_new_doc: function(doctype) { - var me = this; - frappe.model.with_doctype(doctype, function() { - if(me.custom_new_doc) { - me.custom_new_doc(doctype); - } else { - if(me.filter_list) { - frappe.route_options = {}; - $.each(me.filter_list.get_filters(), function(i, f) { - if(f[2]==="=" && !in_list(frappe.model.std_fields_list, f[1])) { - frappe.route_options[f[1]] = f[3]; - } - }); - } - frappe.new_doc(doctype, true); - } - }); - }, - - make_filters: function() { - this.filter_list = new frappe.ui.FilterList({ - listobj: this, - $parent: this.wrapper.find('.list-filters').toggle(true), - doctype: this.doctype, - filter_fields: this.filter_fields, - default_filters:this.default_filters? this.default_filters: this.listview?this.listview.settings.default_filters:[] - }); - if(frappe.model.is_submittable(this.doctype)) { - this.filter_list.add_filter(this.doctype, "docstatus", "!=", 2); - } - }, - - clear: function() { - this.data = []; - this.wrapper.find('.result-list').empty(); - this.wrapper.find('.result').toggle(true); - this.wrapper.find('.no-result').toggle(false); - this.start = 0; - if(this.onreset) this.onreset(); - }, - - set_filters_from_route_options: function() { - var me = this; - this.filter_list.clear_filters(); - $.each(frappe.route_options, function(key, value) { - var doctype = null; - - // if `Child DocType.fieldname` - if (key.indexOf(".")!==-1) { - doctype = key.split(".")[0]; - key = key.split(".")[1]; - } - - // find the table in which the key exists - // for example the filter could be {"item_code": "X"} - // where item_code is in the child table. - - // we can search all tables for mapping the doctype - if(!doctype) { - doctype = frappe.meta.get_doctype_for_field(me.doctype, key); - } - - if(doctype) { - if($.isArray(value)) { - me.filter_list.add_filter(doctype, key, value[0], value[1]); - } else { - me.filter_list.add_filter(doctype, key, "=", value); - } - } - }); - frappe.route_options = null; - }, - - run: function(more) { - var me = this; - if(!more) { - this.start = 0; - if(this.onreset) this.onreset(); - } - - if(!me.opts.no_loading) { - me.set_working(true); - } - - var args = this.get_call_args(); - this.save_list_settings_locally(args); - - // list_settings are saved by db_query.py when dirty - $.extend(args, { - list_settings: frappe.model.list_settings[this.doctype] - }); - - return frappe.call({ - method: this.opts.method || 'frappe.desk.query_builder.runquery', - type: "GET", - freeze: (this.opts.freeze != undefined ? this.opts.freeze : true), - args: args, - callback: function(r) { - if(!me.opts.no_loading) - me.set_working(false); - me.dirty = false; - me.render_results(r); - }, - no_spinner: this.opts.no_loading - }); - }, - save_list_settings_locally: function(args) { - if(this.opts.save_list_settings && this.doctype && !this.docname) { - // save list settings locally - var list_settings = frappe.model.list_settings[this.doctype]; - - if(!list_settings) { - return - } - - var different = false; - - if(!frappe.utils.arrays_equal(args.filters, list_settings.filters)) { - //dont save filters in Kanban view - if(this.current_view!=="Kanban") { - // settings are dirty if filters change - list_settings.filters = args.filters || []; - different = true; - } - } - - if(list_settings.order_by !== args.order_by) { - list_settings.order_by = args.order_by; - different = true; - } - - if(list_settings.limit != args.limit_page_length) { - list_settings.limit = args.limit_page_length || 20 - different = true; - } - - // save fields in list settings - if(args.save_list_settings_fields) { - list_settings.fields = args.fields; - } - - if(different) { - list_settings.updated_on = moment().toString(); - } - } - }, - set_working: function(flag) { - this.wrapper.find('.img-load').toggle(flag); - }, - get_call_args: function() { - // load query - if(!this.method) { - var query = this.get_query ? this.get_query() : this.query; - query = this.add_limits(query); - var args={ - query_max: this.query_max, - as_dict: 1 - } - args.simple_query = query; - } else { - var args = { - limit_start: this.start, - limit_page_length: this.page_length - } - } - - // append user-defined arguments - 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.wrapper.find('.btn-more, .list-loading').toggle(false); - - r.values = []; - - if(r.message) { - r.values = this.get_values_from_response(r.message); - } - - if(r.values.length || this.force_render_view) { - if (this.data.length && this.data[this.data.length - 1]._totals_row) { - this.data.pop(); - } - this.data = this.data.concat(r.values); - this.render_view(r.values); - // this.render_list(r.values); - this.update_paging(r.values); - } else { - if(this.start===0) { - this.wrapper.find('.result').toggle(false); - - var msg = this.get_no_result_message - ? this.get_no_result_message() - : (this.no_result_message - ? this.no_result_message - : __("No Result")); - - this.wrapper.find('.no-result') - .html(msg) - .toggle(true); - } - } - - this.wrapper.find('.list-paging-area').toggle((r.values.length || this.start > 0) ? true : false); - - // callbacks - if(this.onrun) this.onrun(); - if(this.callback) this.callback(r); - this.wrapper.trigger("render-complete"); - }, - - get_values_from_response: function(data) { - // make dictionaries from keys and values - if(data.keys && $.isArray(data.keys)) { - return frappe.utils.dict(data.keys, data.values); - } else { - return data; - } - }, - - render_view: function(values) { - this.list_view = new frappe.views.ListView({ - doctype: this.doctype, - values: values, - }); - }, - - render_list: function(values) { - // TODO: where is this used? - // this.last_page = values; - // if(this.filter_list) { - // // and this? - // this.filter_values = this.filter_list.get_filters(); - // } - - this.render_rows(values); - }, - render_rows: function(values) { - // render the rows - var m = Math.min(values.length, this.page_length); - for(var i=0; i < m; i++) { - this.render_row(this.add_row(values[i]), values[i], this, i); - } - }, - update_paging: function(values) { - if(values.length >= this.page_length) { - this.wrapper.find('.btn-more').toggle(true); - this.start += this.page_length; - } - }, - add_row: function(row) { - return $('