Created
April 21, 2020 14:22
-
-
Save kovenko/00eb89e24b39c274c5e9c4d8ee3ff850 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Ext.define('Project.view.mski.requests.profile.tabEfficiencyCriterion.TariffGrowthRateGrid', { | |
| extend: 'Project.ux.form.field.ValidationGrid', | |
| alias: 'widget.mskiRequestsProfileTabEfficiencyCriterionTariffGrowthRateGrid', | |
| title: 'Темп роста тарифа по годам, %', | |
| height: 235, | |
| requires: [ | |
| 'Project.ux.grid.column.TextAction', | |
| 'Project.model.mski.requests.profile.efficiencyCriterion.TariffGrowthRate', | |
| ], | |
| plugins: ['permission', { | |
| ptype: 'cellediting', | |
| pluginId: 'editing', | |
| clicksToEdit: 1, | |
| }], | |
| config: { | |
| isGranted: true, | |
| request: null, | |
| }, | |
| statics: { | |
| MAX_ROW_GRID: 4, | |
| }, | |
| initComponent() { | |
| let me = this; | |
| let statusId = me.getRequest().getStatus().get('id'); | |
| let firstYear = Math.min(...this.getRequest().get('implementationPeriod')); | |
| me.store = Ext.create('Ext.ux.data.PagingStore', { | |
| model: 'Project.model.mski.requests.profile.efficiencyCriterion.TariffGrowthRate', | |
| data: [], | |
| remoteFilter: false, | |
| remoteSort: false, | |
| autoLoad: false, | |
| proxy: { | |
| type: 'memory', | |
| }, | |
| sorters: [{ | |
| property: 'year', | |
| sorterFn: me.sortFunction, | |
| }], | |
| }); | |
| me.dockedItems = [{ | |
| permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_ADD, | |
| hidden: !me.isGranted || !Project.util.Auth.getGrantByPermission({ | |
| permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_ADD, | |
| statusId: statusId, | |
| }), | |
| permissionStrategy: 'hidden', | |
| xtype: 'toolbar', | |
| docked: 'top', | |
| ui: 'footer', | |
| items: [{ | |
| text: 'Добавить', | |
| glyph: 61694, | |
| itemId: 'addButton', | |
| handler: () => { | |
| me.getStore().add({ | |
| id: null, | |
| year: null, | |
| growthRateWithFund: null, | |
| growthRateWithoutFund: null, | |
| }); | |
| Ext.ComponentQuery.query('mskiRequestsProfileTabEfficiencyCriterionTariffGrowthRateGrid #addButton')[0].setDisabled(me.getStore().data.length >= me.self.MAX_ROW_GRID); | |
| }, | |
| }, { | |
| xtype: 'label', | |
| permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_ADD, | |
| hidden: !me.isGranted || !Project.util.Auth.getGrantByPermission({ | |
| permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_ADD, | |
| statusId: statusId, | |
| }), | |
| text: 'Чтобы добавить дополнительную строку таблицы нажмите на кнопку "Добавить"', | |
| margin: '10 0', | |
| }], | |
| }]; | |
| const editorConfig = { | |
| hideTrigger: true, | |
| allowDecimals: true, | |
| allowExponential: false, | |
| keyNavEnabled: false, | |
| mouseWheelEnabled: false, | |
| minValue: 0, | |
| submitValue: false, | |
| disabled: !(me.isGranted && Project.util.Auth.getGrantByPermission({permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_EDIT})), | |
| }, editorConfigPrecision2 = { | |
| decimalPrecision: 2, | |
| maxValue: Project.ux.form.field.Number.DECIMAL_5_2_MAX, | |
| ...editorConfig, | |
| }, fieldConfigPrecision2 = { | |
| xtype: 'numbercolumn', | |
| format: '0,000.00', | |
| renderer: me.customRenderer, | |
| }; | |
| me.columns = { | |
| defaults: { | |
| align: 'center', | |
| menuDisabled: true, | |
| resizable: true, | |
| sortable: true, | |
| }, | |
| items: [{ | |
| text: 'Год', | |
| xtype: 'referenceBookColumn', | |
| codereference: Project.References.C__PROGRAM_STAGE, | |
| dataIndex: 'year', | |
| width: 75, | |
| height: 45, | |
| format: 'd.m.Y', | |
| editor: { | |
| xtype: 'comboReferenceBook', | |
| codereference: Project.References.C__PROGRAM_STAGE, | |
| filter: (record) => { | |
| let contain = []; | |
| Ext.Array.each(me.store.data.items, (e) => {contain.push(e.data.year)}); | |
| return (parseInt(record.data.name) >= firstYear) && !contain.includes(record.data.id); | |
| }, | |
| submitValue: false, | |
| allowBlank: false, | |
| disabled: !(me.isGranted && Project.util.Auth.getGrantByPermission({ | |
| permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_YEAR, | |
| statusId: statusId, | |
| })), | |
| listeners: { | |
| change: function (combo, newValue) { | |
| console.log('--- change ---------------') | |
| console.log(combo.getStore()); | |
| console.log(combo.editorContext.record); | |
| console.log('------------------') | |
| }, | |
| }, | |
| }, | |
| renderer: me.customRenderer, | |
| }, { | |
| text: 'Темп роста, с финансовой поддержкой Фонда, %', | |
| dataIndex: 'growthRateWithFund', | |
| flex: 1, | |
| ...fieldConfigPrecision2, | |
| editor: Ext.widget('formnumberfield', { | |
| ...editorConfigPrecision2, | |
| maxValue: 100, | |
| }), | |
| }, { | |
| text: 'Темп роста, без финансовой поддержки Фонда, %', | |
| dataIndex: 'growthRateWithoutFund', | |
| flex: 1, | |
| ...fieldConfigPrecision2, | |
| editor: Ext.widget('formnumberfield', { | |
| ...editorConfigPrecision2, | |
| maxValue: 100, | |
| }), | |
| }, { | |
| permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_DELETE, | |
| hidden: !me.isGranted || !Project.util.Auth.getGrantByPermission({ | |
| permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_DELETE, | |
| statusId: statusId, | |
| }), | |
| permissionStrategy: 'hidden', | |
| notEditable: true, | |
| width: 100, | |
| xtype: 'textActionColumn', | |
| resetFilter: true, | |
| align: 'center', | |
| items: [{ | |
| text: 'Удалить', | |
| action: 'deleteAction', | |
| handler(view, rowNum, colNum, action, event, record) { | |
| let grid = view.ownerCt; | |
| Ext.Msg.confirm('Сообщение', 'Вы уверены, что хотите удалить запись из таблицы?', function (action) { | |
| if (action == 'no' || action == 'cancel') { | |
| return; | |
| } | |
| grid.getStore().removeAt(rowNum); | |
| console.log('--- removeAt ---'); | |
| console.log(grid.getStore()); | |
| console.log('----------------'); | |
| Ext.ComponentQuery.query('mskiRequestsProfileTabEfficiencyCriterionTariffGrowthRateGrid #addButton')[0].setDisabled(me.getStore().data.length >= me.self.MAX_ROW_GRID); | |
| }); | |
| }, | |
| isVisible2(view) { | |
| return !view.ownerCt.disabled; | |
| }, | |
| }], | |
| }], | |
| }; | |
| me.callParent(arguments); | |
| me.store.on('load', me.onStoreLoad, this); | |
| me.store.load(); | |
| // let firstYear = Math.min(...this.getRequest().get('implementationPeriod')); | |
| // let yearStore = me.columns[0].store; | |
| // // this.stageField.clearValue(); | |
| // yearStore.clearFilter(true); | |
| // yearStore.filterBy((record, id) => {console.log(parseInt(record.data.name) >= firstYear); /*parseInt(record.data.name) >= firstYear*/ false;}); | |
| }, | |
| customRenderer(value, metaData, record) { | |
| let statusId = this.getRequest().getStatus().get('id'); | |
| // let p1 = !!Project.util.Auth.getGrantByPermission({permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION}); | |
| // let p2 = !!Project.util.Auth.getGrantByPermission({permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_EDIT}); | |
| // let p3 = !!Project.util.Auth.getGrantByPermission({permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_EDIT}); | |
| // let p4 = !!Project.util.Auth.getGrantByPermission({permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_ADD}); | |
| // let p5 = !!Project.util.Auth.getGrantByPermission({permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_DELETE}); | |
| // let p6 = !!Project.util.Auth.getGrantByPermission({permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_YEAR}); | |
| // console.log('Просмотр вкладки "Критерии эффективности (Прил. 6)" ' + (p1 ? 'true' : 'false')); | |
| // console.log('Редактирование вкладки ' + (p2 ? 'true' : 'false')); | |
| // console.log('Редактирование грида "Темп роста тарифа по годам" ' + (p3 ? 'true' : 'false')); | |
| // console.log('Добавление строки ' + (p4 ? 'true' : 'false')); | |
| // console.log('Удаление строки ' + (p5 ? 'true' : 'false')); | |
| // console.log('Редактирование года ' + (p6 ? 'true' : 'false')); | |
| // console.log('------------------------------------------------'); | |
| // 1. статусные привилегии сейчас не на что не влияют | |
| // 2. сейчас можно добавить несколько записей с одним годом https://prnt.sc/s0wlha , уточнил у аналитика, должно быть нельзя | |
| // 5. при добавлении новой записи или редактировании старой сейчас в поле с годом можно выбрать любой год от 2008го до 2026 | |
| // https://prnt.sc/s0wnir ,потому что сказано в задаче что тянем из справочника . Уточнил у аналитика года должны зависеть | |
| // от срока реализации, т.е. первая дата в сроке реализации должна быть самой первой в выпадашке при выборе года в гриде. | |
| // Далее до 2026 года | |
| // let years = []; | |
| // for (let i = Math.min(...this.getRequest().get('implementationPeriod')); i <= 2026; i++) { | |
| // years.push(i); | |
| // } | |
| // | |
| // let store = { | |
| // fields: ['name', 'value'], | |
| // data: [ | |
| // {value: 1, name: 'Форма 1. Реестр перечислений'}, | |
| // {value: 2, name: 'Форма 2. Реестр перечислений по контракту'}, | |
| // {value: 3, name: 'Форма 3. Реестр ДДС по МО'}, | |
| // ], | |
| // }; | |
| // https://ais.reformagkh.localhost/mski/requests/load-card/91?_dc=1587418381261&id=91 | |
| // Request Method: GET | |
| // {success: true,…} | |
| // data: {id: 91, createdAt: 1587321835, updatedAt: 1587326563, projectName: "test 2019-2022",…} | |
| // createdAt: 1587321835 | |
| // geoTag: {id: 2208163, name: "Алтайский край", level: 2, type: "СФ"} | |
| // id: 91 | |
| // implementationPeriod: [2019, 2020, 2021, 2022] | |
| // projectName: "test 2019-2022" | |
| // realizationSphere: {id: 1221, name: "Теплоснабжение", code: "i.communal_inf_mdrnztns_realization_sphere.heating",…} | |
| // status: {id: 580, name: "Заполняется", code: "mski.requests.populating", description: ""} | |
| // updatedAt: 1587326563 | |
| // years: [{id: 715, name: "2016", code: "stage2016", description: null},…] | |
| // 0: {id: 715, name: "2016", code: "stage2016", description: null} | |
| // 1: {id: 716, name: "2017", code: "stage2017", description: null} | |
| // 2: {id: 1909, name: "2018", code: "stage2018", description: null} | |
| // success: true | |
| switch (true) { | |
| case !this.isGranted: | |
| metaData.style = 'background-color: #d3d3d3'; | |
| this.height = 190; | |
| break; | |
| case !Project.util.Auth.getGrantByPermission({ | |
| permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_EDIT, | |
| statusId: statusId, | |
| }): | |
| metaData.style = 'background-color: #d3d3d3'; | |
| this.height = 190; | |
| break; | |
| case metaData.column.dataIndex === 'year' && !Project.util.Auth.getGrantByPermission({ | |
| permission: Project.Permissions.MSKI_REQUESTS_CARD_EFFICIENCY_CRITERION_TARIFF_GROWTH_RATE_YEAR, | |
| statusId: statusId, | |
| }): | |
| metaData.style = 'background-color: #d3d3d3'; | |
| break; | |
| } | |
| return metaData.column.defaultRenderer.apply(metaData.column, arguments); | |
| }, | |
| onStoreLoad(store) { | |
| let addButton = Ext.ComponentQuery.query('mskiRequestsProfileTabEfficiencyCriterionTariffGrowthRateGrid #addButton')[0]; | |
| if (addButton !== undefined) { | |
| addButton.setDisabled(store.data.length >= this.self.MAX_ROW_GRID); | |
| } | |
| }, | |
| sortFunction (o1, o2) { | |
| let me = this; | |
| if (!me.getRoot(o1)[me.property]) { | |
| return 1; | |
| } | |
| return me.defaultSorterFn.apply(this, arguments); | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment