2013-12-20 16:31:41 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Doodle3D project (http://doodle3d.com).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, Doodle3D
|
|
|
|
* This software is licensed under the terms of the GNU GPL v2 or later.
|
|
|
|
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
|
|
|
*/
|
|
|
|
|
2013-09-17 13:08:52 +02:00
|
|
|
/* not using this now
|
2013-09-07 17:08:52 +02:00
|
|
|
var $printProgressContainer = $("#printProgressContainer");
|
|
|
|
var $progressbar = $("#progressbar");
|
|
|
|
var $progressAmount = $(".progressAmount");
|
|
|
|
function setPrintprogress(val) {
|
|
|
|
if (isNaN(val)) return;
|
|
|
|
// console.log("f:setPrintprogress() >> val " + val);
|
|
|
|
$progressbar.css("width", val*100 + "%");
|
|
|
|
$progressAmount.text(Math.floor(val*100) + "%");
|
|
|
|
}
|
2013-09-17 13:08:52 +02:00
|
|
|
//*/
|
2013-09-07 17:08:52 +02:00
|
|
|
|
2013-08-07 20:47:47 +02:00
|
|
|
function Printer() {
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
Printer.WIFIBOX_DISCONNECTED_STATE = "wifibox disconnected";
|
|
|
|
Printer.UNKNOWN_STATE = "unknown"; // happens when a printer is connection but there isn't communication yet
|
|
|
|
Printer.DISCONNECTED_STATE = "disconnected"; // printer disconnected
|
|
|
|
Printer.IDLE_STATE = "idle"; // printer found, but idle
|
|
|
|
Printer.BUFFERING_STATE = "buffering"; // printer is buffering (recieving) data, but not yet printing
|
|
|
|
Printer.PRINTING_STATE = "printing";
|
|
|
|
Printer.STOPPING_STATE = "stopping"; // when you stop (abort) a print it prints the endcode
|
2013-12-18 16:56:06 +01:00
|
|
|
Printer.TOUR_STATE = "tour"; // when in joyride mode
|
2013-10-11 12:39:05 +02:00
|
|
|
|
2013-10-18 16:38:20 +02:00
|
|
|
Printer.ON_BEFORE_UNLOAD_MESSAGE = "You're doodle is still being send to the printer, leaving will result in a incomplete 3D print";
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
this.temperature = 0;
|
|
|
|
this.targetTemperature = 0;
|
|
|
|
this.currentLine = 0;
|
|
|
|
this.totalLines = 0;
|
|
|
|
this.bufferedLines = 0;
|
|
|
|
this.state = Printer.UNKNOWN_STATE;
|
2013-11-22 16:51:26 +01:00
|
|
|
this.hasControl = true; // whether this client has control access
|
|
|
|
|
|
|
|
this.wifiboxURL;
|
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
this.checkStatusInterval = 3000;
|
|
|
|
this.checkStatusDelay;
|
|
|
|
this.timeoutTime = 3000;
|
|
|
|
this.sendPrintPartTimeoutTime = 5000;
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-14 20:54:48 +02:00
|
|
|
this.gcode; // gcode to be printed
|
2013-11-22 16:51:26 +01:00
|
|
|
this.sendLength = 500; // max amount of gcode lines per post (limited because WiFi box can't handle to much)
|
2013-08-14 20:54:48 +02:00
|
|
|
|
|
|
|
this.retryDelay = 2000; // retry setTimout delay
|
|
|
|
this.retrySendPrintPartDelay; // retry setTimout instance
|
2013-10-11 12:39:05 +02:00
|
|
|
this.retryCheckStatusDelay; // retry setTimout instance
|
2013-08-14 20:54:48 +02:00
|
|
|
this.retryStopDelay; // retry setTimout instance
|
|
|
|
this.retryPreheatDelay; // retry setTimout instance
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-23 16:45:24 +02:00
|
|
|
Printer.MAX_GCODE_SIZE = 10; // max size of gcode in MB's (estimation)
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-14 17:40:56 +02:00
|
|
|
this.stateOverruled = false;
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-07 20:47:47 +02:00
|
|
|
// Events
|
|
|
|
Printer.UPDATE = "update";
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
var self = this;
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-07 20:47:47 +02:00
|
|
|
this.init = function() {
|
2014-02-04 12:51:31 +01:00
|
|
|
//console.log("Printer:init");
|
2013-08-07 20:47:47 +02:00
|
|
|
//this.wifiboxURL = "http://" + window.location.host + "/cgi-bin/d3dapi";
|
|
|
|
//this.wifiboxURL = "http://192.168.5.1/cgi-bin/d3dapi";
|
|
|
|
this.wifiboxURL = wifiboxURL;
|
|
|
|
//this.wifiboxURL = "proxy5.php";
|
2014-02-04 12:51:31 +01:00
|
|
|
//console.log(" wifiboxURL: ",this.wifiboxURL);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-27 15:34:28 +02:00
|
|
|
if(autoUpdate) {
|
2013-10-16 18:27:10 +02:00
|
|
|
this.startStatusCheckInterval();
|
2013-08-27 15:34:28 +02:00
|
|
|
}
|
2013-08-07 20:47:47 +02:00
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-07 20:47:47 +02:00
|
|
|
this.preheat = function() {
|
|
|
|
console.log("Printer:preheat");
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-23 12:45:41 +02:00
|
|
|
if( this.state == Printer.BUFFERING_STATE ||
|
|
|
|
this.state == Printer.PRINTING_STATE ||
|
|
|
|
this.state == Printer.STOPPING_STATE) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-12 16:52:31 +02:00
|
|
|
var self = this;
|
2013-08-19 17:55:01 +02:00
|
|
|
if (communicateWithWifibox) {
|
|
|
|
$.ajax({
|
|
|
|
url: this.wifiboxURL + "/printer/heatup",
|
|
|
|
type: "POST",
|
|
|
|
dataType: 'json',
|
|
|
|
timeout: this.timeoutTime,
|
|
|
|
success: function(data){
|
|
|
|
console.log("Printer:preheat response: ",data);
|
2013-12-23 17:38:10 +01:00
|
|
|
if(data.status != "success") {
|
2013-08-19 17:55:01 +02:00
|
|
|
clearTimeout(self.retryPreheatDelay);
|
|
|
|
self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay
|
|
|
|
}
|
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
}).fail(function() {
|
2013-08-19 17:55:01 +02:00
|
|
|
console.log("Printer:preheat: failed");
|
|
|
|
clearTimeout(self.retryPreheatDelay);
|
|
|
|
self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log ("Printer >> f:preheat() >> communicateWithWifibox is false, so not executing this function");
|
|
|
|
}
|
2013-08-14 20:54:48 +02:00
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-14 20:54:48 +02:00
|
|
|
this.print = function(gcode) {
|
|
|
|
console.log("Printer:print");
|
|
|
|
console.log(" gcode total # of lines: " + gcode.length);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
message.set("Sending doodle to printer...",Message.NOTICE);
|
2013-10-18 16:38:20 +02:00
|
|
|
self.addLeaveWarning();
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-14 20:54:48 +02:00
|
|
|
/*for (i = 0; i < gcode.length; i++) {
|
|
|
|
gcode[i] += " (" + i + ")";
|
|
|
|
}*/
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-14 20:54:48 +02:00
|
|
|
this.sendIndex = 0;
|
|
|
|
this.gcode = gcode;
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-14 20:54:48 +02:00
|
|
|
//console.log(" gcode[20]: ",gcode[20]);
|
|
|
|
var gcodeLineSize = this.byteSize(gcode[20]);
|
|
|
|
//console.log(" gcodeLineSize: ",gcodeLineSize);
|
|
|
|
var gcodeSize = gcodeLineSize*gcode.length/1024/1024; // estimate gcode size in MB's
|
|
|
|
console.log(" gcodeSize: ",gcodeSize);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-23 16:45:24 +02:00
|
|
|
if(gcodeSize > Printer.MAX_GCODE_SIZE) {
|
2013-10-23 18:25:05 +02:00
|
|
|
alert("Error: Printer:print: gcode file is probably too big ("+gcodeSize+"MB) (max: "+Printer.MAX_GCODE_SIZE+"MB)");
|
|
|
|
console.log("Error: Printer:print: gcode file is probably too big ("+gcodeSize+"MB) (max: "+Printer.MAX_GCODE_SIZE+"MB)");
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-23 17:41:49 +02:00
|
|
|
this.overruleState(Printer.IDLE_STATE);
|
|
|
|
this.startStatusCheckInterval();
|
|
|
|
message.hide();
|
|
|
|
self.removeLeaveWarning();
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-14 20:54:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-11 15:33:37 +02:00
|
|
|
//this.targetTemperature = settings["printer.temperature"]; // slight hack
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-14 20:54:48 +02:00
|
|
|
this.sendPrintPart(this.sendIndex, this.sendLength);
|
|
|
|
}
|
|
|
|
this.byteSize = function(s){
|
|
|
|
return~-encodeURI(s).split(/%..|./).length;
|
|
|
|
}
|
|
|
|
this.sendPrintPart = function(sendIndex,sendLength) {
|
|
|
|
console.log("Printer:sendPrintPart sendIndex: " + sendIndex + "/" + this.gcode.length + ", sendLength: " + sendLength);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-12-19 17:33:06 +01:00
|
|
|
|
|
|
|
var sendPercentage = Math.round(sendIndex/this.gcode.length*100);
|
|
|
|
message.set("Sending doodle to printer: "+sendPercentage+"%",Message.NOTICE,false,true);
|
|
|
|
|
2013-08-14 20:54:48 +02:00
|
|
|
var firstOne = (sendIndex == 0)? true : false;
|
2013-10-12 17:46:15 +02:00
|
|
|
var start = firstOne; // start printing right away
|
2014-01-18 15:41:09 +01:00
|
|
|
|
2013-10-11 15:33:37 +02:00
|
|
|
var completed = false;
|
2013-08-14 20:54:48 +02:00
|
|
|
if (this.gcode.length < (sendIndex + sendLength)) {
|
|
|
|
console.log(" sending less than max sendLength (and last)");
|
|
|
|
sendLength = this.gcode.length - sendIndex;
|
2013-10-11 15:33:37 +02:00
|
|
|
//lastOne = true;
|
|
|
|
completed = true;
|
2013-08-14 20:54:48 +02:00
|
|
|
}
|
|
|
|
var gcodePart = this.gcode.slice(sendIndex, sendIndex+sendLength);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-11 15:33:37 +02:00
|
|
|
var postData = { gcode: gcodePart.join("\n"), first: firstOne, start: start};
|
2013-08-14 20:54:48 +02:00
|
|
|
var self = this;
|
2013-08-19 17:55:01 +02:00
|
|
|
if (communicateWithWifibox) {
|
|
|
|
$.ajax({
|
|
|
|
url: this.wifiboxURL + "/printer/print",
|
|
|
|
type: "POST",
|
|
|
|
data: postData,
|
|
|
|
dataType: 'json',
|
2013-10-11 12:39:05 +02:00
|
|
|
timeout: this.sendPrintPartTimeoutTime,
|
2013-08-19 17:55:01 +02:00
|
|
|
success: function(data){
|
|
|
|
console.log("Printer:sendPrintPart response: ",data);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-19 17:55:01 +02:00
|
|
|
if(data.status == "success") {
|
2013-10-11 15:33:37 +02:00
|
|
|
if (completed) {
|
2013-08-19 17:55:01 +02:00
|
|
|
console.log("Printer:sendPrintPart:gcode sending completed");
|
|
|
|
this.gcode = [];
|
2013-10-18 16:38:20 +02:00
|
|
|
btnStop.css("display","block"); // hack
|
|
|
|
self.removeLeaveWarning();
|
2013-10-23 18:43:54 +02:00
|
|
|
message.set("Doodle has been sent to printer...",Message.INFO,true);
|
2013-10-11 15:33:37 +02:00
|
|
|
//self.targetTemperature = settings["printer.temperature"]; // slight hack
|
2013-08-19 17:55:01 +02:00
|
|
|
} else {
|
2013-10-14 14:55:22 +02:00
|
|
|
// only if the state hasn't bin changed (by for example pressing stop) we send more gcode
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2014-01-18 17:45:23 +01:00
|
|
|
//console.log("Printer:sendPrintPart:gcode part received (state: ",self.state,")");
|
2013-10-14 17:40:56 +02:00
|
|
|
if(self.state == Printer.PRINTING_STATE || self.state == Printer.BUFFERING_STATE) {
|
2014-01-18 17:45:23 +01:00
|
|
|
//console.log("Printer:sendPrintPart:sending next part");
|
2013-10-14 14:55:22 +02:00
|
|
|
self.sendPrintPart(sendIndex + sendLength, sendLength);
|
|
|
|
}
|
2013-08-19 17:55:01 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-16 18:27:10 +02:00
|
|
|
// after we know the first gcode packed has bin received or failed
|
2013-11-22 16:51:26 +01:00
|
|
|
// (and the driver had time to update the printer.state)
|
2013-10-16 18:27:10 +02:00
|
|
|
// we start checking the status again
|
|
|
|
if(sendIndex == 0) {
|
|
|
|
self.startStatusCheckInterval();
|
|
|
|
}
|
2013-08-19 17:55:01 +02:00
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
}).fail(function() {
|
2013-08-19 17:55:01 +02:00
|
|
|
console.log("Printer:sendPrintPart: failed");
|
|
|
|
clearTimeout(self.retrySendPrintPartDelay);
|
2013-10-11 15:33:37 +02:00
|
|
|
self.retrySendPrintPartDelay = setTimeout(function() {
|
|
|
|
console.log("request printer:sendPrintPart failed retry");
|
2013-11-22 16:51:26 +01:00
|
|
|
self.sendPrintPart(sendIndex, sendLength)
|
2013-10-11 15:33:37 +02:00
|
|
|
},self.retryDelay); // retry after delay
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-16 18:27:10 +02:00
|
|
|
// after we know the gcode packed has bin received or failed
|
2013-11-22 16:51:26 +01:00
|
|
|
// (and the driver had time to update the printer.state)
|
2013-10-16 18:27:10 +02:00
|
|
|
// we start checking the status again
|
|
|
|
self.startStatusCheckInterval();
|
2013-08-19 17:55:01 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log ("Printer >> f:sendPrintPart() >> communicateWithWifibox is false, so not executing this function");
|
|
|
|
}
|
2013-08-07 20:47:47 +02:00
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-08-07 20:47:47 +02:00
|
|
|
this.stop = function() {
|
|
|
|
console.log("Printer:stop");
|
2013-10-28 17:17:50 +01:00
|
|
|
endCode = generateEndCode();
|
|
|
|
console.log(" endCode: ",endCode);
|
|
|
|
var postData = { gcode: endCode.join("\n")};
|
2013-08-16 19:27:48 +02:00
|
|
|
var self = this;
|
2013-08-19 17:55:01 +02:00
|
|
|
if (communicateWithWifibox) {
|
|
|
|
$.ajax({
|
|
|
|
url: this.wifiboxURL + "/printer/stop",
|
|
|
|
type: "POST",
|
2013-10-28 17:17:50 +01:00
|
|
|
data: postData,
|
2013-08-19 17:55:01 +02:00
|
|
|
dataType: 'json',
|
|
|
|
timeout: this.timeoutTime,
|
|
|
|
success: function(data){
|
|
|
|
console.log("Printer:stop response: ", data);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-16 18:27:10 +02:00
|
|
|
// after we know the stop has bin received or failed
|
2013-11-22 16:51:26 +01:00
|
|
|
// (and the driver had time to update the printer.state)
|
2013-10-16 18:27:10 +02:00
|
|
|
// we start checking the status again
|
|
|
|
self.startStatusCheckInterval();
|
2013-08-19 17:55:01 +02:00
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
}).fail(function() {
|
2013-08-19 17:55:01 +02:00
|
|
|
console.log("Printer:stop: failed");
|
|
|
|
clearTimeout(self.retryStopDelay);
|
|
|
|
self.retryStopDelay = setTimeout(function() { self.stop() },self.retryDelay); // retry after delay
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-16 18:27:10 +02:00
|
|
|
// after we know the stop has bin received or failed
|
2013-11-22 16:51:26 +01:00
|
|
|
// (and the driver had time to update the printer.state)
|
2013-10-16 18:27:10 +02:00
|
|
|
// we start checking the status again
|
|
|
|
self.startStatusCheckInterval();
|
2013-08-19 17:55:01 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log ("Printer >> f:communicateWithWifibox() >> communicateWithWifibox is false, so not executing this function");
|
|
|
|
}
|
2013-08-07 20:47:47 +02:00
|
|
|
}
|
2013-10-16 18:27:10 +02:00
|
|
|
this.startStatusCheckInterval = function() {
|
|
|
|
console.log("Printer:startStatusCheckInterval");
|
|
|
|
self.checkStatus();
|
|
|
|
clearTimeout(self.checkStatusDelay);
|
|
|
|
clearTimeout(self.retryCheckStatusDelay);
|
|
|
|
self.checkStatusDelay = setTimeout(function() { self.checkStatus() }, self.checkStatusInterval);
|
|
|
|
}
|
|
|
|
this.stopStatusCheckInterval = function() {
|
|
|
|
console.log("Printer:stopStatusCheckInterval");
|
|
|
|
clearTimeout(self.checkStatusDelay);
|
|
|
|
clearTimeout(self.retryCheckStatusDelay);
|
|
|
|
}
|
2013-10-11 12:39:05 +02:00
|
|
|
this.checkStatus = function() {
|
2014-01-20 12:58:21 +01:00
|
|
|
//console.log("Printer:checkStatus");
|
2013-10-14 17:40:56 +02:00
|
|
|
this.stateOverruled = false;
|
2013-10-18 19:11:10 +02:00
|
|
|
//console.log(" stateOverruled: ",this.stateOverruled);
|
2013-08-09 22:25:14 +02:00
|
|
|
var self = this;
|
2013-08-16 22:25:25 +02:00
|
|
|
if (communicateWithWifibox) {
|
|
|
|
$.ajax({
|
2013-10-11 12:39:05 +02:00
|
|
|
url: this.wifiboxURL + "/info/status",
|
2013-08-16 22:25:25 +02:00
|
|
|
dataType: 'json',
|
|
|
|
timeout: this.timeoutTime,
|
2013-10-11 12:39:05 +02:00
|
|
|
success: function(response){
|
2013-10-18 19:11:10 +02:00
|
|
|
//console.log(" Printer:status: ",response.data.state); //," response: ",response);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
self.handleStatusUpdate(response);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
clearTimeout(self.checkStatusDelay);
|
|
|
|
clearTimeout(self.retryCheckStatusDelay);
|
|
|
|
self.checkStatusDelay = setTimeout(function() { self.checkStatus() }, self.checkStatusInterval);
|
2013-08-16 22:25:25 +02:00
|
|
|
}
|
|
|
|
}).fail(function() {
|
2013-10-11 12:39:05 +02:00
|
|
|
console.log("Printer:checkStatus: failed");
|
2013-10-18 19:11:10 +02:00
|
|
|
self.state = Printer.WIFIBOX_DISCONNECTED_STATE;
|
2013-10-11 12:39:05 +02:00
|
|
|
clearTimeout(self.checkStatusDelay);
|
|
|
|
clearTimeout(self.retryCheckStatusDelay);
|
|
|
|
self.retryCheckStatusDelay = setTimeout(function() { self.checkStatus() },self.retryDelay); // retry after delay
|
2013-10-18 19:11:10 +02:00
|
|
|
$(document).trigger(Printer.UPDATE);
|
2013-08-16 22:25:25 +02:00
|
|
|
});
|
|
|
|
} else {
|
2013-10-11 12:39:05 +02:00
|
|
|
console.log ("Printer >> f:checkStatus() >> communicateWithWifibox is false, so not executing this function");
|
2013-08-16 22:25:25 +02:00
|
|
|
}
|
2013-08-07 20:47:47 +02:00
|
|
|
}
|
2013-10-11 12:39:05 +02:00
|
|
|
this.handleStatusUpdate = function(response) {
|
2014-01-20 12:58:21 +01:00
|
|
|
//console.log("Printer:handleStatusUpdate response: ",response);
|
2013-10-11 12:39:05 +02:00
|
|
|
var data = response.data;
|
|
|
|
if(response.status != "success") {
|
|
|
|
self.state = Printer.UNKNOWN_STATE;
|
|
|
|
} else {
|
|
|
|
// state
|
2013-10-18 19:11:10 +02:00
|
|
|
//console.log(" stateOverruled: ",this.stateOverruled);
|
2013-10-14 17:40:56 +02:00
|
|
|
if(!this.stateOverruled) {
|
|
|
|
self.state = data.state;
|
2013-10-18 19:11:10 +02:00
|
|
|
//console.log(" state > ",self.state);
|
2013-10-14 17:40:56 +02:00
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// temperature
|
|
|
|
self.temperature = data.hotend;
|
|
|
|
self.targetTemperature = data.hotend_target;
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// progress
|
|
|
|
self.currentLine = data.current_line;
|
|
|
|
self.totalLines = data.total_lines;
|
|
|
|
self.bufferedLines = data.buffered_lines
|
2013-09-18 18:55:37 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// access
|
|
|
|
self.hasControl = data.has_control;
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
if(self.state == Printer.PRINTING_STATE || self.state == Printer.STOPPING_STATE) {
|
|
|
|
console.log("progress: ",self.currentLine+"/"+self.totalLines+" ("+self.bufferedLines+") ("+self.state+")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$(document).trigger(Printer.UPDATE);
|
2013-09-18 18:55:37 +02:00
|
|
|
}
|
2013-10-14 17:40:56 +02:00
|
|
|
this.overruleState = function(newState) {
|
|
|
|
this.stateOverruled = true;
|
|
|
|
console.log(" stateOverruled: ",this.stateOverruled);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-14 17:40:56 +02:00
|
|
|
self.state = newState;
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-14 17:40:56 +02:00
|
|
|
$(document).trigger(Printer.UPDATE);
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-16 18:27:10 +02:00
|
|
|
this.stopStatusCheckInterval();
|
2013-10-14 17:40:56 +02:00
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
|
2013-10-18 16:38:20 +02:00
|
|
|
this.removeLeaveWarning = function() {
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
}
|
|
|
|
this.addLeaveWarning = function() {
|
|
|
|
window.onbeforeunload = function() {
|
2013-10-23 17:25:46 +02:00
|
|
|
console.log("WARNING:"+Printer.ON_BEFORE_UNLOAD_MESSAGE);
|
2013-10-18 16:38:20 +02:00
|
|
|
return Printer.ON_BEFORE_UNLOAD_MESSAGE;
|
|
|
|
};
|
|
|
|
}
|
2013-11-22 16:51:26 +01:00
|
|
|
}
|