Refector windows platform

This commit is contained in:
Sebastián Katzer 2016-07-31 13:32:21 +02:00
parent 970060a28e
commit 2472d7208a
2 changed files with 93 additions and 38 deletions

View File

@ -1,44 +1,99 @@
PrinterProxy = { /* globals Windows: true */
printDocumentSource: null,
isAvailable: function (successCallback, failCallback, args) { /*
successCallback(true, 0); Copyright 2013-2016 appPlant GmbH
},
print: function (successCallback, failCallback, args) { Licensed to the Apache Software Foundation (ASF) under one
var documentFragment = document.createDocumentFragment(); or more contributor license agreements. See the NOTICE file
var content = document.createElement("html"); distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
window.printContent = args[0]; http://www.apache.org/licenses/LICENSE-2.0
content.innerHTML = window.printContent;
documentFragment.appendChild(content);
PrinterProxy.getPrintDocumentSource(documentFragment).then(function(source) {
PrinterProxy.printDocumentSource = source;
Windows.Graphics.Printing.PrintManager.showPrintUIAsync();
});
},
getPrintDocumentSource: function(documentFragment) { Unless required by applicable law or agreed to in writing,
var promise; software distributed under the License is distributed on an
if(MSApp.getHtmlPrintDocumentSourceAsync) { "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
promise = MSApp.getHtmlPrintDocumentSourceAsync(documentFragment); KIND, either express or implied. See the License for the
} else { specific language governing permissions and limitations
promise = new WinJS.Promise(function(completeDispatch) { under the License.
completeDispatch(MSApp.getHtmlPrintDocumentSource(documentFragment)); */
});
}
return promise; var PrintManager = Windows.Graphics.Printing.PrintManager;
},
printTaskRequested: function (printEvent) { /**
printEvent.request.createPrintTask("Print", function (args) { * Verifies if printing is supported on the device.
args.setSource(PrinterProxy.printDocumentSource); *
}); * @param {Function} success
} * Success callback function
* @param {Function} error
* Error callback function
* @param {Array} args
* Interface arguments
*/
exports.isAvailable = function (success, fail, args) {
success(MSApp.hasOwnProperty('getHtmlPrintDocumentSourceAsync'), 0);
}; };
var printManager = Windows.Graphics.Printing.PrintManager.getForCurrentView(); /**
printManager.onprinttaskrequested = PrinterProxy.printTaskRequested; * Displays system interface for selecting a printer.
*
* @param {Function} success
* Success callback function
* @param {Function} error
* Error callback function
* @param {Array} args
* Interface arguments
*/
exports.pick = function (success, fail, args) {
success(); // Not supported :(
};
require("cordova/exec/proxy").add("Printer", PrinterProxy); /**
* Sends the content to the Printing Framework.
*
* @param {Function} success
* Success callback function
* @param {Function} error
* Error callback function
* @param {Array} args
* Interface arguments
*/
exports.print = function (success, fail, args) {
var page = document.createDocumentFragment(),
content = document.createElement('html');
content.innerHTML = args[0];
page.appendChild(content);
exports._func = success;
exports._args = args[1];
MSApp.getHtmlPrintDocumentSourceAsync(page).then(function (source) {
exports._page = source;
PrintManager.showPrintUIAsync();
});
};
/**
* Raised when a request to print has occurred.
* Create, configure and schedule the print task.
*
* @param {PrintTaskRequestedEventArgs} event
* Event arguments associated with the request.
*/
exports.onPrintTaskRequested = function (event) {
var config = exports._args,
task;
task = event.request.createPrintTask(config.name, function (args) {
args.setSource(exports._page);
});
};
PrintManager.getForCurrentView()
.onprinttaskrequested = exports.onPrintTaskRequested;
require('cordova/exec/proxy').add('Printer', exports);

View File

@ -45,7 +45,7 @@ exports.getDefaults = function () {
/** /**
* Checks if the printer service is avaible (iOS) * Checks if the printer service is avaible (iOS)
* or if connected to the Internet (Android). * or if services are available (Android).
* *
* @param {Function} callback * @param {Function} callback
* A callback function * A callback function
@ -61,7 +61,7 @@ exports.isAvailable = function (callback, scope) {
}; };
/** /**
* Displays system interface for selecting a printer (iOS only) * Displays system interface for selecting a printer.
* *
* @param {Function} callback * @param {Function} callback
* A callback function * A callback function
@ -78,7 +78,7 @@ exports.pick = function (callback, options) {
}; };
/** /**
* Sends the content to the Google Cloud Print service. * Sends the content to the Printing Framework.
* *
* @param {String} content * @param {String} content
* HTML string or DOM node * HTML string or DOM node