2013-12-20 16:31:41 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
var curSketch = 0;
|
|
|
|
var sketches = []; //contains fileIDs
|
2013-10-29 23:26:09 +01:00
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
function previousSketch(e) {
|
|
|
|
loadSketch(curSketch-1);
|
2013-10-29 23:26:09 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
function nextSketch(e) {
|
|
|
|
loadSketch(curSketch+1);
|
|
|
|
}
|
2013-10-29 23:26:09 +01:00
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
function newSketch(e) {
|
|
|
|
clearDoodle();
|
|
|
|
curSketch = sketches.length; //index of the last item + 1
|
|
|
|
updateSketchButtonStates();
|
|
|
|
}
|
2013-10-29 23:26:09 +01:00
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
function listSketches() {
|
|
|
|
console.log('listSketches')
|
|
|
|
$.get(wifiboxURL + "/sketch/list", function(data) {
|
|
|
|
if (data.status=='success') {
|
|
|
|
sketches = data.data.list;
|
|
|
|
curSketch = sketches.length-1;
|
|
|
|
setSketchModified(false);
|
|
|
|
updateSketchButtonStates();
|
|
|
|
}
|
|
|
|
})
|
2013-10-29 23:26:09 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
function setSketchModified(_isModified) {
|
|
|
|
isModified = _isModified;
|
|
|
|
updateSketchButtonStates();
|
2013-10-29 23:26:09 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
function updateSketchButtonStates() {
|
2016-04-19 18:03:17 +02:00
|
|
|
console.log('sketch: isModified: ' + isModified + ', curSketch: ' + curSketch + ', sketches.length: ' + sketches.length);
|
2013-10-29 23:26:09 +01:00
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
if (isModified) {
|
|
|
|
btnSave.enable();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
btnSave.disable();
|
2013-10-29 23:26:09 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
if (curSketch<sketches.length-1) {
|
2014-01-30 17:49:15 +01:00
|
|
|
btnNext.enable();
|
2014-12-17 09:45:40 +01:00
|
|
|
} else {
|
|
|
|
btnNext.disable();
|
2013-10-29 23:26:09 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
if (curSketch>0) {
|
|
|
|
btnPrevious.enable();
|
|
|
|
} else {
|
|
|
|
btnPrevious.disable();
|
|
|
|
}
|
2013-10-29 23:26:09 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
function loadSketch(_curSketch) {
|
|
|
|
curSketch = _curSketch;
|
2013-10-29 23:26:09 +01:00
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
if (curSketch<0) curSketch=0;
|
|
|
|
if (curSketch>sketches.length-1) curSketch=sketches.length-1;
|
2013-10-29 23:26:09 +01:00
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
var id = sketches[curSketch];
|
2013-10-29 23:26:09 +01:00
|
|
|
|
2016-04-19 18:03:17 +02:00
|
|
|
console.log('sketch: loadSketch curSketch:' + curSketch + ', id: ' + id);
|
2013-10-29 23:26:09 +01:00
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
$.get(wifiboxURL + "/sketch", {id:id}, function(response) {
|
|
|
|
if (response.status=='success') {
|
|
|
|
console.log('sketch: loaded',response);
|
|
|
|
var svgData = response.data.data;
|
|
|
|
loadFromSvg(svgData);
|
|
|
|
setSketchModified(false);
|
|
|
|
} else {
|
|
|
|
console.log('error loading sketch: ',response);
|
|
|
|
listSketches();
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
2013-10-29 23:26:09 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:45:40 +01:00
|
|
|
function saveSketch() {
|
|
|
|
console.log("sketch: saveSketch");
|
|
|
|
var svgData = saveToSvg();
|
|
|
|
|
|
|
|
$.post(wifiboxURL + "/sketch", {data: svgData}, function(response) {
|
|
|
|
console.log("sketch: saveSketch: response",response);
|
|
|
|
listSketches();
|
|
|
|
})
|
2013-10-29 23:26:09 +01:00
|
|
|
|
|
|
|
}
|