Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- $(".print-anchor").click(function(e){
- e.preventDefault();
- var dialogPopup = '.epl2printModal-' + $(this).data("id");
- //WebSocket settings
- JSPM.JSPrintManager.auto_reconnect = false;
- JSPM.JSPrintManager.start();
- JSPM.JSPrintManager.WS.onStatusChanged = function () {
- if (jspmWSStatus()) {
- $(dialogPopup).dialog();
- $(dialogPopup).removeClass("ui-dialog-content ui-widget-content");
- //get client installed printers
- JSPM.JSPrintManager.getPrinters().then(function (myPrinters) {
- var options = '';
- for (var i = 0; i < myPrinters.length; i++) {
- options += '<option>' + myPrinters[i] + '</option>';
- }
- $('.installedPrinterName').html(options);
- });
- }else{
- // alert('JSPrintManager (JSPM) is not installed or not running! Download JSPM Client App from https://neodynamic.com/downloads/jspm \n Please refresh the page and try to print again');
- $(this).unbind('click');
- $(".jspmAlertMessage").dialog();
- e.preventDefault();
- console.log("Here !!!!");
- }
- };
- });
- $(".btn-print").click(function(){
- print($(this).data("unique-id"));
- });
- //Check JSPM WebSocket status
- function jspmWSStatus() {
- if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.Open)
- return true;
- else if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.Closed) {
- // alert('JSPrintManager (JSPM) is not installed or not running! Download JSPM Client App from https://neodynamic.com/downloads/jspm');
- return false;
- }
- else if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.BlackListed) {
- // alert('JSPM has blacklisted this website!');
- return false;
- }
- }
- //Do printing...
- function print(uniqueId) {
- if (jspmWSStatus()) {
- //Create a ClientPrintJob
- var cpj = new JSPM.ClientPrintJob();
- //Set Printer type (Refer to the help, there many of them!)
- cpj.clientPrinter = new JSPM.InstalledPrinter($('.installedPrinterName').val());
- //Set content to print...
- //Create Zebra EPL commands for sample label
- var xhr = new XMLHttpRequest();
- var url_path = '/labels/' + uniqueId + '.txt';
- xhr.open('GET', url_path, true);
- xhr.responseType = 'arraybuffer';
- xhr.onload = function (e) {
- if (this.status === 200) {
- //Create a ClientPrintJob
- var cpj = new JSPM.ClientPrintJob();
- //Set Printer info
- var myPrinter = new JSPM.DefaultPrinter();
- cpj.clientPrinter = myPrinter;
- //Set printer commands...
- cpj.binaryPrinterCommands = new Uint8Array(xhr.response);
- //Send print job to printer!
- cpj.sendToClient();
- }
- };
- xhr.send();
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement