Auto-load file on connect; some refactoring

This commit is contained in:
Alex Ustyantsev committed 2013-02-03 12:02:41 +03:00
1 parent 4b69bde8bb
commit 644e5907ec
2 files changed
+44 -13

No files matched your search

+3
View File
@@ -296,6 +296,9 @@ GCODE.ui = (function(){
}
return -1;
},
updateLayerInfo: function(layerNum){
printLayerInfo(layerNum);
},
processOptions: function(){
if(document.getElementById('sortLayersCheckbox').checked)GCODE.gCodeReader.setOption({sortLayers: true});
+41 -13
View File
@@ -667,13 +667,6 @@ function GcodeFilesViewModel() {
dataType: "json",
data: {filename: filename}
})
$.ajax({
url: "gcodefile/"+filename,
type: "GET",
success: function(response, rstatus) {
self.showGCodeViewer(response, rstatus);
}
})
}
self.viewFile = function() {
@@ -817,18 +810,53 @@ function WebcamViewModel() {
function GcodeViewModel() {
var self = this;
self.loadedFilename = undefined;
self.status = 'idle';
self.loadFile = function(filename){
if(self.status == 'idle'){
self.status = 'request';
$.ajax({
url: "gcodefile/"+filename,
type: "GET",
success: function(response, rstatus) {
if(rstatus === 'success'){
self.showGCodeViewer(response, rstatus);
self.loadedFilename=filename;
self.status = 'idle';
}
},
error: function() {
self.status = 'idle';
}
})
}
}
self.showGCodeViewer = function(response, rstatus){
var par = {};
par.target = {};
par.target.result = response;
GCODE.gCodeReader.loadFile(par);
}
self.fromHistoryData = function(data) {
self._processProgressData(data.progress);
self._processData(data);
}
self.fromCurrentData = function(data) {
self._processProgressData(data.progress);
self._processData(data);
}
self._processProgressData = function(data) {
var cmdIndex = GCODE.gCodeReader.getLinesCmdIndex(data.progress);
if(cmdIndex){
GCODE.renderer.render(cmdIndex.layer, 0, cmdIndex.cmd);
self._processData = function(data) {
if(self.loadedFilename == data.job.filename){
var cmdIndex = GCODE.gCodeReader.getLinesCmdIndex(data.progress.progress);
if(cmdIndex){
GCODE.renderer.render(cmdIndex.layer, 0, cmdIndex.cmd);
GCODE.ui.updateLayerInfo(cmdIndex.layer);
}
}else{
self.loadFile(data.job.filename);
}
}