Описание примера:
Нужно настроить редактируемый реестр в разделе. Это позволит быстро редактировать записи раздела (как в деталях с редактируемым реестром).
Алгоритм реализации:
1. Создайте замещающую модель представления для вашего раздела, например, ContactSectionV2.
2. Добавьте следующие зависимости в массив зависимостей:
define("ActivitySectionV2", ["ConfigurationGrid", "ConfigurationGridGenerator", "ConfigurationGridUtilities"], function() {
3. Добавьте ConfigurationGridUtilites в блок "mixins":
mixins: { ConfigurationGridUtilites: "Terrasoft.ConfigurationGridUtilities" },
4. Добавьте виртуальную колонку с типом boolean в блок "attributes":
attributes: { IsEditable: { dataValueType: Terrasoft.DataValueType.BOOLEAN, type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN, value: true } },
5. Переопределите базовые методы схемы:
edit: function() { var procElId = this.getActiveRow().get("ProcessElementId"); var recordId = this.get("ActiveRow"); if (procElId && !this.Terrasoft.isEmptyGUID(procElId)) { this.sandbox.publish("ProcessExecDataChanged", { procElUId: procElId, recordId: recordId, scope: this, parentMethodArguments: null, parentMethod: function() { return false; } }); return true; } this.editRecord(recordId); }, editRecord: function(primaryColumnValue) { this.Terrasoft.chain( function(next) { var activeRow = this.findActiveRow(); this.saveRowChanges(activeRow, next); }, function() { var activeRow = this.getActiveRow(); var typeColumnValue = this.getTypeColumnValue(activeRow); var schemaName = this.getEditPageSchemaName(typeColumnValue); var config = { schemaName: schemaName, id: primaryColumnValue, operation: Terrasoft.ConfigurationEnums.CardOperation.EDIT, moduleId: this.getChainCardModuleSandboxId(typeColumnValue) }; this.sandbox.publish("PushHistoryState", { hash: Ext.String.format("{0}/{1}/{2}/{3}", "CardModuleV2", schemaName, Terrasoft.ConfigurationEnums.CardOperation.EDIT, primaryColumnValue), silent: true }); this.openCardInChain(config); }, this); }, addRecord: function(typeColumnValue) { if (!typeColumnValue) { if (this.get("EditPages").getCount() > 1) { return false; } var tag = this.get("AddRecordButtonTag"); typeColumnValue = tag || this.Terrasoft.GUID_EMPTY; } this.addRow(typeColumnValue); }, copyRecord: function(primaryColumnValue) { this.copyRow(primaryColumnValue); }, getGridRowViewModelConfig: function() { var gridRowViewModelConfig = this.mixins.GridUtilities.getGridRowViewModelConfig.apply(this, arguments); Ext.apply(gridRowViewModelConfig, {entitySchema: this.entitySchema}); var editPages = this.get("EditPages"); this.Ext.apply(gridRowViewModelConfig.values, {HasEditPages: editPages && !editPages.isEmpty()}); return gridRowViewModelConfig; }, getGridRowViewModelClassName: function() { return this.mixins.GridUtilities.getGridRowViewModelClassName.apply(this, arguments); }, onRender: function() { this.callParent(arguments); if (!this.get("Restored")) { this.reloadGridColumnsConfig(true); } }, getDefaultGridColumns: function() { var systemColumns = this.systemColumns; var allowedDataValueTypes = this.get("AllowedDataValueTypes"); var entitySchema = this.entitySchema; var entitySchemaColumns = []; Terrasoft.each(entitySchema.columns, function(column, columnName) { if (Ext.Array.contains(systemColumns, columnName) || !Ext.Array.contains(allowedDataValueTypes, column.dataValueType)) { return; } entitySchemaColumns.push(column); }, this); var primaryDisplayColumnName = entitySchema.primaryDisplayColumnName; entitySchemaColumns.sort(function(a, b) { if (a.name === primaryDisplayColumnName) { return -1; } if (b.name === primaryDisplayColumnName) { return 1; } return 0; }, this); return (entitySchemaColumns.length > 4) ? entitySchemaColumns.slice(0, 4) : entitySchemaColumns; }, onActiveRowAction: function() { this.mixins.ConfigurationGridUtilities.onActiveRowAction.apply(this, arguments); this.callParent(arguments); }, onActiveRowAction: function(buttonTag, primaryColumnValue) { switch (buttonTag) { case "card": this.edit(); break; case "copy": this.copyRecord(primaryColumnValue); break; case "remove": this.deleteRecords(); break; case "cancel": this.discardChanges(primaryColumnValue); break; case "save": this.onActiveRowSave(primaryColumnValue); break; } }
6. Добавьте следующие элементы в массив "diff":
{ "operation": "merge", "name": "DataGrid", "values": { "className": "Terrasoft.ConfigurationGrid", "generator": "ConfigurationGridGenerator.generatePartial", "generateControlsConfig": {"bindTo": "generatActiveRowControlsConfig"}, "changeRow": {"bindTo": "changeRow"}, "unSelectRow": {"bindTo": "unSelectRow"}, "onGridClick": {"bindTo": "onGridClick"}, "initActiveRowKeyMap": {"bindTo": "initActiveRowKeyMap"}, "activeRowAction": {"bindTo": "onActiveRowAction"}, "multiSelect": {"bindTo": "MultiSelect"} } }, { "operation": "insert", "name": "activeRowActionSave", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "save", "markerValue": "save", "imageConfig": {"bindTo": "Resources.Images.SaveIcon"} } }, { "operation": "insert", "name": "activeRowActionCopy", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "copy", "markerValue": "copy", "imageConfig": {"bindTo": "Resources.Images.CopyIcon"} } }, { "operation": "insert", "name": "activeRowActionCard", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "card", "markerValue": "card", "visible": {"bindTo": "HasEditPages"}, "imageConfig": {"bindTo": "Resources.Images.CardIcon"} } }, { "operation": "insert", "name": "activeRowActionCancel", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "cancel", "markerValue": "cancel", "imageConfig": {"bindTo": "Resources.Images.CancelIcon"} } }, { "operation": "insert", "name": "activeRowActionRemove", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "remove", "markerValue": "remove", "imageConfig": {"bindTo": "Resources.Images.RemoveIcon"} } }, { "operation": "remove", "name": "DataGridActiveRowOpenAction" }, { "operation": "remove", "name": "DataGridActiveRowCopyAction" }, { "operation": "remove", "name": "DataGridActiveRowDeleteAction" }, { "operation": "remove", "name": "ProcessEntryPointGridRowButton" }
Полный исходный код схемы:
define("ContactSectionV2", ["ConfigurationGrid", "ConfigurationGridGenerator", "ConfigurationGridUtilities"], function() { return { entitySchemaName: "Contact", messages: {}, mixins: { ConfigurationGridUtilites: "Terrasoft.ConfigurationGridUtilities" }, attributes: { IsEditable: { dataValueType: Terrasoft.DataValueType.BOOLEAN, type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN, value: true } }, methods: { edit: function() { var procElId = this.getActiveRow().get("ProcessElementId"); var recordId = this.get("ActiveRow"); if (procElId && !this.Terrasoft.isEmptyGUID(procElId)) { this.sandbox.publish("ProcessExecDataChanged", { procElUId: procElId, recordId: recordId, scope: this, parentMethodArguments: null, parentMethod: function() { return false; } }); return true; } this.editRecord(recordId); }, editRecord: function(primaryColumnValue) { this.Terrasoft.chain( function(next) { var activeRow = this.findActiveRow(); this.saveRowChanges(activeRow, next); }, function() { var activeRow = this.getActiveRow(); var typeColumnValue = this.getTypeColumnValue(activeRow); var schemaName = this.getEditPageSchemaName(typeColumnValue); var config = { schemaName: schemaName, id: primaryColumnValue, operation: Terrasoft.ConfigurationEnums.CardOperation.EDIT, moduleId: this.getChainCardModuleSandboxId(typeColumnValue) }; this.sandbox.publish("PushHistoryState", { hash: Ext.String.format("{0}/{1}/{2}/{3}", "CardModuleV2", schemaName, Terrasoft.ConfigurationEnums.CardOperation.EDIT, primaryColumnValue), silent: true }); this.openCardInChain(config); }, this); }, addRecord: function(typeColumnValue) { if (!typeColumnValue) { if (this.get("EditPages").getCount() > 1) { return false; } var tag = this.get("AddRecordButtonTag"); typeColumnValue = tag || this.Terrasoft.GUID_EMPTY; } this.addRow(typeColumnValue); }, copyRecord: function(primaryColumnValue) { this.copyRow(primaryColumnValue); }, getGridRowViewModelConfig: function() { var gridRowViewModelConfig = this.mixins.GridUtilities.getGridRowViewModelConfig.apply(this, arguments); Ext.apply(gridRowViewModelConfig, {entitySchema: this.entitySchema}); var editPages = this.get("EditPages"); this.Ext.apply(gridRowViewModelConfig.values, {HasEditPages: editPages && !editPages.isEmpty()}); return gridRowViewModelConfig; }, getGridRowViewModelClassName: function() { return this.mixins.GridUtilities.getGridRowViewModelClassName.apply(this, arguments); }, onRender: function() { this.callParent(arguments); if (!this.get("Restored")) { this.reloadGridColumnsConfig(true); } }, getDefaultGridColumns: function() { var systemColumns = this.systemColumns; var allowedDataValueTypes = this.get("AllowedDataValueTypes"); var entitySchema = this.entitySchema; var entitySchemaColumns = []; Terrasoft.each(entitySchema.columns, function(column, columnName) { if (Ext.Array.contains(systemColumns, columnName) || !Ext.Array.contains(allowedDataValueTypes, column.dataValueType)) { return; } entitySchemaColumns.push(column); }, this); var primaryDisplayColumnName = entitySchema.primaryDisplayColumnName; entitySchemaColumns.sort(function(a, b) { if (a.name === primaryDisplayColumnName) { return -1; } if (b.name === primaryDisplayColumnName) { return 1; } return 0; }, this); return (entitySchemaColumns.length > 4) ? entitySchemaColumns.slice(0, 4) : entitySchemaColumns; }, onActiveRowAction: function() { this.mixins.ConfigurationGridUtilities.onActiveRowAction.apply(this, arguments); this.callParent(arguments); }, onActiveRowAction: function(buttonTag, primaryColumnValue) { switch (buttonTag) { case "card": this.edit(); break; case "copy": this.copyRecord(primaryColumnValue); break; case "remove": this.deleteRecords(); break; case "cancel": this.discardChanges(primaryColumnValue); break; case "save": this.onActiveRowSave(primaryColumnValue); break; } } }, diff: /**SCHEMA_DIFF*/[ { "operation": "merge", "name": "DataGrid", "values": { "className": "Terrasoft.ConfigurationGrid", "generator": "ConfigurationGridGenerator.generatePartial", "generateControlsConfig": {"bindTo": "generatActiveRowControlsConfig"}, "changeRow": {"bindTo": "changeRow"}, "unSelectRow": {"bindTo": "unSelectRow"}, "onGridClick": {"bindTo": "onGridClick"}, "initActiveRowKeyMap": {"bindTo": "initActiveRowKeyMap"}, "activeRowAction": {"bindTo": "onActiveRowAction"}, "multiSelect": {"bindTo": "MultiSelect"} } }, { "operation": "insert", "name": "activeRowActionSave", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "save", "markerValue": "save", "imageConfig": {"bindTo": "Resources.Images.SaveIcon"} } }, { "operation": "insert", "name": "activeRowActionCopy", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "copy", "markerValue": "copy", "imageConfig": {"bindTo": "Resources.Images.CopyIcon"} } }, { "operation": "insert", "name": "activeRowActionCard", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "card", "markerValue": "card", "visible": {"bindTo": "HasEditPages"}, "imageConfig": {"bindTo": "Resources.Images.CardIcon"} } }, { "operation": "insert", "name": "activeRowActionCancel", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "cancel", "markerValue": "cancel", "imageConfig": {"bindTo": "Resources.Images.CancelIcon"} } }, { "operation": "insert", "name": "activeRowActionRemove", "parentName": "DataGrid", "propertyName": "activeRowActions", "values": { "className": "Terrasoft.Button", "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "tag": "remove", "markerValue": "remove", "imageConfig": {"bindTo": "Resources.Images.RemoveIcon"} } }, { "operation": "remove", "name": "DataGridActiveRowOpenAction" }, { "operation": "remove", "name": "DataGridActiveRowCopyAction" }, { "operation": "remove", "name": "DataGridActiveRowDeleteAction" }, { "operation": "remove", "name": "ProcessEntryPointGridRowButton" } ]/**SCHEMA_DIFF*/ }; } );
ВАЖНО!
Если вы хотите реализовать редактируемый реестр для раздела Активности, вам следует закомментировать "activeRowActionCopy" в массиве "diff". Функциональности копирования не работает в разделе Активности.
Если вы хотите реализовать редактируемый реестр в разделе Лиды, вам следует добавить следующий исходный код в свойство values элемента DataGrid в массиве diff:
"applyControlConfig": Terrasoft.EmptyFn
поправьте п.2 Не
define("ActivitySectionV2", а
define("ContactSectionV2",