/** * SlideSizeSettings.js * * Created by Julia Radzhabova on 4/19/14 * Copyright (c) 2014 Ascensio System SIA. All rights reserved. * */ define([ 'common/main/lib/component/Window', 'common/main/lib/component/ComboBox' ], function () { 'use strict'; PE.Views.SlideSizeSettings = Common.UI.Window.extend(_.extend({ options: { width: 250, header: true, style: 'min-width: 250px;', cls: 'modal-dlg', id: 'window-slide-size-settings' }, initialize : function(options) { _.extend(this.options, { title: this.textTitle }, options || {}); this.template = [ '
', '
', '', '
', '
', '', '', '', '', '', '
', '', '
', '
', '', '
', '
', '
', '
', '' ].join(''); this.options.tpl = _.template(this.template, this.options); this.spinners = []; this._noApply = false; Common.UI.Window.prototype.initialize.call(this, this.options); }, render: function() { Common.UI.Window.prototype.render.call(this); this.cmbSlideSize = new Common.UI.ComboBox({ el: $('#slide-size-combo'), cls: 'input-group-nr', style: 'width: 100%;', menuStyle: 'min-width: 218px;', editable: false, data: [ {value:0, displayValue: this.txtStandard , size: [254, 190.5]}, {value:1, displayValue: this.txtWidescreen1 , size: [254, 143]}, {value:2, displayValue: this.txtWidescreen2 , size: [254, 158.7]}, {value:3, displayValue: this.txtLetter , size: [254, 190.5]}, {value:4, displayValue: this.txtLedger , size: [338.3, 253.7]}, {value:5, displayValue: this.txtA3 , size: [355.6, 266.7]}, {value:6, displayValue: this.txtA4 , size: [275, 190.5]}, {value:7, displayValue: this.txtB4 , size: [300.7, 225.5]}, {value:8, displayValue: this.txtB5 , size: [199.1, 149.3]}, {value:9, displayValue: this.txt35 , size: [285.7, 190.5]}, {value:10, displayValue: this.txtOverhead , size: [254, 190.5]}, {value:11, displayValue: this.txtBanner , size: [203.2, 25.4]}, {value:-1, displayValue: this.txtCustom , size: []} ] }); this.cmbSlideSize.setValue(0); this.cmbSlideSize.on('selected', _.bind(function(combo, record) { this._noApply = true; if (record.value<0) { // set current slide size } else { this.spnWidth.setValue(Common.Utils.Metric.fnRecalcFromMM(record.size[0]), true); this.spnHeight.setValue(Common.Utils.Metric.fnRecalcFromMM(record.size[1]), true); } this._noApply = false; }, this)); this.spnWidth = new Common.UI.MetricSpinner({ el: $('#slide-size-spin-width'), step: .1, width: 98, defaultUnit : "cm", value: '25.4 cm', maxValue: 55.88, minValue: 0 }); this.spinners.push(this.spnWidth); this.spnWidth.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (!this._noApply && this.cmbSlideSize.getValue() >-1) { this.cmbSlideSize.setValue(-1); } }, this)); this.spnHeight = new Common.UI.MetricSpinner({ el: $('#slide-size-spin-height'), step: .1, width: 98, defaultUnit : "cm", value: '19.05 cm', maxValue: 55.88, minValue: 0 }); this.spinners.push(this.spnHeight); this.spnHeight.on('change', _.bind(function(field, newValue, oldValue, eOpts){ if (!this._noApply && this.cmbSlideSize.getValue() >-1) { this.cmbSlideSize.setValue(-1); } }, this)); var $window = this.getChild(); $window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); $window.find('input').on('keypress', _.bind(this.onKeyPress, this)); this.updateMetricUnit(); }, _handleInput: function(state) { if (this.options.handler) { this.options.handler.call(this, this, state); } this.close(); }, onBtnClick: function(event) { this._handleInput(event.currentTarget.attributes['result'].value); }, onKeyPress: function(event) { if (event.keyCode == Common.UI.Keys.RETURN) { this._handleInput('ok'); } }, setSettings: function (type, pagewitdh, pageheight) { this.spnWidth.setValue(Common.Utils.Metric.fnRecalcFromMM(pagewitdh), true); this.spnHeight.setValue(Common.Utils.Metric.fnRecalcFromMM(pageheight), true); this.cmbSlideSize.setValue(type); }, getSettings: function() { var props = [this.cmbSlideSize.getValue(), Common.Utils.Metric.fnRecalcToMM(this.spnWidth.getNumberValue()), Common.Utils.Metric.fnRecalcToMM(this.spnHeight.getNumberValue())]; return props; }, updateMetricUnit: function() { if (this.spinners) { for (var i=0; i