From 374f7d122f662f1d2ef6bd3f347de85f0233e541 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 3 Sep 2019 13:52:52 +0300 Subject: [PATCH] [SSE] Optimize textart loading --- .../main/app/controller/Main.js | 21 +++---- .../main/app/controller/RightMenu.js | 4 -- .../main/app/controller/Toolbar.js | 63 +++++-------------- .../main/app/view/TextArtSettings.js | 8 +++ .../main/app/view/Toolbar.js | 22 +++++++ 5 files changed, 52 insertions(+), 66 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 30d09aa07e..fe95858207 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -766,7 +766,6 @@ define([ if (shapes) me.fillAutoShapes(shapes[0], shapes[1]); - me.fillTextArt(me.api.asc_getTextArtPreviews()); me.updateThemeColors(); toolbarController.activateControls(); } @@ -1800,11 +1799,14 @@ define([ }, fillTextArt: function(shapes){ - if (_.isEmpty(shapes)) return; - - var me = this, arr = [], + var arr = [], artStore = this.getCollection('Common.Collections.TextArt'); + if (!shapes && artStore.length>0) {// shapes == undefined when update textart collection (from asc_onSendThemeColors) + shapes = this.api.asc_getTextArtPreviews(); + } + if (_.isEmpty(shapes)) return; + _.each(shapes, function(shape, index){ arr.push({ imageUrl : shape, @@ -1814,15 +1816,6 @@ define([ }); }); artStore.reset(arr); - - setTimeout(function(){ - me.getApplication().getController('Toolbar').fillTextArt(); - }, 50); - - setTimeout(function(){ - me.getApplication().getController('RightMenu').fillTextArt(); - }, 50); - }, updateThemeColors: function() { @@ -1846,7 +1839,7 @@ define([ this.updateThemeColors(); var me = this; setTimeout(function(){ - me.fillTextArt(me.api.asc_getTextArtPreviews()); + me.fillTextArt(); }, 1); } }, diff --git a/apps/spreadsheeteditor/main/app/controller/RightMenu.js b/apps/spreadsheeteditor/main/app/controller/RightMenu.js index 7df7b35a15..6018498c15 100644 --- a/apps/spreadsheeteditor/main/app/controller/RightMenu.js +++ b/apps/spreadsheeteditor/main/app/controller/RightMenu.js @@ -299,10 +299,6 @@ define([ this.rightmenu.imageSettings.updateMetricUnit(); }, - fillTextArt: function() { - this.rightmenu.textartSettings.fillTextArt(); - }, - createDelayedElements: function() { var me = this; if (this.api) { diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 231ec7a3cf..0ca318d0a6 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -71,7 +71,8 @@ define([ this.addListeners({ 'Toolbar': { 'change:compact': this.onClickChangeCompact.bind(me), - 'add:chart' : this.onSelectChart + 'add:chart' : this.onSelectChart, + 'insert:textart': this.onInsertTextart }, 'FileMenu': { 'menu:hide': me.onFileMenu.bind(me, 'hide'), @@ -1019,6 +1020,19 @@ define([ Common.NotificationCenter.trigger('edit:complete', this.toolbar); }, + onInsertTextart: function (data) { + if (this.api) { + this.toolbar.fireEvent('inserttextart', this.toolbar); + this.api.asc_addTextArt(data); + + if (this.toolbar.btnInsertShape.pressed) + this.toolbar.btnInsertShape.toggle(false, true); + + Common.NotificationCenter.trigger('edit:complete', this.toolbar, this.toolbar.btnInsertTextArt); + Common.component.Analytics.trackEvent('ToolBar', 'Add Text Art'); + } + }, + onBtnInsertTextClick: function(btn, e) { if (this.api) this._addAutoshape(btn.pressed, 'textRect'); @@ -2614,53 +2628,6 @@ define([ } }, - fillTextArt: function() { - if (!this.toolbar.btnInsertTextArt.rendered) return; - - if ( this.toolbar.mnuTextArtPicker ) { - var models = this.getApplication().getCollection('Common.Collections.TextArt').models, - count = this.toolbar.mnuTextArtPicker.store.length; - if (count>0 && count==models.length) { - var data = this.toolbar.mnuTextArtPicker.store.models; - _.each(models, function(template, index){ - data[index].set('imageUrl', template.get('imageUrl')); - }); - } else { - this.toolbar.mnuTextArtPicker.store.reset(models); - } - } else if (!this.binding.onShowBeforeTextArt) { - var me = this; - me.binding.onShowBeforeTextArt = function(menu) { - me.toolbar.mnuTextArtPicker = new Common.UI.DataView({ - el: $('#id-toolbar-menu-insart'), - store: me.getApplication().getCollection('Common.Collections.TextArt'), - parentMenu: menu, - showLast: false, - itemTemplate: _.template('
') - }); - - me.toolbar.mnuTextArtPicker.on('item:click', - function(picker, item, record, e) { - if (record) { - me.toolbar.fireEvent('inserttextart', me.toolbar); - me.api.asc_addTextArt(record.get('data')); - } - if ( me.toolbar.btnInsertShape.pressed ) - me.toolbar.btnInsertShape.toggle(false, true); - - if ( e.type !== 'click' ) - me.toolbar.btnInsertTextArt.menu.hide(); - - Common.NotificationCenter.trigger('edit:complete', me.toolbar, me.toolbar.btnInsertTextArt); - Common.component.Analytics.trackEvent('ToolBar', 'Add Text Art'); - } - ); - menu.off('show:before', me.binding.onShowBeforeTextArt); - }; - me.toolbar.btnInsertTextArt.menu.on('show:before', me.binding.onShowBeforeTextArt); - } - }, - fillEquations: function() { if (!this.toolbar.btnInsertEquation.rendered || this.toolbar.btnInsertEquation.menu.items.length>0) return; diff --git a/apps/spreadsheeteditor/main/app/view/TextArtSettings.js b/apps/spreadsheeteditor/main/app/view/TextArtSettings.js index 9b33043d38..d3d6291d78 100644 --- a/apps/spreadsheeteditor/main/app/view/TextArtSettings.js +++ b/apps/spreadsheeteditor/main/app/view/TextArtSettings.js @@ -124,6 +124,10 @@ define([ this.FillPatternContainer = $('#textart-panel-pattern-fill'); this.FillGradientContainer = $('#textart-panel-gradient-fill'); this.TransparencyContainer = $('#textart-panel-transparent-fill'); + + SSE.getCollection('Common.Collections.TextArt').bind({ + reset: this.fillTextArt.bind(this) + }); }, render: function () { @@ -1436,6 +1440,10 @@ define([ var models = this.application.getCollection('Common.Collections.TextArt').models, count = this.cmbTextArt.menuPicker.store.length; + if (models.length<1) { + SSE.getController('Main').fillTextArt(this.api.asc_getTextArtPreviews()); + return; + } if (count>0 && count==models.length) { var data = this.cmbTextArt.menuPicker.store.models; _.each(models, function(template, index){ diff --git a/apps/spreadsheeteditor/main/app/view/Toolbar.js b/apps/spreadsheeteditor/main/app/view/Toolbar.js index c9e9c6eac3..00373bb7a0 100644 --- a/apps/spreadsheeteditor/main/app/view/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/view/Toolbar.js @@ -1836,6 +1836,28 @@ define([ this.btnInsertChart.menu.on('show:before', onShowBefore); } + if (this.btnInsertTextArt) { + var onShowBeforeTextArt = function (menu) { + var collection = SSE.getCollection('Common.Collections.TextArt'); + if (collection.length<1) + SSE.getController('Main').fillTextArt(me.api.asc_getTextArtPreviews()); + var picker = new Common.UI.DataView({ + el: $('#id-toolbar-menu-insart'), + store: collection, + parentMenu: menu, + showLast: false, + itemTemplate: _.template('
') + }); + picker.on('item:click', function (picker, item, record, e) { + if (record) + me.fireEvent('insert:textart', [record.get('data')]); + if (e.type !== 'click') menu.hide(); + }); + menu.off('show:before', onShowBeforeTextArt); + }; + this.btnInsertTextArt.menu.on('show:before', onShowBeforeTextArt); + } + if (!this.mode.isEditMailMerge && !this.mode.isEditDiagram) this.updateMetricUnit(); },