diff --git a/apps/common/main/resources/less/dropdown-menu.less b/apps/common/main/resources/less/dropdown-menu.less index 5aa203037..0f0c477cf 100644 --- a/apps/common/main/resources/less/dropdown-menu.less +++ b/apps/common/main/resources/less/dropdown-menu.less @@ -57,6 +57,9 @@ margin-left: -18px; background-position: @menu-check-offset-x @menu-check-offset-y; } + &.custom-scale:before { + margin-top: 3px; + } } .menu-item-icon { diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 3884bdfd1..18d2cfa96 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -72,7 +72,8 @@ define([ this.addListeners({ 'Toolbar': { 'change:compact': this.onClickChangeCompact.bind(me), - 'change:scalespn': this.onClickChangeScaleInMenu.bind(me) + 'change:scalespn': this.onClickChangeScaleInMenu.bind(me), + 'click:customscale': this.onScaleClick.bind(me) }, 'FileMenu': { 'menu:hide': me.onFileMenu.bind(me, 'hide'), @@ -1841,11 +1842,9 @@ define([ } else { this._state.scale = 5; } - if (this.toolbar.spnScale) { - this.toolbar.spnScale.setValue(scale); - } + this.toolbar.setValueCustomScale(scale); } else if (scale === undefined) { - this.toolbar.spnScale.setValue(this.api.asc_getPageOptions().asc_getPageSetup().asc_getScale()); + this.toolbar.setValueCustomScale(this.api.asc_getPageOptions().asc_getPageSetup().asc_getScale()); } _.each(this.toolbar.btnScale.menu.items, function(item){ if (item.value === me._state.scale) { @@ -3394,52 +3393,76 @@ define([ Common.NotificationCenter.trigger('edit:complete', this.toolbar); }, - onClickChangeScaleInMenu: function(scale) { + onClickChangeScaleInMenu: function(type, curScale) { if (this.api) { + var scale; + if (type === 'up') { + if (curScale % 5 > 0.001) { + scale = Math.ceil(curScale / 5) * 5; + } else { + scale = curScale + 5; + } + } else { + if (curScale % 5 > 0.001) { + scale = Math.floor(curScale / 5) * 5; + } else { + scale = curScale - 5; + } + } + if (scale > 400) { + scale = 400; + } else if (scale < 10) { + scale = 10; + } this.api.asc_SetPrintScale(0, 0, scale); this.onChangeScaleSettings(0, 0, scale); } }, - onScaleClick: function(menu, item, state) { + onScaleClick: function(menu, item, event, scale) { var me = this; if (me.api) { - switch (item.value) { - case 0: - me.api.asc_SetPrintScale(0, 0, 100); - me._state.scale = 0; - break; - case 1: - me.api.asc_SetPrintScale(1, 1, 100); - me._state.scale = 1; - break; - case 2: - me.api.asc_SetPrintScale(1, 0, 100); - me._state.scale = 2; - break; - case 3: - me.api.asc_SetPrintScale(0, 1, 100); - me._state.scale = 3; - break; - case 5: - var win = new SSE.Views.ScaleDialog({ - api: me.api, - props: null, - handler: function(dlg, result) { - if (dlg == 'ok') { - if (me.api && result) { - me.api.asc_SetPrintScale(result.width, result.height, result.scale); - me.onChangeScaleSettings(result.width, result.height, result.scale); + if (scale !== undefined) { + me.api.asc_SetPrintScale(0, 0, scale); + me._state.scale = 4; + } else { + switch (item.value) { + case 0: + me.api.asc_SetPrintScale(0, 0, 100); + me._state.scale = 0; + break; + case 1: + me.api.asc_SetPrintScale(1, 1, 100); + me._state.scale = 1; + break; + case 2: + me.api.asc_SetPrintScale(1, 0, 100); + me._state.scale = 2; + break; + case 3: + me.api.asc_SetPrintScale(0, 1, 100); + me._state.scale = 3; + break; + case 5: + var win = new SSE.Views.ScaleDialog({ + api: me.api, + props: null, + handler: function (dlg, result) { + if (dlg == 'ok') { + if (me.api && result) { + me.api.asc_SetPrintScale(result.width, result.height, result.scale); + me.onChangeScaleSettings(result.width, result.height, result.scale); + } + me._state.scale = 5; + } else { + me.onChangeScaleSettings(); } - me._state.scale = 5; - } else { - me.onChangeScaleSettings(); + Common.NotificationCenter.trigger('edit:complete'); } - Common.NotificationCenter.trigger('edit:complete'); - } - }); - win.show(); - break; + }); + win.show(); + break; + } } } diff --git a/apps/spreadsheeteditor/main/app/view/Toolbar.js b/apps/spreadsheeteditor/main/app/view/Toolbar.js index 281198ff8..1c30dce1f 100644 --- a/apps/spreadsheeteditor/main/app/view/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/view/Toolbar.js @@ -1347,15 +1347,20 @@ define([ me.mnuCustomScale = new Common.UI.MenuItem({ template: _.template([ - '
', - '', - '
', + '
', + 'data-stopPropagation="true"', + '<% } %>', '>', + '', + '', + '', + '', '
' ].join('')), stopPropagation: true, - value: 4, toggleGroup: 'menuScale', - checkable: true + checkable: true, + value: 4 }); me.btnScale = new Common.UI.Button({ @@ -1473,24 +1478,39 @@ define([ onAfterShowMenuScale: function () { var me = this; - if (!this.spnScale) { - this.spnScale = new Common.UI.MetricSpinner({ - el: $('#spn-scale-settings'), - step: 1, - width: 80, - defaultUnit: "%", - maxValue: 400, - minValue: 10, - defaultValue: '100 %' - }); - if (this.api) { - var scale = this.api.asc_getPageOptions().asc_getPageSetup().asc_getScale(); - this.spnScale.setValue(scale); - } - this.spnScale.on('change', _.bind(function(field){ - me.fireEvent('change:scalespn', [field.getNumberValue()]); + if (me.api) { + var scale = me.api.asc_getPageOptions().asc_getPageSetup().asc_getScale(); + $('#value-custom-scale', me.mnuCustomScale.$el).html(scale + '%'); + me.valueCustomScale = scale; + } + if (!me.itemCustomScale) { + me.itemCustomScale = $('.custom-scale', me.mnuCustomScale.$el).on('click', _.bind(function () { + me.fireEvent('click:customscale', [undefined, undefined, undefined, me.valueCustomScale], this); }, this)); } + if (!me.btnCustomScaleUp) { + me.btnCustomScaleUp = new Common.UI.Button({ + el: $('#custom-scale-up', me.mnuCustomScale.$el), + cls: 'btn-toolbar' + }).on('click', _.bind(function () { + me.fireEvent('change:scalespn', ['up', me.valueCustomScale], this); + }, this)); + } + if (!me.btnCustomScaleDown) { + me.btnCustomScaleDown = new Common.UI.Button({ + el: $('#custom-scale-down', me.mnuCustomScale.$el), + cls: 'btn-toolbar' + }).on('click', _.bind(function () { + me.fireEvent('change:scalespn', ['down', me.valueCustomScale], this); + }, this)); + } + }, + + setValueCustomScale: function(val) { + if (this.api && val !== null && val !== undefined) { + $('#value-custom-scale', this.mnuCustomScale.$el).html(val + '%'); + this.valueCustomScale = val; + } }, render: function (mode) {