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

import GridRow from "./grid_row";

frappe.ui.form.get_open_grid_form = function() {
	return $(".grid-row-open").data("grid_row");
}

frappe.ui.form.close_grid_form = function() {
	var open_form = frappe.ui.form.get_open_grid_form();
	open_form && open_form.hide_form();

	// hide editable row too
	if(frappe.ui.form.editable_row) {
		frappe.ui.form.editable_row.toggle_editable_row(false);
	}
}


export default class Grid {
	constructor(opts) {
		$.extend(this, opts);
		this.fieldinfo = {};
		this.doctype = this.df.options;

		if(this.doctype) {
			this.meta = frappe.get_meta(this.doctype);
		}
		this.fields_map = {};
		this.template = null;
		this.multiple_set = false;
		if(this.frm && this.frm.meta.__form_grid_templates
			&& this.frm.meta.__form_grid_templates[this.df.fieldname]) {
			this.template = this.frm.meta.__form_grid_templates[this.df.fieldname];
		}

		this.is_grid = true;
	}

	allow_on_grid_editing() {
		if(frappe.utils.is_xs()) {
			return false;
		} else if(this.meta && this.meta.editable_grid || !this.meta) {
			return true;
		} else {
			return false;
		}
	}
	make() {
		var me = this;

		let template = `<div class="form-group">
			<div class="clearfix">
				<label class="control-label" style="padding-right: 0px;">${__(this.df.label)}</label>
			</div>
			<div class="form-grid">
				<div class="grid-heading-row"></div>
				<div class="grid-body">
					<div class="rows"></div>
					<div class="grid-empty text-center hide">${__("No Data")}</div>
					<div class="small form-clickable-section grid-footer">
						<div class="row">
							<div class="col-sm-6 grid-buttons">
								<button type="reset"
									class="btn btn-xs btn-danger grid-remove-rows hide"
									style="margin-right: 4px;">
									${__("Delete")}</button>
								<button type="reset"
									class="grid-add-multiple-rows btn btn-xs btn-default hide"
									style="margin-right: 4px;">
									${__("Add Multiple")}</a>
								<!-- hack to allow firefox include this in tabs -->
								<button type="reset" class="btn btn-xs btn-default grid-add-row">
									${__("Add Row")}</button>
							</div>
							<div class="col-sm-6 text-right">
								<a href="#" class="grid-download btn btn-xs btn-default hide"
									style="margin-left: 10px;">
									${__("Download")}</a>
								<a href="#" class="grid-upload btn btn-xs btn-default hide"
									style="margin-left: 10px;">
									${__("Upload")}</a>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>`;

		this.wrapper = $(template)
			.appendTo(this.parent)
			.attr("data-fieldname", this.df.fieldname);

		this.form_grid = this.wrapper.find('.form-grid');

		this.wrapper.find(".grid-add-row").click(function() {
			me.add_new_row(null, null, true);
			me.set_focus_on_row();

			return false;
		});<commit_msg>fix (web-form): In form grid<commit_after>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

import GridRow from "./grid_row";

frappe.ui.form.get_open_grid_form = function() {
	return $(".grid-row-open").data("grid_row");
}

frappe.ui.form.close_grid_form = function() {
	var open_form = frappe.ui.form.get_open_grid_form();
	open_form && open_form.hide_form();

	// hide editable row too
	if(frappe.ui.form.editable_row) {
		frappe.ui.form.editable_row.toggle_editable_row(false);
	}
}


export default class Grid {
	constructor(opts) {
		$.extend(this, opts);
		this.fieldinfo = {};
		this.doctype = this.df.options;

		if(this.doctype) {
			this.meta = frappe.get_meta(this.doctype);
		}
		this.fields_map = {};
		this.template = null;
		this.multiple_set = false;
		if(this.frm && this.frm.meta.__form_grid_templates
			&& this.frm.meta.__form_grid_templates[this.df.fieldname]) {
			this.template = this.frm.meta.__form_grid_templates[this.df.fieldname];
		}

		this.is_grid = true;
	}

	allow_on_grid_editing() {
		if(frappe.utils.is_xs()) {
			return false;
		} else if(this.meta && this.meta.editable_grid || !this.meta) {
			return true;
		} else {
			return false;
		}
	}
	make() {
		var me = this;

		let template = `<div class="form-group">
			<div class="clearfix">
				<label class="control-label" style="padding-right: 0px;">${__(this.df.label)}</label>
			</div>
			<div class="form-grid">
				<div class="grid-heading-row"></div>
				<div class="grid-body">
					<div class="rows"></div>
					<div class="grid-empty text-center hide">${__("No Data")}</div>
				</div>
			</div>
			<div class="mt-2 small form-clickable-section grid-footer">
				<div class="row">
					<div class="col-sm-6 grid-buttons">
						<button type="reset"
							class="btn btn-xs btn-danger grid-remove-rows hide"
							style="margin-right: 4px;">
							${__("Delete")}</button>
						<button type="reset"
							class="grid-add-multiple-rows btn btn-xs btn-default hide"
							style="margin-right: 4px;">
							${__("Add Multiple")}</a>
						<!-- hack to allow firefox include this in tabs -->
						<button type="reset" class="btn btn-xs btn-default grid-add-row">
							${__("Add Row")}</button>
					</div>
					<div class="col-sm-6 text-right">
						<a href="#" class="grid-download btn btn-xs btn-default hide"
							style="margin-left: 10px;">
							${__("Download")}</a>
						<a href="#" class="grid-upload btn btn-xs btn-default hide"
							style="margin-left: 10px;">
							${__("Upload")}</a>
					</div>
				</div>
			</div>
		</div>`;

		this.wrapper = $(template)
			.appendTo(this.parent)
			.attr("data-fieldname", this.df.fieldname);

		this.form_grid = this.wrapper.find('.form-grid');

		this.wrapper.find(".grid-add-row").click(function() {
			me.add_new_row(null, null, true);
			me.set_focus_on_row();

			return false;
		});
{'fraction_non_alphanumeric': 0.18099315068493152, 'fraction_numerical': 0.004623287671232877, 'mean_word_length': 3.119181946403385, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2347596', 'n_tokens_mistral': 2568, 'n_tokens_neox': 2071, 'n_words': 387}