diff --git a/apps/spreadsheeteditor/main/app/controller/DataTab.js b/apps/spreadsheeteditor/main/app/controller/DataTab.js index 0e36b5a07..070045995 100644 --- a/apps/spreadsheeteditor/main/app/controller/DataTab.js +++ b/apps/spreadsheeteditor/main/app/controller/DataTab.js @@ -46,6 +46,7 @@ define([ 'spreadsheeteditor/main/app/view/RemoveDuplicatesDialog', 'spreadsheeteditor/main/app/view/DataValidationDialog', 'spreadsheeteditor/main/app/view/ExternalLinksDlg', + 'spreadsheeteditor/main/app/view/ImportFromXmlDialog', 'common/main/lib/view/OptionsDialog' ], function () { 'use strict'; @@ -265,6 +266,8 @@ define([ })).show(); } else if (type === 'storage') { // Common.NotificationCenter.trigger('storage:data-load', 'add'); + } else if (type === 'xml') { + this.api && this.api.asc_ImportXmlStart(_.bind(this.onDataFromXMLCallback, this)); } }, @@ -286,6 +289,39 @@ define([ })).show(); }, + onDataFromXMLCallback: function(fileContent) { + if (!fileContent) return; + + var me = this; + (new SSE.Views.ImportFromXmlDialog({ + api: me.api, + handler: function (result, settings) { + if (result == 'ok' && settings) { + if (settings.destination) + me.api.asc_ImportXmlEnd(fileContent, settings.destination, me.api.asc_getWorksheetName(me.api.asc_getActiveWorksheetIndex())); + else + me.api.asc_ImportXmlEnd(fileContent, null, me.createSheetName()); + } + Common.NotificationCenter.trigger('edit:complete', me); + } + })).show(); + }, + + createSheetName: function() { + var items = [], wc = this.api.asc_getWorksheetsCount(); + while (wc--) { + items.push(this.api.asc_getWorksheetName(wc).toLowerCase()); + } + + var index = 0, name; + while(++index < 1000) { + name = this.strSheet + index; + if (items.indexOf(name.toLowerCase()) < 0) break; + } + + return name; + }, + onShowClick: function() { this.api.asc_changeGroupDetails(true); }, @@ -575,7 +611,8 @@ define([ textEmptyUrl: 'You need to specify URL.', txtImportWizard: 'Text Import Wizard', txtUrlTitle: 'Paste a data URL', - txtErrorExternalLink: 'Error: updating is failed' + txtErrorExternalLink: 'Error: updating is failed', + strSheet: 'Sheet' }, SSE.Controllers.DataTab || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/view/DataTab.js b/apps/spreadsheeteditor/main/app/view/DataTab.js index 1b88616f6..4bec61b70 100644 --- a/apps/spreadsheeteditor/main/app/view/DataTab.js +++ b/apps/spreadsheeteditor/main/app/view/DataTab.js @@ -133,7 +133,8 @@ define([ cls: 'btn-toolbar x-huge icon-top', iconCls: 'toolbar__icon btn-import-data', caption: this.capDataFromText, - menu: !this.toolbar.mode.isDesktopApp, + // menu: !this.toolbar.mode.isDesktopApp, + menu: true, disabled: true, lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.sheetLock, _set.wbLock, _set.lostConnect, _set.coAuth, _set.wsLock], dataHint: '1', @@ -311,10 +312,12 @@ define([ me.btnDataFromText.menu && me.btnDataFromText.setMenu(new Common.UI.Menu({ items: [ { caption: me.mniFromFile, value: 'file' }, - { caption: me.mniFromUrl, value: 'url' } + { caption: me.mniFromUrl, value: 'url' }, + { caption: me.mniFromXMLFile, value: 'xml' } // { caption: me.mniImageFromStorage, value: 'storage'} ] })); + me.toolbar.mode.isDesktopApp && me.btnDataFromText.menu.items[1].setVisible(false); me.btnTextToColumns.updateHint(me.tipToColumns); me.btnRemoveDuplicates.updateHint(me.tipRemDuplicates); @@ -394,11 +397,12 @@ define([ capBtnTextDataValidation: 'Data Validation', tipDataValidation: 'Data validation', capDataFromText: 'From Text/CSV', - tipDataFromText: 'Get data from Text/CSV file', + tipDataFromText: 'Get data from file', mniFromFile: 'Get Data from File', mniFromUrl: 'Get Data from URL', capDataExternalLinks: 'External Links', - tipExternalLinks: 'View other files this spreadsheet is linked to' + tipExternalLinks: 'View other files this spreadsheet is linked to', + mniFromXMLFile: 'From Local XML' } }()), SSE.Views.DataTab || {})); }); diff --git a/apps/spreadsheeteditor/main/app/view/ImportFromXmlDialog.js b/apps/spreadsheeteditor/main/app/view/ImportFromXmlDialog.js new file mode 100644 index 000000000..ac3edc6f5 --- /dev/null +++ b/apps/spreadsheeteditor/main/app/view/ImportFromXmlDialog.js @@ -0,0 +1,240 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2019 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +/** + * CreatePivotDialog.js + * + * Created by Julia Radzhabova on 08.12.2022 + * Copyright (c) 2019 Ascensio System SIA. All rights reserved. + * + */ +define([ + 'common/main/lib/util/utils', + 'common/main/lib/component/InputField', + 'common/main/lib/component/RadioBox', + 'common/main/lib/view/AdvancedSettingsWindow' +], function () { 'use strict'; + + SSE.Views.ImportFromXmlDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({ + options: { + contentWidth: 310, + height: 200 + }, + + initialize : function(options) { + var me = this; + + _.extend(this.options, { + title: this.textTitle, + template: [ + '
', + '
', + '
', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '
', + '', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
' + ].join('') + }, options); + + this.api = options.api; + + this.options.handler = function(result, value) { + if ( result != 'ok' || this.isRangeValid() ) { + if (options.handler) + options.handler.call(this, result, value); + return; + } + return true; + }; + + this.dataDestValid = ''; + + Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); + }, + + render: function() { + Common.Views.AdvancedSettingsWindow.prototype.render.call(this); + var me = this; + + this.txtDestRange = new Common.UI.InputFieldBtn({ + el : $('#import-xml-input-dest'), + name : 'range', + style : 'width: 100%;', + btnHint : this.textSelectData, + allowBlank : true, + validateOnChange: true, + validateOnBlur: false + }); + this.txtDestRange.on('button:click', _.bind(this.onSelectData, this, 'dest')); + + this.radioNew = new Common.UI.RadioBox({ + el: $('#import-xml-radio-new'), + labelText: this.textNew, + name: 'asc-radio-xml-dest' + }).on('change', function(field, newValue) { + me.txtDestRange.setDisabled(newValue); + me.txtDestRange.showError(); + }); + + this.radioExist = new Common.UI.RadioBox({ + el: $('#import-xml-radio-exist'), + labelText: this.textExist, + name: 'asc-radio-xml-dest', + checked: true + }).on('change', function(field, newValue) { + me.txtDestRange.setDisabled(!newValue); + me.txtDestRange.cmpEl.find('input').focus(); + }); + + this.afterRender(); + }, + + getFocusedComponents: function() { + return [this.radioNew, this.radioExist, this.txtDestRange]; + }, + + getDefaultFocusableComponent: function () { + if (this._alreadyRendered) return; // focus only at first show + this._alreadyRendered = true; + return this.txtDestRange; + }, + + afterRender: function() { + this._setDefaults(); + }, + + _setDefaults: function () { + var me = this; + this.txtDestRange.validation = function(value) { + var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.ImportXml, value, false); + return (isvalid==Asc.c_oAscError.ID.DataRangeError) ? me.textInvalidRange : true; + }; + var range = this.api.asc_getActiveRangeStr(Asc.referenceType.A); + this.txtDestRange.setValue(range); + this.dataDestValid = range; + }, + + getSettings: function () { + var dest = this.radioExist.getValue() ? this.txtDestRange.getValue() : null; + + return {destination: dest}; + }, + + isRangeValid: function() { + var isvalid = true, + txtError = ''; + + if (this.radioExist.getValue()) { + if (_.isEmpty(this.txtDestRange.getValue())) { + isvalid = false; + txtError = this.txtEmpty; + } else { + isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.ImportXml, this.txtDestRange.getValue()); + isvalid = (isvalid == Asc.c_oAscError.ID.No); + !isvalid && (txtError = this.textInvalidRange); + } + if (!isvalid) { + this.txtDestRange.showError([txtError]); + this.txtDestRange.cmpEl.find('input').focus(); + return isvalid; + } + } + + return isvalid; + }, + + onSelectData: function(type) { + var me = this, + txtRange = me.txtDestRange; + + if (me.api) { + var handlerDlg = function(dlg, result) { + if (result == 'ok') { + var txt = dlg.getSettings(); + me.dataDestValid = txt; + txtRange.setValue(txt); + txtRange.checkValidate(); + } + }; + + var win = new SSE.Views.CellRangeDialog({ + handler: handlerDlg + }).on('close', function() { + me.show(); + _.delay(function(){ + txtRange.focus(); + },1); + }); + + var xy = me.$window.offset(); + me.hide(); + win.show(xy.left + 160, xy.top + 125); + win.setSettings({ + api : me.api, + range : (!_.isEmpty(txtRange.getValue()) && (txtRange.checkValidate()==true)) ? txtRange.getValue() : me.dataDestValid, + type : Asc.c_oAscSelectionDialogType.ImportXml + }); + } + }, + + textTitle: 'Import Data', + textSelectData: 'Select data', + textDestination: 'Choose, where to place the data', + textNew: 'New worksheet', + textExist: 'Existing worksheet', + txtEmpty: 'This field is required', + textInvalidRange: 'Invalid cells range' + }, SSE.Views.ImportFromXmlDialog || {})) +}); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index 43f107581..a360f8958 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -668,6 +668,7 @@ "SSE.Controllers.DataTab.txtRemoveDataValidation": "The selection contains more than one type of validation.
Erase current settings and continue?", "SSE.Controllers.DataTab.txtRemSelected": "Remove in selected", "SSE.Controllers.DataTab.txtUrlTitle": "Paste a data URL", + "SSE.Controllers.DataTab.strSheet": "Sheet", "SSE.Controllers.DocumentHolder.alignmentText": "Alignment", "SSE.Controllers.DocumentHolder.centerText": "Center", "SSE.Controllers.DocumentHolder.deleteColumnText": "Delete Column", @@ -2036,13 +2037,14 @@ "SSE.Views.DataTab.textRightOf": "Summary Columns To Right Of Detail", "SSE.Views.DataTab.textRows": "Ungroup Rows", "SSE.Views.DataTab.tipCustomSort": "Custom sort", - "SSE.Views.DataTab.tipDataFromText": "Get data from Text/CSV file", + "SSE.Views.DataTab.tipDataFromText": "Get data from file", "SSE.Views.DataTab.tipDataValidation": "Data validation", "SSE.Views.DataTab.tipExternalLinks": "View other files this spreadsheet is linked to", "SSE.Views.DataTab.tipGroup": "Group range of cells", "SSE.Views.DataTab.tipRemDuplicates": "Remove duplicate rows from a sheet", "SSE.Views.DataTab.tipToColumns": "Separate cell text into columns", "SSE.Views.DataTab.tipUngroup": "Ungroup range of cells", + "SSE.Views.DataTab.mniFromXMLFile": "From Local XML", "SSE.Views.DataValidationDialog.errorFormula": "The value currently evaluates to an error. Do you want to continue?", "SSE.Views.DataValidationDialog.errorInvalid": "The value you entered for the field \"{0}\" is invalid.", "SSE.Views.DataValidationDialog.errorInvalidDate": "The date you entered for the field \"{0}\" is invalid.", @@ -2766,6 +2768,13 @@ "SSE.Views.ImageSettingsAdvanced.textTitle": "Image - Advanced settings", "SSE.Views.ImageSettingsAdvanced.textTwoCell": "Move and size with cells", "SSE.Views.ImageSettingsAdvanced.textVertically": "Vertically", + "SSE.Views.ImportFromXmlDialog.textTitle": "Import Data", + "SSE.Views.ImportFromXmlDialog.textSelectData": "Select data", + "SSE.Views.ImportFromXmlDialog.textDestination": "Choose, where to place the data", + "SSE.Views.ImportFromXmlDialog.textNew": "New worksheet", + "SSE.Views.ImportFromXmlDialog.textExist": "Existing worksheet", + "SSE.Views.ImportFromXmlDialog.txtEmpty": "This field is required", + "SSE.Views.ImportFromXmlDialog.textInvalidRange": "Invalid cells range", "SSE.Views.LeftMenu.tipAbout": "About", "SSE.Views.LeftMenu.tipChat": "Chat", "SSE.Views.LeftMenu.tipComments": "Comments",