diff --git a/js/api/PrinterAPI.js b/js/api/PrinterAPI.js new file mode 100644 index 0000000..fe96d23 --- /dev/null +++ b/js/api/PrinterAPI.js @@ -0,0 +1,46 @@ +/* + * 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. + */ +function PrinterAPI() { + + var _wifiboxURL; + var _wifiboxCGIBinURL; + var _timeoutTime = 3000; + + var _self = this; + + this.init = function(wifiboxURL,wifiboxCGIBinURL) { + //console.log("PrinterAPI:init"); + //console.log(" wifiboxURL: ",wifiboxURL); + //console.log(" wifiboxCGIBinURL: ",wifiboxCGIBinURL); + _wifiboxURL = wifiboxURL; + _wifiboxCGIBinURL = wifiboxCGIBinURL; + } + + this.listAll = function(completeHandler,failedHandler) { + //console.log("PrinterAPI:listAll"); + //console.log(" _wifiboxURL: ",_wifiboxURL); + $.ajax({ + url: _wifiboxURL + "/printer/listall", + type: "GET", + dataType: 'json', + timeout: _timeoutTime, + success: function(response){ + //console.log("PrinterAPI response: ",response); + if(response.status == "error" || response.status == "fail") { + //console.log("PrinterAPI:listAll failed: ",response); + if(failedHandler) failedHandler(response); + } else { + completeHandler(response.data); + } + } + }).fail(function() { + //console.log("PrinterAPI:listAll failed"); + if(failedHandler) failedHandler(); + }); + }; +} \ No newline at end of file diff --git a/js/settings/PrinterPanel.js b/js/settings/PrinterPanel.js index 8db0fe9..16a4620 100644 --- a/js/settings/PrinterPanel.js +++ b/js/settings/PrinterPanel.js @@ -9,6 +9,7 @@ function PrinterPanel() { this.printerType; + var _api = new PrinterAPI(); var _form = new FormPanel(); // ui elements @@ -21,8 +22,8 @@ function PrinterPanel() { this.init = function(wifiboxURL,wifiboxCGIBinURL,panelElement) { _form.init(wifiboxURL,wifiboxCGIBinURL,panelElement) + _api.init(wifiboxURL,wifiboxCGIBinURL); _element = panelElement; - _printerSelector = _element.find("#printerType"); _printerSelector.change(_self.printerSelectorChanged); @@ -33,6 +34,16 @@ function PrinterPanel() { var gcodePanel = _element.find("#gcodePanel"); gcodePanel.coolfieldset({collapsed:true}); } + this.load = function(completeHandler) { + + _api.listAll(function(data) { + $.each(data.printers, function(key, value) { + // console.log(key,value); + $('#printerType').append($('