define("UsrProductInPedidoDetail", ["ConfigurationEnums"], function(ConfigurationEnums) { return { entitySchemaName: "UsrProductInPedido", methods: { getGridDataColumns: function() { return { "Id": {patch: "Id"}, "UsrProduct": {patch: "UsrProduct"}, "UsrProduct.Name": {patch: "UsrProduct.Name"} }; }, openDocumentLookup: function() { var config = { entitySchemaName: "BaseProductEntry", multiSelect: true, columns: ["Name", "Price", "Notes"] }; var PedidoId = this.get("MasterRecordId"); if (this.Ext.isEmpty(PedidoId)) { return; } var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: this.entitySchemaName }); esq.addColumn("Id"); esq.addColumn("UsrProduct.Id", "BaseProductEntryId"); esq.filters.add("FilterProduct", this.Terrasoft.createColumnFilterWithParameter( this.Terrasoft.ComparisonType.EQUAL, "UsrPedido", PedidoId)); esq.getEntityCollection(function(result) { var existsDocumentCollection = []; if (result.success) { result.collection.each(function(item) { existsDocumentCollection.push(item.get("BaseProductEntryId")); }); } if (existsDocumentCollection.length > 0) { var existsFilter = this.Terrasoft.createColumnFilterWithParameter("Id", existsDocumentCollection); existsFilter.comparasonType = this.Terrasoft.comparasonType.NOT_EQUAL; existsFilter.Name = "existsFilter"; config.filters = existsFilter; } this.openLookup(config, this.addCallBack, this); }, this); }, onCardSaved: function() { this.openDocumentLookup(); }, addRecord: function() { var masterCardState = this.sandbox.publish("GetCardState", null, [this.sandbox.id]); var isNewRecord = (masterCardState.state === ConfigurationEnums.CardStateV2.ADD || masterCardState.state === ConfigurationEnums.CardStateV2.COPY); if (isNewRecord === true) { var args = { isSilent: true, messageTags: [this.sandbox.id] }; this.sandbox.publish("SaveRecord", args, [this.sandbox.id]); return; } this.openDocumentLookup(); }, addCallBack: function(args) { var bq = this.Ext.create("Terrasoft.BatchQuery"); var PedidoId = this.get("MasterRecordId"); this.selectedRows = args.selectedRows.getItems(); this.selectedItems = []; this.selectedRows.forEach(function(item) { item.UsrPedido = PedidoId; item.UsrProduct = item.value; bq.add(this.getDocumentInsertQuery(item)); this.selectedItems.push(item.value); }, this); if (bq.queries.length) { this.showBodyMask.call(this); bq.execute(this.onDocumentInsert, this); } }, getDocumentInsertQuery: function(item) { var insert = Ext.create("Terrasoft.InsertQuery", { rootSchemaName: this.entitySchemaName }); insert.setParameterValue("Pedido", item.UsrPedido, this.Terrasoft.DataValueType.GUID); insert.setParameterValue("Product", item.UsrProduct, this.Terrasoft.DataValueType.GUID); return insert; }, onDocumentInsert: function(response) { this.hideBodyMask.call(this); this.beforeLoadGridData(); var filterCollection = []; response.queryResults.forEach(function(item) { filterCollection.push(item.id); }); var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: this.entitySchemaName }); this.initQueryColumns(esq); esq.filters.add("recordId", Terrasoft.createColumnInFilterWithParameters("Id", filterCollection)); esq.getEntityCollection(function(response) { this.afterLoadGridData(); if (response.success) { var responseCollection = response.collection; this.prepareResponseCollection(responseCollection); } }, this); }, deleteRecords: function() { var selectedRows = this.getSelectedItems(); if (selectedRows.length > 0) { this.set("SelectedRows", selectedRows); } }, getCopyRecordMenuItem: Terrasoft.emptyFn, getEditRecordMenuItem: Terrasoft.emptyFn, getFilterDefaultColumnName: function() { return "Product"; } }, diff: [ {"operation": "merge", "name": "DataGrid", "values": {"rowDataItemMarkerColumnName": "Product"}}, {"operation": "merge", "name": "AddRecordButton", "values": {"visible": {"bindTo": "getToolsVisible"}}} ] }; } );