0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-27 02:53:48 +01:00
doodle3d-connect/js/PrintPage.js

190 lines
5.6 KiB
JavaScript
Raw Normal View History

2017-06-20 21:43:57 +02:00
/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013-2017, 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.
*/
(function (w) {
var _page;
var _form;
var _statusField;
var _infoField;
var _noRetainCheckbox;
var _includeBetasCheckbox;
var _submitButton;
var _printerItem;
var _infoAPI = new InfoAPI();
var _networkAPI = new NetworkAPI();
var _serverAPI = new ServerAPI();
var _updateAPI = new UpdateAPI();
var _configAPI = new ConfigAPI();
var _printerAPI = new PrinterAPI();
var _pageData = {};
var _updateStatus = {};
var _title;
var _settings;
var PAGE_ID = "#print";
var _self = this;
$.mobile.document.on( "pageinit", PAGE_ID, function( event, data ) {
console.log(PAGE_ID+":pageinit");
_page = $(this);
_title = _page.find(".ui-title");
2017-07-11 12:31:13 +02:00
$("#btnPrint").button().on("click", fetchPrint);
$("#btnPrint").button('disable');
2017-06-20 21:43:57 +02:00
});
2017-07-11 12:31:13 +02:00
$.mobile.document.on("pagebeforeshow", PAGE_ID, function( event, data ) {
2017-06-20 21:43:57 +02:00
_pageData = d3d.util.getPageParams(PAGE_ID);
2017-07-11 12:31:13 +02:00
console.log(PAGE_ID,'_pageData',_pageData);
2017-06-20 21:43:57 +02:00
if(_pageData === undefined) {
console.log("ERROR",PAGE_ID,"_pageData undefined");
$.mobile.changePage("#boxes");
return;
}
var boxURL = "http://"+_pageData.localip;
2017-07-11 12:31:13 +02:00
// $("#lstPrint li.boxItem h2").text(_pageData.wifiboxid);
2017-06-20 21:43:57 +02:00
$("#lstPrint li.gcodeItem").attr("title",d3d.pageParams.uuid);
_infoAPI.init(boxURL);
_configAPI.init(boxURL);
_networkAPI.init(boxURL);
_printerAPI.init(boxURL);
_serverAPI.init("https://gcodeserver.doodle3d.com");
2017-07-11 12:31:13 +02:00
$("#btnPrint").button('disable');
// $("#lstPrint li.materialItem p").html(d3d.pageParams.uuid);
// $("#lstPrint li.gcodeItem p").text("...")
2017-06-20 21:43:57 +02:00
_serverAPI.getInfo(d3d.pageParams.uuid, function(successData) {
console.log("getInfo success",successData);
2017-07-11 12:31:13 +02:00
var filesize = d3d.util.formatBytes(successData["bytes"]);
_serverAPI.fetchHeader(d3d.pageParams.uuid,function(successData) {
console.log("_serverAPI fetchHeader success",successData);
var header = successData;
// $("#lstPrint li.gcodeItem h2").text("GCODE File");
$("#lstPrint li.gcodeItem p").text(header.name + " (" + filesize + ")");
}, function(failData) {
console.log("_serverAPI fetchHeader fail",failData);
});
2017-06-20 21:43:57 +02:00
},function(failData) {
console.log("getInfo failed",failData);
2017-07-11 12:31:13 +02:00
$("#lstPrint li.gcodeItem p").text("Problem: '"+(failData?failData.msg:"Unknown error") + "'");
$("#lstPrint li.gcodeItem p").addClass('failState');
$("#btnPrint").button('disable');
2017-06-20 21:43:57 +02:00
});
2017-07-11 12:31:13 +02:00
2017-06-20 21:43:57 +02:00
_networkAPI.status(function(successData) {
console.log("network status",successData);
2017-07-11 12:31:13 +02:00
$("#lstPrint li.boxItem p").text(successData.statusMessage + " (" + successData.ssid + " @ " + _pageData.localip + ")");
2017-06-20 21:43:57 +02:00
}, function(failData) {
2017-07-11 12:31:13 +02:00
console.log("_networkAPI status failed",failData);
2017-06-20 21:43:57 +02:00
});
2017-07-11 12:31:13 +02:00
_infoAPI.getInfo(function(successData) {
console.log("info/",successData);
$("#lstPrint li.boxItem h2").text(successData.wifiboxid);
}, function(failData) {
console.log("info/ failed",failData);
});
2017-06-20 21:43:57 +02:00
_infoAPI.getStatus(function(successData) {
2017-07-11 12:31:13 +02:00
$("#lstPrint li.printerItem p").removeClass();
$("#lstPrint li.printerItem p").addClass(successData.state);
2017-06-20 21:43:57 +02:00
$("#lstPrint li.printerItem p").text("Status: " + successData.state);
2017-07-11 12:31:13 +02:00
// console.log("info getStatus",successData.state);
if (successData.state==="idle") {
$("#btnPrint").button('enable');
}
if (successData.state==="printing") { //redirect to Control page
// var url = d3d.util.replaceURLParameters("#control",_pageData);
// $.mobile.changePage(url);
$("#btnPrint").button('disable');
console.log("already printing...");
}
2017-06-20 21:43:57 +02:00
},function(failData) {
console.log("getStatus fail");
d3d.util.hideLoader();
});
_configAPI.loadAll(function(successData) {
_settings = successData;
console.log(_settings);
2017-06-20 21:43:57 +02:00
var printerLink = $("#lstPrint li.printerItem a").attr("href");
printerLink = d3d.util.replaceURLParameters(printerLink,_pageData);
$("#lstPrint li.printerItem a").attr("href",printerLink);
var materialInfo =
_settings["printer.filamentThickness"] + "mm @ " +
_settings["printer.temperature"] + " °C";
$("#lstPrint li.materialItem p").html(materialInfo);
$("#lstPrint li.materialItem a").attr("href",printerLink);
_printerAPI.listAll(function(successData) {
console.log("printer listAll");
var printerId = _settings["printer.type"];
var printerName = successData[printerId];
$("#lstPrint li.printerItem h2").text(printerName);
$("#lstPrint li.printerItem img").attr('src','img/icons/printers/'+printerId+'.png');
},function(failData) {
console.log("printer listAll fail",failData);
});
},function(failData) {
console.log(failData);
});
});
$.mobile.document.on("pagebeforehide", PAGE_ID, function( event, data ) {
2017-06-20 21:43:57 +02:00
});
function fetchPrint() {
var startcode = _configAPI.subsituteVariables(_settings["printer.startcode"],_settings);
var endcode = _configAPI.subsituteVariables(_settings["printer.endcode"],_settings);
var data = {
2017-06-20 21:43:57 +02:00
"id": d3d.pageParams.uuid,
"start_code": startcode,
"end_code": endcode
};
console.log("fetchPrint",d3d.pageParams.uuid,data);
_printerAPI.fetch(data,function(successData) {
2017-06-20 21:43:57 +02:00
console.log("fetchPrint success",successData);
var url = d3d.util.replaceURLParameters("#control",_pageData);
$.mobile.changePage(url);
2017-06-20 21:43:57 +02:00
},function(failData) {
console.log("fetchPrint fail",failData);
window.alert("Problem: " + failData.msg);
2017-06-20 21:43:57 +02:00
});
}
})(window);