2010-08-05 16:34:07 +00:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<script src="http://oxjs.org/js/jquery-1.4.2.min.js"></script>
|
2010-08-09 13:42:46 +00:00
|
|
|
<script type="text/javascript" src="/static/oxjs/build/js/ox.js"></script>
|
|
|
|
<script>
|
|
|
|
pandora = {};
|
|
|
|
pandora.request_url = '/api/';
|
|
|
|
|
|
|
|
pandora.request = function(fn, data, callback) {
|
|
|
|
data = JSON.stringify(data);
|
|
|
|
return jQuery.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: this.request_url,
|
|
|
|
dataType: "json",
|
|
|
|
data: {"action": fn, data: data},
|
|
|
|
success: function(response) {
|
|
|
|
if (typeof callback != "undefined")
|
|
|
|
callback(response);
|
|
|
|
console.log(response);
|
|
|
|
},
|
|
|
|
error: function (xhr, ajaxOptions, thrownError){
|
|
|
|
var response = {};
|
|
|
|
response.status = {code:xhr.status, text:xhr.statusText};
|
|
|
|
|
|
|
|
//FIXME: this should only happen if debugging/admin
|
|
|
|
error = jQuery('<iframe>').css({width:'99%', height: '99%'});
|
|
|
|
var debug = new Ox.Dialog({
|
|
|
|
title: "API Request failed: " + fn,
|
|
|
|
buttons: [
|
|
|
|
new Ox.Button({value:'Close'})
|
|
|
|
.click(function() {
|
|
|
|
debug.close();
|
|
|
|
})
|
|
|
|
],
|
|
|
|
width: 1000,
|
|
|
|
height: 310
|
|
|
|
}).append(error).open();
|
|
|
|
|
|
|
|
//write error response from server into iframe
|
|
|
|
//this might be required instead
|
|
|
|
/*
|
|
|
|
var ifrm = error[0];
|
|
|
|
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
|
|
|
|
var ifrm = error[0].contentWindow;
|
|
|
|
ifrm.document.open();
|
|
|
|
ifrm.document.write(xhr.responseText);
|
|
|
|
ifrm.document.close();
|
|
|
|
*/
|
|
|
|
|
|
|
|
var doc = error[0].contentDocument || error[0].contentWindow.document;
|
|
|
|
doc.open();
|
|
|
|
doc.write(xhr.responseText);
|
|
|
|
doc.close();
|
|
|
|
|
|
|
|
if (typeof callback != "undefined")
|
|
|
|
callback(response);
|
|
|
|
console.log(response);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
</script>
|
2010-08-03 20:49:30 +00:00
|
|
|
<script>
|
2010-08-05 16:34:07 +00:00
|
|
|
|
2010-08-05 18:33:27 +00:00
|
|
|
var _ids = new Array();
|
|
|
|
|
2010-08-03 20:49:30 +00:00
|
|
|
var ox = new OxFF();
|
|
|
|
ox.access(true);
|
2010-08-05 16:34:07 +00:00
|
|
|
ox.login('username');
|
2010-08-03 20:49:30 +00:00
|
|
|
|
2010-08-05 16:34:07 +00:00
|
|
|
//ox.get('b2c8f0aa3a447d09', 'stills', function(result) { console.log(result);});
|
2010-08-03 20:49:30 +00:00
|
|
|
//ox.files(function(result) { console.log(result);});
|
|
|
|
|
2010-08-05 18:33:27 +00:00
|
|
|
function safe_id(id) {
|
|
|
|
var _id = _ids.indexOf(id);
|
|
|
|
if(_id < 0) {
|
|
|
|
_ids.push(id);
|
|
|
|
_id = _ids.indexOf(id);
|
|
|
|
}
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function for_each_sorted(elements, callback) {
|
|
|
|
function pad(str) {
|
|
|
|
var len = 10;
|
|
|
|
while (str.length < len) {
|
|
|
|
str = '0' + str;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
var keys = new Array();
|
|
|
|
$.each(elements, function(k) {
|
|
|
|
keys.push(k);
|
|
|
|
});
|
|
|
|
keys.sort(function(a,b) {
|
|
|
|
a = a.replace(/\d+/, pad);
|
|
|
|
b = b.replace(/\d+/, pad);
|
|
|
|
return a > b;
|
|
|
|
});
|
|
|
|
$.each(keys, function(i, k) {
|
|
|
|
var v = elements[k];
|
|
|
|
callback(k, v);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-08-05 16:34:07 +00:00
|
|
|
function update() {
|
|
|
|
var updating = true;
|
2010-08-09 13:42:46 +00:00
|
|
|
ox.update(function(result) {
|
|
|
|
updating = false;
|
|
|
|
ox.volumes(function(result) {
|
|
|
|
var volumes = JSON.parse(result);
|
|
|
|
for(volume in volumes) {
|
|
|
|
ox.files(volume, function(result) {
|
|
|
|
var _files = [];
|
|
|
|
var _info = {};
|
|
|
|
var data = JSON.parse(result);
|
|
|
|
$.each(data, function(folder, files) {
|
|
|
|
$.each(files, function(f, info) {
|
|
|
|
var f = {
|
|
|
|
oshash: info.oshash,
|
|
|
|
name: f,
|
|
|
|
folder: folder,
|
|
|
|
ctime: info.ctime, atime: info.atime, mtime: info.mtime
|
|
|
|
};
|
|
|
|
_files.push(f);
|
|
|
|
_info[info.oshash] = info;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
pandora.request('update', {
|
|
|
|
'volume': volume, 'files': _files
|
|
|
|
}, function(result) {
|
|
|
|
var data = {'info': {}};
|
|
|
|
if (result.data.info.length>0) {
|
|
|
|
$.each(_info, function(oshash, info) {
|
|
|
|
if($.inArray(oshash, result.data.info) >= 0) {
|
|
|
|
data.info[oshash] = info;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
pandora.request('update', data, function(result) {
|
|
|
|
console.log(result);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$.each(result.data.data, function(i, oshash) {
|
|
|
|
$('#' + oshash).css('background', 'red');
|
|
|
|
$('#' + oshash).parent().css('background', 'orange');
|
|
|
|
});
|
|
|
|
$.each(result.data.file, function(i, oshash) {
|
|
|
|
$('#' + oshash).css('background', 'blue');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2010-08-05 16:34:07 +00:00
|
|
|
var getFiles = function() {
|
|
|
|
ox.volumes(function(result) {
|
|
|
|
var volumes = JSON.parse(result);
|
|
|
|
for(volume in volumes) {
|
|
|
|
(function(volume) {
|
2010-08-05 18:33:27 +00:00
|
|
|
var volumeId = "volume_"+safe_id(volume);
|
2010-08-05 16:34:07 +00:00
|
|
|
var $volume = $('#'+volumeId);
|
2010-08-05 18:33:27 +00:00
|
|
|
if($volume.length==0) {
|
|
|
|
$volume = $('<div>').attr('id', volumeId).html('<h2>'+volume+'</h2>');
|
|
|
|
$volume.find('h2').click(function() { $(this).parent().find('div').toggle();});
|
|
|
|
}
|
2010-08-05 16:34:07 +00:00
|
|
|
$('#files').append($volume);
|
|
|
|
ox.files(volume, function(result) {
|
2010-08-05 18:33:27 +00:00
|
|
|
var data = JSON.parse(result);
|
2010-08-09 13:42:46 +00:00
|
|
|
var _files = [];
|
2010-08-05 18:33:27 +00:00
|
|
|
$.each(data, function(folder, files) {
|
|
|
|
if(!folder) folder = "rootfolder";
|
|
|
|
var folderId = 'folder_'+safe_id(folder);
|
|
|
|
var $folder = $('#'+folderId);
|
|
|
|
if($folder.length==0) {
|
|
|
|
$folder = $('<div>').attr('id', folderId).html('<h3>'+folder+'</h3>');
|
|
|
|
$folder.find('h3').click(function() { $(this).parent().find('div').toggle();});
|
|
|
|
$volume.append($folder);
|
|
|
|
}
|
|
|
|
for_each_sorted(files, function(f, info) {
|
2010-08-09 13:42:46 +00:00
|
|
|
var fileId = info.oshash;
|
2010-08-05 18:33:27 +00:00
|
|
|
var $file = $('#'+fileId);
|
|
|
|
if($file.length==0) {
|
|
|
|
$file = $('<div>').attr('id', fileId).html(f).hide();
|
|
|
|
$folder.append($file);
|
|
|
|
}
|
|
|
|
});
|
2010-08-05 16:34:07 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}(volume));
|
|
|
|
}
|
|
|
|
if(updating) {
|
|
|
|
setTimeout(getFiles, 2000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
getFiles();
|
|
|
|
}
|
2010-08-03 20:49:30 +00:00
|
|
|
|
2010-08-09 13:42:46 +00:00
|
|
|
function setLocation(name) {
|
|
|
|
console.log(ox.setLocation(name))
|
2010-08-05 16:34:07 +00:00
|
|
|
}
|
2010-08-03 20:49:30 +00:00
|
|
|
</script>
|
2010-08-05 16:34:07 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2010-08-09 13:42:46 +00:00
|
|
|
<input type="button" onClick="setLocation('test')" value="Set Location">
|
2010-08-05 16:34:07 +00:00
|
|
|
<input type="button" onClick="update()" value="Update">
|
|
|
|
<div id="files">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|