[DE] Add handler to zoom buttons in view tab

This commit is contained in:
JuliaSvinareva 2021-12-09 16:06:11 +03:00
parent 4b29c97952
commit cd1f2105f2
2 changed files with 45 additions and 2 deletions

View file

@ -64,7 +64,7 @@ define([
setApi: function (api) {
if (api) {
this.api = api;
this.api.asc_registerCallback('asc_onZoomChange', _.bind(this.onZoomChange, this));
}
return this;
},
@ -77,7 +77,9 @@ define([
});
this.addListeners({
'ViewTab': {
'zoom:value': _.bind(this.onChangeZoomValue, this),
'zoom:topage': _.bind(this.onBtnZoomTo, this, 'topage'),
'zoom:towidth': _.bind(this.onBtnZoomTo, this, 'towidth')
},
'Statusbar': {
@ -134,5 +136,33 @@ define([
}
},
onZoomChange: function (percent, type) {
this.view.btnFitToPage.toggle(type == 2, true);
this.view.btnFitToWidth.toggle(type == 1, true);
this.view.cmbZoom.setValue(percent, percent + '%');
},
onChangeZoomValue: function (value) {
this.api.zoom(value);
Common.NotificationCenter.trigger('edit:complete', this.view);
},
onBtnZoomTo: function(type) {
var btn, func;
if ( type === 'topage' ) {
btn = 'btnFitToPage';
func = 'zoomFitToPage';
} else {
btn = 'btnFitToWidth';
func = 'zoomFitToWidth';
}
if ( !this.view[btn].pressed )
this.api.zoomCustomMode();
else
this.api[func]();
Common.NotificationCenter.trigger('edit:complete', this.view);
},
}, DE.Controllers.ViewTab || {}));
});

View file

@ -54,6 +54,15 @@ define([
me.btnNavigation && me.btnNavigation.on('click', function (btn, e) {
me.fireEvent('viewtab:navigation', [btn.pressed]);
});
me.cmbZoom && me.cmbZoom.on('selected', function (combo, record) {
me.fireEvent('zoom:value', [record.value]);
});
me.btnFitToPage && me.btnFitToPage.on('click', function () {
me.fireEvent('zoom:topage');
});
me.btnFitToWidth && me.btnFitToWidth.on('click', function () {
me.fireEvent('zoom:towidth');
});
},
initialize: function (options) {
@ -107,6 +116,8 @@ define([
cls: 'btn-toolbar',
iconCls: 'toolbar__icon btn-ic-zoomtopage',
caption: this.textFitToPage,
toggleGroup: 'view-zoom',
enableToggle: true,
dataHint: '1',
dataHintDirection: 'left',
dataHintOffset: 'medium'
@ -118,6 +129,8 @@ define([
cls: 'btn-toolbar',
iconCls: 'toolbar__icon btn-ic-zoomtowidth',
caption: this.textFitToWidth,
toggleGroup: 'view-zoom',
enableToggle: true,
dataHint: '1',
dataHintDirection: 'left',
dataHintOffset: 'medium'