From 2bce4a8971575ed5d5922b54b08e01f0f9bd7143 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 30 Aug 2019 15:04:02 +0300 Subject: [PATCH] Refactoring textures loading --- .../main/app/view/ShapeSettings.js | 68 +++++++++++-------- .../main/app/view/ShapeSettings.js | 67 ++++++++++-------- .../main/app/view/SlideSettings.js | 67 ++++++++++-------- .../main/app/view/TextArtSettings.js | 68 +++++++++++-------- .../main/app/view/ShapeSettings.js | 67 ++++++++++-------- .../main/app/view/TextArtSettings.js | 45 +++++++----- 6 files changed, 219 insertions(+), 163 deletions(-) diff --git a/apps/documenteditor/main/app/view/ShapeSettings.js b/apps/documenteditor/main/app/view/ShapeSettings.js index db785780e..1d227611a 100644 --- a/apps/documenteditor/main/app/view/ShapeSettings.js +++ b/apps/documenteditor/main/app/view/ShapeSettings.js @@ -78,6 +78,7 @@ define([ this.imgprops = null; this._sendUndoPoint = true; this._sliderChanged = false; + this._texturearray = null; this.txtPt = Common.Utils.Metric.getMetricName(Common.Utils.Metric.c_MetricUnits.pt); @@ -1516,6 +1517,7 @@ define([ this.PatternFillType = this.patternViewData[0].type; } + this.onInitStandartTextures(); this.onApiAutoShapes(); this.UpdateThemeColors(); }, @@ -1523,29 +1525,9 @@ define([ onInitStandartTextures: function(texture) { var me = this; if (texture && texture.length>0){ - if (!this.btnTexture) { - this.btnTexture = new Common.UI.ComboBox({ - el: $('#shape-combo-fill-texture'), - template: _.template([ - '' - ].join('')) - }); - this.textureMenu = new Common.UI.Menu({ - items: [ - { template: _.template('
') } - ] - }); - this.textureMenu.render($('#shape-combo-fill-texture')); - this.fillControls.push(this.btnTexture); - } - - var texturearray = []; + me._texturearray = []; _.each(texture, function(item){ - texturearray.push({ + me._texturearray.push({ imageUrl: item.get_image(), name : me.textureNames[item.get_id()], type : item.get_id(), @@ -1553,15 +1535,41 @@ define([ selected: false }); }); - var mnuTexturePicker = new Common.UI.DataView({ - el: $('#id-shape-menu-texture'), - restoreHeight: 174, - parentMenu: me.textureMenu, - showLast: false, - store: new Common.UI.DataViewStore(texturearray), - itemTemplate: _.template('
') + } + + if (!me._texturearray || me._texturearray.length<1) return; + if (!this._initSettings && !this.btnTexture) { + this.btnTexture = new Common.UI.ComboBox({ + el: $('#shape-combo-fill-texture'), + template: _.template([ + '' + ].join('')) }); - mnuTexturePicker.on('item:click', _.bind(this.onSelectTexture, this)); + this.textureMenu = new Common.UI.Menu({ + items: [ + { template: _.template('
') } + ] + }); + this.textureMenu.render($('#shape-combo-fill-texture')); + this.fillControls.push(this.btnTexture); + + var onShowBefore = function(menu) { + var mnuTexturePicker = new Common.UI.DataView({ + el: $('#id-shape-menu-texture'), + restoreHeight: 174, + parentMenu: menu, + showLast: false, + store: new Common.UI.DataViewStore(me._texturearray || []), + itemTemplate: _.template('
') + }); + mnuTexturePicker.on('item:click', _.bind(me.onSelectTexture, me)); + menu.off('show:before', onShowBefore); + }; + this.textureMenu.on('show:before', onShowBefore); } }, diff --git a/apps/presentationeditor/main/app/view/ShapeSettings.js b/apps/presentationeditor/main/app/view/ShapeSettings.js index d83531a1d..0ab44f978 100644 --- a/apps/presentationeditor/main/app/view/ShapeSettings.js +++ b/apps/presentationeditor/main/app/view/ShapeSettings.js @@ -76,6 +76,7 @@ define([ this._noApply = true; this._sendUndoPoint = true; this._sliderChanged = false; + this._texturearray = null; this.txtPt = Common.Utils.Metric.getMetricName(Common.Utils.Metric.c_MetricUnits.pt); @@ -1391,6 +1392,7 @@ define([ this.PatternFillType = this.patternViewData[0].type; } + this.onInitStandartTextures(); this.onApiAutoShapes(); this.UpdateThemeColors(); }, @@ -1398,28 +1400,9 @@ define([ onInitStandartTextures: function(texture) { var me = this; if (texture && texture.length>0){ - if (!this.btnTexture) { - this.btnTexture = new Common.UI.ComboBox({ - el: $('#shape-combo-fill-texture'), - template: _.template([ - '' - ].join('')) - }); - this.textureMenu = new Common.UI.Menu({ - items: [ - { template: _.template('
') } - ] - }); - this.textureMenu.render($('#shape-combo-fill-texture')); - this.fillControls.push(this.btnTexture); - } - var texturearray = []; + me._texturearray = []; _.each(texture, function(item){ - texturearray.push({ + me._texturearray.push({ imageUrl: item.get_image(), name : me.textureNames[item.get_id()], type : item.get_id(), @@ -1427,15 +1410,41 @@ define([ selected: false }); }); - var mnuTexturePicker = new Common.UI.DataView({ - el: $('#id-shape-menu-texture'), - restoreHeight: 174, - parentMenu: me.textureMenu, - showLast: false, - store: new Common.UI.DataViewStore(texturearray), - itemTemplate: _.template('
') + } + + if (!me._texturearray || me._texturearray.length<1) return; + if (!this._initSettings && !this.btnTexture) { + this.btnTexture = new Common.UI.ComboBox({ + el: $('#shape-combo-fill-texture'), + template: _.template([ + '' + ].join('')) }); - mnuTexturePicker.on('item:click', _.bind(this.onSelectTexture, this)); + this.textureMenu = new Common.UI.Menu({ + items: [ + { template: _.template('
') } + ] + }); + this.textureMenu.render($('#shape-combo-fill-texture')); + this.fillControls.push(this.btnTexture); + + var onShowBefore = function(menu) { + var mnuTexturePicker = new Common.UI.DataView({ + el: $('#id-shape-menu-texture'), + restoreHeight: 174, + parentMenu: menu, + showLast: false, + store: new Common.UI.DataViewStore(me._texturearray || []), + itemTemplate: _.template('
') + }); + mnuTexturePicker.on('item:click', _.bind(me.onSelectTexture, me)); + menu.off('show:before', onShowBefore); + }; + this.textureMenu.on('show:before', onShowBefore); } }, diff --git a/apps/presentationeditor/main/app/view/SlideSettings.js b/apps/presentationeditor/main/app/view/SlideSettings.js index feb56b5f4..f71abc046 100644 --- a/apps/presentationeditor/main/app/view/SlideSettings.js +++ b/apps/presentationeditor/main/app/view/SlideSettings.js @@ -73,6 +73,7 @@ define([ this._noApply = true; this._sendUndoPoint = true; this._sliderChanged = false; + this._texturearray = null; this.FillItems = []; @@ -842,34 +843,16 @@ define([ this.PatternFillType = this.patternViewData[0].type; } + this.onInitStandartTextures(); this.UpdateThemeColors(); }, onInitStandartTextures: function(texture) { var me = this; if (texture && texture.length>0){ - if (!this.btnTexture) { - this.btnTexture = new Common.UI.ComboBox({ - el: $('#slide-combo-fill-texture'), - template: _.template([ - '' - ].join('')) - }); - this.textureMenu = new Common.UI.Menu({ - items: [ - { template: _.template('
') } - ] - }); - this.textureMenu.render($('#slide-combo-fill-texture')); - this.FillItems.push(this.btnTexture); - } - var texturearray = []; + me._texturearray = []; _.each(texture, function(item){ - texturearray.push({ + me._texturearray.push({ imageUrl: item.get_image(), name : me.textureNames[item.get_id()], type : item.get_id(), @@ -877,15 +860,41 @@ define([ selected: false }); }); - var mnuTexturePicker = new Common.UI.DataView({ - el: $('#id-slide-menu-texture'), - restoreHeight: 174, - parentMenu: me.textureMenu, - showLast: false, - store: new Common.UI.DataViewStore(texturearray), - itemTemplate: _.template('
') + } + + if (!me._texturearray || me._texturearray.length<1) return; + if (!this._initSettings && !this.btnTexture) { + this.btnTexture = new Common.UI.ComboBox({ + el: $('#slide-combo-fill-texture'), + template: _.template([ + '' + ].join('')) }); - mnuTexturePicker.on('item:click', _.bind(this.onSelectTexture, this)); + this.textureMenu = new Common.UI.Menu({ + items: [ + { template: _.template('
') } + ] + }); + this.textureMenu.render($('#slide-combo-fill-texture')); + this.FillItems.push(this.btnTexture); + + var onShowBefore = function(menu) { + var mnuTexturePicker = new Common.UI.DataView({ + el: $('#id-slide-menu-texture'), + restoreHeight: 174, + parentMenu: menu, + showLast: false, + store: new Common.UI.DataViewStore(me._texturearray || []), + itemTemplate: _.template('
') + }); + mnuTexturePicker.on('item:click', _.bind(me.onSelectTexture, me)); + menu.off('show:before', onShowBefore); + }; + this.textureMenu.on('show:before', onShowBefore); } }, diff --git a/apps/presentationeditor/main/app/view/TextArtSettings.js b/apps/presentationeditor/main/app/view/TextArtSettings.js index f0eed18d8..eccff24a6 100644 --- a/apps/presentationeditor/main/app/view/TextArtSettings.js +++ b/apps/presentationeditor/main/app/view/TextArtSettings.js @@ -75,6 +75,7 @@ define([ this.shapeprops = null; this._sendUndoPoint = true; this._sliderChanged = false; + this._texturearray = null; this.txtPt = Common.Utils.Metric.getMetricName(Common.Utils.Metric.c_MetricUnits.pt); @@ -1328,6 +1329,7 @@ define([ this.PatternFillType = this.patternViewData[0].type; } this.UpdateThemeColors(); + this.onInitStandartTextures(); this.fillTextArt(); this.fillTransform(this.api.asc_getPropertyEditorTextArts()); }, @@ -1335,43 +1337,51 @@ define([ onInitStandartTextures: function(texture) { var me = this; if (texture && texture.length>0){ - if (!this.btnTexture) { - this.btnTexture = new Common.UI.ComboBox({ - el: $('#textart-combo-fill-texture'), - template: _.template([ - '' - ].join('')) - }); - this.textureMenu = new Common.UI.Menu({ - items: [ - { template: _.template('
') } - ] - }); - this.textureMenu.render($('#textart-combo-fill-texture')); - this.lockedControls.push(this.btnTexture); - } - var texturearray = []; + me._texturearray = []; _.each(texture, function(item){ - texturearray.push({ + me._texturearray.push({ imageUrl: item.get_image(), name : me.textureNames[item.get_id()], type : item.get_id(), +// allowSelected : false, selected: false }); }); - var mnuTexturePicker = new Common.UI.DataView({ - el: $('#id-textart-menu-texture'), - restoreHeight: 174, - parentMenu: me.textureMenu, - showLast: false, - store: new Common.UI.DataViewStore(texturearray), - itemTemplate: _.template('
') + } + + if (!me._texturearray || me._texturearray.length<1) return; + if (!this._initSettings && !this.btnTexture) { + this.btnTexture = new Common.UI.ComboBox({ + el: $('#textart-combo-fill-texture'), + template: _.template([ + '' + ].join('')) }); - mnuTexturePicker.on('item:click', _.bind(this.onSelectTexture, this)); + this.textureMenu = new Common.UI.Menu({ + items: [ + { template: _.template('
') } + ] + }); + this.textureMenu.render($('#textart-combo-fill-texture')); + this.lockedControls.push(this.btnTexture); + + var onShowBefore = function(menu) { + var mnuTexturePicker = new Common.UI.DataView({ + el: $('#id-textart-menu-texture'), + restoreHeight: 174, + parentMenu: menu, + showLast: false, + store: new Common.UI.DataViewStore(me._texturearray || []), + itemTemplate: _.template('
') + }); + mnuTexturePicker.on('item:click', _.bind(me.onSelectTexture, me)); + menu.off('show:before', onShowBefore); + }; + this.textureMenu.on('show:before', onShowBefore); } }, diff --git a/apps/spreadsheeteditor/main/app/view/ShapeSettings.js b/apps/spreadsheeteditor/main/app/view/ShapeSettings.js index 2f776f928..370a0a0c9 100644 --- a/apps/spreadsheeteditor/main/app/view/ShapeSettings.js +++ b/apps/spreadsheeteditor/main/app/view/ShapeSettings.js @@ -77,6 +77,7 @@ define([ this.imgprops = null; this._sendUndoPoint = true; this._sliderChanged = false; + this._texturearray = null; this.txtPt = Common.Utils.Metric.getMetricName(Common.Utils.Metric.c_MetricUnits.pt); @@ -1415,6 +1416,7 @@ define([ this.PatternFillType = this.patternViewData[0].type; } + this.onInitStandartTextures(); this.onApiAutoShapes(); this.UpdateThemeColors(); }, @@ -1422,28 +1424,9 @@ define([ onInitStandartTextures: function(texture) { var me = this; if (texture && texture.length>0){ - if (!this.btnTexture) { - this.btnTexture = new Common.UI.ComboBox({ - el: $('#shape-combo-fill-texture'), - template: _.template([ - '' - ].join('')) - }); - this.textureMenu = new Common.UI.Menu({ - items: [ - { template: _.template('
') } - ] - }); - this.textureMenu.render($('#shape-combo-fill-texture')); - this.fillControls.push(this.btnTexture); - } - var texturearray = []; + me._texturearray = []; _.each(texture, function(item){ - texturearray.push({ + me._texturearray.push({ imageUrl: item.asc_getImage(), name : me.textureNames[item.asc_getId()], type : item.asc_getId(), @@ -1451,15 +1434,41 @@ define([ selected: false }); }); - var mnuTexturePicker = new Common.UI.DataView({ - el: $('#id-shape-menu-texture'), - restoreHeight: 174, - parentMenu: me.textureMenu, - showLast: false, - store: new Common.UI.DataViewStore(texturearray), - itemTemplate: _.template('
') + } + + if (!me._texturearray || me._texturearray.length<1) return; + if (!this._initSettings && !this.btnTexture) { + this.btnTexture = new Common.UI.ComboBox({ + el: $('#shape-combo-fill-texture'), + template: _.template([ + '' + ].join('')) }); - mnuTexturePicker.on('item:click', _.bind(this.onSelectTexture, this)); + this.textureMenu = new Common.UI.Menu({ + items: [ + { template: _.template('
') } + ] + }); + this.textureMenu.render($('#shape-combo-fill-texture')); + this.fillControls.push(this.btnTexture); + + var onShowBefore = function(menu) { + var mnuTexturePicker = new Common.UI.DataView({ + el: $('#id-shape-menu-texture'), + restoreHeight: 174, + parentMenu: menu, + showLast: false, + store: new Common.UI.DataViewStore(me._texturearray || []), + itemTemplate: _.template('
') + }); + mnuTexturePicker.on('item:click', _.bind(me.onSelectTexture, me)); + menu.off('show:before', onShowBefore); + }; + this.textureMenu.on('show:before', onShowBefore); } }, diff --git a/apps/spreadsheeteditor/main/app/view/TextArtSettings.js b/apps/spreadsheeteditor/main/app/view/TextArtSettings.js index 41d884790..9b33043d3 100644 --- a/apps/spreadsheeteditor/main/app/view/TextArtSettings.js +++ b/apps/spreadsheeteditor/main/app/view/TextArtSettings.js @@ -76,6 +76,7 @@ define([ this.shapeprops = null; this._sendUndoPoint = true; this._sliderChanged = false; + this._texturearray = null; this.txtPt = Common.Utils.Metric.getMetricName(Common.Utils.Metric.c_MetricUnits.pt); @@ -1333,6 +1334,7 @@ define([ } this.UpdateThemeColors(); + this.onInitStandartTextures(); this.fillTextArt(); this.fillTransform(this.api.asc_getPropertyEditorTextArts()); }, @@ -1340,6 +1342,20 @@ define([ onInitStandartTextures: function(texture) { var me = this; if (texture && texture.length>0){ + me._texturearray = []; + _.each(texture, function(item){ + me._texturearray.push({ + imageUrl: item.get_image(), + name : me.textureNames[item.get_id()], + type : item.get_id(), +// allowSelected : false, + selected: false + }); + }); + } + + if (!me._texturearray || me._texturearray.length<1) return; + if (!this._initSettings && !this.btnTexture) { this.btnTexture = new Common.UI.ComboBox({ el: $('#textart-combo-fill-texture'), template: _.template([ @@ -1358,24 +1374,19 @@ define([ this.textureMenu.render($('#textart-combo-fill-texture')); this.lockedControls.push(this.btnTexture); - var texturearray = []; - _.each(texture, function(item){ - texturearray.push({ - imageUrl: item.get_image(), - name : me.textureNames[item.get_id()], - type : item.get_id(), - selected: false + var onShowBefore = function(menu) { + var mnuTexturePicker = new Common.UI.DataView({ + el: $('#id-textart-menu-texture'), + restoreHeight: 174, + parentMenu: menu, + showLast: false, + store: new Common.UI.DataViewStore(me._texturearray || []), + itemTemplate: _.template('
') }); - }); - var mnuTexturePicker = new Common.UI.DataView({ - el: $('#id-textart-menu-texture'), - restoreHeight: 174, - parentMenu: me.textureMenu, - showLast: false, - store: new Common.UI.DataViewStore(texturearray), - itemTemplate: _.template('
') - }); - mnuTexturePicker.on('item:click', _.bind(this.onSelectTexture, this)); + mnuTexturePicker.on('item:click', _.bind(me.onSelectTexture, me)); + menu.off('show:before', onShowBefore); + }; + this.textureMenu.on('show:before', onShowBefore); } },