mirror of
https://github.com/Doodle3D/doodle3d-client.git
synced 2025-04-20 11:16:27 +02:00
update for API changes & cleanup
This commit is contained in:
parent
a3fc3995d8
commit
ed8faf058f
@ -6,17 +6,12 @@
|
||||
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
*/
|
||||
|
||||
// http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery
|
||||
function getURLParameter(name) {
|
||||
return decodeURI((new RegExp('[&?]'+name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]);
|
||||
}
|
||||
var filemanager = function() {
|
||||
var className = 'filemanager';
|
||||
var sketchAPI = new SketchAPI();
|
||||
|
||||
var wifiboxURL = "";
|
||||
|
||||
if (getURLParameter("r") != "null") wifiboxURL = 'http://192.168.5.1';
|
||||
if (getURLParameter("wifiboxURL") != "null") wifiboxURL = getURLParameter("wifiboxURL");
|
||||
|
||||
var api = wifiboxURL+'/d3dapi/sketch/';
|
||||
if (location.host=='doodle3d') API.setURL('http://wifibox/d3dapi/'); //local
|
||||
else API.setURL('/d3dapi/');
|
||||
|
||||
$("#logo").click(onLogoClick)
|
||||
$("#btnDelete").click(deleteSelectedSketches);
|
||||
@ -36,30 +31,20 @@ var isBusy = true;
|
||||
|
||||
updateButtonStates();
|
||||
|
||||
$.get(api+'list', function(data) { //?id=00003
|
||||
|
||||
if (data.status=='success') {
|
||||
var list = data.data.list;
|
||||
// list.reverse();
|
||||
|
||||
sketchAPI.list(function(data) {
|
||||
isBusy = true;
|
||||
updateButtonStates();
|
||||
updateStatusMessage('loading '+list.length+' sketches...');
|
||||
updateStatusMessage('loading '+data.list.length+' sketches...');
|
||||
|
||||
loadSketch(list, function() {
|
||||
loadSketch(data.list, function() {
|
||||
console.log('done');
|
||||
isBusy = false;
|
||||
updateFreeSpace();
|
||||
updateButtonStates();
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log('failure',data)
|
||||
}
|
||||
|
||||
}).fail(function(status) {
|
||||
alert("Error ("+status.status+") connecting to "+api+'list');
|
||||
console.log(status);
|
||||
},function(response) {
|
||||
alert('Error reading sketches');
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
|
||||
@ -70,12 +55,14 @@ function onLogoClick() {
|
||||
function loadSketch(list,cb) {
|
||||
var id = list.pop();
|
||||
|
||||
$.get(api+'?id='+id, function(data) {
|
||||
|
||||
if (data.status=='success') {
|
||||
addItem(id,data.data.data);
|
||||
if (!id) {
|
||||
if (cb) cb();
|
||||
return;
|
||||
}
|
||||
|
||||
sketchAPI.load(id,function(response) {
|
||||
// console.log(className,'loadSketch',response);
|
||||
addItem(id,response.data);
|
||||
updateStatusMessage('loading '+list.length+' sketches...');
|
||||
|
||||
if (list.length>0) {
|
||||
@ -85,7 +72,8 @@ function loadSketch(list,cb) {
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function addItem(id,svgData,doPrepend) {
|
||||
@ -115,7 +103,9 @@ function addItem(id,svgData,doPrepend) {
|
||||
function deleteSketches(list,cb) {
|
||||
var id = list.pop();
|
||||
|
||||
$.post(api+'delete', {id:id}, function(data) {
|
||||
// $.post(api+'delete', {id:id}, function(data) {
|
||||
|
||||
sketchAPI.del(id,function(data) {
|
||||
|
||||
$('.item[data='+id+']').fadeOut('slow',function() {
|
||||
$(this).remove(); //remove when effect is finished
|
||||
@ -133,7 +123,9 @@ function deleteSketches(list,cb) {
|
||||
}
|
||||
|
||||
function deleteSelectedSketches() {
|
||||
if (confirm('Do you want to delete '+$('.item.selected').length+' drawings?')) {
|
||||
if (!confirm('Do you want to delete '+$('.item.selected').length+' drawings?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = [];
|
||||
$('.item.selected').map(function(){
|
||||
@ -153,7 +145,6 @@ function deleteSelectedSketches() {
|
||||
deselectAll();
|
||||
updateButtonStates();
|
||||
}
|
||||
}
|
||||
|
||||
function selectAll() {
|
||||
$('.item').addClass('selected');
|
||||
@ -231,12 +222,10 @@ function upload() {
|
||||
}
|
||||
|
||||
function updateFreeSpace() {
|
||||
$.get(api+'status', function(data) { //?id=00003
|
||||
if (data.status=='success') {
|
||||
var numSketches = data.data.number_of_sketches;
|
||||
var freeKb = Math.round(data.data.available/1024);
|
||||
sketchAPI.status(function(data) {
|
||||
var numSketches = data.number_of_sketches;
|
||||
var freeKb = Math.round(data.available/1024);
|
||||
updateStatusMessage(numSketches+" sketches, "+freeKb+"k bytes free");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -281,3 +270,10 @@ function combine() {
|
||||
location.href = '/printmanager/?ids=' + ids.join(); //+ location.search +
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery
|
||||
function getURLParameter(name) {
|
||||
return decodeURI((new RegExp('[&?]'+name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]);
|
||||
}
|
||||
|
||||
|
||||
}();
|
||||
|
Loading…
x
Reference in New Issue
Block a user