<commit_before>import '../class';

frappe.ui.form.Layout = Class.extend({
	init: function(opts) {
		this.views = {};
		this.pages = [];
		this.sections = [];
		this.fields_list = [];
		this.fields_dict = {};

		$.extend(this, opts);
	},
	make: function() {
		if(!this.parent && this.body) {
			this.parent = this.body;
		}
		this.wrapper = $('<div class="form-layout">').appendTo(this.parent);
		this.message = $('<div class="form-message text-muted small hidden"></div>').appendTo(this.wrapper);
		if(!this.fields) {
			this.fields = this.get_doctype_fields();
		}
		this.setup_tabbing();
		this.render();
	},
	show_empty_form_message: function() {
		if(!(this.wrapper.find(".frappe-control:visible").length || this.wrapper.find(".section-head.collapsed").length)) {
			this.show_message(__("This form does not have any input"));
		}
	},
	get_doctype_fields: function() {
		let fields = [
			{
				parent: this.frm.doctype,
				fieldtype: 'Data',
				fieldname: '__newname',
				reqd: 1,
				hidden: 1,
				label: __('Name'),
				get_status: function(field) {
					if (field.frm && field.frm.is_new()
						&& field.frm.meta.autoname
						&& ['prompt', 'name'].includes(field.frm.meta.autoname.toLowerCase())) {
						return 'Write';
					}
					return 'None';
				}
			}
		];
		fields = fields.concat(frappe.meta.sort_docfields(frappe.meta.docfield_map[this.doctype]));
		return fields;
	},
	show_message: function(html, color) {
		if (this.message_color) {
			// remove previous color
			this.message.removeClass(this.message_color);
		}
		this.message_color = (color && ['yellow', 'blue'].includes(color)) ? color : 'blue';
		if(html) {
			if(html.substr(0, 1)!=='<') {
				// wrap in a block
				html = '<div>' + html + '</div>';
			}
			this.message.removeClass('hidden').addClass(this.message_color);
			$(html).appendTo(this.message);
		} else {
			this.message.empty().addClass('hidden');
		}
	},
	render: function(new_fields) {
		var me = this;
		var fields = new_fields || this.fields;

		this.section = null;
		this.column = null;

		if (this.with_dashboard) {
			this.setup_dashboard_section();
		}

		if (this.no_opening_section()) {
			this.make_section();
		}
		$.each(fields, function(i, df) {
			switch(df.fieldtype) {
				case "Fold":
					me.make_page(df);
					break;
				case "Section Break":
					me.make_section(df);
					break;
				case "Column Break":
					me.make_column(df);
					break;
				default:
					me.make_field(df);
			}
		});

	},

	no_opening_section: function() {
		return (this.fields[0] && this.fields[0].fieldtype!="Section Break") || !this.fields.length;
	},

	setup_dashboard_section: function() {
		if (this.no_opening_section()) {
			this.fields.unshift({fieldtype: 'Section Break'});
		}

		this.fields.unshift({
			fieldtype: 'Section Break',
			fieldname: '_form_dashboard',
			label: __('Dashboard'),
			cssClass: 'form-dashboard',
			collapsible: 1,
			//hidden: 1
		});
	},

	replace_field: function(fieldname, df, render) {
		df.fieldname = fieldname; // change of fieldname is avoided
		if (this.fields_dict[fieldname] && this.fields_dict[fieldname].df) {
			const fieldobj = this.init_field(df, render);
			this.fields_dict[fieldname].$wrapper.remove();
			this.fields_list.splice(this.fields_dict[fieldname], 1, fieldobj);
			this.fields_dict[fieldname] = fieldobj;
			if (this.frm) {<commit_msg>fix: dashboard show even if no data is present<commit_after>import '../class';

frappe.ui.form.Layout = Class.extend({
	init: function(opts) {
		this.views = {};
		this.pages = [];
		this.sections = [];
		this.fields_list = [];
		this.fields_dict = {};

		$.extend(this, opts);
	},
	make: function() {
		if(!this.parent && this.body) {
			this.parent = this.body;
		}
		this.wrapper = $('<div class="form-layout">').appendTo(this.parent);
		this.message = $('<div class="form-message text-muted small hidden"></div>').appendTo(this.wrapper);
		if(!this.fields) {
			this.fields = this.get_doctype_fields();
		}
		this.setup_tabbing();
		this.render();
	},
	show_empty_form_message: function() {
		if(!(this.wrapper.find(".frappe-control:visible").length || this.wrapper.find(".section-head.collapsed").length)) {
			this.show_message(__("This form does not have any input"));
		}
	},
	get_doctype_fields: function() {
		let fields = [
			{
				parent: this.frm.doctype,
				fieldtype: 'Data',
				fieldname: '__newname',
				reqd: 1,
				hidden: 1,
				label: __('Name'),
				get_status: function(field) {
					if (field.frm && field.frm.is_new()
						&& field.frm.meta.autoname
						&& ['prompt', 'name'].includes(field.frm.meta.autoname.toLowerCase())) {
						return 'Write';
					}
					return 'None';
				}
			}
		];
		fields = fields.concat(frappe.meta.sort_docfields(frappe.meta.docfield_map[this.doctype]));
		return fields;
	},
	show_message: function(html, color) {
		if (this.message_color) {
			// remove previous color
			this.message.removeClass(this.message_color);
		}
		this.message_color = (color && ['yellow', 'blue'].includes(color)) ? color : 'blue';
		if(html) {
			if(html.substr(0, 1)!=='<') {
				// wrap in a block
				html = '<div>' + html + '</div>';
			}
			this.message.removeClass('hidden').addClass(this.message_color);
			$(html).appendTo(this.message);
		} else {
			this.message.empty().addClass('hidden');
		}
	},
	render: function(new_fields) {
		var me = this;
		var fields = new_fields || this.fields;

		this.section = null;
		this.column = null;

		if (this.with_dashboard) {
			this.setup_dashboard_section();
		}

		if (this.no_opening_section()) {
			this.make_section();
		}
		$.each(fields, function(i, df) {
			switch(df.fieldtype) {
				case "Fold":
					me.make_page(df);
					break;
				case "Section Break":
					me.make_section(df);
					break;
				case "Column Break":
					me.make_column(df);
					break;
				default:
					me.make_field(df);
			}
		});

	},

	no_opening_section: function() {
		return (this.fields[0] && this.fields[0].fieldtype!="Section Break") || !this.fields.length;
	},

	setup_dashboard_section: function() {
		if (this.no_opening_section()) {
			this.fields.unshift({fieldtype: 'Section Break'});
		}

		this.fields.unshift({
			fieldtype: 'Section Break',
			fieldname: '_form_dashboard',
			label: __('Dashboard'),
			cssClass: 'form-dashboard',
			collapsible: 1,
			hidden: 1
		});
	},

	replace_field: function(fieldname, df, render) {
		df.fieldname = fieldname; // change of fieldname is avoided
		if (this.fields_dict[fieldname] && this.fields_dict[fieldname].df) {
			const fieldobj = this.init_field(df, render);
			this.fields_dict[fieldname].$wrapper.remove();
			this.fields_list.splice(this.fields_dict[fieldname], 1, fieldobj);
			this.fields_dict[fieldname] = fieldobj;
			if (this.frm) {
{'fraction_non_alphanumeric': 0.1767849191034585, 'fraction_numerical': 0.0026718123793973577, 'mean_word_length': 3.5373737373737373, 'pattern_counts': {'":': 6, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3297128', 'n_tokens_mistral': 2796, 'n_tokens_neox': 2380, 'n_words': 406}