<commit_before>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

frappe.provide("frappe.ui.form");
frappe.ui.form.Toolbar = Class.extend({
	init: function(opts) {
		$.extend(this, opts);
		this.refresh();
		this.add_update_button_on_dirty();
		this.setup_editable_title();
	},
	refresh: function() {
		this.make_menu();
		this.set_title();
		this.page.clear_user_actions();
		this.show_title_as_dirty();
		this.set_primary_action();

		if(this.frm.meta.hide_toolbar) {
			this.page.hide_menu();
		} else {
			if(this.frm.doc.__islocal) {
				this.page.hide_menu();
				this.print_icon && this.print_icon.addClass("hide");
			} else {
				this.page.show_menu();
				this.print_icon && this.print_icon.removeClass("hide");
			}
		}
	},
	set_title: function() {
		if(this.frm.meta.title_field) {
			var title = (this.frm.doc[this.frm.meta.title_field] || "").trim() || this.frm.docname;
			if(this.frm.doc.__islocal || title === this.frm.docname || this.frm.meta.autoname==="hash") {
				this.page.set_title_sub("");
			} else {
				this.page.set_title_sub(this.frm.docname);
			}
		} else {
			var title = this.frm.docname;
		}
		var me = this;
		title = __(title);
		this.page.set_title(title);
		if(this.frm.meta.title_field) {
			frappe.utils.set_title(title + " - " + this.frm.docname);
		}
		this.page.$title_area.toggleClass("editable-title",
			!!(this.is_title_editable() || this.can_rename()));

		this.set_indicator();
	},
	is_title_editable: function() {
		if (this.frm.meta.title_field==="title"
			&& this.frm.perm[0].write
			&& !this.frm.get_docfield("title").options) {
			return true;
		} else {
			return false;
		}
	},
	can_rename: function() {
		return this.frm.perm[0].write && this.frm.meta.allow_rename;
	},
	setup_editable_title: function() {
		var me = this;
		this.page.$title_area.find(".title-text").on("click", function() {
			if(me.is_title_editable()) {
				frappe.prompt({fieldname: "title", fieldtype:"Data",
					label: __("Title"), reqd: 1, "default": me.frm.doc.title },
					function(data) {
						if(data.title) {
							me.frm.set_value("title", data.title);
							if(!me.frm.doc.__islocal) {
								me.frm.save_or_update();
							} else {
								me.set_title();
							}
						}
					}, __("Edit Title"), __("Update"));
			}
			if(me.can_rename()) {
				me.frm.rename_doc();
			}
		});
	},
	get_dropdown_menu: function(label) {
		return this.page.add_dropdown(label);
	},
	set_indicator: function() {
		var indicator = frappe.get_indicator(this.frm.doc);
		if(indicator) {
			this.page.set_indicator(indicator[0], indicator[1]);
		} else {
			this.page.clear_indicator();
		}
	},
	make_menu: function() {
		this.page.clear_icons();
		this.page.clear_menu();
		var me = this;
		var p = this.frm.perm[0];
		var docstatus = cint(this.frm.doc.docstatus);
		var print_settings = frappe.model.get_doc(":Print Settings", "Print Settings")
		var prevent_draft_from_printing = print_settings.prevent_draft_from_printing
		
		// Print
		if(!prevent_draft_from_printing || prevent_draft_from_printing && docstatus !== 0 || in_list(user_roles, "Administrator")){
			if(frappe.model.can_print(null, me.frm)) {
				this.page.add_menu_item(__("Print"), function() {
					me.frm.print_doc();}, true);
				this.print_icon = this.page.add_action_icon("icon-print", function() {
					me.frm.print_doc();});
			}
		}

		// email<commit_msg>changes for enable print to non submittable document<commit_after>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

frappe.provide("frappe.ui.form");
frappe.ui.form.Toolbar = Class.extend({
	init: function(opts) {
		$.extend(this, opts);
		this.refresh();
		this.add_update_button_on_dirty();
		this.setup_editable_title();
	},
	refresh: function() {
		this.make_menu();
		this.set_title();
		this.page.clear_user_actions();
		this.show_title_as_dirty();
		this.set_primary_action();

		if(this.frm.meta.hide_toolbar) {
			this.page.hide_menu();
		} else {
			if(this.frm.doc.__islocal) {
				this.page.hide_menu();
				this.print_icon && this.print_icon.addClass("hide");
			} else {
				this.page.show_menu();
				this.print_icon && this.print_icon.removeClass("hide");
			}
		}
	},
	set_title: function() {
		if(this.frm.meta.title_field) {
			var title = (this.frm.doc[this.frm.meta.title_field] || "").trim() || this.frm.docname;
			if(this.frm.doc.__islocal || title === this.frm.docname || this.frm.meta.autoname==="hash") {
				this.page.set_title_sub("");
			} else {
				this.page.set_title_sub(this.frm.docname);
			}
		} else {
			var title = this.frm.docname;
		}
		var me = this;
		title = __(title);
		this.page.set_title(title);
		if(this.frm.meta.title_field) {
			frappe.utils.set_title(title + " - " + this.frm.docname);
		}
		this.page.$title_area.toggleClass("editable-title",
			!!(this.is_title_editable() || this.can_rename()));

		this.set_indicator();
	},
	is_title_editable: function() {
		if (this.frm.meta.title_field==="title"
			&& this.frm.perm[0].write
			&& !this.frm.get_docfield("title").options) {
			return true;
		} else {
			return false;
		}
	},
	can_rename: function() {
		return this.frm.perm[0].write && this.frm.meta.allow_rename;
	},
	setup_editable_title: function() {
		var me = this;
		this.page.$title_area.find(".title-text").on("click", function() {
			if(me.is_title_editable()) {
				frappe.prompt({fieldname: "title", fieldtype:"Data",
					label: __("Title"), reqd: 1, "default": me.frm.doc.title },
					function(data) {
						if(data.title) {
							me.frm.set_value("title", data.title);
							if(!me.frm.doc.__islocal) {
								me.frm.save_or_update();
							} else {
								me.set_title();
							}
						}
					}, __("Edit Title"), __("Update"));
			}
			if(me.can_rename()) {
				me.frm.rename_doc();
			}
		});
	},
	get_dropdown_menu: function(label) {
		return this.page.add_dropdown(label);
	},
	set_indicator: function() {
		var indicator = frappe.get_indicator(this.frm.doc);
		if(indicator) {
			this.page.set_indicator(indicator[0], indicator[1]);
		} else {
			this.page.clear_indicator();
		}
	},
	make_menu: function() {
		this.page.clear_icons();
		this.page.clear_menu();
		var me = this;
		var p = this.frm.perm[0];
		var docstatus = cint(this.frm.doc.docstatus);
		var print_settings = frappe.model.get_doc(":Print Settings", "Print Settings")
		var prevent_draft_from_printing = print_settings.prevent_draft_from_printing
		var is_submittable = frappe.model.is_submittable(this.frm.doc.doctype)
		
		// Print
		if(!is_submittable || !prevent_draft_from_printing || prevent_draft_from_printing && docstatus !== 0 || in_list(user_roles, "Administrator")){
			if(frappe.model.can_print(null, me.frm)) {
				this.page.add_menu_item(__("Print"), function() {
					me.frm.print_doc();}, true);
				this.print_icon = this.page.add_action_icon("icon-print", function() {
					me.frm.print_doc();});
			}
		}

		// email
{'fraction_non_alphanumeric': 0.17712972274098548, 'fraction_numerical': 0.0031604654503663266, 'mean_word_length': 3.6382411725516324, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '4110306', 'n_tokens_mistral': 3035, 'n_tokens_neox': 2657, 'n_words': 358}