Refactoring buttons render

This commit is contained in:
Julia Radzhabova 2019-06-10 13:45:38 +03:00
parent 964220a560
commit 863e500d67
8 changed files with 59 additions and 127 deletions

View file

@ -822,6 +822,36 @@ Common.Utils.lockControls = function(causes, lock, opts, defControls) {
});
};
Common.Utils.injectComponents = function ($slots, id, iconCls, caption, lock, split, menu, toggle) {
var btnsArr = [];
id = id || ("id-toolbar-" + iconCls);
$slots.each(function(index, el) {
var _cls = 'btn-toolbar';
/x-huge/.test(el.className) && (_cls += ' x-huge icon-top');
var button = new Common.UI.Button({
id: id + index,
cls: _cls,
iconCls: iconCls,
caption: caption,
split: split || false,
menu: menu || false,
enableToggle: toggle || false,
lock: lock,
disabled: true
}).render( $slots.eq(index) );
btnsArr.push(button);
});
return btnsArr;
};
Common.Utils.injectComponent = function ($slot, cmp) {
if (cmp && $slot.length) {
cmp.rendered ? $slot.append(cmp.$el) : cmp.render($slot);
}
};
Common.Utils.InternalSettings.set('toolbar-height-tabs', 32);
Common.Utils.InternalSettings.set('toolbar-height-tabs-top-title', 28);
Common.Utils.InternalSettings.set('toolbar-height-controls', 67);

View file

