diff --git a/apps/documenteditor/main/app/controller/ViewTab.js b/apps/documenteditor/main/app/controller/ViewTab.js index 2194829bc..4f8128f23 100644 --- a/apps/documenteditor/main/app/controller/ViewTab.js +++ b/apps/documenteditor/main/app/controller/ViewTab.js @@ -168,11 +168,12 @@ define([ this.view.btnFitToWidth.toggle(type == 1, true); this.view.cmbZoom.setValue(percent, percent + '%'); + + this._state.zoomValue = percent; }, applyZoom: function (value) { - var val = parseFloat(value); - val = isNaN(val) ? 25 : Math.max(25, Math.min(500, val)); + var val = Math.max(25, Math.min(500, value)); this.api.zoom(val); Common.NotificationCenter.trigger('edit:complete', this.view); }, @@ -182,24 +183,20 @@ define([ }, onZoomChanged: function (before, combo, record, e) { - var me = this; + var value = parseFloat(record.value); if (before) { - var value = parseFloat(record.value), - expr = new RegExp('^\\s*(\\d*(\\.|,)?\\d+)\\s*(%)?\\s*$'); - if (!(expr.exec(record.value)) || value<25 || value>500) { - setTimeout( function() { - Common.UI.error({ - msg: me.textZoomErr, - callback: function() { - _.defer(function() { - me.fireEvent('editcomplete', me); - }) - } - }); - }, 10); + var expr = new RegExp('^\\s*(\\d*(\\.|,)?\\d+)\\s*(%)?\\s*$'); + if (!expr.exec(record.value)) { + this.view.cmbZoom.setValue(this._state.zoomValue, this._state.zoomValue + '%'); + Common.NotificationCenter.trigger('edit:complete', this.view); } - } else - this.applyZoom(record.value); + } else { + if (this._state.zoomValue !== value && !isNaN(value)) { + this.applyZoom(value); + } else if (record.value !== this._state.zoomValue + '%') { + this.view.cmbZoom.setValue(this._state.zoomValue, this._state.zoomValue + '%'); + } + } }, onBtnZoomTo: function(type) { @@ -246,10 +243,8 @@ define([ }, onComboBlur: function() { - this.fireEvent('editcomplete', this); - }, - - textZoomErr: 'The entered value is incorrect.
Please enter a value between 25% and 500%.' + Common.NotificationCenter.trigger('edit:complete', this.view); + } }, DE.Controllers.ViewTab || {})); }); \ No newline at end of file diff --git a/apps/presentationeditor/main/app/controller/ViewTab.js b/apps/presentationeditor/main/app/controller/ViewTab.js index dd0ebd423..bfd39f5fc 100644 --- a/apps/presentationeditor/main/app/controller/ViewTab.js +++ b/apps/presentationeditor/main/app/controller/ViewTab.js @@ -82,7 +82,6 @@ define([ }); this.addListeners({ 'ViewTab': { - 'zoom:value': _.bind(this.onChangeZoomValue, this), 'zoom:toslide': _.bind(this.onBtnZoomTo, this, 'toslide'), 'zoom:towidth': _.bind(this.onBtnZoomTo, this, 'towidth'), 'rulers:change': _.bind(this.onChangeRulers, this), @@ -141,6 +140,10 @@ define([ accept(); })).then(function () { me.view.setEvents(); + me.view.cmbZoom.on('selected', _.bind(me.onSelectedZoomValue, me)) + .on('changed:before',_.bind(me.onZoomChanged, me, true)) + .on('changed:after', _.bind(me.onZoomChanged, me, false)) + .on('combo:blur', _.bind(me.onComboBlur, me, false)); }); var menuItems = [], @@ -165,13 +168,6 @@ define([ } }, - onChangeZoomValue: function (value) { - this._state.zoom_type = undefined; - this._state.zoom_percent = undefined; - this.api.zoom(value); - Common.NotificationCenter.trigger('edit:complete', this.view); - }, - onBtnZoomTo: function (type, btn) { this._state.zoom_type = undefined; this._state.zoom_percent = undefined; @@ -207,5 +203,38 @@ define([ } }, + applyZoom: function (value) { + this._state.zoom_percent = undefined; + this._state.zoom_type = undefined; + var val = Math.max(25, Math.min(500, value)); + this.api.zoom(val); + Common.NotificationCenter.trigger('edit:complete', this.view); + }, + + onSelectedZoomValue: function (combo, record) { + this.applyZoom(record.value); + }, + + onZoomChanged: function (before, combo, record, e) { + var value = parseFloat(record.value); + if (before) { + var expr = new RegExp('^\\s*(\\d*(\\.|,)?\\d+)\\s*(%)?\\s*$'); + if (!expr.exec(record.value)) { + this.view.cmbZoom.setValue(this._state.zoom_percent, this._state.zoom_percent + '%'); + Common.NotificationCenter.trigger('edit:complete', this.view); + } + } else { + if (this._state.zoom_percent !== value && !isNaN(value)) { + this.applyZoom(value); + } else if (record.value !== this._state.zoom_percent + '%') { + this.view.cmbZoom.setValue(this._state.zoom_percent, this._state.zoom_percent + '%'); + } + } + }, + + onComboBlur: function() { + Common.NotificationCenter.trigger('edit:complete', this.view); + } + }, PE.Controllers.ViewTab || {})); }); \ No newline at end of file diff --git a/apps/presentationeditor/main/app/view/ViewTab.js b/apps/presentationeditor/main/app/view/ViewTab.js index e493256c6..b9b3a6f1a 100644 --- a/apps/presentationeditor/main/app/view/ViewTab.js +++ b/apps/presentationeditor/main/app/view/ViewTab.js @@ -51,9 +51,6 @@ define([ setEvents: function () { var me = this; - me.cmbZoom && me.cmbZoom.on('selected', function (combo, record) { - me.fireEvent('zoom:value', [record.value]); - }); me.btnFitToSlide && me.btnFitToSlide.on('click', function () { me.fireEvent('zoom:toslide', [me.btnFitToSlide]); }); @@ -89,7 +86,7 @@ define([ el: $host.find('#slot-field-zoom'), cls: 'input-group-nr', menuStyle: 'min-width: 55px;', - editable: false, + editable: true, lock: [_set.disableOnStart], data: [ { displayValue: "50%", value: 50 }, diff --git a/apps/spreadsheeteditor/main/app/controller/ViewTab.js b/apps/spreadsheeteditor/main/app/controller/ViewTab.js index 3558a6314..beaa8ce92 100644 --- a/apps/spreadsheeteditor/main/app/controller/ViewTab.js +++ b/apps/spreadsheeteditor/main/app/controller/ViewTab.js @@ -85,6 +85,9 @@ define([ }); this.addListeners({ 'ViewTab': { + 'zoom:selected': _.bind(this.onSelectedZoomValue, this), + 'zoom:changedbefore': _.bind(this.onZoomChanged, this), + 'zoom:changedafter': _.bind(this.onZoomChanged, this), 'viewtab:freeze': this.onFreeze, 'viewtab:freezeshadow': this.onFreezeShadow, 'viewtab:formula': this.onViewSettings, @@ -151,13 +154,36 @@ define([ Common.NotificationCenter.trigger('edit:complete', this.view); }, - onZoom: function(zoom) { - if (this.api) { - this.api.asc_setZoom(zoom/100); - } + applyZoom: function (value) { + var val = Math.max(25, Math.min(500, value)); + this.api.asc_setZoom(val/100); Common.NotificationCenter.trigger('edit:complete', this.view); }, + onSelectedZoomValue: function (combo, record) { + this.applyZoom(record.value); + }, + + onZoomChanged: function (before, combo, record, e) { + var value = parseFloat(record.value); + if (this._state.zoomValue === undefined) { + this._state.zoomValue = 100; + } + if (before) { + var expr = new RegExp('^\\s*(\\d*(\\.|,)?\\d+)\\s*(%)?\\s*$'); + if (!expr.exec(record.value)) { + this.view.cmbZoom.setValue(this._state.zoomValue, this._state.zoomValue + '%'); + Common.NotificationCenter.trigger('edit:complete', this.view); + } + } else { + if (this._state.zoomValue !== value && !isNaN(value)) { + this.applyZoom(value); + } else if (record.value !== this._state.zoomValue + '%') { + this.view.cmbZoom.setValue(this._state.zoomValue, this._state.zoomValue + '%'); + } + } + }, + onViewSettings: function(type, value){ if (this.api) { switch (type) { @@ -245,8 +271,10 @@ define([ }, onApiZoomChange: function(zf, type){ + console.log('zoom'); var value = Math.floor((zf + .005) * 100); this.view.cmbZoom.setValue(value, value + '%'); + this._state.zoomValue = value; }, onThemeChanged: function () { diff --git a/apps/spreadsheeteditor/main/app/view/ViewTab.js b/apps/spreadsheeteditor/main/app/view/ViewTab.js index 3b69969af..b4b7e29ee 100644 --- a/apps/spreadsheeteditor/main/app/view/ViewTab.js +++ b/apps/spreadsheeteditor/main/app/view/ViewTab.js @@ -76,15 +76,21 @@ define([ this.chZeros.on('change', function (field, value) { me.fireEvent('viewtab:zeros', [3, value]); }); - this.cmbZoom.on('selected', function(combo, record) { - me.fireEvent('viewtab:zoom', [record.value]); - }); this.chToolbar.on('change', function (field, value) { me.fireEvent('viewtab:showtoolbar', [field, value !== 'checked']); }); this.chStatusbar.on('change', function (field, value) { me.fireEvent('statusbar:setcompact', [field, value === 'checked']); }); + this.cmbZoom.on('selected', function (combo, record) { + me.fireEvent('zoom:selected', [combo, record]); + }).on('changed:before', function (combo, record) { + me.fireEvent('zoom:changedbefore', [true, combo, record]); + }).on('changed:after', function (combo, record) { + me.fireEvent('zoom:changedafter', [false, combo, record]); + }).on('combo:blur', function () { + me.fireEvent('editcomplete', me); + }); } return { @@ -160,7 +166,7 @@ define([ cls : 'input-group-nr', menuStyle : 'min-width: 55px;', hint : me.tipFontSize, - editable : false, + editable : true, lock : [_set.coAuth, _set.lostConnect, _set.editCell], data : [ { displayValue: "50%", value: 50 },