From 4e45c72734cae01252f554f5d70b7c9d1ecac09b Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 4 Oct 2019 14:44:42 +0300 Subject: [PATCH] [SSE] Add dialog for creating pivot table --- .../main/app/controller/PivotTable.js | 20 ++++++-- .../main/app/view/PivotSettingsAdvanced.js | 51 +++++++++---------- apps/spreadsheeteditor/main/locale/en.json | 8 +++ 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/PivotTable.js b/apps/spreadsheeteditor/main/app/controller/PivotTable.js index c877d2d0c..5b662b42b 100644 --- a/apps/spreadsheeteditor/main/app/controller/PivotTable.js +++ b/apps/spreadsheeteditor/main/app/controller/PivotTable.js @@ -40,7 +40,8 @@ define([ 'core', - 'spreadsheeteditor/main/app/view/PivotTable' + 'spreadsheeteditor/main/app/view/PivotTable', + 'spreadsheeteditor/main/app/view/CreatePivotDialog' ], function () { 'use strict'; @@ -155,8 +156,21 @@ define([ if (this.api) { var options = this.api.asc_getAddPivotTableOptions(); if (options) { - this.api.asc_insertPivotNewWorksheet(options.asc_getRange(), this.createSheetName()); - // this.api.asc_insertPivotExistingWorksheet(options.asc_getRange(), "Sheet1!B17:B17"); + var me = this; + (new SSE.Views.CreatePivotDialog( + { + props: options, + api: me.api, + handler: function(result, settings) { + if (result == 'ok' && settings) { + if (settings.destination) + me.api.asc_insertPivotExistingWorksheet(settings.source, settings.destination); + else + me.api.asc_insertPivotNewWorksheet(settings.source, me.createSheetName()); + } + Common.NotificationCenter.trigger('edit:complete', me); + } + })).show(); } } Common.NotificationCenter.trigger('edit:complete', this); diff --git a/apps/spreadsheeteditor/main/app/view/PivotSettingsAdvanced.js b/apps/spreadsheeteditor/main/app/view/PivotSettingsAdvanced.js index 95fc39a47..b9005182a 100644 --- a/apps/spreadsheeteditor/main/app/view/PivotSettingsAdvanced.js +++ b/apps/spreadsheeteditor/main/app/view/PivotSettingsAdvanced.js @@ -72,9 +72,17 @@ define([ 'text!spreadsheeteditor/main/app/template/PivotSettingsAdvanced.temp }, options); this.api = options.api; - this.handler = options.handler; this.props = options.props; + this.options.handler = function(result, value) { + if ( result != 'ok' || this.isRangeValid() ) { + if (options.handler) + options.handler.call(this, result, value); + return; + } + return true; + }; + Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); }, @@ -227,36 +235,25 @@ define([ 'text!spreadsheeteditor/main/app/template/PivotSettingsAdvanced.temp return props; }, - onDlgBtnClick: function(event) { - var me = this; - var state = (typeof(event) == 'object') ? event.currentTarget.attributes['result'].value : event; - if (state == 'ok' && this.isRangeValid()) { - this.handler && this.handler.call(this, state, (state == 'ok') ? this.getSettings() : undefined); - } - - this.close(); - }, - - onPrimary: function() { - this.onDlgBtnClick('ok'); - return false; - }, - isRangeValid: function() { - if (this.isChart) { - var isvalid; - if (!_.isEmpty(this.txtDataRange.getValue())) { - isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Pivot, this.txtDataRange.getValue()); - if (isvalid == Asc.c_oAscError.ID.No) - return true; - } else - this.txtDataRange.showError([this.txtEmpty]); + var isvalid = true, + txtError = ''; + if (_.isEmpty(this.txtDataRange.getValue())) { + isvalid = false; + txtError = this.txtEmpty; + } else { + // isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Pivot, this.txtDataRange.getValue()); + // isvalid = (isvalid == Asc.c_oAscError.ID.No); + !isvalid && (txtError = this.textInvalidRange); + } + if (!isvalid) { this.setActiveCategory(1); + this.txtDataRange.showError([txtError]); this.txtDataRange.cmpEl.find('input').focus(); - return false; - } else - return true; + return isvalid; + } + return isvalid; }, onSelectData: function() { diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index ecec32f3e..9a454236a 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -1341,6 +1341,14 @@ "SSE.Views.ChartSettingsDlg.textYAxisTitle": "Y Axis Title", "SSE.Views.ChartSettingsDlg.textZero": "Zero", "SSE.Views.ChartSettingsDlg.txtEmpty": "This field is required", + "SSE.Views.CreatePivotDialog.textTitle": "Create Table", + "SSE.Views.CreatePivotDialog.textDataRange": "Source data range", + "SSE.Views.CreatePivotDialog.textSelectData": "Select", + "SSE.Views.CreatePivotDialog.textDestination": "Choose, where to place the table", + "SSE.Views.CreatePivotDialog.textNew": "New worksheet", + "SSE.Views.CreatePivotDialog.textExist": "Existing worksheet", + "SSE.Views.CreatePivotDialog.txtEmpty": "This field is required", + "SSE.Views.CreatePivotDialog.textInvalidRange": "Invalid cells range", "SSE.Views.DataTab.capBtnGroup": "Group", "SSE.Views.DataTab.capBtnTextToCol": "Text to Columns", "SSE.Views.DataTab.capBtnUngroup": "Ungroup",