diff --git a/apps/common/main/lib/util/utils.js b/apps/common/main/lib/util/utils.js index a56b883b4..f6e983059 100644 --- a/apps/common/main/lib/util/utils.js +++ b/apps/common/main/lib/util/utils.js @@ -114,7 +114,8 @@ Common.Utils = _.extend(new(function() { CSV: 1, TXT: 2, Paste: 3, - Columns: 4 + Columns: 4, + Data: 5 }, isMobile = /android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent || navigator.vendor || window.opera), me = this, diff --git a/apps/common/main/lib/view/OpenDialog.js b/apps/common/main/lib/view/OpenDialog.js index 8b5dca3b5..796ab4cfb 100644 --- a/apps/common/main/lib/view/OpenDialog.js +++ b/apps/common/main/lib/view/OpenDialog.js @@ -57,10 +57,22 @@ define([ if (options.preview) { width = 414; - height = 277; + height = (options.type==Common.Utils.importTextType.Data) ? 385 : 277; } else { width = (options.type !== Common.Utils.importTextType.DRM) ? 340 : (options.warning ? 420 : 280); - height = (options.type == Common.Utils.importTextType.CSV || options.type == Common.Utils.importTextType.Paste || options.type == Common.Utils.importTextType.Columns) ? 190 : (options.warning ? 187 : 147); + switch (options.type) { + case Common.Utils.importTextType.CSV: + case Common.Utils.importTextType.Paste: + case Common.Utils.importTextType.Columns: + height = 190; + break; + case Common.Utils.importTextType.Data: + height = 245; + break; + default: + height = options.warning ? 187 : 147; + break; + } } _.extend(_options, { @@ -114,13 +126,13 @@ define([ '', '', '<% } %>', - '<% if (type == Common.Utils.importTextType.Paste || type == Common.Utils.importTextType.Columns) { %>', + '<% if (type == Common.Utils.importTextType.Paste || type == Common.Utils.importTextType.Columns || type == Common.Utils.importTextType.Data) { %>', '
', '', '
', '
', '
', - '', + '', '
', '
', '<% } %>', @@ -138,6 +150,10 @@ define([ '', '', '<% } %>', + '<% if (type == Common.Utils.importTextType.Data) { %>', + '', + '
', + '<% } %>', '<% } %>', '', '', @@ -204,6 +220,19 @@ define([ (this.previewData) ? this.previewCallback(this.previewData) : this.updatePreview(); } } + if (this.type == Common.Utils.importTextType.Data) { + this.txtDestRange = new Common.UI.InputFieldBtn({ + el : $('#id-open-data-range'), + name : 'range', + style : 'width: 100%;', + btnHint : this.textSelectData, + allowBlank : true, + validateOnChange: true, + validateOnBlur: false + }); + this.txtDestRange.on('button:click', _.bind(this.onSelectData, this)); + } + this.onPrimary = function() { me._handleInput('ok'); return false; @@ -235,8 +264,12 @@ define([ _handleInput: function(state) { if (this.handler) { if (this.type == Common.Utils.importTextType.DRM) { - this.handler.call(this, state, this.inputPwd.getValue()); + this.handler.call(this, state, {drmOptions: new Asc.asc_CDRMAdvancedOptions(this.inputPwd.getValue())}); } else { + if ( this.type == Common.Utils.importTextType.Data && state == 'ok' && !this.isRangeValid() ) { + return; + } + var encoding = (this.cmbEncoding && !this.cmbEncoding.isDisabled()) ? this.cmbEncoding.getValue() : ((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : 0), delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null, @@ -248,7 +281,14 @@ define([ var decimal = this.separatorOptions ? this.separatorOptions.decimal : undefined, thousands = this.separatorOptions ? this.separatorOptions.thousands : undefined; - this.handler.call(this, state, encoding, delimiter, delimiterChar, decimal, thousands); + var options = new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar); + decimal && options.asc_setNumberDecimalSeparator(decimal); + thousands && options.asc_setNumberGroupSeparator(thousands); + this.handler.call(this, state, { + textOptions: options, + range: this.txtDestRange ? this.txtDestRange.getValue() : '', + data: this.data + }); } } @@ -321,7 +361,7 @@ define([ ul.find('li div').width(width); } - if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) { + if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns || this.type == Common.Utils.importTextType.Data) { this.cmbDelimiter = new Common.UI.ComboBox({ el: $('#id-delimiters-combo', this.$window), style: 'width: 100px;', @@ -351,7 +391,7 @@ define([ if (this.preview) this.inputDelimiter.on ('changing', _.bind(this.updatePreview, this)); - if (this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) { + if (this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns || this.type == Common.Utils.importTextType.Data) { this.btnAdvanced = new Common.UI.Button({ el: $('#id-delimiters-advanced') }); @@ -383,6 +423,14 @@ define([ } this.api.asc_TextImport(options, _.bind(this.previewCallback, this), this.type == Common.Utils.importTextType.Paste); break; + case Common.Utils.importTextType.Data: + var options = new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar); + if (this.separatorOptions) { + options.asc_setNumberDecimalSeparator(this.separatorOptions.decimal); + options.asc_setNumberGroupSeparator(this.separatorOptions.thousands); + } + this.api.asc_decodeBuffer(this.preview, options, _.bind(this.previewCallback, this)); + break; } }, @@ -424,7 +472,7 @@ define([ delete this.scrollerX; } - if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) { + if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns || this.type == Common.Utils.importTextType.Data) { var maxlength = 0; for (var i=0; imaxlength) @@ -492,6 +540,60 @@ define([ })).show(); }, + 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.Chart + }); + } + }, + + isRangeValid: function() { + var isvalid = true, + txtError = ''; + if (_.isEmpty(this.txtDestRange.getValue())) { + isvalid = false; + txtError = this.txtEmpty; + } else { + isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Chart, this.txtDestRange.getValue()); + isvalid = (isvalid == Asc.c_oAscError.ID.No); + !isvalid && (txtError = this.textInvalidRange); + } + if (!isvalid) { + this.txtDestRange.showError([txtError]); + this.txtDestRange.focus(); + return isvalid; + } + + return isvalid; + }, + txtDelimiter : "Delimiter", txtEncoding : "Encoding ", txtSpace : "Space", @@ -508,7 +610,11 @@ define([ txtSemicolon: 'Semicolon', txtProtected: 'Once you enter the password and open the file, the current password to the file will be reset.', txtAdvanced: 'Advanced', - txtOpenFile: "Enter a password to open the file" + txtOpenFile: "Enter a password to open the file", + textSelectData: 'Select data', + txtDestData: 'Choose where to put the data', + txtEmpty: 'This field is required', + textInvalidRange: 'Invalid cells range' }, Common.Views.OpenDialog || {})); }); \ No newline at end of file diff --git a/apps/common/main/resources/less/opendialog.less b/apps/common/main/resources/less/opendialog.less index 97cc5ec0b..a58a97b26 100644 --- a/apps/common/main/resources/less/opendialog.less +++ b/apps/common/main/resources/less/opendialog.less @@ -77,7 +77,7 @@ } } - .icon { + .icon.img-commonctrl { float: left; width: 35px; height: 35px; diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index f90cd8460..ebc79a5e0 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -2179,15 +2179,15 @@ define([ codepages: advOptions.asc_getCodePages(), settings: advOptions.asc_getRecommendedSettings(), api: me.api, - handler: function (result, encoding) { + handler: function (result, settings) { me.isShowOpenDialog = false; if (result == 'ok') { if (me && me.api) { if (mode==2) { - formatOptions && formatOptions.asc_setAdvancedOptions(new Asc.asc_CTextOptions(encoding)); + formatOptions && formatOptions.asc_setAdvancedOptions(settings.textOptions); me.api.asc_DownloadAs(formatOptions); } else - me.api.asc_setAdvancedOptions(type, new Asc.asc_CTextOptions(encoding)); + me.api.asc_setAdvancedOptions(type, settings.textOptions); me.loadMask && me.loadMask.show(); } } @@ -2206,7 +2206,7 @@ define([ me.isShowOpenDialog = false; if (result == 'ok') { if (me.api) { - me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value)); + me.api.asc_setAdvancedOptions(type, value.drmOptions); me.loadMask && me.loadMask.show(); } } else { diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index f3468f5cd..4c447e55a 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -2020,7 +2020,7 @@ define([ me.isShowOpenDialog = false; if (result == 'ok') { if (me.api) { - me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value)); + me.api.asc_setAdvancedOptions(type, value.drmOptions); me.loadMask && me.loadMask.show(); } } else { diff --git a/apps/spreadsheeteditor/main/app/controller/DataTab.js b/apps/spreadsheeteditor/main/app/controller/DataTab.js index ff9de160d..486cffcb8 100644 --- a/apps/spreadsheeteditor/main/app/controller/DataTab.js +++ b/apps/spreadsheeteditor/main/app/controller/DataTab.js @@ -92,7 +92,8 @@ define([ 'data:groupsettings': this.onGroupSettings, 'data:sortcustom': this.onCustomSort, 'data:remduplicates': this.onRemoveDuplicates, - 'data:datavalidation': this.onDataValidation + 'data:datavalidation': this.onDataValidation, + 'data:fromtext': this.onDataFromText }, 'Statusbar': { 'sheet:changed': this.onApiSheetChanged @@ -208,15 +209,59 @@ define([ previewData: data, settings: me._state.CSVOptions, api: me.api, - handler: function (result, encoding, delimiter, delimiterChar, decimal, thousands) { - if (result == 'ok') { - if (me && me.api) { - var options = new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar); - decimal && options.asc_setNumberDecimalSeparator(decimal); - thousands && options.asc_setNumberGroupSeparator(thousands); - me.api.asc_TextToColumns(options); + handler: function (result, settings) { + if (result == 'ok' && me.api) { + me.api.asc_TextToColumns(settings.textOptions); + } + } + })).show(); + }, + + onDataFromText: function(type) { + var me = this; + if (type === 'file') { + if (this.api) + this.api.asc_TextFromFileOrUrl(this._state.CSVOptions, _.bind(this.onDataFromTextCallback, this)); + + Common.NotificationCenter.trigger('edit:complete', this.toolbar); + } else if (type === 'url') { + (new Common.Views.ImageFromUrlDialog({ + handler: function(result, value) { + if (result == 'ok') { + if (me.api) { + var checkUrl = value.replace(/\s/g, ''); + if (!_.isEmpty(checkUrl)) { + me.api.asc_TextFromFileOrUrl(me._state.CSVOptions, _.bind(me.onDataFromTextCallback, me), checkUrl); + } else { + Common.UI.warning({ + msg: me.textEmptyUrl + }); + } + } + + Common.NotificationCenter.trigger('edit:complete', me.toolbar); } } + })).show(); + } else if (type === 'storage') { + // Common.NotificationCenter.trigger('storage:data-load', 'add'); + } + }, + + onDataFromTextCallback: function(advOptions) { + var me = this; + (new Common.Views.OpenDialog({ + title: me.txtImportWizard, + closable: true, + type: Common.Utils.importTextType.Data, + preview: advOptions.asc_getData(), + settings: advOptions ? advOptions.asc_getRecommendedSettings() : me._state.CSVOptions, + codepages: advOptions ? advOptions.asc_getCodePages() : null, + api: me.api, + handler: function (result, settings) { + if (result == 'ok' && me.api) { + me.api.asc_TextToColumns(settings.textOptions, settings.data, settings.range); + } } })).show(); }, @@ -379,7 +424,9 @@ define([ textColumns: 'Columns', txtDataValidation: 'Data Validation', txtExtendDataValidation: 'The selection contains some cells without Data Validation settings.
Do you want to extend Data Validation to these cells?', - txtRemoveDataValidation: 'The selection contains more than one type of validation.
Erase current settings and continue?' + txtRemoveDataValidation: 'The selection contains more than one type of validation.
Erase current settings and continue?', + textEmptyUrl: 'You need to specify URL.', + txtImportWizard: 'Text Import Wizard' }, SSE.Controllers.DataTab || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index 838ecb42a..c3bbf9e64 100644 --- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js @@ -2592,16 +2592,12 @@ define([ type: Common.Utils.importTextType.Paste, preview: true, api: me.api, - handler: function (result, encoding, delimiter, delimiterChar, decimal, thousands) { + handler: function (result, settings) { if (result == 'ok') { if (me && me.api) { var props = new Asc.SpecialPasteProps(); props.asc_setProps(Asc.c_oSpecialPasteProps.useTextImport); - - var options = new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar); - decimal && options.asc_setNumberDecimalSeparator(decimal); - thousands && options.asc_setNumberGroupSeparator(thousands); - props.asc_setAdvancedOptions(options); + props.asc_setAdvancedOptions(settings.textOptions); me.api.asc_SpecialPaste(props); } me._state.lastSpecPasteChecked = item; diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index b18d393e2..f43f78654 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -1917,15 +1917,15 @@ define([ codepages: advOptions.asc_getCodePages(), settings: advOptions.asc_getRecommendedSettings(), api: me.api, - handler: function (result, encoding, delimiter, delimiterChar) { + handler: function (result, settings) { me.isShowOpenDialog = false; if (result == 'ok') { if (me && me.api) { if (mode==2) { - formatOptions && formatOptions.asc_setAdvancedOptions(new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar)); + formatOptions && formatOptions.asc_setAdvancedOptions(settings.textOptions); me.api.asc_DownloadAs(formatOptions); } else - me.api.asc_setAdvancedOptions(type, new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar)); + me.api.asc_setAdvancedOptions(type, settings.textOptions); me.loadMask && me.loadMask.show(); } } @@ -1944,7 +1944,7 @@ define([ me.isShowOpenDialog = false; if (result == 'ok') { if (me && me.api) { - me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value)); + me.api.asc_setAdvancedOptions(type, value.drmOptions); me.loadMask && me.loadMask.show(); } } else { diff --git a/apps/spreadsheeteditor/main/app/template/Toolbar.template b/apps/spreadsheeteditor/main/app/template/Toolbar.template index 55a1bf9a0..624f73351 100644 --- a/apps/spreadsheeteditor/main/app/template/Toolbar.template +++ b/apps/spreadsheeteditor/main/app/template/Toolbar.template @@ -199,6 +199,10 @@
+
+ +
+
diff --git a/apps/spreadsheeteditor/main/app/view/DataTab.js b/apps/spreadsheeteditor/main/app/view/DataTab.js index 0e2f1599a..4ed17b13e 100644 --- a/apps/spreadsheeteditor/main/app/view/DataTab.js +++ b/apps/spreadsheeteditor/main/app/view/DataTab.js @@ -102,6 +102,12 @@ define([ me.btnCustomSort.on('click', function (b, e) { me.fireEvent('data:sortcustom'); }); + me.btnDataFromText.menu ? + me.btnDataFromText.menu.on('item:click', function (menu, item, e) { + me.fireEvent('data:fromtext', [item.value]); + }) : me.btnDataFromText.on('click', function (b, e) { + me.fireEvent('data:fromtext', ['file']); + }); } return { @@ -117,6 +123,17 @@ define([ $host = me.toolbar.$el, _set = SSE.enumLock; + this.btnDataFromText = new Common.UI.Button({ + parentEl: $host.find('#slot-btn-data-from-text'), + cls: 'btn-toolbar x-huge icon-top', + iconCls: 'toolbar__icon btn-import-data', + caption: this.capDataFromText, + menu: !this.toolbar.mode.isDesktopApp, + disabled: true, + lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.sheetLock, _set.lostConnect, _set.coAuth] + }); + this.lockedControls.push(this.btnDataFromText); + this.btnGroup = new Common.UI.Button({ parentEl: $host.find('#slot-btn-group'), cls: 'btn-toolbar x-huge icon-top', @@ -251,6 +268,15 @@ define([ }); me.btnGroup.setMenu(_menu); + me.btnDataFromText.updateHint(me.tipDataFromText); + me.btnDataFromText.menu && me.btnDataFromText.setMenu(new Common.UI.Menu({ + items: [ + { caption: me.mniFromFile, value: 'file' }, + { caption: me.mniFromUrl, value: 'url' } + // { caption: me.mniImageFromStorage, value: 'storage'} + ] + })); + me.btnTextToColumns.updateHint(me.tipToColumns); me.btnRemoveDuplicates.updateHint(me.tipRemDuplicates); me.btnDataValidation.updateHint(me.tipDataValidation); @@ -326,7 +352,11 @@ define([ capBtnTextRemDuplicates: 'Remove Duplicates', tipRemDuplicates: 'Remove duplicate rows from a sheet', capBtnTextDataValidation: 'Data Validation', - tipDataValidation: 'Data validation' + tipDataValidation: 'Data validation', + capDataFromText: 'From Text/CSV', + tipDataFromText: 'Get data from Text/CSV file', + mniFromFile: 'Get Data from File', + mniFromUrl: 'Get Data from URL' } }()), SSE.Views.DataTab || {})); }); diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index 9e5df070f..5725cd740 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -249,6 +249,10 @@ "Common.Views.OpenDialog.txtTab": "Tab", "Common.Views.OpenDialog.txtTitle": "Choose %1 options", "Common.Views.OpenDialog.txtTitleProtected": "Protected File", + "Common.Views.OpenDialog.textSelectData": "Select data", + "Common.Views.OpenDialog.txtDestData": "Choose where to put the data", + "Common.Views.OpenDialog.txtEmpty": "This field is required", + "Common.Views.OpenDialog.textInvalidRange": "Invalid cells range", "Common.Views.PasswordDialog.txtDescription": "Set a password to protect this document", "Common.Views.PasswordDialog.txtIncorrectPwd": "Confirmation password is not identical", "Common.Views.PasswordDialog.txtPassword": "Password", @@ -398,6 +402,8 @@ "SSE.Controllers.DataTab.txtRemDuplicates": "Remove Duplicates", "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.textEmptyUrl": "You need to specify URL.", + "SSE.Controllers.DataTab.txtImportWizard": "Text Import Wizard", "SSE.Controllers.DocumentHolder.alignmentText": "Alignment", "SSE.Controllers.DocumentHolder.centerText": "Center", "SSE.Controllers.DocumentHolder.deleteColumnText": "Delete Column", @@ -1673,6 +1679,10 @@ "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.capDataFromText": "From Text/CSV", + "SSE.Views.DataTab.tipDataFromText": "Get data from Text/CSV file", + "SSE.Views.DataTab.mniFromFile": "Get Data from File", + "SSE.Views.DataTab.mniFromUrl": "Get Data from URL", "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.",