Refactoring loading textarts

This commit is contained in:
Julia Radzhabova 2019-08-21 17:08:21 +03:00
parent 8332c3b133
commit e9bf021e17
6 changed files with 87 additions and 69 deletions

View file

@ -103,6 +103,7 @@ define([
this.diagramEditor = null; this.diagramEditor = null;
this._isAddingShape = false; this._isAddingShape = false;
this.editMode = true; this.editMode = true;
this.binding = {};
this.addListeners({ this.addListeners({
'Toolbar': { 'Toolbar': {
@ -2562,8 +2563,7 @@ define([
fillTextArt: function() { fillTextArt: function() {
if (!this.toolbar.btnInsertTextArt.rendered) return; if (!this.toolbar.btnInsertTextArt.rendered) return;
var me = this;
if (this.toolbar.mnuTextArtPicker) { if (this.toolbar.mnuTextArtPicker) {
var models = this.getApplication().getCollection('Common.Collections.TextArt').models, var models = this.getApplication().getCollection('Common.Collections.TextArt').models,
count = this.toolbar.mnuTextArtPicker.store.length; count = this.toolbar.mnuTextArtPicker.store.length;
@ -2575,31 +2575,36 @@ define([
} else { } else {
this.toolbar.mnuTextArtPicker.store.reset(models); this.toolbar.mnuTextArtPicker.store.reset(models);
} }
} else { } else if (!this.binding.onShowBeforeTextArt) {
this.toolbar.mnuTextArtPicker = new Common.UI.DataView({ var me = this;
el: $('#id-toolbar-menu-insart'), me.binding.onShowBeforeTextArt = function(menu) {
store: this.getApplication().getCollection('Common.Collections.TextArt'), me.toolbar.mnuTextArtPicker = new Common.UI.DataView({
parentMenu: this.toolbar.btnInsertTextArt.menu, el: $('#id-toolbar-menu-insart'),
showLast: false, store: me.getApplication().getCollection('Common.Collections.TextArt'),
itemTemplate: _.template('<div class="item-art"><img src="<%= imageUrl %>" id="<%= id %>" style="width:50px;height:50px;"></div>') parentMenu: menu,
}); showLast: false,
itemTemplate: _.template('<div class="item-art"><img src="<%= imageUrl %>" id="<%= id %>" style="width:50px;height:50px;"></div>')
});
this.toolbar.mnuTextArtPicker.on('item:click', function(picker, item, record, e) { me.toolbar.mnuTextArtPicker.on('item:click', function(picker, item, record, e) {
if (me.api) { if (me.api) {
if (record) { if (record) {
me.toolbar.fireEvent('inserttextart', me.toolbar); me.toolbar.fireEvent('inserttextart', me.toolbar);
me.api.AddTextArt(record.get('data')); me.api.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');
} }
});
if (me.toolbar.btnInsertShape.pressed) menu.off('show:before', me.binding.onShowBeforeTextArt);
me.toolbar.btnInsertShape.toggle(false, true); };
me.toolbar.btnInsertTextArt.menu.on('show:before', me.binding.onShowBeforeTextArt);
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');
}
});
} }
}, },

View file

@ -985,15 +985,17 @@ define([
}, },
createDelayedElements: function() { createDelayedElements: function() {
this._initSettings = false;
this.createDelayedControls(); this.createDelayedControls();
this.UpdateThemeColors(); this.UpdateThemeColors();
this.fillTransform(this.api.asc_getPropertyEditorTextArts()); this.fillTransform(this.api.asc_getPropertyEditorTextArts());
this._initSettings = false; this.fillTextArt();
}, },
fillTextArt: function() { fillTextArt: function() {
if (this._initSettings) return;
var me = this; var me = this;
if (!this.cmbTextArt) { if (!this.cmbTextArt) {
this.cmbTextArt = new Common.UI.ComboDataView({ this.cmbTextArt = new Common.UI.ComboDataView({
itemWidth: 50, itemWidth: 50,
@ -1132,7 +1134,6 @@ define([
this.colorsBack.on('select', _.bind(this.onColorsBackSelect, this)); this.colorsBack.on('select', _.bind(this.onColorsBackSelect, this));
this.btnBackColor.menu.items[1].on('click', _.bind(this.addNewColor, this, this.colorsBack, this.btnBackColor)); this.btnBackColor.menu.items[1].on('click', _.bind(this.addNewColor, this, this.colorsBack, this.btnBackColor));
} }
this.colorsBorder.updateColors(Common.Utils.ThemeColor.getEffectColors(), Common.Utils.ThemeColor.getStandartColors()); this.colorsBorder.updateColors(Common.Utils.ThemeColor.getEffectColors(), Common.Utils.ThemeColor.getStandartColors());
this.colorsBack.updateColors(Common.Utils.ThemeColor.getEffectColors(), Common.Utils.ThemeColor.getStandartColors()); this.colorsBack.updateColors(Common.Utils.ThemeColor.getEffectColors(), Common.Utils.ThemeColor.getStandartColors());
this.colorsGrad.updateColors(Common.Utils.ThemeColor.getEffectColors(), Common.Utils.ThemeColor.getStandartColors()); this.colorsGrad.updateColors(Common.Utils.ThemeColor.getEffectColors(), Common.Utils.ThemeColor.getStandartColors());

View file

@ -1294,6 +1294,7 @@ define([
}, },
createDelayedElements: function() { createDelayedElements: function() {
this._initSettings = false;
this.createDelayedControls(); this.createDelayedControls();
var global_hatch_menu_map = [ var global_hatch_menu_map = [
@ -1327,8 +1328,8 @@ define([
this.PatternFillType = this.patternViewData[0].type; this.PatternFillType = this.patternViewData[0].type;
} }
this.UpdateThemeColors(); this.UpdateThemeColors();
this.fillTextArt();
this.fillTransform(this.api.asc_getPropertyEditorTextArts()); this.fillTransform(this.api.asc_getPropertyEditorTextArts());
this._initSettings = false;
}, },
onInitStandartTextures: function(texture) { onInitStandartTextures: function(texture) {
@ -1395,6 +1396,7 @@ define([
}, },
fillTextArt: function() { fillTextArt: function() {
if (this._initSettings) return;
var me = this; var me = this;
if (!this.cmbTextArt) { if (!this.cmbTextArt) {
this.cmbTextArt = new Common.UI.ComboDataView({ this.cmbTextArt = new Common.UI.ComboDataView({

View file

@ -113,6 +113,7 @@ define([
me._state = { me._state = {
hasCollaborativeChanges: undefined hasCollaborativeChanges: undefined
}; };
me.binding = {};
Common.NotificationCenter.on('app:ready', me.onAppReady.bind(this)); Common.NotificationCenter.on('app:ready', me.onAppReady.bind(this));
return this; return this;
@ -1461,21 +1462,25 @@ define([
} else { } else {
btn.textartPicker.store.reset( collection.models ); btn.textartPicker.store.reset( collection.models );
} }
} else { } else if (!this.binding.onShowBeforeTextArt) {
btn.textartPicker = new Common.UI.DataView({ me.binding.onShowBeforeTextArt = function(menu) {
el: $('#view-insert-art', btn.menu.$el), btn.textartPicker = new Common.UI.DataView({
store: collection, el: $('#view-insert-art', btn.menu.$el),
parentMenu: btn.menu, store: collection,
showLast: false, parentMenu: btn.menu,
itemTemplate: _.template('<div class="item-art"><img src="<%= imageUrl %>" id="<%= id %>" style="width:50px;height:50px;"></div>') showLast: false,
}); itemTemplate: _.template('<div class="item-art"><img src="<%= imageUrl %>" id="<%= id %>" style="width:50px;height:50px;"></div>')
});
btn.textartPicker.on('item:click', function(picker, item, record, e) { btn.textartPicker.on('item:click', function(picker, item, record, e) {
if (record) if (record)
me.fireEvent('insert:textart', [record.get('data')]); me.fireEvent('insert:textart', [record.get('data')]);
if (e.type !== 'click') btn.menu.hide(); if (e.type !== 'click') btn.menu.hide();
}); });
menu.off('show:before', me.binding.onShowBeforeTextArt);
};
me.btnInsertTextArt.menu.on('show:before', me.binding.onShowBeforeTextArt);
} }
}, },

View file

@ -173,6 +173,7 @@ define([
pgorient: undefined, pgorient: undefined,
lock_doc: undefined lock_doc: undefined
}; };
this.binding = {};
var checkInsertAutoshape = function(e, action) { var checkInsertAutoshape = function(e, action) {
var cmp = $(e.target), var cmp = $(e.target),
@ -2620,8 +2621,6 @@ define([
fillTextArt: function() { fillTextArt: function() {
if (!this.toolbar.btnInsertTextArt.rendered) return; if (!this.toolbar.btnInsertTextArt.rendered) return;
var me = this;
if ( this.toolbar.mnuTextArtPicker ) { if ( this.toolbar.mnuTextArtPicker ) {
var models = this.getApplication().getCollection('Common.Collections.TextArt').models, var models = this.getApplication().getCollection('Common.Collections.TextArt').models,
count = this.toolbar.mnuTextArtPicker.store.length; count = this.toolbar.mnuTextArtPicker.store.length;
@ -2633,31 +2632,36 @@ define([
} else { } else {
this.toolbar.mnuTextArtPicker.store.reset(models); this.toolbar.mnuTextArtPicker.store.reset(models);
} }
} else { } else if (!this.binding.onShowBeforeTextArt) {
this.toolbar.mnuTextArtPicker = new Common.UI.DataView({ var me = this;
el: $('#id-toolbar-menu-insart'), me.binding.onShowBeforeTextArt = function(menu) {
store: this.getApplication().getCollection('Common.Collections.TextArt'), me.toolbar.mnuTextArtPicker = new Common.UI.DataView({
parentMenu: this.toolbar.btnInsertTextArt.menu, el: $('#id-toolbar-menu-insart'),
showLast: false, store: me.getApplication().getCollection('Common.Collections.TextArt'),
itemTemplate: _.template('<div class="item-art"><img src="<%= imageUrl %>" id="<%= id %>" style="width:50px;height:50px;"></div>') parentMenu: menu,
}); showLast: false,
itemTemplate: _.template('<div class="item-art"><img src="<%= imageUrl %>" id="<%= id %>" style="width:50px;height:50px;"></div>')
});
this.toolbar.mnuTextArtPicker.on('item:click', me.toolbar.mnuTextArtPicker.on('item:click',
function(picker, item, record, e) { function(picker, item, record, e) {
if (record) { if (record) {
me.toolbar.fireEvent('inserttextart', me.toolbar); me.toolbar.fireEvent('inserttextart', me.toolbar);
me.api.asc_addTextArt(record.get('data')); 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');
} }
if ( me.toolbar.btnInsertShape.pressed ) );
me.toolbar.btnInsertShape.toggle(false, true); menu.off('show:before', me.binding.onShowBeforeTextArt);
};
if ( e.type !== 'click' ) me.toolbar.btnInsertTextArt.menu.on('show:before', me.binding.onShowBeforeTextArt);
me.toolbar.btnInsertTextArt.menu.hide();
Common.NotificationCenter.trigger('edit:complete', me.toolbar, me.toolbar.btnInsertTextArt);
Common.component.Analytics.trackEvent('ToolBar', 'Add Text Art');
}
);
} }
}, },

View file

@ -1298,6 +1298,7 @@ define([
}, },
createDelayedElements: function() { createDelayedElements: function() {
this._initSettings = false;
this.createDelayedControls(); this.createDelayedControls();
var global_hatch_menu_map = [ var global_hatch_menu_map = [
@ -1332,8 +1333,8 @@ define([
} }
this.UpdateThemeColors(); this.UpdateThemeColors();
this.fillTextArt();
this.fillTransform(this.api.asc_getPropertyEditorTextArts()); this.fillTransform(this.api.asc_getPropertyEditorTextArts());
this._initSettings = false;
}, },
onInitStandartTextures: function(texture) { onInitStandartTextures: function(texture) {
@ -1399,8 +1400,8 @@ define([
}, },
fillTextArt: function() { fillTextArt: function() {
if (this._initSettings) return;
var me = this; var me = this;
if (!this.cmbTextArt) { if (!this.cmbTextArt) {
this.cmbTextArt = new Common.UI.ComboDataView({ this.cmbTextArt = new Common.UI.ComboDataView({
itemWidth: 50, itemWidth: 50,