0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-26 18:43:48 +01:00
doodle3d-connect/js/SettingsPage.js

194 lines
5.1 KiB
JavaScript
Raw Normal View History

2017-05-16 09:55:32 +02:00
/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
2017-05-16 11:02:29 +02:00
* Copyright (c) 2013-2017, Doodle3D
2017-05-16 09:55:32 +02:00
* 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 _updateAPI = new UpdateAPI();
var _configAPI = new ConfigAPI();
var _printerAPI = new PrinterAPI();
2017-06-20 21:43:33 +02:00
var _infoAPI = new InfoAPI();
2017-05-16 09:55:32 +02:00
var _pageData = {};
var _updateStatus = {};
2017-05-16 11:57:13 +02:00
var _title;
2017-05-16 09:55:32 +02:00
var PAGE_ID = "#settings";
2017-06-20 21:43:33 +02:00
var timerObject = {
interval_id : null
};
2017-05-16 09:55:32 +02:00
var _self = this;
2017-05-16 11:02:29 +02:00
function showOrHideFields() {
if ($("#chkBed").prop("checked")) {
2017-05-16 09:55:32 +02:00
$("#grpBedTemp").show();
} else {
$("#grpBedTemp").hide();
}
}
$.mobile.document.on( "pageinit", PAGE_ID, function( event, data ) {
console.log(PAGE_ID+":pageinit");
_page = $(this);
2017-05-16 11:57:13 +02:00
_title = _page.find(".ui-title");
2017-05-16 09:55:32 +02:00
$("#divSettings").hide();
d3d.util.showLoader();
2017-05-16 11:02:29 +02:00
$("#lstPrinters").on("change", function(data) {
var printerType = $(this).val();
2017-05-16 11:57:13 +02:00
d3d.util.showLoader();
2017-05-16 11:02:29 +02:00
_configAPI.savePrinterType(printerType,function(successData) {
refreshSettings();
},function(failData) {
console.log("savePrinterType fail",failData);
});
});
$("#nozzleTemperature").on('slidestop', function( event ) {
_configAPI.save({"printer.temperature":$(this).val()});
});
$("#nozzleTemperature").on('focusout', function( event ) {
_configAPI.save({"printer.temperature":$(this).val()});
});
$("#bedTemperature").on('slidestop', function( event ) {
_configAPI.save({"printer.bed.temperature":$(this).val()});
});
$("#bedTemperature").on('focusout', function( event ) {
_configAPI.save({"printer.bed.temperature":$(this).val()});
2017-05-16 09:55:32 +02:00
});
$("#filamentThickness").on("change", function(data) {
2017-05-16 11:02:29 +02:00
_configAPI.save({"printer.filamentThickness":$(this).val()});
2017-05-16 09:55:32 +02:00
});
2017-05-16 11:02:29 +02:00
$("#dimensionsX").on("change", function(data) {
_configAPI.save({"printer.dimensions.x":$(this).val()});
});
$("#dimensionsY").on("change", function(data) {
_configAPI.save({"printer.dimensions.y":$(this).val()});
2017-05-16 09:55:32 +02:00
});
2017-05-16 11:02:29 +02:00
$("#dimensionsZ").on("change", function(data) {
_configAPI.save({"printer.dimensions.z":$(this).val()});
});
$('#startgcode').on("change", function(data) {
_configAPI.save({"printer.startcode":$(this).val()});
});
$('#endgcode').on("change", function(data) {
_configAPI.save({"printer.end":$(this).val()});
});
$("#chkBed").on("change", function(data) {
showOrHideFields();
});
});
2017-06-20 21:43:33 +02:00
$.mobile.document.on("pagebeforeshow", PAGE_ID, function( event, data ) {
2017-05-16 09:55:32 +02:00
_pageData = d3d.util.getPageParams(PAGE_ID);
if(_pageData === undefined) {
console.log("ERROR",PAGE_ID,"_pageData undefined");
$.mobile.changePage("#boxes");
return;
}
var boxURL = "http://"+_pageData.localip;
2017-05-16 11:57:13 +02:00
_title.text("Settings for " + _pageData.wifiboxid);
2017-05-16 09:55:32 +02:00
_configAPI.init(boxURL);
_printerAPI.init(boxURL);
2017-06-20 21:43:33 +02:00
_infoAPI.init(boxURL);
2017-05-16 09:55:32 +02:00
2017-05-16 11:02:29 +02:00
refreshSettings();
2017-06-20 21:43:33 +02:00
2017-05-16 11:02:29 +02:00
});
2017-06-20 21:43:33 +02:00
$.mobile.document.on('pagehide', PAGE_ID, function(){
});
2017-05-16 11:02:29 +02:00
$.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) {
2017-06-20 21:43:33 +02:00
console.log("pagebeforehide");
2017-05-16 11:02:29 +02:00
});
2017-05-16 09:55:32 +02:00
2017-05-16 11:02:29 +02:00
function refreshSettings() {
2017-05-16 09:55:32 +02:00
_configAPI.loadAll(function(successData) {
var printerType = successData["printer.type"];
var printerStartGCode = successData["printer.startcode"];
var printerEndGCode = successData["printer.endcode"];
var heatedBedEnabled = successData["printer.heatedbed"];
var bedTemperature = successData["printer.bed.temperature"];
var dimensionsX = successData["printer.dimensions.x"];
var dimensionsY = successData["printer.dimensions.y"];
var dimensionsZ = successData["printer.dimensions.z"];
var filamentThickness = successData["printer.filamentThickness"];
var nozzleTemperature = successData["printer.temperature"];
$('#chkBed').prop('checked', heatedBedEnabled);
$('#chkBed').val('on').flipswitch('refresh');
$('#bedTemperature').val(bedTemperature);
$('#dimensionsX').val(dimensionsX);
$('#dimensionsY').val(dimensionsY);
$('#dimensionsZ').val(dimensionsZ);
$('#filamentThickness').val(filamentThickness);
$('#startgcode').val(printerStartGCode);
$('#endgcode').val(printerEndGCode);
$('#nozzleTemperature').val(nozzleTemperature);
_printerAPI.listAll(function(printers) {
$("#lstPrinters").empty();
for (var id in printers) {
var selected = (id===printerType) ? "selected " : "";
$("#lstPrinters").append("<option "+selected+" value='"+id+"'>"+printers[id]+"</option>");
}
$("#lstPrinters").selectmenu("refresh", true);
$("#divSettings").show();
d3d.util.hideLoader();
2017-05-16 11:02:29 +02:00
showOrHideFields();
$("#bedTemperature").slider("refresh");
$("#nozzleTemperature").slider("refresh");
2017-05-16 09:55:32 +02:00
2017-05-16 11:02:29 +02:00
},function(failData) {
console.log(PAGE_ID,'FAIL _printerAPI.listAll');
2017-05-16 09:55:32 +02:00
$.mobile.changePage("#boxes");
return;
});
},function(failData) {
console.log("FAIL loadPrinterType",failData);
$.mobile.changePage("#boxes");
return;
});
2017-05-16 11:02:29 +02:00
}
2017-05-16 09:55:32 +02:00
})(window);