0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2025-04-20 19:26:27 +02:00

update for API changes & cleanup

This commit is contained in:
Rick Companje 2015-06-02 14:44:10 +02:00
parent a3fc3995d8
commit ed8faf058f

View File

@ -6,17 +6,12 @@
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details. * 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 var filemanager = function() {
function getURLParameter(name) { var className = 'filemanager';
return decodeURI((new RegExp('[&?]'+name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]); var sketchAPI = new SketchAPI();
}
var wifiboxURL = ""; if (location.host=='doodle3d') API.setURL('http://wifibox/d3dapi/'); //local
else API.setURL('/d3dapi/');
if (getURLParameter("r") != "null") wifiboxURL = 'http://192.168.5.1';
if (getURLParameter("wifiboxURL") != "null") wifiboxURL = getURLParameter("wifiboxURL");
var api = wifiboxURL+'/d3dapi/sketch/';
$("#logo").click(onLogoClick) $("#logo").click(onLogoClick)
$("#btnDelete").click(deleteSelectedSketches); $("#btnDelete").click(deleteSelectedSketches);
@ -36,30 +31,20 @@ var isBusy = true;
updateButtonStates(); updateButtonStates();
$.get(api+'list', function(data) { //?id=00003 sketchAPI.list(function(data) {
if (data.status=='success') {
var list = data.data.list;
// list.reverse();
isBusy = true; isBusy = true;
updateButtonStates(); updateButtonStates();
updateStatusMessage('loading '+list.length+' sketches...'); updateStatusMessage('loading '+data.list.length+' sketches...');
loadSketch(list, function() { loadSketch(data.list, function() {
console.log('done'); console.log('done');
isBusy = false; isBusy = false;
updateFreeSpace(); updateFreeSpace();
updateButtonStates(); updateButtonStates();
}); });
},function(response) {
} else { alert('Error reading sketches');
console.log('failure',data) console.log(response);
}
}).fail(function(status) {
alert("Error ("+status.status+") connecting to "+api+'list');
console.log(status);
}); });
@ -70,12 +55,14 @@ function onLogoClick() {
function loadSketch(list,cb) { function loadSketch(list,cb) {
var id = list.pop(); var id = list.pop();
$.get(api+'?id='+id, function(data) { if (!id) {
if (cb) cb();
if (data.status=='success') { return;
addItem(id,data.data.data);
} }
sketchAPI.load(id,function(response) {
// console.log(className,'loadSketch',response);
addItem(id,response.data);
updateStatusMessage('loading '+list.length+' sketches...'); updateStatusMessage('loading '+list.length+' sketches...');
if (list.length>0) { if (list.length>0) {
@ -85,7 +72,8 @@ function loadSketch(list,cb) {
} else { } else {
cb(); cb();
} }
}); })
} }
function addItem(id,svgData,doPrepend) { function addItem(id,svgData,doPrepend) {
@ -115,7 +103,9 @@ function addItem(id,svgData,doPrepend) {
function deleteSketches(list,cb) { function deleteSketches(list,cb) {
var id = list.pop(); 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() { $('.item[data='+id+']').fadeOut('slow',function() {
$(this).remove(); //remove when effect is finished $(this).remove(); //remove when effect is finished
@ -133,7 +123,9 @@ function deleteSketches(list,cb) {
} }
function deleteSelectedSketches() { 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 = []; var ids = [];
$('.item.selected').map(function(){ $('.item.selected').map(function(){
@ -153,7 +145,6 @@ function deleteSelectedSketches() {
deselectAll(); deselectAll();
updateButtonStates(); updateButtonStates();
} }
}
function selectAll() { function selectAll() {
$('.item').addClass('selected'); $('.item').addClass('selected');
@ -231,12 +222,10 @@ function upload() {
} }
function updateFreeSpace() { function updateFreeSpace() {
$.get(api+'status', function(data) { //?id=00003 sketchAPI.status(function(data) {
if (data.status=='success') { var numSketches = data.number_of_sketches;
var numSketches = data.data.number_of_sketches; var freeKb = Math.round(data.available/1024);
var freeKb = Math.round(data.data.available/1024);
updateStatusMessage(numSketches+" sketches, "+freeKb+"k bytes free"); updateStatusMessage(numSketches+" sketches, "+freeKb+"k bytes free");
}
}); });
} }
@ -281,3 +270,10 @@ function combine() {
location.href = '/printmanager/?ids=' + ids.join(); //+ location.search + 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]);
}
}();