Merge pull request #186 from ONLYOFFICE/feature/buttons-set

Feature/buttons set
This commit is contained in:
Julia Radzhabova 2019-06-11 17:15:20 +03:00 committed by GitHub
commit 94e17d2d3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 253 deletions

View file

@ -822,6 +822,36 @@ Common.Utils.lockControls = function(causes, lock, opts, defControls) {
});
};
Common.Utils.injectButtons = function($slots, id, iconCls, caption, lock, split, menu, toggle) {
var btnsArr = createButtonSet();
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.add(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

@ -149,22 +149,14 @@ define([
control_plain = (control_props) ? (control_props.get_ContentControlType()==Asc.c_oAscSdtLevelType.Inline) : false;
var need_disable = paragraph_locked || in_equation || in_image || in_header || control_plain;
_.each (this.view.btnsNotes, function(item){
item.setDisabled(need_disable);
}, this);
this.view.btnsNotes.setDisabled(need_disable);
need_disable = paragraph_locked || header_locked || in_header || control_plain;
this.view.btnBookmarks.setDisabled(need_disable);
},
onApiCanAddHyperlink: function(value) {
var need_disable = !value || this._state.prcontrolsdisable;
if ( this.toolbar.editMode ) {
_.each (this.view.btnsHyperlink, function(item){
item.setDisabled(need_disable);
}, this);
}
this.toolbar.editMode && this.view.btnsHyperlink.setDisabled(!value || this._state.prcontrolsdisable);
},
onHyperlinkClick: function(btn) {

View file

@ -2832,22 +2832,7 @@ define([
me.appOptions = config;
if ( config.canCoAuthoring && config.canComments ) {
this.btnsComment = createButtonSet();
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',
caption: me.toolbar.capBtnComment
}).render( slots.eq(index) );
me.btnsComment.add(button);
});
this.btnsComment = Common.Utils.injectButtons(this.toolbar.$el.find('.slot-comment'), 'tlbtn-addcomment-', 'btn-menu-comments', this.toolbar.capBtnComment);
if ( this.btnsComment.length ) {
var _comments = DE.getController('Common.Controllers.Comments').getView();
this.btnsComment.forEach(function (btn) {

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.injectButtons($host.find('.btn-slot.btn-contents'), '', 'btn-contents', me.capBtnInsContents );
this.btnsNotes = Common.Utils.injectButtons($host.find('.btn-slot.slot-notes'), '', 'btn-notes', me.capBtnInsFootnote, undefined, true, true);
this.btnsHyperlink = Common.Utils.injectButtons($host.find('.btn-slot.slot-inshyperlink'), '', 'btn-inserthyperlink', me.capBtnInsLink);
Array.prototype.push.apply(this.paragraphControls, this.btnsContents.concat(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);
@ -1323,30 +1319,8 @@ define([
_injectComponent('#slot-img-movebkwd', this.btnImgBackward);
_injectComponent('#slot-img-wrapping', this.btnImgWrapping);
+function injectBreakButtons() {
var me = this;
me.btnsPageBreak = createButtonSet();
var $slots = $host.find('.btn-slot.btn-pagebreak');
$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({
cls: _cls,
iconCls: 'btn-pagebreak',
caption: me.capBtnInsPagebreak,
split: true,
menu: true
}).render( $slots.eq(index) );
me.btnsPageBreak.add(button);
});
me.btnsPageBreak.setDisabled(true);
Array.prototype.push.apply(me.paragraphControls, me.btnsPageBreak);
}.call(this);
this.btnsPageBreak = Common.Utils.injectButtons($host.find('.btn-slot.btn-pagebreak'), '', 'btn-pagebreak', this.capBtnInsPagebreak, undefined, true, true);
Array.prototype.push.apply(this.paragraphControls, this.btnsPageBreak);
return $host;
},

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);
});
this.btnsComment = Common.Utils.injectButtons(this.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);
@ -930,78 +926,20 @@ define([
_injectComponent('#slot-btn-slidesize', this.btnSlideSize);
_injectComponent('#slot-field-styles', this.listTheme);
function _injectBtns(opts) {
var array = createButtonSet();
var $slots = $host.find(opts.slot);
var id = opts.btnconfig.id;
$slots.each(function(index, el) {
if ( !!id ) opts.btnconfig.id = id + index;
this.btnsInsertImage = Common.Utils.injectButtons($host.find('.slot-insertimg'), 'tlbtn-insertimage-', 'btn-insertimage', this.capInsertImage,
[PE.enumLock.slideDeleted, PE.enumLock.lostConnect, PE.enumLock.noSlides, PE.enumLock.disableOnStart], false, true);
this.btnsInsertText = Common.Utils.injectButtons($host.find('.slot-instext'), 'tlbtn-inserttext-', 'btn-text', this.capInsertText,
[PE.enumLock.slideDeleted, PE.enumLock.lostConnect, PE.enumLock.noSlides, PE.enumLock.disableOnStart], false, false, true);
this.btnsInsertShape = Common.Utils.injectButtons($host.find('.slot-insertshape'), 'tlbtn-insertshape-', 'btn-insertshape', this.capInsertShape,
[PE.enumLock.slideDeleted, PE.enumLock.lostConnect, PE.enumLock.noSlides, PE.enumLock.disableOnStart], false, true, true);
this.btnsAddSlide = Common.Utils.injectButtons($host.find('.slot-addslide'), 'tlbtn-addslide-', 'btn-addslide', this.capAddSlide,
[PE.enumLock.menuFileOpen, PE.enumLock.lostConnect, PE.enumLock.disableOnStart], true, true);
var button = new Common.UI.Button(opts.btnconfig);
button.render( $slots.eq(index) );
array.add(button);
});
return array;
}
var me = this;
me.btnsInsertImage = _injectBtns({
slot: '.slot-insertimg',
btnconfig: {
id : 'tlbtn-insertimage-',
cls : 'btn-toolbar x-huge icon-top',
iconCls : 'btn-insertimage',
caption : me.capInsertImage,
lock : [PE.enumLock.slideDeleted, PE.enumLock.lostConnect, PE.enumLock.noSlides, PE.enumLock.disableOnStart],
menu : true
}
});
me.btnsInsertText = _injectBtns({
slot: '.slot-instext',
btnconfig: {
id : 'tlbtn-inserttext-',
cls : 'btn-toolbar x-huge icon-top',
iconCls : 'btn-text',
caption : me.capInsertText,
lock : [PE.enumLock.slideDeleted, PE.enumLock.lostConnect, PE.enumLock.noSlides, PE.enumLock.disableOnStart],
enableToggle: true
}
});
me.btnsInsertShape = _injectBtns({
slot: '.slot-insertshape',
btnconfig: {
id : 'tlbtn-insertshape-',
cls : 'btn-toolbar x-huge icon-top',
iconCls : 'btn-insertshape',
caption : me.capInsertShape,
lock : [PE.enumLock.slideDeleted, PE.enumLock.lostConnect, PE.enumLock.noSlides, PE.enumLock.disableOnStart],
enableToggle: true,
menu : true
}
});
me.btnsAddSlide = _injectBtns({
slot: '.slot-addslide',
btnconfig: {
id : 'tlbtn-addslide-',
cls : 'btn-toolbar x-huge icon-top',
iconCls : 'btn-addslide',
split : true,
caption : me.capAddSlide,
lock : [PE.enumLock.menuFileOpen, PE.enumLock.lostConnect, PE.enumLock.disableOnStart],
menu : true
}
});
var created = me.btnsInsertImage.concat(me.btnsInsertText, me.btnsInsertShape, me.btnsAddSlide);
var created = this.btnsInsertImage.concat(this.btnsInsertText, this.btnsInsertShape, this.btnsAddSlide);
this.lockToolbar(PE.enumLock.disableOnStart, true, {array: created});
Array.prototype.push.apply(me.slideOnlyControls, created);
Array.prototype.push.apply(me.lockControls, created);
Array.prototype.push.apply(this.slideOnlyControls, created);
Array.prototype.push.apply(this.lockControls, created);
return $host;
},

View file

@ -2185,14 +2185,12 @@ define([
val = (filterInfo) ? filterInfo.asc_getIsAutoFilter() : null;
if (this._state.filter !== val) {
toolbar.btnsSetAutofilter.forEach(function(button) {
button.toggle(val===true, true);
});
toolbar.btnsSetAutofilter.toggle(val===true, true);
this._state.filter = val;
}
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.btnsSetAutofilter.concat(toolbar.btnsSortDown, toolbar.btnsSortUp, toolbar.btnTableTemplate) });
val = (formatTableInfo) ? formatTableInfo.asc_getTableStyleName() : null;
if (this._state.tablestylename !== val && this.toolbar.mnuTableTemplatePicker) {
@ -2222,10 +2220,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.btnsSetAutofilter.concat(toolbar.btnsClearAutofilter, toolbar.btnsSortDown, toolbar.btnsSortUp, toolbar.btnMerge, toolbar.btnInsertHyperlink)});
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.btnsSetAutofilter.concat(toolbar.btnsSortDown, toolbar.btnsSortUp, toolbar.btnTableTemplate, toolbar.btnClearStyle.menu.items[0], toolbar.btnClearStyle.menu.items[2])});
}
@ -3147,21 +3145,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);
});
this.btnsComment = Common.Utils.injectButtons(this.toolbar.$el.find('.slot-comment'), 'tlbtn-addcomment-', 'btn-menu-comments', this.toolbar.capBtnComment, [_set.lostConnect, _set.commentLock]);
if ( this.btnsComment.length ) {
var _comments = SSE.getController('Common.Controllers.Comments').getView();

View file

@ -96,42 +96,11 @@ define([
this.toolbar = options.toolbar;
this.lockedControls = [];
this.btnsSortDown = [];
this.btnsSortUp = [];
this.btnsSetAutofilter = [];
this.btnsClearAutofilter = [];
var me = this,
$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 +109,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 +121,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 +132,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 +142,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 +152,23 @@ 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.injectButtons($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.injectButtons($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.injectButtons($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.injectButtons($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]);
Array.prototype.push.apply(this.lockedControls, this.btnsSortDown.concat(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);