mirror of
https://github.com/ONLYOFFICE/web-apps.git
synced 2026-07-24 06:08:33 +08:00
[SSE] Add select printer and print using the system dialog
This commit is contained in:
@ -577,6 +577,7 @@ define([
|
||||
this.mode.canPrint = this.mode.canDownload = false;
|
||||
} else {
|
||||
this.mode = mode;
|
||||
this.mode.canPreviewPrint = true;
|
||||
}
|
||||
|
||||
if (!delay) {
|
||||
|
||||
@ -48,6 +48,13 @@ define([
|
||||
this.adjPrintParams = new Asc.asc_CAdjustPrint();
|
||||
this.adjPrintParams.asc_setPrintType(value);
|
||||
|
||||
this._state = {
|
||||
firstPrintPage: 0,
|
||||
isPrinterInfoLoad: false,
|
||||
currentPrinter: null,
|
||||
printersList: []
|
||||
};
|
||||
|
||||
this._changedProps = null;
|
||||
this._originalPageSettings = null;
|
||||
|
||||
@ -99,15 +106,16 @@ define([
|
||||
this.printSettings.printScroller && this.printSettings.printScroller.update();
|
||||
}
|
||||
}, this));
|
||||
this.printSettings.btnPrintSystemDialog.on('click', _.bind(this.querySavePrintSettings, this, 'print', true));
|
||||
this.printSettings.btnsSave.forEach(function (btn) {
|
||||
btn.on('click', _.bind(me.querySavePrintSettings, me, 'save'));
|
||||
btn.on('click', _.bind(me.querySavePrintSettings, me, 'save', false));
|
||||
});
|
||||
this.printSettings.btnsPrint.forEach(function (btn) {
|
||||
btn.on('click', _.bind(me.querySavePrintSettings, me, 'print'));
|
||||
btn.on('click', _.bind(me.querySavePrintSettings, me, 'print', false));
|
||||
});
|
||||
if (this.mode.isDesktopApp) {
|
||||
this.printSettings.btnsPrintPDF.forEach(function (btn) {
|
||||
btn.on('click', _.bind(me.querySavePrintSettings, me, 'print-pdf'));
|
||||
btn.on('click', _.bind(me.querySavePrintSettings, me, 'print-pdf', false));
|
||||
});
|
||||
}
|
||||
this.printSettings.btnPrevPage.on('click', _.bind(this.onChangePreviewPage, this, false));
|
||||
@ -124,6 +132,10 @@ define([
|
||||
this.fillComponents(this.printSettings);
|
||||
this.registerControlEvents(this.printSettings);
|
||||
|
||||
if(this._state.isPrinterInfoLoad) {
|
||||
this.printSettings.updateCmbPrinter(this._state.currentPrinter, this._state.printersList);
|
||||
}
|
||||
|
||||
Common.NotificationCenter.on('window:resize', _.bind(function () {
|
||||
if (this._isPreviewVisible) {
|
||||
this.notUpdateSheetSettings = true;
|
||||
@ -214,9 +226,9 @@ define([
|
||||
item = null;
|
||||
for (var i=0; i<store.length; i++) {
|
||||
var rec = store.at(i),
|
||||
value = rec.get('value'),
|
||||
pagewidth = parseFloat(/^\d{3}\.?\d*/.exec(value)),
|
||||
pageheight = parseFloat(/\d{3}\.?\d*$/.exec(value));
|
||||
size = rec.get('size'),
|
||||
pagewidth = size[0],
|
||||
pageheight = size[1];
|
||||
if (Math.abs(pagewidth - w) < 0.1 && Math.abs(pageheight - h) < 0.1) {
|
||||
item = rec;
|
||||
break;
|
||||
@ -309,11 +321,12 @@ define([
|
||||
var opt = this._changedProps[sheet] ? this._changedProps[sheet].asc_getPageSetup() : new Asc.asc_CPageSetup();
|
||||
opt.asc_setOrientation(panel.cmbPaperOrientation.getValue() == '-' ? undefined : panel.cmbPaperOrientation.getValue());
|
||||
|
||||
var pagew = /^\d{3}\.?\d*/.exec(panel.cmbPaperSize.getValue());
|
||||
var pageh = /\d{3}\.?\d*$/.exec(panel.cmbPaperSize.getValue());
|
||||
var size = panel.cmbPaperSize.getSelectedRecord().size;
|
||||
var pagew = size[0];
|
||||
var pageh = size[1];
|
||||
|
||||
opt.asc_setWidth(pagew ? parseFloat(pagew[0]) : (this._originalPageSettings ? this._originalPageSettings.asc_getWidth() : undefined));
|
||||
opt.asc_setHeight(pageh? parseFloat(pageh[0]) : (this._originalPageSettings ? this._originalPageSettings.asc_getHeight() : undefined));
|
||||
opt.asc_setWidth(pagew ? pagew : (this._originalPageSettings ? this._originalPageSettings.asc_getWidth() : undefined));
|
||||
opt.asc_setHeight(pageh? pageh : (this._originalPageSettings ? this._originalPageSettings.asc_getHeight() : undefined));
|
||||
|
||||
var value = panel.cmbLayout.getValue();
|
||||
if (value !== 4) {
|
||||
@ -437,9 +450,9 @@ define([
|
||||
item = null;
|
||||
for (var i=0; i<store.length-1; i++) {
|
||||
var rec = store.at(i),
|
||||
value = rec.get('value'),
|
||||
pagewidth = parseFloat(/^\d{3}\.?\d*/.exec(value)),
|
||||
pageheight = parseFloat(/\d{3}\.?\d*$/.exec(value));
|
||||
size = rec.get('size'),
|
||||
pagewidth = size[0],
|
||||
pageheight = size[1];
|
||||
if (Math.abs(pagewidth - width) < 0.1 && Math.abs(pageheight - height) < 0.1) {
|
||||
item = rec;
|
||||
break;
|
||||
@ -504,7 +517,7 @@ define([
|
||||
this.printSettingsDlg = null;
|
||||
},
|
||||
|
||||
querySavePrintSettings: function(print) {
|
||||
querySavePrintSettings: function(print, useSystemDialog) {
|
||||
var view = SSE.getController('Toolbar').getView('Toolbar');
|
||||
this.savePageOptions(this.printSettings);
|
||||
this._isPrint = print === 'print';
|
||||
@ -530,8 +543,11 @@ define([
|
||||
props = this._changedProps[sheetIndex] || this.api.asc_getPageOptions(sheetIndex),
|
||||
pageSetup = props.asc_getPageSetup(),
|
||||
size = [pageSetup.asc_getWidth(), pageSetup.asc_getHeight()],
|
||||
orientation = pageSetup.asc_getOrientation();
|
||||
orientation = pageSetup.asc_getOrientation(),
|
||||
printerOption = this.printSettings.cmbPrinter.getSelectedRecord();
|
||||
this.adjPrintParams.asc_setNativeOptions({
|
||||
usesystemdialog: useSystemDialog,
|
||||
printer: printerOption ? printerOption.value : null,
|
||||
paperSize: {
|
||||
w: size[0],
|
||||
h: size[1],
|
||||
@ -702,6 +718,15 @@ define([
|
||||
}
|
||||
},
|
||||
|
||||
setPrinterInfo: function(currentPrinter, list) {
|
||||
this._state.isPrinterInfoLoad = true;
|
||||
this._state.currentPrinter = currentPrinter;
|
||||
this._state.printersList = list;
|
||||
if(this.printSettings) {
|
||||
this.printSettings.updateCmbPrinter(this._state.currentPrinter, this._state.printersList);
|
||||
}
|
||||
},
|
||||
|
||||
fillComponents: function(panel, selectdata) {
|
||||
var me = this;
|
||||
panel.txtRangeTop.validation = function(value) {
|
||||
|
||||
@ -2702,6 +2702,8 @@ define([], function () {
|
||||
'<div class="main-header"><%= scope.txtPrint %></div>',
|
||||
'<table style="width: 100%;">',
|
||||
'<tbody>',
|
||||
'<tr><td><label class="font-weight-bold"><%= scope.txtPrinter %></label></td></tr>',
|
||||
'<tr><td class="padding-large"><div id="print-combo-printer" style="width: 248px;"></div></td></tr>',
|
||||
'<tr><td><label class="font-weight-bold"><%= scope.txtPrintRange %></label></td></tr>',
|
||||
'<tr><td class="padding-small"><div id="print-combo-range" style="width: 248px;"></div></td></tr>',
|
||||
'<tr><td class="padding-large"><div id="print-chb-ignore" style="width: 248px;"></div></td></tr>',
|
||||
@ -2762,6 +2764,7 @@ define([], function () {
|
||||
'<label><%= scope.txtFirstPageNumber %></label>',
|
||||
'<div id="print-spin-first-page"></div>',
|
||||
'</td></tr>',
|
||||
'<tr class="header-settings"><td class="padding-large"><label class="link" id="print-btn-system-dialog" data-hint="2" data-hint-direction="bottom" data-hint-offset="medium"><%= scope.txtPrintUsingSystemDialog %></label></td></tr>',
|
||||
//'<tr><td class="padding-large"><button type="button" class="btn btn-text-default" id="print-apply-all" style="width: 118px;" data-hint="2" data-hint-direction="bottom" data-hint-offset="medium"><%= scope.txtApplyToAllSheets %></button></td></tr>',
|
||||
'<tr class="fms-btn-apply"><td>',
|
||||
'<div class="footer justify">',
|
||||
@ -2811,6 +2814,22 @@ define([], function () {
|
||||
Common.UI.BaseView.prototype.initialize.call(this,arguments);
|
||||
|
||||
this.menu = options.menu;
|
||||
|
||||
this._defaultPaperSizeList = [
|
||||
{value:'215.9|279.4', displayValue:['US Letter', '21,59', '27,94', 'cm'], caption: 'US Letter', size: [215.9, 279.4]},
|
||||
{value:'215.9|355.6', displayValue:['US Legal', '21,59', '35,56', 'cm'], caption: 'US Legal', size: [215.9, 355.6]},
|
||||
{value:'210|297', displayValue:['A4', '21', '29,7', 'cm'], caption: 'A4', size: [210, 297]},
|
||||
{value:'148|210', displayValue:['A5', '14,8', '21', 'cm'], caption: 'A5', size: [148, 210]},
|
||||
{value:'176|250', displayValue:['B5', '17,6', '25', 'cm'], caption: 'B5', size: [176, 250]},
|
||||
{value:'104.8|241.3', displayValue:['Envelope #10', '10,48', '24,13', 'cm'], caption: 'Envelope #10', size: [104.8, 241.3]},
|
||||
{value:'110|220', displayValue:['Envelope DL', '11', '22', 'cm'], caption: 'Envelope DL', size: [110, 220]},
|
||||
{value:'279.4|431.8', displayValue:['Tabloid', '27,94', '43,18', 'cm'], caption: 'Tabloid', size: [279.4, 431.8]},
|
||||
{value:'297|420', displayValue:['A3', '29,7', '42', 'cm'], caption: 'A3', size: [297, 420]},
|
||||
{value:'296.9|457.2', displayValue:['Tabloid Oversize', '29,69', '45,72', 'cm'], caption: 'Tabloid Oversize', size: [296.9, 457.2]},
|
||||
{value:'196.8|273', displayValue:['ROC 16K', '19,68', '27,3', 'cm'], caption: 'ROC 16K', size: [196.8, 273]},
|
||||
{value:'120|235', displayValue:['Envelope Choukei 3', '12', '23,5', 'cm'], caption: 'Envelope Choukei 3', size: [120, 235]},
|
||||
{value:'305|487', displayValue:['Super B/A3', '30,5', '48,7', 'cm'], caption: 'Super B/A3', size: [305, 487]}
|
||||
];
|
||||
|
||||
this._initSettings = true;
|
||||
this.extendedPrintTitles = Common.localStorage.getBool('sse-print-titles-extended', true);
|
||||
@ -2821,6 +2840,29 @@ define([], function () {
|
||||
|
||||
var $markup = $(this.template({scope: this, isRTL: Common.UI.isRTL()}));
|
||||
|
||||
this.cmbPrinter = new Common.UI.ComboBox({
|
||||
el: $markup.findById('#print-combo-printer'),
|
||||
menuStyle: 'min-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) { %>',
|
||||
'<li id="<%= item.id %>" data-value="<%= item.value %>"><a tabindex="-1" type="menuitem" <% if (typeof(item.checked) !== "undefined" && item.checked) { %> class="checked" <% } %> ><%= scope.getDisplayValue(item) %></a></li>',
|
||||
'<% }); %>',
|
||||
'<% } else { %>',
|
||||
'<li><a style="background:none; cursor: default;" onclick="event.stopPropagation();">' + this.txtPrintersNotFound + '</a></li>',
|
||||
'<% } %>'
|
||||
].join('')),
|
||||
data: [],
|
||||
dataHint: '2',
|
||||
dataHintDirection: 'bottom',
|
||||
dataHintOffset: 'big'
|
||||
});
|
||||
this.cmbPrinter.on('selected', _.bind(this.onPrinterSelected, this));
|
||||
|
||||
this.cmbRange = new Common.UI.ComboBox({
|
||||
el: $markup.findById('#print-combo-range'),
|
||||
menuStyle: 'min-width: 248px;max-height: 280px;',
|
||||
@ -2899,11 +2941,7 @@ define([], function () {
|
||||
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 }
|
||||
],
|
||||
data : [],
|
||||
itemsTemplate: _.template([
|
||||
'<% _.each(items, function(item) { %>',
|
||||
'<li id="<%= item.id %>" data-value="<%- item.value %>"><a tabindex="-1" type="menuitem" style ="display: flex; flex-direction: column;">',
|
||||
@ -2967,21 +3005,7 @@ define([], function () {
|
||||
takeFocusOnClose: true,
|
||||
template: paperSizeTemplate,
|
||||
itemsTemplate: paperSizeItemsTemplate,
|
||||
data: [
|
||||
{value:'215.9|279.4', displayValue:['US Letter', '21,59', '27,94', 'cm'], caption: 'US Letter'},
|
||||
{value:'215.9|355.6', displayValue:['US Legal', '21,59', '35,56', 'cm'], caption: 'US Legal'},
|
||||
{value:'210|297', displayValue:['A4', '21', '29,7', 'cm'], caption: 'A4'},
|
||||
{value:'148|210', displayValue:['A5', '14,8', '21', 'cm'], caption: 'A5'},
|
||||
{value:'176|250', displayValue:['B5', '17,6', '25', 'cm'], caption: 'B5'},
|
||||
{value:'104.8|241.3', displayValue:['Envelope #10', '10,48', '24,13', 'cm'], caption: 'Envelope #10'},
|
||||
{value:'110|220', displayValue:['Envelope DL', '11', '22', 'cm'], caption: 'Envelope DL'},
|
||||
{value:'279.4|431.8', displayValue:['Tabloid', '27,94', '43,18', 'cm'], caption: 'Tabloid'},
|
||||
{value:'297|420', displayValue:['A3', '29,7', '42', 'cm'], caption: 'A3'},
|
||||
{value:'296.9|457.2', displayValue:['Tabloid Oversize', '29,69', '45,72', 'cm'], caption: 'Tabloid Oversize'},
|
||||
{value:'196.8|273', displayValue:['ROC 16K', '19,68', '27,3', 'cm'], caption: 'ROC 16K'},
|
||||
{value:'120|235', displayValue:['Envelope Choukei 3', '12', '23,5', 'cm'], caption: 'Envelope Choukei 3'},
|
||||
{value:'305|487', displayValue:['Super B/A3', '30,5', '48,7', 'cm'], caption: 'Super B/A3'}
|
||||
],
|
||||
data: [],
|
||||
dataHint: '2',
|
||||
dataHintDirection: 'bottom',
|
||||
dataHintOffset: 'big',
|
||||
@ -3162,6 +3186,9 @@ define([], function () {
|
||||
this.pnlTable = $(this.pnlSettings.find('table')[0]);
|
||||
this.trApply = $markup.find('.fms-btn-apply');
|
||||
|
||||
|
||||
this.btnPrintSystemDialog = $markup.findById('#print-btn-system-dialog');
|
||||
|
||||
this.btnsSave = [];
|
||||
this.btnsPrint = [];
|
||||
if (this.mode.isDesktopApp) {
|
||||
@ -3189,7 +3216,8 @@ define([], function () {
|
||||
el: $markup.findById('#print-btn-save-'+i)
|
||||
}));
|
||||
this.btnsPrint.push(new Common.UI.Button({
|
||||
el: $markup.findById('#print-btn-print-'+i)
|
||||
el: $markup.findById('#print-btn-print-'+i),
|
||||
disabled: true
|
||||
}));
|
||||
}
|
||||
|
||||
@ -3289,10 +3317,110 @@ define([], function () {
|
||||
this.updateMetricUnit();
|
||||
this._initSettings = false;
|
||||
}
|
||||
this.updateSettings();
|
||||
this.updateScroller();
|
||||
this.fireEvent('show', this);
|
||||
},
|
||||
|
||||
updateSettings: function() {
|
||||
var selectedPrinter = this.cmbPrinter.getSelectedRecord();
|
||||
this.setCmbSidesOptions(selectedPrinter ? selectedPrinter.isDuplexSupported : true);
|
||||
this.setCmbPaperSizeOptions(selectedPrinter ? selectedPrinter.paperSupported : null);
|
||||
},
|
||||
|
||||
updateCmbPrinter: function(currentPrinter, printers) {
|
||||
var cmbPrinterOptions = [];
|
||||
|
||||
printers = printers || [];
|
||||
|
||||
//If the current printer is not in the list of printers, add it
|
||||
if(currentPrinter && !_.some(printers, function(printer) { return printer.name == currentPrinter })) {
|
||||
printers.push({
|
||||
name: currentPrinter,
|
||||
duplex_supported: true,
|
||||
paperSupported: this._defaultPaperSizeList
|
||||
});
|
||||
}
|
||||
|
||||
cmbPrinterOptions = printers.map(function(printer) {
|
||||
return {
|
||||
value: printer.name,
|
||||
displayValue: printer.name,
|
||||
paperSupported: printer.paper_supported,
|
||||
isDuplexSupported: printer.duplex_supported
|
||||
}
|
||||
});
|
||||
|
||||
this.cmbPrinter.setData(cmbPrinterOptions);
|
||||
this.cmbPrinter.setValue(currentPrinter);
|
||||
this.cmbPrinter.trigger('selected', this, this.cmbPrinter.getSelectedRecord());
|
||||
},
|
||||
|
||||
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(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);
|
||||
}
|
||||
|
||||
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.round(option.size[0]) === width && Math.round(option.size[1]) === height;
|
||||
});
|
||||
}
|
||||
|
||||
// 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 no matching option is found, look for the default size 210x297 (A4)
|
||||
if (!newSelectedOption) {
|
||||
newSelectedOption = findOptionBySize(resultList, 210, 297);
|
||||
}
|
||||
if (!newSelectedOption && resultList[0]) {
|
||||
newSelectedOption = resultList[0];
|
||||
}
|
||||
|
||||
this.cmbPaperSize.setData(resultList);
|
||||
this.updatePaperSizeMetricUnit();
|
||||
this.cmbPaperSize.setValue(newSelectedOption ? newSelectedOption.value : null);
|
||||
this.cmbPaperSize.trigger('selected', this, this.cmbPaperSize.getSelectedRecord());
|
||||
},
|
||||
|
||||
updateScroller: function() {
|
||||
if (this.scroller) {
|
||||
Common.UI.Menu.Manager.hideAll();
|
||||
@ -3324,13 +3452,27 @@ define([], function () {
|
||||
|
||||
},
|
||||
|
||||
onPrinterSelected: function(combo, record) {
|
||||
this.setCmbSidesOptions(record ? record.isDuplexSupported : true);
|
||||
this.setCmbPaperSizeOptions(record ? record.paperSupported : null);
|
||||
this.btnsPrint.forEach(function(btn) {
|
||||
btn.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<store.length; i++) {
|
||||
var item = store.at(i),
|
||||
value = item.get('value'),
|
||||
pagewidth = /^\d{3}\.?\d*/.exec(value),
|
||||
pageheight = /\d{3}\.?\d*$/.exec(value);
|
||||
size = item.get('size'),
|
||||
pagewidth = size[0],
|
||||
pageheight = size[1];
|
||||
|
||||
item.set('displayValue', [item.get('caption'),
|
||||
parseFloat(Common.Utils.Metric.fnRecalcFromMM(pagewidth).toFixed(2)),
|
||||
@ -3338,7 +3480,6 @@ define([], function () {
|
||||
Common.Utils.Metric.getCurrentMetricName()]);
|
||||
}
|
||||
this.cmbPaperSize.onResetItems();
|
||||
this.cmbPaperMargins.onResetItems();
|
||||
},
|
||||
|
||||
addCustomScale: function (add) {
|
||||
@ -3431,6 +3572,10 @@ define([], function () {
|
||||
txtPrint: 'Print',
|
||||
txtSave: 'Save',
|
||||
txtPrintToPDF: 'Print to PDF',
|
||||
txtPrinter: 'Printer',
|
||||
txtPrinterNotSelected: 'Printer not selected',
|
||||
txtPrintersNotFound: 'Printers not found',
|
||||
txtPrintUsingSystemDialog: 'Print using the system dialog',
|
||||
txtPrintRange: 'Print range',
|
||||
txtCurrentSheet: 'Current sheet',
|
||||
txtActiveSheets: 'Active sheets',
|
||||
|
||||
Reference in New Issue
Block a user