diff --git a/apps/common/main/resources/less/combo-dataview.less b/apps/common/main/resources/less/combo-dataview.less index fbbf830de5..30ebd1c33e 100644 --- a/apps/common/main/resources/less/combo-dataview.less +++ b/apps/common/main/resources/less/combo-dataview.less @@ -410,6 +410,38 @@ } +.combo-table-template { + .combo-template(56px); + + top: -4px; + position: absolute; + .padding-right-12(); + + .more-container & { + position: static; + } + + .view .dataview, .dropdown-menu { + padding: 1px; + } + + .dropdown-menu { + padding: 5px 1px 5px 1px; + + .dataview { + .group-description { + padding: 3px 0 3px 10px; + .font-weight-bold(); + + .rtl & { + padding: 3px 10px 3px 0; + } + } + } + } + +} + .combo-slicer-style { .combo-textart(60px, 4px); } diff --git a/apps/spreadsheeteditor/main/app.js b/apps/spreadsheeteditor/main/app.js index 3a3a58e043..7e344f954e 100644 --- a/apps/spreadsheeteditor/main/app.js +++ b/apps/spreadsheeteditor/main/app.js @@ -145,6 +145,7 @@ require([ 'PivotTable', 'DataTab', 'ViewTab', + 'TableDesignTab', 'Search', 'WBProtection', 'Common.Controllers.Fonts', @@ -182,6 +183,7 @@ require([ 'spreadsheeteditor/main/app/controller/PivotTable', 'spreadsheeteditor/main/app/controller/DataTab', 'spreadsheeteditor/main/app/controller/ViewTab', + 'spreadsheeteditor/main/app/controller/TableDesignTab', 'spreadsheeteditor/main/app/controller/Search', 'spreadsheeteditor/main/app/controller/WBProtection', // 'spreadsheeteditor/main/app/view/ParagraphSettings', diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 36047ae615..f85ef94c31 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -471,6 +471,7 @@ define([ this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false)); this.appOptions.canMakeActionLink = this.editorConfig.canMakeActionLink; this.appOptions.canFeaturePivot = true; + this.appOptions.canFeatureTable = true; this.appOptions.canFeatureViews = true; this.appOptions.canRequestReferenceData = this.editorConfig.canRequestReferenceData; this.appOptions.canRequestOpen = this.editorConfig.canRequestOpen; @@ -1052,7 +1053,6 @@ define([ chatController = application.getController('Common.Controllers.Chat'), pluginsController = application.getController('Common.Controllers.Plugins'), spellcheckController = application.getController('Spellcheck'); - leftMenuView.getMenu('file').loadDocument({doc:me.appOptions.spreadsheet}); leftmenuController.setMode(me.appOptions).createDelayedElements().setApi(me.api); @@ -1719,6 +1719,9 @@ define([ if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram && !me.appOptions.isEditOle && me.appOptions.canFeaturePivot) application.getController('PivotTable').setMode(me.appOptions); + if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram && !me.appOptions.isEditOle && me.appOptions.canFeatureTable) + application.getController('TableDesignTab').setMode(me.appOptions); + var viewport = this.getApplication().getController('Viewport').getView('Viewport'); viewport.applyEditorMode(); rightmenuController.getView('RightMenu').setMode(me.appOptions).setApi(me.api); diff --git a/apps/spreadsheeteditor/main/app/controller/PivotTable.js b/apps/spreadsheeteditor/main/app/controller/PivotTable.js index 92e7dcd6f2..725a293a49 100644 --- a/apps/spreadsheeteditor/main/app/controller/PivotTable.js +++ b/apps/spreadsheeteditor/main/app/controller/PivotTable.js @@ -71,6 +71,9 @@ define([ 'TableSettings': { 'pivottable:create': _.bind(this.onCreateClick, this) }, + 'TableDesignTab': { + 'pivottable:create': _.bind(this.onCreateClick, this) + }, 'Toolbar': { 'tab:active': _.bind(this.onActiveTab, this) } diff --git a/apps/spreadsheeteditor/main/app/controller/RightMenu.js b/apps/spreadsheeteditor/main/app/controller/RightMenu.js index 07e8ce71a6..fa21d3d34c 100644 --- a/apps/spreadsheeteditor/main/app/controller/RightMenu.js +++ b/apps/spreadsheeteditor/main/app/controller/RightMenu.js @@ -60,7 +60,7 @@ define([ 'insertshape': this.onInsertShape.bind(this), 'insertchart': this.onInsertChart.bind(this), 'inserttextart': this.onInsertTextArt.bind(this), - 'inserttable': this.onInsertTable.bind(this) + // 'inserttable': this.onInsertTable.bind(this) }, 'RightMenu': { 'rightmenuclick': this.onRightMenuClick, @@ -100,7 +100,7 @@ define([ this._settings[Common.Utils.documentSettingsType.Shape] = {panelId: "id-shape-settings", panel: rightMenu.shapeSettings, btn: rightMenu.btnShape, hidden: 1, locked: false}; this._settings[Common.Utils.documentSettingsType.TextArt] = {panelId: "id-textart-settings", panel: rightMenu.textartSettings, btn: rightMenu.btnTextArt, hidden: 1, locked: false}; this._settings[Common.Utils.documentSettingsType.Chart] = {panelId: "id-chart-settings", panel: rightMenu.chartSettings, btn: rightMenu.btnChart, hidden: 1, locked: false}; - this._settings[Common.Utils.documentSettingsType.Table] = {panelId: "id-table-settings", panel: rightMenu.tableSettings, btn: rightMenu.btnTable, hidden: 1, locked: false}; + // this._settings[Common.Utils.documentSettingsType.Table] = {panelId: "id-table-settings", panel: rightMenu.tableSettings, btn: rightMenu.btnTable, hidden: 1, locked: false}; this._settings[Common.Utils.documentSettingsType.Pivot] = {panelId: "id-pivot-settings", panel: rightMenu.pivotSettings, btn: rightMenu.btnPivot, hidden: 1, locked: false}; this._settings[Common.Utils.documentSettingsType.Signature] = {panelId: "id-signature-settings", panel: rightMenu.signatureSettings, btn: rightMenu.btnSignature, hidden: 1, props: {}, locked: false}; this._settings[Common.Utils.documentSettingsType.Cell] = {panelId: "id-cell-settings", panel: rightMenu.cellSettings, btn: rightMenu.btnCell, hidden: 1, locked: false}; @@ -132,12 +132,12 @@ define([ Common.Utils.InternalSettings.set("sse-rightpanel-active-pivot", 1); else if (type == Common.Utils.documentSettingsType.Chart && !this._settings[Common.Utils.documentSettingsType.Cell].hidden) {//sparkline Common.Utils.InternalSettings.set("sse-rightpanel-active-spark", 2); - if (!this._settings[Common.Utils.documentSettingsType.Table].hidden) { - Common.Utils.InternalSettings.set("sse-rightpanel-active-table", Math.min(Common.Utils.InternalSettings.get("sse-rightpanel-active-table"), 1)); - } + // if (!this._settings[Common.Utils.documentSettingsType.Table].hidden) { + // Common.Utils.InternalSettings.set("sse-rightpanel-active-table", Math.min(Common.Utils.InternalSettings.get("sse-rightpanel-active-table"), 1)); + // } } else if (Common.Utils.documentSettingsType.Cell) { - if (!this._settings[Common.Utils.documentSettingsType.Table].hidden) - Common.Utils.InternalSettings.set("sse-rightpanel-active-table", 0); + // if (!this._settings[Common.Utils.documentSettingsType.Table].hidden) + // Common.Utils.InternalSettings.set("sse-rightpanel-active-table", 0); if (!this._settings[Common.Utils.documentSettingsType.Pivot].hidden) Common.Utils.InternalSettings.set("sse-rightpanel-active-pivot", 0); if (!this._settings[Common.Utils.documentSettingsType.Chart].hidden) @@ -237,12 +237,12 @@ define([ this._settings[Common.Utils.documentSettingsType.Paragraph].locked = this._state.wsProps['Objects'] && locktext; } - if (formatTableInfo) { - settingsType = Common.Utils.documentSettingsType.Table; - this._settings[settingsType].props = formatTableInfo; - this._settings[settingsType].locked = isTableLocked; - this._settings[settingsType].hidden = 0; - } + // if (formatTableInfo) { + // settingsType = Common.Utils.documentSettingsType.Table; + // // this._settings[settingsType].props = formatTableInfo; + // this._settings[settingsType].locked = isTableLocked; + // this._settings[settingsType].hidden = 0; + // } if (sparkLineInfo) { settingsType = Common.Utils.documentSettingsType.Chart; @@ -313,19 +313,21 @@ define([ } if (priorityactive<0 && !this._settings[Common.Utils.documentSettingsType.Cell].hidden && - (!this._settings[Common.Utils.documentSettingsType.Table].hidden || !this._settings[Common.Utils.documentSettingsType.Pivot].hidden || + (!this._settings[Common.Utils.documentSettingsType.Pivot].hidden || !this._settings[Common.Utils.documentSettingsType.Chart].hidden)) { var tableactive = Common.Utils.InternalSettings.get("sse-rightpanel-active-table"), pivotactive = Common.Utils.InternalSettings.get("sse-rightpanel-active-pivot"), sparkactive = Common.Utils.InternalSettings.get("sse-rightpanel-active-spark"); - if (!this._settings[Common.Utils.documentSettingsType.Table].hidden && !this._settings[Common.Utils.documentSettingsType.Chart].hidden) { - if (tableactive == sparkactive) - priorityactive = (tableactive===0) ? Common.Utils.documentSettingsType.Cell : Common.Utils.documentSettingsType.Chart; - else - priorityactive = (tableactive > sparkactive) ? Common.Utils.documentSettingsType.Table : Common.Utils.documentSettingsType.Chart; - } else if (!this._settings[Common.Utils.documentSettingsType.Table].hidden) { - priorityactive = (tableactive===0) ? Common.Utils.documentSettingsType.Cell : Common.Utils.documentSettingsType.Table; - } else if (!this._settings[Common.Utils.documentSettingsType.Chart].hidden) { + // if (!this._settings[Common.Utils.documentSettingsType.Table].hidden && !this._settings[Common.Utils.documentSettingsType.Chart].hidden) { + // if (tableactive == sparkactive) + // priorityactive = (tableactive===0) ? Common.Utils.documentSettingsType.Cell : Common.Utils.documentSettingsType.Chart; + // else + // priorityactive = (tableactive > sparkactive) ? Common.Utils.documentSettingsType.Table : Common.Utils.documentSettingsType.Chart; + // } + // else if (!this._settings[Common.Utils.documentSettingsType.Table].hidden) { + // priorityactive = (tableactive===0) ? Common.Utils.documentSettingsType.Cell : Common.Utils.documentSettingsType.Table; + // } + if (!this._settings[Common.Utils.documentSettingsType.Chart].hidden) { priorityactive = (sparkactive===0) ? Common.Utils.documentSettingsType.Cell : Common.Utils.documentSettingsType.Chart; } if (!this._settings[Common.Utils.documentSettingsType.Pivot].hidden) @@ -353,7 +355,7 @@ define([ this._settings[Common.Utils.documentSettingsType.Image].needShow = false; this._settings[Common.Utils.documentSettingsType.Chart].needShow = false; - this._settings[Common.Utils.documentSettingsType.Table].needShow = false; + // this._settings[Common.Utils.documentSettingsType.Table].needShow = false; pivotInfo && (this._settings[Common.Utils.documentSettingsType.Pivot].needShow = false); }, @@ -378,9 +380,9 @@ define([ this._settings[Common.Utils.documentSettingsType.TextArt].needShow = true; }, - onInsertTable: function() { - // this._settings[Common.Utils.documentSettingsType.Table].needShow = true; - }, + // onInsertTable: function() { + // // this._settings[Common.Utils.documentSettingsType.Table].needShow = true; + // }, onInsertPivot: function() { this._settings[Common.Utils.documentSettingsType.Pivot].needShow = true; @@ -468,7 +470,7 @@ define([ this.rightmenu.shapeSettings.disableControls(disabled); this.rightmenu.imageSettings.disableControls(disabled); this.rightmenu.chartSettings.disableControls(disabled); - this.rightmenu.tableSettings.disableControls(disabled); + // this.rightmenu.tableSettings.disableControls(disabled); this.rightmenu.pivotSettings.disableControls(disabled); this.rightmenu.cellSettings.disableControls(disabled); this.rightmenu.slicerSettings.disableControls(disabled); @@ -480,7 +482,7 @@ define([ if (disabled) { this.rightmenu.btnText.setDisabled(disabled); - this.rightmenu.btnTable.setDisabled(disabled); + // this.rightmenu.btnTable.setDisabled(disabled); this.rightmenu.btnImage.setDisabled(disabled); this.rightmenu.btnShape.setDisabled(disabled); this.rightmenu.btnTextArt.setDisabled(disabled); diff --git a/apps/spreadsheeteditor/main/app/controller/TableDesignTab.js b/apps/spreadsheeteditor/main/app/controller/TableDesignTab.js new file mode 100644 index 0000000000..4454af7da9 --- /dev/null +++ b/apps/spreadsheeteditor/main/app/controller/TableDesignTab.js @@ -0,0 +1,484 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2024 + * + * 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-6 Ernesta Birznieka-Upish + * 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 + * + */ + +/** + * TableDesignTab.js + * + * Created on 07.07.2025 + * + */ + +define([ + 'core', + 'spreadsheeteditor/main/app/view/TableDesignTab' +], function () { + 'use strict'; + + SSE.Controllers.TableDesignTab = Backbone.Controller.extend(_.extend({ + models : [], + collections : [ + ], + views : [ + 'TableDesignTab' + ], + sdkViewName : '#id_main', + + initialize: function () { + this._state = { + TableName: '', + TemplateName: '', + Range: '', + CheckHeader: false, + CheckTotal: false, + CheckBanded: false, + CheckFirst: false, + CheckLast: false, + CheckColBanded: false, + CheckFilter: false, + DisabledControls: false, + TableNameError: false + }; + this.lockedControls = []; + this._locked = false; + this._originalProps = null; + + this.addListeners({ + 'TableDesignTab': { + 'tabledesigntab:insertslicer': _.bind(this.onInsertSlicer, this), + 'tabledesigntab:advanced': _.bind(this.openAdvancedSettings, this), + 'tabledesigntab:style': _.bind(this.onTableStyleSelect, this), + 'tabledesigntab:selectdata': _.bind(this.onSelectData, this), + 'tabledesign:namechanged': _.bind(this.onTableNameChanged, this), + 'tabledesigntab:convertrange': _.bind(this.convertToRange, this), + 'tabledesigntab:edit': _.bind(this.onEditClick, this), + 'tabledesigntab:stylechange': _.bind(this.changeTableInfo, this) + }, + }); + }, + + onSelectData: function() { + var me = this; + if (me.api) { + var handlerDlg = function(dlg, result) { + if (result == 'ok') { + me.api.asc_setSelectionDialogMode(Asc.c_oAscSelectionDialogType.None); + + var settings = dlg.getSettings(); + if (settings.selectionType == Asc.c_oAscSelectionType.RangeMax || settings.selectionType == Asc.c_oAscSelectionType.RangeRow || + settings.selectionType == Asc.c_oAscSelectionType.RangeCol) + Common.UI.warning({ + title: me.textLongOperation, + msg: me.warnLongOperation, + buttons: ['ok', 'cancel'], + callback: function(btn) { + if (btn == 'ok') + setTimeout(function() { me.api.asc_changeTableRange(me._state.TableName, settings.range)}, 1); + Common.NotificationCenter.trigger('edit:complete', me); + } + }); + else + me.api.asc_changeTableRange(me._state.TableName, settings.range); + } + + Common.NotificationCenter.trigger('edit:complete', me); + }; + var win = new SSE.Views.TableOptionsDialog({ + handler: handlerDlg + }); + win.show(); + win.setSettings({ + api : me.api, + range : me._state.Range, + title: me.textResize + }); + } + }, + + onTableNameChanged: function(input, newValue, oldValue) { + var oldName = this._state.TableName; + this._state.TableName = ''; + + if (oldName.toLowerCase() == newValue.toLowerCase()) { + Common.NotificationCenter.trigger('edit:complete', this); + return; + } + + var me = this, + isvalid = this.api.asc_checkDefinedName(newValue, null); + if (isvalid.asc_getStatus() === true) isvalid = true; + else { + switch (isvalid.asc_getReason()) { + case Asc.c_oAscDefinedNameReason.IsLocked: + isvalid = this.textIsLocked; + break; + case Asc.c_oAscDefinedNameReason.Existed: + isvalid = this.textExistName; + break; + case Asc.c_oAscDefinedNameReason.NameReserved: + isvalid = this.textReservedName; + break; + default: + isvalid = this.textInvalidName; + } + } + if (isvalid === true) { + this.api.asc_changeDisplayNameTable(oldName, newValue); + Common.NotificationCenter.trigger('edit:complete', this); + } else if (!this._state.TableNameError) { + this._state.TableNameError = true; + Common.UI.alert({ + msg: isvalid, + title: this.notcriticalErrorTitle, + iconCls: 'warn', + buttons: ['ok'], + callback: function(btn){ + Common.NotificationCenter.trigger('edit:complete', this); + me._state.TableNameError = false; + } + }); + } + }, + + ChangeSettings: function(props) { + if (props )//formatTableInfo + { + this._originalProps = props; + this.view._originalProps = props; + var view = this.view; + var value = props.asc_getTableName(); + if (this._state.TableName!==value) { + view.txtTableName.setValue(value); + this._state.TableName=value; + } + + this._state.Range = props.asc_getTableRange(); + + var needTablePictures = false; + value = props.asc_getFirstRow(); + if (this._state.CheckHeader!==value) { + view.chHeaderRow.setValue(value, true); + this._state.CheckHeader=value; + needTablePictures = true; + } + + value = props.asc_getLastRow(); + if (this._state.CheckTotal!==value) { + view.chTotalRow.setValue(value, true); + this._state.CheckTotal=value; + needTablePictures = true; + } + + value = props.asc_getBandHor(); + if (this._state.CheckBanded!==value) { + view.chBandedRows.setValue(value, true); + this._state.CheckBanded=value; + needTablePictures = true; + } + + value = props.asc_getFirstCol(); + if (this._state.CheckFirst!==value) { + view.chFirstColumn.setValue(value, true); + this._state.CheckFirst=value; + needTablePictures = true; + } + + value = props.asc_getLastCol(); + if (this._state.CheckLast!==value) { + view.chLastColumn.setValue(value, true); + this._state.CheckLast=value; + needTablePictures = true; + } + + value = props.asc_getBandVer(); + if (this._state.CheckColBanded!==value) { + view.chBandedColumns.setValue(value, true); + this._state.CheckColBanded=value; + needTablePictures = true; + } + + value = props.asc_getFilterButton(); + if (this._state.CheckFilter!==value) { + view.chFilterButton.setValue(value, true); + this._state.CheckFilter=value; + } + Common.Utils.lockControls(Common.enumLock.isFilterAvailable, !this._state.CheckHeader || value===null, {array: [this.view.chFilterButton]}); + + if (needTablePictures) + this.onApiInitTableStyles(this.api.asc_getTablePictures(props)); + + // for table-template + value = props.asc_getTableStyleName(); + if (this._state.TemplateName!==value || this._isTemplatesChanged) { + view.tableStyles.suspendEvents(); + var rec = view.tableStyles.menuPicker.store.findWhere({ + name: value + }); + view.tableStyles.menuPicker.selectRecord(rec); + view.tableStyles.resumeEvents(); + + if (this._isTemplatesChanged) { + if (rec) + view.tableStyles.fillComboView(view.tableStyles.menuPicker.getSelectedRec(),true); + else + view.tableStyles.fillComboView(view.tableStyles.menuPicker.store.at(0), true); + } + this._state.TemplateName=value; + } + this._isTemplatesChanged = false; + } + }, + + onTableStyleSelect: function(record){ + if (this.api) { + this.api.asc_changeAutoFilter(this._state.TableName, Asc.c_oAscChangeFilterOptions.style, record.get('name')); + } + Common.NotificationCenter.trigger('edit:complete', this); + }, + + convertToRange: function(btn) { + if (this.api) this.api.asc_convertTableToRange(this._state.TableName); + Common.NotificationCenter.trigger('edit:complete', this); + }, + + changeTableInfo: function(type, stateName, newValue) { + this._state[stateName] = undefined; + if (this.api) + this.api.asc_changeFormatTableInfo(this._state.TableName, type, newValue=='checked'); + Common.NotificationCenter.trigger('edit:complete', this); + }, + + onEditClick: function(item) { + if (this.api) { + if (item.options.idx>=0 && item.options.idx<4) + this.api.asc_changeSelectionFormatTable(this._state.TableName, item.value); + else if (item.options.idx>=4 && item.options.idx<8) { + this.api.asc_insertCellsInTable(this._state.TableName, item.value); + } else { + this.api.asc_deleteCellsInTable(this._state.TableName, item.value); + } + } + Common.NotificationCenter.trigger('edit:complete', this); + }, + + setApi: function(api) { + if (api) { + this.api = api; + this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.SetDisabled, this)); + Common.NotificationCenter.on('api:disconnect', _.bind(this.SetDisabled, this)); + this.api.asc_registerCallback('asc_onSelectionChanged', _.bind(this.onSelectionChanged, this)); + this.api.asc_registerCallback('asc_onSendThemeColors', _.bind(this.onSendThemeColors, this)); + Common.NotificationCenter.on('cells:range', _.bind(this.onCellsRange, this)); + } + return this; + }, + + onSendThemeColors: function() { + if (this.view.tableStyles && this._originalProps) { + this.onApiInitTableStyles(this.api.asc_getTablePictures(this._originalProps)); + this.view.tableStyles.menuPicker.scroller.update({alwaysVisibleY: true}); + } + }, + + onApiInitTableStyles: function(Templates){ + var self = this, + styles = this.view.tableStyles; + this._isTemplatesChanged = true; + var count = styles.menuPicker.store.length; + + if (count>0 && count==Templates.length) { + var data = styles.menuPicker.dataViewItems; + var findDataViewItem = function(template) { + for(var i = 0; i < data.length; i++) { + if(data[i].model.get('name') && data[i].model.get('name') === template.asc_getName()) return data[i]; + else if(data[i].model.get('caption') === template.asc_getDisplayName()) return data[i]; + } + return undefined; + }; + + data && _.each(Templates, function(template, index){ + var img = template.asc_getImage(); + var dataViewItem = findDataViewItem(template); + dataViewItem && dataViewItem.model.set('imageUrl', img, {silent: true}); + dataViewItem && $(dataViewItem.el).find('img').attr('src', img); + }); + styles.fieldPicker.store.reset(styles.fieldPicker.store.models); + } else { + styles.menuPicker.store.reset([]); + var templates = []; + var groups = [ + {id: 'menu-table-group-custom', caption: self.view.txtGroupTable_Custom, templates: []}, + {id: 'menu-table-group-light', caption: self.view.txtGroupTable_Light, templates: []}, + {id: 'menu-table-group-medium', caption: self.view.txtGroupTable_Medium, templates: []}, + {id: 'menu-table-group-dark', caption: self.view.txtGroupTable_Dark, templates: []}, + {id: 'menu-table-group-no-name', caption: ' ', templates: []}, + ]; + _.each(Templates, function(template, index){ + var tip = template.asc_getDisplayName(), + groupItem = '', + lastWordInTip = null; + + if (template.asc_getType()==0) { + var arr = tip.split(' '); + lastWordInTip = arr.pop(); + + if(template.asc_getName() === null){ + groupItem = 'menu-table-group-light'; + } + else { + if(arr.length > 0){ + groupItem = 'menu-table-group-' + arr[arr.length - 1].toLowerCase(); + } + if(groups.some(function(item) {return item.id === groupItem;}) == false) { + groupItem = 'menu-table-group-no-name'; + } + } + arr = 'txtTable_' + arr.join(''); + tip = self.view[arr] ? self.view[arr] + ' ' + lastWordInTip : tip; + lastWordInTip = parseInt(lastWordInTip); + } + else { + groupItem = 'menu-table-group-custom' + } + groups.filter(function(item){ return item.id == groupItem; })[0].templates.push({ + id : Common.UI.getId(), + name : template.asc_getName(), + caption : template.asc_getDisplayName(), + type : template.asc_getType(), + imageUrl : template.asc_getImage(), + group : groupItem, + allowSelected : true, + selected : false, + tip : tip, + numInGroup : (lastWordInTip != null && !isNaN(lastWordInTip) ? lastWordInTip : null) + }); + }); + + var sortFunc = function(a, b) { + var aNum = a.numInGroup, + bNum = b.numInGroup; + return aNum - bNum; + }; + + groups[1].templates.sort(sortFunc); + groups[2].templates.sort(sortFunc); + groups[3].templates.sort(sortFunc); + + groups = groups.filter(function(item, index){ + return item.templates.length > 0 + }); + + groups.forEach(function(item){ + templates = templates.concat(item.templates); + delete item.templates; + }); + + styles.groups.reset(groups); + styles.menuPicker.store.reset(templates); + } + }, + + setMode: function(mode) { + this.appConfig = mode; + return this; + }, + + openAdvancedSettings: function(e) { + var me = this; + var win; + if (me.api && !this._locked){ + (new SSE.Views.TableSettingsAdvanced( + { + tableProps: me._originalProps, + api: me.api, + handler: function(result, value) { + if (result == 'ok' && me.api && value) { + me.api.asc_changeFormatTableInfo(me._state.TableName, Asc.c_oAscChangeTableStyleInfo.advancedSettings, value); + } + + Common.NotificationCenter.trigger('edit:complete', me); + } + })).show(); + } + }, + + setConfig: function(config) { + this.view = this.createView('TableDesignTab', { + toolbar: config.toolbar.toolbar + }); + }, + + SetDisabled: function(state) { + this.view && this.view.SetDisabled(state); + }, + + onInsertSlicer: function() { + var me = this, + props = me.api.asc_beforeInsertSlicer(); + if (props) { + (new SSE.Views.SlicerAddDialog({ + props: props, + handler: function (result, settings) { + if (me && me.api && result == 'ok') { + me.api.asc_insertSlicer(settings); + } + Common.NotificationCenter.trigger('edit:complete', me); + } + })).show(); + } + }, + + createToolbarPanel: function() { + return this.view.getPanel(); + }, + + getView: function(name) { + return !name && this.view ? + this.view : Backbone.Controller.prototype.getView.call(this, name); + }, + + onCoAuthoringDisconnect: function() { + this.SetDisabled(true); + }, + + onSelectionChanged: function(info) { + if (this.rangeSelectionMode || !this.appConfig.isEdit || !this.view) return; + var tableInfo = info.asc_getFormatTableInfo(); + if (tableInfo) + this.ChangeSettings(tableInfo); + }, + + onCellsRange: function(status) { + this.rangeSelectionMode = (status != Asc.c_oAscSelectionDialogType.None); + }, + + }, SSE.Controllers.TableDesignTab || {})); +}); diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index faac375309..5ef864e8c2 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -204,7 +204,8 @@ define([ is_lockText: false, is_lockShape: false, isUserProtected: false, - showPivotTab: false + showPivotTab: false, + showTableDesignTab: false }; this.binding = {}; @@ -3161,7 +3162,7 @@ define([ } need_disable = this._state.controlsdisabled.filters || (val===null); toolbar.lockToolbar(Common.enumLock.ruleFilter, need_disable, - { array: toolbar.btnsSetAutofilter.concat(toolbar.btnCustomSort, toolbar.btnTableTemplate, toolbar.btnInsertTable, toolbar.btnRemoveDuplicates, toolbar.btnDataValidation) }); + { array: toolbar.btnsSetAutofilter.concat(toolbar.btnCustomSort, toolbar.btnTableTemplate, toolbar.btnInsertTable, toolbar.btnDataValidation).concat(toolbar.btnsRemoveDuplicates)}); toolbar.lockToolbar(Common.enumLock.tableHasSlicer, filterInfo && filterInfo.asc_getIsSlicerAdded(), { array: toolbar.btnsSetAutofilter }); @@ -3195,6 +3196,16 @@ define([ this._state.multiselect = info.asc_getMultiselect(); toolbar.lockToolbar(Common.enumLock.multiselect, this._state.multiselect, { array: [toolbar.btnTableTemplate, toolbar.btnInsertHyperlink, toolbar.btnInsertTable]}); + var intabledesign = info.asc_getFormatTableInfo(); + if (this._state.intabledesign !== intabledesign) { + if ( !intabledesign && this.toolbar.isTabActive('tabledesign') ) + this.toolbar.setTab('home'); + this.toolbar.setVisible('tabledesign', !!intabledesign); + if (intabledesign && this._state.showTableDesignTab) + this.toolbar.setTab('tabledesign'); + this._state.intabledesign = intabledesign; + } + var inpivot = !!info.asc_getPivotTableInfo(); if (this._state.inpivot !== inpivot) { if ( !inpivot && this.toolbar.isTabActive('pivot') ) @@ -3204,13 +3215,12 @@ define([ this.toolbar.setTab('pivot'); this._state.inpivot = inpivot; } - toolbar.lockToolbar(Common.enumLock.editPivot, this._state.inpivot, { array: toolbar.btnsSetAutofilter.concat(toolbar.btnMerge, toolbar.btnInsertHyperlink, toolbar.btnInsertTable, toolbar.btnRemoveDuplicates, toolbar.btnDataValidation)}); + toolbar.lockToolbar(Common.enumLock.editPivot, this._state.inpivot, { array: toolbar.btnsSetAutofilter.concat(toolbar.btnMerge, toolbar.btnInsertHyperlink, toolbar.btnInsertTable, toolbar.btnDataValidation).concat(toolbar.btnsRemoveDuplicates)}); toolbar.lockToolbar(Common.enumLock.noSlicerSource, !(this._state.inpivot || formatTableInfo), { array: [toolbar.btnInsertSlicer]}); need_disable = !this.appConfig.canModifyFilter; toolbar.lockToolbar(Common.enumLock.cantModifyFilter, need_disable, { array: toolbar.btnsSetAutofilter.concat(toolbar.btnsSortDown, toolbar.btnsSortUp, toolbar.btnCustomSort, toolbar.btnTableTemplate, - toolbar.btnClearStyle.menu.items[0], toolbar.btnClearStyle.menu.items[2], toolbar.btnInsertTable, toolbar.btnRemoveDuplicates, toolbar.btnDataValidation)}); - + toolbar.btnClearStyle.menu.items[0], toolbar.btnClearStyle.menu.items[2], toolbar.btnInsertTable, toolbar.btnDataValidation).concat(toolbar.btnsRemoveDuplicates).concat(toolbar.btnsTableDesign)}); } val = xfs.asc_getNumFormatInfo(); @@ -4544,7 +4554,7 @@ define([ me.toolbar.btnsSetAutofilter = datatab.getButtons('set-filter'); me.toolbar.btnsClearAutofilter = datatab.getButtons('clear-filter'); me.toolbar.btnCustomSort = datatab.getButtons('sort-custom'); - me.toolbar.btnRemoveDuplicates = datatab.getButtons('rem-duplicates'); + me.toolbar.btnsRemoveDuplicates = [datatab.getButtons('rem-duplicates')]; me.toolbar.btnDataValidation = datatab.getButtons('data-validation'); var formulatab = me.getApplication().getController('FormulaDialog'); @@ -4567,6 +4577,22 @@ define([ } } + if ( config.canFeatureTable ) { + tab = {caption: 'Table Design', action: 'tabledesign', extcls: config.isEdit ? 'canedit' : '', layoutname: 'toolbar-tabledesign', dataHintTitle: 'B'}; + var tabledesigntab = me.getApplication().getController('TableDesignTab'); + tabledesigntab.setApi(me.api).setConfig({toolbar: me}); + var view = tabledesigntab.getView('TableDesignTab'); + var tabledesignbuttons = view.getButtons(); + var $panel = tabledesigntab.createToolbarPanel(); + if ($panel) { + me.toolbar.addTab(tab, $panel, Common.UI.LayoutManager.lastTabIdx+1); + me._state.intabledesign && me.toolbar.setVisible('tabledesign', true); + Array.prototype.push.apply(me.toolbar.lockControls, tabledesignbuttons); + } + me.toolbar.btnsRemoveDuplicates.push(view.getButtons('rem-duplicates')); + me.toolbar.btnsTableDesign = tabledesignbuttons; + } + if (!config.compactHeader) { // hide 'print' and 'save' buttons group and next separator me.toolbar.btnPrint.$el.parents('.group').hide().next().hide(); diff --git a/apps/spreadsheeteditor/main/app/template/RightMenu.template b/apps/spreadsheeteditor/main/app/template/RightMenu.template index 4da149286a..b49c564c37 100644 --- a/apps/spreadsheeteditor/main/app/template/RightMenu.template +++ b/apps/spreadsheeteditor/main/app/template/RightMenu.template @@ -16,7 +16,7 @@