mirror of
https://github.com/Doodle3D/doodle3d-client.git
synced 2024-11-22 01:07:56 +01:00
Moved retrieve printer types list to PrinterPanel
This commit is contained in:
parent
05e49a54ff
commit
079ed5a164
46
js/api/PrinterAPI.js
Normal file
46
js/api/PrinterAPI.js
Normal file
@ -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();
|
||||
});
|
||||
};
|
||||
}
|
@ -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($('<option>').text(value).attr('value', key));
|
||||
});
|
||||
completeHandler();
|
||||
});
|
||||
}
|
||||
this.printerSelectorChanged = function(e) {
|
||||
_self.printerType = _printerSelector.find("option:selected").val();
|
||||
var settings = {};
|
||||
|
Loading…
Reference in New Issue
Block a user