0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-12-12 01:05:53 +01:00
doodle3d-client/js/sketches.js

103 lines
2.2 KiB
JavaScript
Raw Normal View History

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
var sketchLoaded = false;
2014-12-17 09:45:40 +01:00
function previousSketch(e) {
loadSketch(curSketch-1);
}
2014-12-17 09:45:40 +01:00
function nextSketch(e) {
loadSketch(curSketch+1);
}
2014-12-17 09:45:40 +01:00
function newSketch(e) {
clearDoodle();
curSketch = sketches.length; //index of the last item + 1
updateSketchButtonStates();
}
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();
}
})
}
2014-12-17 09:45:40 +01:00
function setSketchModified(_isModified) {
isModified = _isModified;
updateSketchButtonStates();
}
2014-12-17 09:45:40 +01:00
function updateSketchButtonStates() {
console.log('sketch: isModified',isModified,'curSketch',curSketch,'sketches.length',sketches.length);
2014-12-17 09:45:40 +01:00
if (isModified) {
btnSave.enable();
}
else {
btnSave.disable();
}
2014-12-17 09:45:40 +01:00
if (curSketch<sketches.length-1) {
btnNext.enable();
2014-12-17 09:45:40 +01:00
} else {
btnNext.disable();
}
2014-12-17 09:45:40 +01:00
if (curSketch>0) {
btnPrevious.enable();
} else {
btnPrevious.disable();
}
}
2014-12-17 09:45:40 +01:00
function loadSketch(_curSketch) {
curSketch = _curSketch;
2014-12-17 09:45:40 +01:00
if (curSketch<0) curSketch=0;
if (curSketch>sketches.length-1) curSketch=sketches.length-1;
2014-12-17 09:45:40 +01:00
var id = sketches[curSketch];
2014-12-17 09:45:40 +01:00
console.log('sketch: loadSketch curSketch',curSketch,'id',id);
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);
sketchLoaded = true;
2014-12-17 09:45:40 +01:00
} else {
console.log('error loading sketch: ',response);
listSketches();
}
})
}
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();
})
}