diff --git a/apps/documenteditor/main/app/controller/ViewTab.js b/apps/documenteditor/main/app/controller/ViewTab.js index 36beb7c6d..2194829bc 100644 --- a/apps/documenteditor/main/app/controller/ViewTab.js +++ b/apps/documenteditor/main/app/controller/ViewTab.js @@ -80,7 +80,6 @@ define([ }); this.addListeners({ 'ViewTab': { - 'zoom:value': _.bind(this.onChangeZoomValue, this), 'zoom:topage': _.bind(this.onBtnZoomTo, this, 'topage'), 'zoom:towidth': _.bind(this.onBtnZoomTo, this, 'towidth'), 'rulers:change': _.bind(this.onChangeRulers, this), @@ -125,6 +124,11 @@ define([ })).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)); + me.getApplication().getController('LeftMenu').leftMenu.btnNavigation.on('toggle', function (btn, state) { if (state !== me.view.btnNavigation.pressed) me.view.turnNavigation(state); @@ -166,11 +170,38 @@ define([ this.view.cmbZoom.setValue(percent, percent + '%'); }, - onChangeZoomValue: function (value) { - this.api.zoom(value); + applyZoom: function (value) { + var val = parseFloat(value); + val = isNaN(val) ? 25 : Math.max(25, Math.min(500, val)); + 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 me = this; + 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); + } + } else + this.applyZoom(record.value); + }, + onBtnZoomTo: function(type) { var btn, func; if ( type === 'topage' ) { @@ -214,5 +245,11 @@ define([ } }, + onComboBlur: function() { + this.fireEvent('editcomplete', this); + }, + + textZoomErr: 'The entered value is incorrect.
Please enter a value between 25% and 500%.' + }, DE.Controllers.ViewTab || {})); }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/view/ViewTab.js b/apps/documenteditor/main/app/view/ViewTab.js index 8e2710c58..1dec42cd3 100644 --- a/apps/documenteditor/main/app/view/ViewTab.js +++ b/apps/documenteditor/main/app/view/ViewTab.js @@ -54,9 +54,6 @@ define([ me.btnNavigation.on('click', function (btn, e) { me.fireEvent('viewtab:navigation', [btn.pressed]); }); - me.cmbZoom.on('selected', function (combo, record) { - me.fireEvent('zoom:value', [record.value]); - }); me.btnFitToPage.on('click', function () { me.fireEvent('zoom:topage'); }); @@ -104,7 +101,7 @@ define([ el: $host.find('#slot-field-zoom'), cls: 'input-group-nr', menuStyle: 'min-width: 55px;', - editable: false, + editable: true, disabled: true, data: [ { displayValue: "50%", value: 50 },