/*
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
/**
* FileMenuPanels.js
*
* Contains views for menu 'File'
*
* Created on 20 February 2014
*
*/
define([], function () {
'use strict';
!DE.Views.FileMenuPanels && (DE.Views.FileMenuPanels = {});
DE.Views.FileMenuPanels.ViewSaveAs = Common.UI.BaseView.extend({
el: '#panel-saveas',
menu: undefined,
formats: [[
{name: 'DOCX', imgCls: 'docx', type: Asc.c_oAscFileType.DOCX},
{name: 'PDF', imgCls: 'pdf', type: Asc.c_oAscFileType.PDF},
{name: 'ODT', imgCls: 'odt', type: Asc.c_oAscFileType.ODT}
],[
{name: 'DOTX', imgCls: 'dotx', type: Asc.c_oAscFileType.DOTX},
{name: 'DOCM', imgCls: 'docm', type: Asc.c_oAscFileType.DOCM},
{name: 'PDFA', imgCls: 'pdfa', type: Asc.c_oAscFileType.PDFA},
{name: 'OTT', imgCls: 'ott', type: Asc.c_oAscFileType.OTT}
],[
{name: 'RTF', imgCls: 'rtf', type: Asc.c_oAscFileType.RTF},
{name: 'TXT', imgCls: 'txt', type: Asc.c_oAscFileType.TXT},
{name: 'FB2', imgCls: 'fb2', type: Asc.c_oAscFileType.FB2},
{name: 'EPUB', imgCls: 'epub', type: Asc.c_oAscFileType.EPUB},
{name: 'HTML (Zipped)', imgCls: 'html', type: Asc.c_oAscFileType.HTML}
], [
{name: 'JPG', imgCls: 'jpg', type: Asc.c_oAscFileType.JPG},
{name: 'PNG', imgCls: 'png', type: Asc.c_oAscFileType.PNG}
]],
template: _.template([
'
',
'
<%= tipText %>
',
'
',
'' + me.txtView + ' ',
'' + me.txtEdit + ' ',
'',
'
'
].join(''));
},
render: function() {
this.$el.html(this.template({scope: this}));
var protection = DE.getController('Common.Controllers.Protection').getView();
this.btnAddPwd = protection.getButton('add-password');
this.btnAddPwd.render(this.$el.find('#fms-btn-add-pwd'));
this.btnAddPwd.on('click', _.bind(this.closeMenu, this));
this.btnChangePwd = protection.getButton('change-password');
this.btnChangePwd.render(this.$el.find('#fms-btn-change-pwd'));
this.btnChangePwd.on('click', _.bind(this.closeMenu, this));
this.btnDeletePwd = protection.getButton('del-password');
this.btnDeletePwd.render(this.$el.find('#fms-btn-delete-pwd'));
this.btnDeletePwd.on('click', _.bind(this.closeMenu, this));
this.cntPassword = $('#id-fms-password');
this.cntEncryptBlock = this.$el.find('.encrypt-block');
this.cntEncryptedBlock = this.$el.find('.encrypted-block');
this.btnAddInvisibleSign = protection.getButton('signature');
this.btnAddInvisibleSign.render(this.$el.find('#fms-btn-invisible-sign'));
this.btnAddInvisibleSign.on('click', _.bind(this.closeMenu, this));
this.cntSignature = $('#id-fms-signature');
this.cntSignatureView = $('#id-fms-signature-view');
this.cntAddSignature = this.$el.find('.add-signature-block');
this.cntAddedSignature = this.$el.find('.added-signature-block');
if (_.isUndefined(this.scroller)) {
this.scroller = new Common.UI.Scroller({
el: this.$el,
suppressScrollX: true,
alwaysVisibleY: true
});
}
this.$el.on('click', '.signature-edit-link', _.bind(this.onEdit, this));
this.$el.on('click', '.signature-view-link', _.bind(this.onView, this));
return this;
},
show: function() {
Common.UI.BaseView.prototype.show.call(this,arguments);
this.updateSignatures();
this.updateEncrypt();
this.scroller && this.scroller.update();
},
setMode: function(mode) {
this.mode = mode;
this.cntSignature.toggleClass('hidden', !this.mode.isSignatureSupport);
this.cntPassword.toggleClass('hidden', !this.mode.isPasswordSupport);
},
setApi: function(o) {
this.api = o;
return this;
},
closeMenu: function() {
this.menu && this.menu.hide();
},
onEdit: function() {
this.menu && this.menu.hide();
var me = this;
Common.UI.warning({
title: this.notcriticalErrorTitle,
msg: this.txtEditWarning,
buttons: ['ok', 'cancel'],
primary: 'ok',
callback: function(btn) {
if (btn == 'ok') {
me.api.asc_RemoveAllSignatures();
}
}
});
},
onView: function() {
this.menu && this.menu.hide();
DE.getController('RightMenu').rightmenu.SetActivePane(Common.Utils.documentSettingsType.Signature, true);
},
updateSignatures: function(){
var requested = this.api.asc_getRequestSignatures(),
valid = this.api.asc_getSignatures(),
hasRequested = requested && requested.length>0,
hasValid = false,
hasInvalid = false;
_.each(valid, function(item, index){
if (item.asc_getValid()==0)
hasValid = true;
else
hasInvalid = true;
});
// hasRequested = true;
// hasValid = true;
// hasInvalid = true;
var tipText = (hasInvalid) ? this.txtSignedInvalid : (hasValid ? this.txtSigned : "");
if (hasRequested)
tipText = this.txtRequestedSignatures + (tipText!="" ? "
" : "")+ tipText;
this.cntSignatureView.html(this.templateSignature({tipText: tipText, hasSigned: (hasValid || hasInvalid), hasRequested: hasRequested}));
var isAddedSignature = this.btnAddInvisibleSign.$el.find('button').hasClass('hidden');
this.cntAddSignature.toggleClass('hidden', isAddedSignature);
this.cntAddedSignature.toggleClass('hidden', !isAddedSignature);
},
updateEncrypt: function() {
var isProtected = this.btnAddPwd.$el.find('button').hasClass('hidden');
this.cntEncryptBlock.toggleClass('hidden', isProtected);
this.cntEncryptedBlock.toggleClass('hidden', !isProtected);
},
strProtect: 'Protect Document',
strSignature: 'With Signature',
txtView: 'View signatures',
txtEdit: 'Edit document',
txtSigned: 'Valid signatures has been added to the document. The document is protected from editing.',
txtSignedInvalid: 'Some of the digital signatures in document are invalid or could not be verified. The document is protected from editing.',
txtRequestedSignatures: 'This document needs to be signed.',
notcriticalErrorTitle: 'Warning',
txtEditWarning: 'Editing will remove the signatures from the document.
Are you sure you want to continue?',
strEncrypt: 'With Password',
txtProtectDocument: 'Encrypt this document with a password',
txtEncrypted: 'A password is required to open this document',
txtAddSignature: 'Ensure the integrity of the document by adding an
invisible digital signature',
txtAddedSignature: 'Valid signatures have been added to the document.
The document is protected from editing.'
}, DE.Views.FileMenuPanels.ProtectDoc || {}));
DE.Views.PrintWithPreview = Common.UI.BaseView.extend(_.extend({
el: '#panel-print',
menu: undefined,
template: _.template([
'
',
'
',
'
',
'
',
'
<%= scope.txtPrint %>
',
'
',
'',
'<%= scope.txtPrinter %> ',
'
',
'<%= scope.txtColorPrinting %> ',
'
',
'<%= scope.txtPrintRange %> ',
'
',
'',
'',
'<%= scope.txtPages %>:
',
'<%= scope.txtCopies %>:
',
'
',
' ',
'<%= scope.txtPrintSides %> ',
'
',
'<%= scope.txtPageSize %> ',
'
',
'<%= scope.txtPageOrientation %> ',
'
',
'<%= scope.txtMargins %> ',
'
',
'',
'',
'',
' ',
' ',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'<% if (!isRTL) { %>',
'
',
'
',
'<% } else { %>',
'
',
'
',
'<% } %>',
'
',
'
<%= scope.txtPage %> ',
'
',
'
<%= scope.txtOf %> ',
'
',
'
',
'
',
'
'
].join('')),
initialize: function(options) {
Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.menu = options.menu;
this._defaultPaperSizeList = [
{ value: 0, displayValue: ['US Letter', '21,59', '27,94', 'cm'], caption: 'US Letter', size: [215.9, 279.4]},
{ value: 1, displayValue: ['US Legal', '21,59', '35,56', 'cm'], caption: 'US Legal', size: [215.9, 355.6]},
{ value: 2, displayValue: ['A4', '21', '29,7', 'cm'], caption: 'A4', size: [210, 297]},
{ value: 3, displayValue: ['A5', '14,8', '21', 'cm'], caption: 'A5', size: [148, 210]},
{ value: 4, displayValue: ['B5', '17,6', '25', 'cm'], caption: 'B5', size: [176, 250]},
{ value: 5, displayValue: ['Envelope #10', '10,48', '24,13', 'cm'], caption: 'Envelope #10', size: [104.8, 241.3]},
{ value: 6, displayValue: ['Envelope DL', '11', '22', 'cm'], caption: 'Envelope DL', size: [110, 220]},
{ value: 7, displayValue: ['Tabloid', '27,94', '43,18', 'cm'], caption: 'Tabloid', size: [279.4, 431.8]},
{ value: 8, displayValue: ['A3', '29,7', '42', 'cm'], caption: 'A3', size: [297, 420]},
{ value: 9, displayValue: ['Tabloid Oversize', '29,69', '45,72', 'cm'], caption: 'Tabloid Oversize', size: [296.9, 457.2]},
{ value: 10, displayValue: ['ROC 16K', '19,68', '27,3', 'cm'], caption: 'ROC 16K', size: [196.8, 273]},
{ value: 11, displayValue: ['Envelope Choukei 3', '12', '23,5', 'cm'], caption: 'Envelope Choukei 3', size: [120, 235]},
{ value: 12, displayValue: ['Super B/A3', '30,5', '48,7', 'cm'], caption: 'Super B/A3', size: [305, 487]},
{ value: 13, displayValue: ['A4', '84,1', '118,9', 'cm'], caption: 'A0', size: [841, 1189]},
{ value: 14, displayValue: ['A4', '59,4', '84,1', 'cm'], caption: 'A1', size: [594, 841]},
{ value: 16, displayValue: ['A4', '42', '59,4', 'cm'], caption: 'A2', size: [420, 594]},
{ value: 17, displayValue: ['A4', '10,5', '14,8', 'cm'], caption: 'A6', size: [105, 148]}
];
this._initSettings = true;
this._originalPageSize = undefined;
this._colorPrinting = '';
},
render: function(node) {
var me = this;
var $markup = $(this.template({scope: this, isRTL: Common.UI.isRTL()}));
this.cmbPrinter = new Common.UI.ComboBox({
el: $markup.findById('#print-combo-printer'),
menuStyle: 'width: 248px; max-height: 280px;',
editable: false,
takeFocusOnClose: true,
cls: 'input-group-nr',
placeHolder: this.txtPrinterNotSelected,
itemsTemplate: _.template([
'<% if (items.length > 0) { %>',
'<% _.each(items, function(item) { %>',
'
class="checked" <% } %> ><%= scope.getDisplayValue(item) %> ',
'<% }); %>',
'<% } %>',
'<% if(scope.options.isWatingForPrinters) { %>',
'
' + this.txtWaitingForPrinters + '
',
'<% } else if(items.length == 0) {%>',
'
' + this.txtPrintersNotFound + ' ',
'<% } %>'
].join('')),
isWatingForPrinters: true,
data: [],
dataHint: '2',
dataHintDirection: 'bottom',
dataHintOffset: 'big'
});
this.cmbPrinter.on('selected', _.bind(this.onPrinterSelected, this));
this.cmbColorPrinting = new Common.UI.ComboBox({
el: $markup.findById('#print-combo-color-printing'),
menuStyle: 'width: 248px; max-height: 280px;',
editable: false,
takeFocusOnClose: true,
cls: 'input-group-nr',
disabled: true,
data: [
{ value: 'color', displayValue: this.txtColorPrinting },
{ value: 'black-and-white', displayValue: this.txtBlackAndWhitePrinting }
],
dataHint: '2',
dataHintDirection: 'bottom',
dataHintOffset: 'big'
});
this.cmbColorPrinting.on('selected', _.bind(function(combo, record) {
this._colorPrinting = record.value
}, this));
this.cmbColorPrinting.setValue('black-and-white');
this._colorPrinting = 'black-and-white';
this.cmbRange = new Common.UI.ComboBox({
el: $markup.findById('#print-combo-range'),
menuStyle: 'min-width: 248px;max-height: 280px;',
editable: false,
takeFocusOnClose: true,
cls: 'input-group-nr',
data: [
{ value: 'all', displayValue: this.txtAllPages },
{ value: 'current', displayValue: this.txtCurrentPage },
{ value: -1, displayValue: this.txtCustomPages }
],
dataHint: '2',
dataHintDirection: 'bottom',
dataHintOffset: 'big'
});
this.cmbRange.setValue('all');
this.inputPages = new Common.UI.InputField({
el: $markup.findById('#print-txt-pages'),
allowBlank: true,
validateOnChange: true,
validateOnBlur: false,
maskExp: /[0-9,\-]/,
dataHint: '2',
dataHintDirection: 'left',
dataHintOffset: 'small'
});
this.spnCopies = new Common.UI.MetricSpinner({
el: $markup.findById('#print-txt-copies'),
step: 1,
width: 60,
defaultUnit : '',
value: 1,
maxValue: 32767,
minValue: 1,
allowDecimal: false,
maskExp: /[0-9]/,
dataHint: '2',
dataHintDirection: 'bottom',
dataHintOffset: 'big'
});
this.cmbSides = new Common.UI.ComboBox({
el : $markup.findById('#print-combo-sides'),
menuStyle : 'width:100%;',
editable: false,
takeFocusOnClose: true,
cls : 'input-group-nr',
data : [
{ value: 'one', displayValue: this.txtOneSide, descValue: this.txtOneSideDesc },
{ value: 'both-long', displayValue: this.txtBothSides, descValue: this.txtBothSidesLongDesc },
{ value: 'both-short', displayValue: this.txtBothSides, descValue: this.txtBothSidesShortDesc }
],
itemsTemplate: _.template([
'<% _.each(items, function(item) { %>',
'
',
'<%= scope.getDisplayValue(item) %> ',
'<% }); %>'
].join('')),
dataHint: '2',
dataHintDirection: 'bottom',
dataHintOffset: 'big'
});
this.cmbSides.setValue('one');
var paperSizeItemsTemplate = !Common.UI.isRTL() ?
_.template([
'<% _.each(items, function(item) { %>',
'
',
'<% if (typeof item.displayValue === "string") { %>',
'<%= item.displayValue %>',
'<% } else { %>',
'<%= item.displayValue[0] %>',
' (<%= item.displayValue[1] %> <%= item.displayValue[3] %> x',
' <%= item.displayValue[2] %> <%= item.displayValue[3] %>)',
'<% } %>',
' ',
'<% }); %>'
].join('')) :
_.template([
'<% _.each(items, function(item) { %>',
'
',
'<% if (typeof item.displayValue === "string") { %>',
'<%= item.displayValue %>',
'<% } else { %>',
'(<%= item.displayValue[2] %> <%= item.displayValue[3] %> ',
' x ',
'<%= item.displayValue[1] %> <%= item.displayValue[3] %> )',
' <%= item.displayValue[0] %> ',
'<% } %>',
' ',
'<% }); %>'
].join(''));
var paperSizeTemplate = _.template([
'
'
]).join(''));
this.cmbPaperSize = new Common.UI.ComboBoxCustom({
el: $markup.findById('#print-combo-pages'),
menuStyle: 'max-height: 280px; width: 248px;',
editable: false,
takeFocusOnClose: true,
template: paperSizeTemplate,
itemsTemplate: paperSizeItemsTemplate,
data: [].concat(this._defaultPaperSizeList, [{ value: -1, displayValue: this.txtCustom, caption: this.txtCustom, size: []}]),
dataHint: '2',
dataHintDirection: 'bottom',
dataHintOffset: 'big',
updateFormControl: function (record, customValue){
var formcontrol = $(this.el).find('.form-control');
if (record || customValue) {
var displayValue = customValue ? customValue : record.get('displayValue');
if (typeof displayValue === 'string') {
formcontrol[0].innerHTML = displayValue;
} else {
if (!Common.UI.isRTL()) {
formcontrol[0].innerHTML = displayValue[0] + ' (' + displayValue[1] + ' ' + displayValue[3] + ' x ' +
displayValue[2] + ' ' + displayValue[3] + ')';
} else {
formcontrol[0].innerHTML = '
(' + displayValue[2] + ' ' + displayValue[3] + ' ' +
' x ' + '' + displayValue[1] + ' ' + displayValue[3] + ' )' +
' ' + displayValue[0] + ' ';
}
}
} else
formcontrol[0].innerHTML = '';
}
});
this.cmbPaperOrientation = new Common.UI.ComboBox({
el : $markup.findById('#print-combo-orient'),
menuStyle : 'min-width: 150px;',
editable : false,
takeFocusOnClose: true,
cls : 'input-group-nr',
data : [
{ value: Asc.c_oAscPageOrientation.PagePortrait, displayValue: this.txtPortrait },
{ value: Asc.c_oAscPageOrientation.PageLandscape, displayValue: this.txtLandscape }
],
dataHint: '2',
dataHintDirection: 'bottom',
dataHintOffset: 'big'
});
this.cmbPaperMargins = new Common.UI.ComboBox({
el: $markup.findById('#print-combo-margins'),
menuStyle: 'max-height: 280px; min-width: 248px;',
editable: false,
takeFocusOnClose: true,
cls: 'input-group-nr',
data: [
{ value: 0, displayValue: this.textMarginsNormal, size: (/^(ca|us)$/i.test(Common.Utils.InternalSettings.get("de-config-region"))) ? [25.4, 25.4, 25.4, 25.4] : [20, 30, 20, 15]},
{ value: 2, displayValue: this.textMarginsNarrow, size: [12.7, 12.7, 12.7, 12.7]},
{ value: 3, displayValue: this.textMarginsModerate, size: [25.4, 19.1, 25.4, 19.1]},
{ value: 4, displayValue: this.textMarginsWide, size: [25.4, 50.8, 25.4, 50.8]},
{ value: -1, displayValue: this.txtCustom, size: null}
],
itemsTemplate: _.template([
'<% _.each(items, function(item) { %>',
'
',
'<%= scope.getDisplayValue(item) %>
',
'<% if (item.size !== null) { %>' +
'' + this.txtTop + ': <%= parseFloat(Common.Utils.Metric.fnRecalcFromMM(item.size[0]).toFixed(2)) %> <%= Common.Utils.Metric.getCurrentMetricName() %> ' +
'' + this.txtLeft + ': <%= parseFloat(Common.Utils.Metric.fnRecalcFromMM(item.size[1]).toFixed(2)) %> <%= Common.Utils.Metric.getCurrentMetricName() %>
' +
'' + this.txtBottom + ': <%= parseFloat(Common.Utils.Metric.fnRecalcFromMM(item.size[2]).toFixed(2)) %> <%= Common.Utils.Metric.getCurrentMetricName() %> ' +
'' + this.txtRight + ': <%= parseFloat(Common.Utils.Metric.fnRecalcFromMM(item.size[3]).toFixed(2)) %> <%= Common.Utils.Metric.getCurrentMetricName() %>
' +
'<% } %>',
'<% }); %>'
].join('')),
dataHint: '2',
dataHintDirection: 'bottom',
dataHintOffset: 'big'
});
this.pnlSettings = $markup.find('.flex-settings').addBack().filter('.flex-settings');
this.pnlTable = $(this.pnlSettings.find('table')[0]);
this.trApply = $markup.find('.fms-btn-apply');
this.btnPrintSystemDialog = $markup.find('#print-btn-system-dialog > span');
this.btnPrint = new Common.UI.Button({
el: $markup.findById('#print-btn-print'),
disabled: true
});
this.btnPrintPdf = new Common.UI.Button({
el: $markup.findById('#print-btn-print-pdf')
});
this.btnPrevPage = new Common.UI.Button({
parentEl: $markup.findById('#print-prev-page'),
cls: 'btn-prev-page',
iconCls: 'arrow',
scaling: false,
dataHint: '2',
dataHintDirection: 'top'
});
this.btnNextPage = new Common.UI.Button({
parentEl: $markup.findById('#print-next-page'),
cls: 'btn-next-page',
iconCls: 'arrow',
scaling: false,
dataHint: '2',
dataHintDirection: 'top'
});
this.countOfPages = $markup.findById('#print-count-page');
this.txtNumberPage = new Common.UI.InputField({
el: $markup.findById('#print-number-page'),
allowBlank: true,
validateOnChange: true,
style: 'width: 50px;',
maskExp: /[0-9]/,
validation: function(value) {
if (/(^[0-9]+$)/.test(value)) {
value = parseInt(value);
if (undefined !== value && value > 0 && value <= me.pageCount)
return true;
}
return me.txtPageNumInvalid;
},
dataHint: '2',
dataHintDirection: 'left',
dataHintOffset: 'small'
});
this.$el = $(node).html($markup);
this.$previewBox = $('#print-preview-box');
if (_.isUndefined(this.scroller)) {
this.scroller = new Common.UI.Scroller({
el: this.pnlSettings,
suppressScrollX: true,
alwaysVisibleY: true
});
}
Common.NotificationCenter.on({
'window:resize': function() {
me.isVisible() && me.updateScroller();
}
});
this.updateMetricUnit();
this.fireEvent('render:after', this);
return this;
},
show: function() {
Common.UI.BaseView.prototype.show.call(this,arguments);
if (this._initSettings) {
this.updateMetricUnit();
this._initSettings = false;
}
this.updateScroller();
this.fireEvent('show', this);
},
updateCmbPrinter: function(currentPrinter, printers, isWaitingForPrinters) {
const cmbPrinterOptions = (printers || []).map(function(printer) {
return {
value: printer.name,
displayValue: printer.name,
paperSupported: printer.paper_supported,
isDuplexSupported: printer.duplex_supported,
colorSupported: !!printer.color_supported
}
});
this.cmbPrinter.options.isWatingForPrinters = isWaitingForPrinters;
this.cmbPrinter.setData(cmbPrinterOptions);
let selectedPrinter = this.cmbPrinter.getValue();
if(!selectedPrinter && _.some(cmbPrinterOptions, function(option) { return option.value == currentPrinter })) {
selectedPrinter = currentPrinter;
}
if(selectedPrinter) {
const isChanged = selectedPrinter != this.cmbPrinter.getValue();
this.cmbPrinter.setValue(selectedPrinter);
if(isChanged) {
this.cmbPrinter.trigger('selected', this, this.cmbPrinter.getSelectedRecord());
}
}
},
setCmbColorPrintingDisabled: function(disabled) {
if(disabled) {
this.cmbColorPrinting.setValue('black-and-white');
} else {
this.cmbColorPrinting.setValue(this._colorPrinting);
}
this.cmbColorPrinting.setDisabled(disabled);
},
setCmbSidesOptions: function(isDuplexSupported) {
var cmbValue = this.cmbSides.getValue();
var list = [{ value: 'one', displayValue: this.txtOneSide, descValue: this.txtOneSideDesc }];
if(isDuplexSupported) {
list.push(
{ value: 'both-long', displayValue: this.txtBothSides, descValue: this.txtBothSidesLongDesc },
{ value: 'both-short', displayValue: this.txtBothSides, descValue: this.txtBothSidesShortDesc }
);
} else if(cmbValue != 'one') {
cmbValue = 'one';
}
this.cmbSides.setData(list);
this.cmbSides.setValue(cmbValue);
},
setCmbPaperSizeOptions: function(paperSizeList) {
var resultList = [];
if(paperSizeList && paperSizeList.length > 0) {
resultList = paperSizeList.map(function(item, index) {
return {
value: index,
displayValue: [item.name, item.width / 10, item.height / 10, 'cm'],
caption: item.name,
size: [item.width, item.height]
}
});
} else {
resultList = [].concat(this._defaultPaperSizeList);
}
resultList.push({ value: -1, displayValue: this.txtCustom, caption: this.txtCustom, size: []});
var prevSelectedOption = this.cmbPaperSize.store.findWhere({
value: this.cmbPaperSize.getValue()
});
var newSelectedOption = null;
function findOptionBySize(list, width, height) {
return _.find(list, function(option) {
return Math.abs(option.size[0] - width) < 0.1 && Math.abs(option.size[1] - height) < 0.1;
});
}
// If a previously selected option exists, search for a matching one in resultList
if (prevSelectedOption) {
newSelectedOption = findOptionBySize(
resultList,
Math.round(prevSelectedOption.get('size')[0]),
Math.round(prevSelectedOption.get('size')[1])
);
}
if (!newSelectedOption) {
if(prevSelectedOption) {
newSelectedOption = {
custom: true,
value: [
this.txtCustom,
parseFloat(Common.Utils.Metric.fnRecalcFromMM(prevSelectedOption.get('size')[0]).toFixed(2)),
parseFloat(Common.Utils.Metric.fnRecalcFromMM(prevSelectedOption.get('size')[1]).toFixed(2)),
Common.Utils.Metric.getCurrentMetricName()
]
}
} else {
const _w = this._originalPageSize ? this._originalPageSize.w : 210,
_h = this._originalPageSize ? this._originalPageSize.h : 297;
// If no matching option is found, look for the default size 210x297 (A4)
if (!newSelectedOption) {
newSelectedOption = findOptionBySize(resultList, _w, _h);
}
if (!newSelectedOption) {
newSelectedOption = {
custom: true,
value: [
this.txtCustom,
parseFloat(Common.Utils.Metric.fnRecalcFromMM(_w).toFixed(2)),
parseFloat(Common.Utils.Metric.fnRecalcFromMM(_h).toFixed(2)),
Common.Utils.Metric.getCurrentMetricName()
]
};
}
if (!newSelectedOption && resultList[0]) {
newSelectedOption = resultList[0];
}
}
}
this.cmbPaperSize.setData(resultList);
this.updatePaperSizeMetricUnit();
if (!newSelectedOption) {
this.cmbPaperSize.setValue(null);
} else if (newSelectedOption.custom) {
this.cmbPaperSize.setValue(undefined, newSelectedOption.value);
} else {
this.cmbPaperSize.setValue(newSelectedOption.value);
}
},
updateScroller: function() {
if (this.scroller) {
Common.UI.Menu.Manager.hideAll();
var scrolled = this.$el.height()< this.pnlTable.height() + 25 + this.$el.find('.main-header').outerHeight(true);
this.pnlSettings.css('overflow', scrolled ? 'hidden' : 'visible');
this.scroller.update();
}
},
setMode: function(mode) {
this.mode = mode;
},
setApi: function(api) {
},
onPrinterSelected: function(combo, record) {
this.setCmbSidesOptions(record ? record.isDuplexSupported : true);
this.setCmbPaperSizeOptions(record ? record.paperSupported : null);
this.setCmbColorPrintingDisabled(record ? !record.colorSupported : true);
this.btnPrint.setDisabled(!record);
},
updateMetricUnit: function() {
this.updatePaperSizeMetricUnit();
this.cmbPaperMargins.onResetItems();
},
updatePaperSizeMetricUnit: function() {
if (!this.cmbPaperSize) return;
var store = this.cmbPaperSize.store;
for (var i=0; i