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:
parent
a3fc3995d8
commit
ed8faf058f
@ -6,76 +6,63 @@
|
|||||||
* 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';
|
$("#logo").click(onLogoClick)
|
||||||
if (getURLParameter("wifiboxURL") != "null") wifiboxURL = getURLParameter("wifiboxURL");
|
$("#btnDelete").click(deleteSelectedSketches);
|
||||||
|
$("#btnSelectAll").click(selectAll);
|
||||||
|
$("#btnDeselectAll").click(deselectAll);
|
||||||
|
$("#uploads").change(upload);
|
||||||
|
$("#btnDownload").click(download);
|
||||||
|
$("#btnRefresh").click(refresh);
|
||||||
|
$("#btnCombine").click(combine);
|
||||||
|
|
||||||
var api = wifiboxURL+'/d3dapi/sketch/';
|
$("#btnUpload").click(function(e) {
|
||||||
|
|
||||||
$("#logo").click(onLogoClick)
|
|
||||||
$("#btnDelete").click(deleteSelectedSketches);
|
|
||||||
$("#btnSelectAll").click(selectAll);
|
|
||||||
$("#btnDeselectAll").click(deselectAll);
|
|
||||||
$("#uploads").change(upload);
|
|
||||||
$("#btnDownload").click(download);
|
|
||||||
$("#btnRefresh").click(refresh);
|
|
||||||
$("#btnCombine").click(combine);
|
|
||||||
|
|
||||||
$("#btnUpload").click(function(e) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$("#uploads").trigger('click');
|
$("#uploads").trigger('click');
|
||||||
});
|
});
|
||||||
|
|
||||||
var isBusy = true;
|
var isBusy = true;
|
||||||
|
|
||||||
updateButtonStates();
|
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;
|
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) {
|
||||||
|
alert('Error reading sketches');
|
||||||
|
console.log(response);
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log('failure',data)
|
function onLogoClick() {
|
||||||
|
location.href='/'+location.search;
|
||||||
}
|
}
|
||||||
|
|
||||||
}).fail(function(status) {
|
function loadSketch(list,cb) {
|
||||||
alert("Error ("+status.status+") connecting to "+api+'list');
|
|
||||||
console.log(status);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function onLogoClick() {
|
|
||||||
location.href='/'+location.search;
|
|
||||||
}
|
|
||||||
|
|
||||||
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,10 +72,11 @@ function loadSketch(list,cb) {
|
|||||||
} else {
|
} else {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
|
||||||
|
|
||||||
function addItem(id,svgData,doPrepend) {
|
}
|
||||||
|
|
||||||
|
function addItem(id,svgData,doPrepend) {
|
||||||
var path;
|
var path;
|
||||||
|
|
||||||
if (!svgData) path = "";
|
if (!svgData) path = "";
|
||||||
@ -110,12 +98,14 @@ function addItem(id,svgData,doPrepend) {
|
|||||||
item.hide().fadeIn();
|
item.hide().fadeIn();
|
||||||
|
|
||||||
updateButtonStates();
|
updateButtonStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@ -130,10 +120,12 @@ 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,19 +145,18 @@ function deleteSelectedSketches() {
|
|||||||
deselectAll();
|
deselectAll();
|
||||||
updateButtonStates();
|
updateButtonStates();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function selectAll() {
|
function selectAll() {
|
||||||
$('.item').addClass('selected');
|
$('.item').addClass('selected');
|
||||||
updateButtonStates();
|
updateButtonStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
function deselectAll() {
|
function deselectAll() {
|
||||||
$('.item').removeClass('selected');
|
$('.item').removeClass('selected');
|
||||||
updateButtonStates();
|
updateButtonStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateButtonStates() {
|
function updateButtonStates() {
|
||||||
var numItems = $('.item').length;
|
var numItems = $('.item').length;
|
||||||
var numSelected = $('.item.selected').length;
|
var numSelected = $('.item.selected').length;
|
||||||
var noSelection = numSelected==0;
|
var noSelection = numSelected==0;
|
||||||
@ -179,9 +170,9 @@ function updateButtonStates() {
|
|||||||
// $("#btnDelete").text("Delete" + (noSelection ? "" : " ("+numSelected+")"));
|
// $("#btnDelete").text("Delete" + (noSelection ? "" : " ("+numSelected+")"));
|
||||||
// $("#btnDownload").text("Download" + (noSelection ? "" : " ("+numSelected+")"));
|
// $("#btnDownload").text("Download" + (noSelection ? "" : " ("+numSelected+")"));
|
||||||
// $("#btnPrint").text("Print" + (noSelection ? "..." : " ("+numSelected+")..."));
|
// $("#btnPrint").text("Print" + (noSelection ? "..." : " ("+numSelected+")..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadFile(files, index, next) {
|
function uploadFile(files, index, next) {
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.readAsText(files[index], "UTF-8");
|
reader.readAsText(files[index], "UTF-8");
|
||||||
reader.onload = function (evt) {
|
reader.onload = function (evt) {
|
||||||
@ -211,9 +202,9 @@ function uploadFile(files, index, next) {
|
|||||||
console.log("onerror");
|
console.log("onerror");
|
||||||
next(); //stop processing file(s), call back/
|
next(); //stop processing file(s), call back/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function upload() {
|
function upload() {
|
||||||
var files = $("#uploads")[0].files
|
var files = $("#uploads")[0].files
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
var cur = 0;
|
var cur = 0;
|
||||||
@ -228,23 +219,21 @@ function upload() {
|
|||||||
updateFreeSpace();
|
updateFreeSpace();
|
||||||
$("#frmUpload")[0].reset();
|
$("#frmUpload")[0].reset();
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
updateStatusMessage(numSketches+" sketches, "+freeKb+"k bytes free");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateFreeSpace() {
|
||||||
|
sketchAPI.status(function(data) {
|
||||||
|
var numSketches = data.number_of_sketches;
|
||||||
|
var freeKb = Math.round(data.available/1024);
|
||||||
|
updateStatusMessage(numSketches+" sketches, "+freeKb+"k bytes free");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStatusMessage(msg) {
|
function updateStatusMessage(msg) {
|
||||||
$("#txtInfo").text(msg);
|
$("#txtInfo").text(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertSvg(svg) {
|
function convertSvg(svg) {
|
||||||
if (!svg) return "";
|
if (!svg) return "";
|
||||||
if (typeof(svg)!='string') return "";
|
if (typeof(svg)!='string') return "";
|
||||||
if (svg.indexOf("CDATA")>-1) return svg; //assume this SVG is already ok
|
if (svg.indexOf("CDATA")>-1) return svg; //assume this SVG is already ok
|
||||||
@ -258,26 +247,33 @@ function convertSvg(svg) {
|
|||||||
svg = svg.replace("M0,0 ",""); //RC: hack
|
svg = svg.replace("M0,0 ",""); //RC: hack
|
||||||
|
|
||||||
return svg;
|
return svg;
|
||||||
}
|
}
|
||||||
|
|
||||||
function download() {
|
function download() {
|
||||||
$('.item.selected').each(function() {
|
$('.item.selected').each(function() {
|
||||||
var id = $(this).attr('data');
|
var id = $(this).attr('data');
|
||||||
var svgData = $(this).html();
|
var svgData = $(this).html();
|
||||||
console.log('downloading',id);
|
console.log('downloading',id);
|
||||||
$('<a target="_blank" href="data:image/svg+xml,'+encodeURIComponent(svgData)+'" download="'+id+'.svg">')[0].click();
|
$('<a target="_blank" href="data:image/svg+xml,'+encodeURIComponent(svgData)+'" download="'+id+'.svg">')[0].click();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
function combine() {
|
function combine() {
|
||||||
var ids = [];
|
var ids = [];
|
||||||
$('.item.selected').each(function() {
|
$('.item.selected').each(function() {
|
||||||
ids.push($(this).attr('data'));
|
ids.push($(this).attr('data'));
|
||||||
});
|
});
|
||||||
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user