@ -115,44 +115,17 @@ define([
Common.UI.BaseView.prototype.initialize.call(this);
this.toolbar = options.toolbar;
this.btnsContents = [];
this.btnsNotes = [];
this.btnsPrevNote = [];
this.btnsNextNote = [];
this.btnsHyperlink = [];
this.paragraphControls = [];
var me = this,
$host = me.toolbar.$el;
var _injectComponent = function (id, cmp) {
var $slot = $host.find(id);
if ($slot.length)
cmp.rendered ? $slot.append(cmp.$el) : cmp.render($slot);
};
var _injectComponents = function ($slots, iconCls, split, menu, caption, btnsArr) {
$slots.each(function(index, el) {
var _cls = 'btn-toolbar';
/x-huge/.test(el.className) && (_cls += ' x-huge icon-top');
var button = new Common.UI.Button({
id: "id-toolbar-" + iconCls + index,
cls: _cls,
iconCls: iconCls,
caption: caption,
split: split,
menu: menu,
disabled: true
}).render( $slots.eq(index) );
btnsArr.push(button);
me.paragraphControls.push(button);
});
};
_injectComponents($host.find('.btn-slot.btn-contents'), 'btn-contents', true, true, me.capBtnInsContents, me.btnsContents);
_injectComponents($host.find('.btn-slot.slot-notes'), 'btn-notes', true, true, me.capBtnInsFootnote, me.btnsNotes);
_injectComponents($host.find('.btn-slot.slot-inshyperlink'), 'btn-inserthyperlink', false, false, me.capBtnInsLink, me.btnsHyperlink);
this.btnsContents = Common.Utils.injectComponents($host.find('.btn-slot.btn-contents'), '', 'btn-contents', me.capBtnInsContents );
this.btnsNotes = Common.Utils.injectComponents($host.find('.btn-slot.slot-notes'), '', 'btn-notes', me.capBtnInsFootnote, undefined, true, true);
this.btnsHyperlink = Common.Utils.injectComponents($host.find('.btn-slot.slot-inshyperlink'), '', 'btn-inserthyperlink', me.capBtnInsLink);
this.paragraphControls = this.paragraphControls.concat(this.btnsContents, this.btnsNotes, this.btnsHyperlink);
this.btnContentsUpdate = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
@ -162,7 +135,7 @@ define([
menu: true,
disabled: true
});
_injectComponent('#slot-btn-contents-update', this.btnContentsUpdate);
Common.Utils.injectComponent($host.find('#slot-btn-contents-update'), this.btnContentsUpdate);
this.paragraphControls.push(this.btnContentsUpdate);
this.btnBookmarks = new Common.UI.Button({
@ -171,7 +144,7 @@ define([
caption: this.capBtnBookmarks,
disabled: true
});
_injectComponent('#slot-btn-bookmarks', this.btnBookmarks);
Common.Utils.injectComponent($host.find('#slot-btn-bookmarks'), this.btnBookmarks);
this.paragraphControls.push(this.btnBookmarks);
this._state = {disabled: false};
@ -258,7 +231,7 @@ define([
el: $('#id-menu-goto-footnote-prev-'+index),
cls: 'btn-toolbar'
}));
me.btnsNextNote.push(me.mnuGotoFootNext = new Common.UI.Button({
me.btnsNextNote.push(new Common.UI.Button({
el: $('#id-menu-goto-footnote-next-'+index),
cls: 'btn-toolbar'
}));

View file

@ -1259,11 +1259,7 @@ define([
rendererComponents: function (html) {
var $host = $(html);
var _injectComponent = function (id, cmp) {
var $slot = $host.find(id);
if ($slot.length) {
cmp.rendered ?
$slot.append(cmp.$el) : cmp.render($slot);
}
Common.Utils.injectComponent($host.find(id), cmp);
};
_injectComponent('#slot-field-fontname', this.cmbFontName);

View file

@ -2052,21 +2052,7 @@ define([
this.btnsComment = [];
if ( config.canCoAuthoring && config.canComments ) {
var _set = PE.enumLock;
var slots = me.toolbar.$el.find('.slot-comment');
slots.each(function(index, el) {
var _cls = 'btn-toolbar';
/x-huge/.test(el.className) && (_cls += ' x-huge icon-top');
var button = new Common.UI.Button({
id: 'tlbtn-addcomment-' + index,
cls: _cls,
iconCls: 'btn-menu-comments',
lock: [_set.lostConnect, _set.noSlides],
caption: me.toolbar.capBtnComment
}).render( slots.eq(index) );
me.btnsComment.push(button);
});
me.btnsComment = Common.Utils.injectComponents(me.toolbar.$el.find('.slot-comment'), 'tlbtn-addcomment-', 'btn-menu-comments', me.toolbar.capBtnComment, [_set.lostConnect, _set.noSlides]);
if ( this.btnsComment.length ) {
var _comments = PE.getController('Common.Controllers.Comments').getView();

View file

@ -886,11 +886,7 @@ define([
rendererComponents: function (html) {
var $host = $(html);
var _injectComponent = function (id, cmp) {
var $slot = $host.find(id);
if ($slot.length) {
cmp.rendered ?
$slot.append(cmp.$el) : cmp.render($slot);
}
Common.Utils.injectComponent($host.find(id), cmp);
};
_injectComponent('#slot-field-fontname', this.cmbFontName);

View file

@ -2195,7 +2195,7 @@ define([
}
need_disable = this._state.controlsdisabled.filters || (val===null);
toolbar.lockToolbar(SSE.enumLock.ruleFilter, need_disable,
{ array: [toolbar.btnTableTemplate].concat(toolbar.btnsSetAutofilter).concat(toolbar.btnsSortDown).concat(toolbar.btnsSortUp) });
{ array: [toolbar.btnTableTemplate].concat(toolbar.btnsSetAutofilter, toolbar.btnsSortDown, toolbar.btnsSortUp) });
val = (formatTableInfo) ? formatTableInfo.asc_getTableStyleName() : null;
if (this._state.tablestylename !== val && this.toolbar.mnuTableTemplatePicker) {
@ -2225,10 +2225,10 @@ define([
toolbar.lockToolbar(SSE.enumLock.multiselect, this._state.multiselect, { array: [toolbar.btnTableTemplate, toolbar.btnInsertHyperlink]});
this._state.inpivot = !!info.asc_getPivotTableInfo();
toolbar.lockToolbar(SSE.enumLock.editPivot, this._state.inpivot, { array: [toolbar.btnMerge, toolbar.btnInsertHyperlink].concat(toolbar.btnsSetAutofilter).concat(toolbar.btnsClearAutofilter).concat(toolbar.btnsSortDown).concat(toolbar.btnsSortUp)});
toolbar.lockToolbar(SSE.enumLock.editPivot, this._state.inpivot, { array: [toolbar.btnMerge, toolbar.btnInsertHyperlink].concat(toolbar.btnsSetAutofilter, toolbar.btnsClearAutofilter, toolbar.btnsSortDown, toolbar.btnsSortUp)});
need_disable = !this.appConfig.canModifyFilter;
toolbar.lockToolbar(SSE.enumLock.cantModifyFilter, need_disable, { array: [toolbar.btnTableTemplate, toolbar.btnClearStyle.menu.items[0], toolbar.btnClearStyle.menu.items[2] ].concat(toolbar.btnsSetAutofilter).concat(toolbar.btnsSortDown).concat(toolbar.btnsSortUp)});
toolbar.lockToolbar(SSE.enumLock.cantModifyFilter, need_disable, { array: [toolbar.btnTableTemplate, toolbar.btnClearStyle.menu.items[0], toolbar.btnClearStyle.menu.items[2] ].concat(toolbar.btnsSetAutofilter, toolbar.btnsSortDown, toolbar.btnsSortUp)});
}
@ -3150,21 +3150,7 @@ define([
this.btnsComment = [];
if ( config.canCoAuthoring && config.canComments ) {
var _set = SSE.enumLock;
var slots = me.toolbar.$el.find('.slot-comment');
slots.each(function(index, el) {
var _cls = 'btn-toolbar';
/x-huge/.test(el.className) && (_cls += ' x-huge icon-top');
var button = new Common.UI.Button({
id: 'tlbtn-addcomment-' + index,
cls: _cls,
iconCls: 'btn-menu-comments',
lock: [_set.lostConnect, _set.commentLock],
caption: me.toolbar.capBtnComment
}).render( slots.eq(index) );
me.btnsComment.push(button);
});
me.btnsComment = Common.Utils.injectComponents(me.toolbar.$el.find('.slot-comment'), 'tlbtn-addcomment-', 'btn-menu-comments', me.toolbar.capBtnComment, [_set.lostConnect, _set.commentLock]);
if ( this.btnsComment.length ) {
var _comments = SSE.getController('Common.Controllers.Comments').getView();

View file

@ -105,33 +105,6 @@ define([
$host = me.toolbar.$el,
_set = SSE.enumLock;
var _injectComponent = function (id, cmp) {
var $slot = $host.find(id);
if ($slot.length)
cmp.rendered ? $slot.append(cmp.$el) : cmp.render($slot);
};
var _injectComponents = function ($slots, iconCls, split, menu, caption, toggle, lock, btnsArr) {
$slots.each(function(index, el) {
var _cls = 'btn-toolbar';
/x-huge/.test(el.className) && (_cls += ' x-huge icon-top');
var button = new Common.UI.Button({
id: "id-toolbar-" + iconCls + index,
cls: _cls,
iconCls: iconCls,
caption: caption,
split: split,
menu: menu,
lock: lock,
disabled: true
}).render( $slots.eq(index) );
btnsArr.push(button);
me.lockedControls.push(button);
});
};
this.btnGroup = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
iconCls: 'btn-cell-group',
@ -140,7 +113,7 @@ define([
disabled: true,
lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth]
});
_injectComponent('#slot-btn-group', this.btnGroup);
Common.Utils.injectComponent($host.find('#slot-btn-group'), this.btnGroup);
this.lockedControls.push(this.btnGroup);
this.btnUngroup = new Common.UI.Button({
@ -152,7 +125,7 @@ define([
disabled: true,
lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth]
});
_injectComponent('#slot-btn-ungroup', this.btnUngroup);
Common.Utils.injectComponent($host.find('#slot-btn-ungroup'), this.btnUngroup);
this.lockedControls.push(this.btnUngroup);
this.btnTextToColumns = new Common.UI.Button({
@ -163,7 +136,7 @@ define([
disabled: true,
lock: [_set.multiselect, _set.multiselectCols, _set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth]
});
_injectComponent('#slot-btn-text-column', this.btnTextToColumns);
Common.Utils.injectComponent($host.find('#slot-btn-text-column'), this.btnTextToColumns);
this.lockedControls.push(this.btnTextToColumns);
this.btnShow = new Common.UI.Button({
@ -173,7 +146,7 @@ define([
caption: this.capBtnTextShow,
lock : [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth]
});
_injectComponent('#slot-btn-show-details', this.btnShow);
Common.Utils.injectComponent($host.find('#slot-btn-show-details'), this.btnShow);
this.lockedControls.push(this.btnShow);
this.btnHide = new Common.UI.Button({
@ -183,24 +156,22 @@ define([
caption: this.capBtnTextHide,
lock : [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth]
});
_injectComponent('#slot-btn-hide-details', this.btnHide);
Common.Utils.injectComponent($host.find('#slot-btn-hide-details'), this.btnHide);
this.lockedControls.push(this.btnHide);
_injectComponents($host.find('.slot-sortdesc'), 'btn-sort-down', false, false, '', false,
[_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.editPivot, _set.cantModifyFilter],
this.btnsSortDown);
this.btnsSortDown = Common.Utils.injectComponents($host.find('.slot-sortdesc'), '', 'btn-sort-down', '',
[_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.editPivot, _set.cantModifyFilter]);
_injectComponents($host.find('.slot-sortasc'), 'btn-sort-up', false, false, '', false,
[_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.editPivot, _set.cantModifyFilter],
this.btnsSortUp);
this.btnsSortUp = Common.Utils.injectComponents($host.find('.slot-sortasc'), '', 'btn-sort-up', '',
[_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.editPivot, _set.cantModifyFilter]);
_injectComponents($host.find('.slot-btn-setfilter'), 'btn-autofilter', false, false, '', true,
this.btnsSetAutofilter = Common.Utils.injectComponents($host.find('.slot-btn-setfilter'), '', 'btn-autofilter', '',
[_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.editPivot, _set.cantModifyFilter],
this.btnsSetAutofilter);
false, false, true);
_injectComponents($host.find('.slot-btn-clear-filter'), 'btn-clear-filter', false, false, '', false,
[_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleDelFilter, _set.editPivot],
this.btnsClearAutofilter);
this.btnsClearAutofilter = Common.Utils.injectComponents($host.find('.slot-btn-clear-filter'), '', 'btn-clear-filter', '',
[_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleDelFilter, _set.editPivot]);
this.lockedControls = this.lockedControls.concat(this.btnsSortDown, this.btnsSortUp, this.btnsSetAutofilter,this.btnsClearAutofilter);
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
},

View file

@ -1487,13 +1487,7 @@ define([
rendererComponents: function(html) {
var $host = $(html);
var _injectComponent = function (id, cmp) {
if ( cmp ) {
var $slot = $host.find(id);
if ( $slot.length ) {
cmp.rendered ?
$slot.append(cmp.$el) : cmp.render($slot);
}
}
Common.Utils.injectComponent($host.find(id), cmp);
};
_injectComponent('#slot-field-fontname', this.cmbFontName);