<commit_before>wn.provide("wn.ui.form");
wn.ui.form.Toolbar = Class.extend({
	init: function(opts) {
		$.extend(this, opts);
		this.make();
		this.add_update_button_on_dirty();
		this.appframe.add_module_icon(this.frm.meta.module);
		this.appframe.set_views_for(this.frm.meta.name, "form");
	},
	make: function() {
		this.appframe.clear_buttons();
		this.set_title();
		this.set_title_image();
		this.show_title_as_dirty();

		if(this.frm.meta.hide_toolbar) {
			this.frm.save_disabled = true;
			return;
		}

		this.make_file_menu();
		if(!this.frm.view_is_edit) {
			// print view
			this.show_print_toolbar();
		}
		this.show_infobar();
	},
	refresh: function() {
		this.make();
	},
	set_title: function() {
		var title = this.frm.docname;
		if(title.length > 30) {
			title = title.substr(0,30) + "...";
		}
		this.appframe.set_title(title, wn._(this.frm.docname));
	},
	show_infobar: function() {
		/* docs:
		Render info bar that shows timestamp, # of comments, # of attachments etc.
		only if saved doc. (doc.__islocal is falsy)
		*/
		var me = this;
		this.appframe.clear_infobar();
		if(this.frm.doc.__islocal)
			return;
		this.appframe.add_infobar(
			wn.user.full_name(this.frm.doc.modified_by) + " / " + comment_when(this.frm.doc.modified), function() {
			msgprint("Created By: " + wn.user.full_name(me.frm.doc.owner) + "<br>" +
				"Created On: " + dateutil.str_to_user(me.frm.doc.creation) + "<br>" +
				"Last Modified By: " + wn.user.full_name(me.frm.doc.modified_by) + "<br>" +
				"Last Modifed On: " + dateutil.str_to_user(me.frm.doc.modified), "History");
		})

		var comments = JSON.parse(this.frm.doc.__comments || "[]").length,
			attachments = keys(JSON.parse(this.frm.doc.file_list || "{}")).length,
			assignments = JSON.parse(this.frm.doc.__assign_to || "[]").length;
			
		var $li1 = this.appframe.add_infobar(comments + " " + (comments===1 ? 
			wn._("Comment") : wn._("Comments")),
			function() {
				$('html, body').animate({
					scrollTop: $(me.frm.wrapper).find(".form-comments").offset().top
				}, 2000);
			});
		comments > 0 && $li1.addClass("bold");

		var $li2 = this.appframe.add_infobar(attachments + " " + (attachments===1 ? 
			wn._("Attachment") : wn._("Attachments")),
			function() {
				$('html, body').animate({
					scrollTop: $(me.frm.wrapper).find(".form-attachments").offset().top
				}, 2000);
			});
		attachments > 0 && $li2.addClass("bold");
		
		var $li3 = this.appframe.add_infobar(assignments + " " + (assignments===1 ? 
			wn._("Assignment") : wn._("Assignments")),
			function() {
				$('html, body').animate({
					scrollTop: $(me.frm.wrapper).find(".form-assignments").offset().top
				}, 2000);
			})
		assignments > 0 && $li3.addClass("bold");
		
		this.appframe.$w.find(".form-icon").remove();
		if(!me.frm.meta.allow_print) {
			$('<i class="icon-print pull-right form-icon" title="Print" style="margin-right: 10px;"></i>')
				.click(function() {
					me.frm.print_doc();
				})
				.appendTo(this.appframe.$w.find(".info-bar"));
		}
		
		if(!me.frm.meta.allow_email) {
			$('<i class="icon-envelope pull-right form-icon" title="Email"></i>')
				.click(function() {
					me.frm.email_doc();
				})
				.appendTo(this.appframe.$w.find(".info-bar"));		
		}
	},
	show_print_toolbar: function() {
		var me = this;
		this.appframe.add_button("Edit", function() {
			me.frm.edit_doc();
			return false;
		})
		this.frm.$print_view_select = 
			this.appframe.add_select("Print Format", this.frm.print_formats)
				.val(this.frm.print_formats[0])
				.change(function() {
					me.frm.refresh_print_layout();
				});
	},
	get_dropdown_menu: function(label) {
		return this.appframe.add_dropdown(label);
	},
	set_title_image: function() {
		var img = this.frm.appframe.$w.find('.title-status-img').toggle(false);
		if(this.frm.doc.docstatus==1) {
			img.attr("src", "lib/images/ui/submitted.png").toggle(true);
		}
		else if(this.frm.doc.docstatus==2) {
			img.attr("src", "lib/images/ui/cancelled.png").toggle(true);
		}
	},
	make_file_menu: function() {
		var me = this;
		var p = this.frm.perm[0];
		var docstatus = cint(this.frm.doc.docstatus);

		// New
		if(p[CREATE]) {
			this.appframe.add_dropdown_button("File", wn._("New") + " " 
				+ wn._(me.frm.doctype), function() { 
				new_doc(me.frm.doctype);}, 'icon-plus');
		}

		// Save
		if(docstatus==0 && p[WRITE] && !this.read_only) {
			this.appframe.add_dropdown_button("File", wn._("Save"), function() { 
				me.frm.save('Save', null, this);}, 'icon-save');
		}
		
		// Print
		if(!(me.frm.doc.__islocal || me.frm.meta.allow_print)) {
			this.appframe.add_dropdown_button("File", wn._("Print..."), function() { 
				me.frm.print_doc();}, 'icon-print');
		}

		// email
		if(!(me.frm.doc.__islocal || me.frm.meta.allow_email)) {
			this.appframe.add_dropdown_button("File", wn._("Email..."), function() { 
				me.frm.email_doc();}, 'icon-envelope');
		}

		// Linked With
		if(!me.frm.doc.__islocal && !me.frm.meta.issingle) {
			this.appframe.add_dropdown_button("File", wn._('Linked With'), function() { 
				if(!me.frm.linked_with) {
					me.frm.linked_with = new wn.ui.form.LinkedWith({
						frm: me.frm
					});
				}
				me.frm.linked_with.show();
			}, "icon-link")
		}
		
		// copy
		if(in_list(profile.can_create, me.frm.doctype) && !me.frm.meta.allow_copy) {
			this.appframe.add_dropdown_button("File", wn._("Copy"), function() { 
				me.frm.copy_doc();}, 'icon-file');
		}
		
		// rename
		if(me.frm.meta.allow_rename && me.frm.perm[0][WRITE]) {
			this.appframe.add_dropdown_button("File", wn._("Rename..."), function() { 
				me.frm.rename_doc();}, 'icon-retweet');
		}
		
		// delete
		if((cint(me.frm.doc.docstatus) != 1) && !me.frm.doc.__islocal 
			&& wn.model.can_delete(me.frm.doctype)) {
			this.appframe.add_dropdown_button("File", wn._("Delete"), function() { 
				me.frm.savetrash();}, 'icon-remove-sign');
		}
		
	},
	set_title_button: function() {
		var me = this;
		var docstatus = cint(this.frm.doc.docstatus);
		var p = this.frm.perm[0];
		var has_workflow = wn.model.get("Workflow", {document_type: me.frm.doctype}).length;

		// remove existing title buttons
		this.appframe.toolbar.find(".btn-title").remove();
		
		if(has_workflow && (this.frm.doc.__islocal || this.frm.doc.__unsaved)) {
			this.make_save_button();
		} else if(!has_workflow) {
			if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal) 
				&& (!me.frm.doc.__unsaved)) {
				this.appframe.add_button('Submit', function() { 
					me.frm.savesubmit(this);}, 'icon-lock', true).addClass("btn-primary");
			}
			else if(docstatus==0) {
				this.make_save_button();
			}
			else if(docstatus==1  && p[CANCEL]) {
				this.appframe.add_dropdown_button("File", 'Cancel', function() { 
					me.frm.savecancel(this) }, 'icon-remove');
			}
			else if(docstatus==2  && p[AMEND]) {
				this.appframe.add_button('Amend', function() { 
					me.frm.amend_doc() }, 'icon-pencil', true);
			}
		}
	},
	make_save_button: function() {
		var me = this;
		this.appframe.add_button('Save', function() { 
			me.frm.save('Save', null, this);}, 'icon-save', true).addClass("btn-primary");
	},
	add_update_button_on_dirty: function() {
		var me = this;
		$(this.frm.wrapper).on("dirty", function() {
			me.show_title_as_dirty();<commit_msg>[toolbars] removed view / module menus<commit_after>wn.provide("wn.ui.form");
wn.ui.form.Toolbar = Class.extend({
	init: function(opts) {
		$.extend(this, opts);
		this.make();
		this.add_update_button_on_dirty();
		this.appframe.add_module_icon(this.frm.meta.module);
		this.appframe.set_views_for(this.frm.meta.name, "form");
	},
	make: function() {
		this.appframe.clear_buttons();
		this.set_title();
		this.set_title_image();
		this.show_title_as_dirty();

		if(this.frm.meta.hide_toolbar) {
			this.frm.save_disabled = true;
			return;
		}

		this.make_file_menu();
		if(!this.frm.view_is_edit) {
			// print view
			this.show_print_toolbar();
		}
		this.show_infobar();
	},
	refresh: function() {
		this.make();
	},
	set_title: function() {
		var title = this.frm.docname;
		if(title.length > 30) {
			title = title.substr(0,30) + "...";
		}
		this.appframe.set_title(title, wn._(this.frm.docname));
	},
	show_infobar: function() {
		/* docs:
		Render info bar that shows timestamp, # of comments, # of attachments etc.
		only if saved doc. (doc.__islocal is falsy)
		*/
		var me = this;
		this.appframe.clear_infobar();
		if(this.frm.doc.__islocal)
			return;
		this.appframe.add_infobar(
			wn.user.full_name(this.frm.doc.modified_by) + " / " + comment_when(this.frm.doc.modified), function() {
			msgprint("Created By: " + wn.user.full_name(me.frm.doc.owner) + "<br>" +
				"Created On: " + dateutil.str_to_user(me.frm.doc.creation) + "<br>" +
				"Last Modified By: " + wn.user.full_name(me.frm.doc.modified_by) + "<br>" +
				"Last Modifed On: " + dateutil.str_to_user(me.frm.doc.modified), "History");
		})

		var comments = JSON.parse(this.frm.doc.__comments || "[]").length,
			attachments = keys(JSON.parse(this.frm.doc.file_list || "{}")).length,
			assignments = JSON.parse(this.frm.doc.__assign_to || "[]").length;
			
		var $li1 = this.appframe.add_infobar(comments + " " + (comments===1 ? 
			wn._("Comment") : wn._("Comments")),
			function() {
				$('html, body').animate({
					scrollTop: $(me.frm.wrapper).find(".form-comments").offset().top
				}, 2000);
			});
		comments > 0 && $li1.addClass("bold");

		var $li2 = this.appframe.add_infobar(attachments + " " + (attachments===1 ? 
			wn._("Attachment") : wn._("Attachments")),
			function() {
				$('html, body').animate({
					scrollTop: $(me.frm.wrapper).find(".form-attachments").offset().top
				}, 2000);
			});
		attachments > 0 && $li2.addClass("bold");
		
		var $li3 = this.appframe.add_infobar(assignments + " " + (assignments===1 ? 
			wn._("Assignment") : wn._("Assignments")),
			function() {
				$('html, body').animate({
					scrollTop: $(me.frm.wrapper).find(".form-assignments").offset().top
				}, 2000);
			})
		assignments > 0 && $li3.addClass("bold");
		
		this.appframe.$w.find(".form-icon").remove();
		if(!me.frm.meta.allow_print) {
			$('<i class="icon-print pull-right form-icon" title="Print" style="margin-right: 10px;"></i>')
				.click(function() {
					me.frm.print_doc();
				})
				.appendTo(this.appframe.$w.find(".info-bar"));
		}
		
		if(!me.frm.meta.allow_email) {
			$('<i class="icon-envelope pull-right form-icon" title="Email"></i>')
				.click(function() {
					me.frm.email_doc();
				})
				.appendTo(this.appframe.$w.find(".info-bar"));		
		}
	},
	show_print_toolbar: function() {
		var me = this;
		this.appframe.add_button("Edit", function() {
			me.frm.edit_doc();
			return false;
		})
		this.frm.$print_view_select = 
			this.appframe.add_select("Print Format", this.frm.print_formats)
				.val(this.frm.print_formats[0])
				.change(function() {
					me.frm.refresh_print_layout();
				});
	},
	get_dropdown_menu: function(label) {
		return this.appframe.add_dropdown(label);
	},
	set_title_image: function() {
		var img = this.frm.appframe.$w.find('.title-status-img').toggle(false);
		if(this.frm.doc.docstatus==1) {
			img.attr("src", "lib/images/ui/submitted.png").toggle(true);
		}
		else if(this.frm.doc.docstatus==2) {
			img.attr("src", "lib/images/ui/cancelled.png").toggle(true);
		}
	},
	make_file_menu: function() {
		var me = this;
		var p = this.frm.perm[0];
		var docstatus = cint(this.frm.doc.docstatus);

		// New
		if(p[CREATE]) {
			this.appframe.add_dropdown_button("File", wn._("New") + " " 
				+ wn._(me.frm.doctype), function() { 
				new_doc(me.frm.doctype);}, 'icon-plus');
		}

		// Save
		if(docstatus==0 && p[WRITE] && !this.read_only) {
			this.appframe.add_dropdown_button("File", wn._("Save"), function() { 
				me.frm.save('Save', null, this);}, 'icon-save');
		}
		
		// Print
		if(!(me.frm.doc.__islocal || me.frm.meta.allow_print)) {
			this.appframe.add_dropdown_button("File", wn._("Print..."), function() { 
				me.frm.print_doc();}, 'icon-print');
		}

		// email
		if(!(me.frm.doc.__islocal || me.frm.meta.allow_email)) {
			this.appframe.add_dropdown_button("File", wn._("Email..."), function() { 
				me.frm.email_doc();}, 'icon-envelope');
		}

		// Linked With
		if(!me.frm.doc.__islocal && !me.frm.meta.issingle) {
			this.appframe.add_dropdown_button("File", wn._('Linked With'), function() { 
				if(!me.frm.linked_with) {
					me.frm.linked_with = new wn.ui.form.LinkedWith({
						frm: me.frm
					});
				}
				me.frm.linked_with.show();
			}, "icon-link")
		}
		
		// copy
		if(in_list(profile.can_create, me.frm.doctype) && !me.frm.meta.allow_copy) {
			this.appframe.add_dropdown_button("File", wn._("Copy"), function() { 
				me.frm.copy_doc();}, 'icon-file');
		}
		
		// rename
		if(me.frm.meta.allow_rename && me.frm.perm[0][WRITE]) {
			this.appframe.add_dropdown_button("File", wn._("Rename..."), function() { 
				me.frm.rename_doc();}, 'icon-retweet');
		}
		
		// delete
		if((cint(me.frm.doc.docstatus) != 1) && !me.frm.doc.__islocal 
			&& wn.model.can_delete(me.frm.doctype)) {
			this.appframe.add_dropdown_button("File", wn._("Delete"), function() { 
				me.frm.savetrash();}, 'icon-remove-sign');
		}
		
	},
	set_title_button: function() {
		var me = this;
		var docstatus = cint(this.frm.doc.docstatus);
		var p = this.frm.perm[0];
		var has_workflow = wn.model.get("Workflow", {document_type: me.frm.doctype}).length;

		// remove existing title buttons
		this.appframe.toolbar.find(".btn-title").remove();
		
		// Print Preview
		if(this.frm.meta.read_only_onload && !this.frm.doc.__islocal && this.frm.view_is_edit) {
			this.appframe.add_button(wn._('Preview'), function() { 
				me.frm.last_view_is_edit[me.frm.docname] = 0;
				me.frm.refresh(); }, 'icon-print');
		}
		
		if(has_workflow && (this.frm.doc.__islocal || this.frm.doc.__unsaved)) {
			this.make_save_button();
		} else if(!has_workflow) {
			if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal) 
				&& (!me.frm.doc.__unsaved)) {
				this.appframe.add_button('Submit', function() { 
					me.frm.savesubmit(this);}, 'icon-lock', true).addClass("btn-primary");
			}
			else if(docstatus==0) {
				this.make_save_button();
			}
			else if(docstatus==1  && p[CANCEL]) {
				this.appframe.add_dropdown_button("File", 'Cancel', function() { 
					me.frm.savecancel(this) }, 'icon-remove');
			}
			else if(docstatus==2  && p[AMEND]) {
				this.appframe.add_button('Amend', function() { 
					me.frm.amend_doc() }, 'icon-pencil', true);
			}
		}
	},
	make_save_button: function() {
		var me = this;
		this.appframe.add_button('Save', function() { 
			me.frm.save('Save', null, this);}, 'icon-save', true).addClass("btn-primary");
	},
	add_update_button_on_dirty: function() {
		var me = this;
		$(this.frm.wrapper).on("dirty", function() {
			me.show_title_as_dirty();
{'fraction_non_alphanumeric': 0.2074054017464293, 'fraction_numerical': 0.005889122046977595, 'mean_word_length': 3.5305121128488195, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, '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': '3802015', 'n_tokens_mistral': 6586, 'n_tokens_neox': 5740, 'n_words': 742}