2010-12-22 14:11:38 +00:00
|
|
|
if(typeof(pandora.afterLaunch) == "undefined")
|
|
|
|
pandora.afterLaunch = [];
|
2010-09-10 09:58:59 +00:00
|
|
|
|
2010-12-22 14:11:38 +00:00
|
|
|
//pandora.afterLaunch[0]();
|
|
|
|
pandora.afterLaunch.push(function() {
|
2010-09-06 20:47:24 +00:00
|
|
|
if (typeof(OxFF) == 'undefined')
|
|
|
|
return;
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.local = {
|
2010-09-06 20:47:24 +00:00
|
|
|
api: new OxFF(),
|
|
|
|
volumes: function(cb) {
|
|
|
|
var _this = this;
|
2010-09-27 08:15:25 +00:00
|
|
|
Ox.print('api.volumes');
|
2010-12-22 14:11:38 +00:00
|
|
|
this.api.login(window, pandora.user.username);
|
2010-09-27 08:15:25 +00:00
|
|
|
Ox.print('api.now access');
|
2010-09-06 20:47:24 +00:00
|
|
|
this.api.access(function(access) {
|
|
|
|
Ox.print('access callback', access);
|
|
|
|
if(!access) {
|
2010-12-22 14:11:38 +00:00
|
|
|
var dialogHeight = pandora.$document.height()/2,
|
2010-09-06 20:47:24 +00:00
|
|
|
dialogWidth = parseInt((dialogHeight - 48) * 0.75);
|
|
|
|
|
|
|
|
var $dialog = new Ox.Dialog({
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
title: 'Close',
|
|
|
|
click: function() {
|
|
|
|
$dialog.close();
|
|
|
|
delete $dialog;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
height: dialogHeight,
|
|
|
|
padding: 0,
|
|
|
|
title: "Pan.do/ra OxFF Local Archive",
|
|
|
|
width: dialogWidth
|
|
|
|
})
|
|
|
|
.append("For this part of the page to work, you have to allow OxFF to send data to this site")
|
|
|
|
.open();
|
|
|
|
} else {
|
|
|
|
_this.api.volumes(function(result) {
|
|
|
|
var data = JSON.parse(result);
|
|
|
|
cb(data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
files: function(archive, cb) {
|
2010-12-22 14:11:38 +00:00
|
|
|
this.api.login(window, pandora.user.username);
|
2010-09-06 20:47:24 +00:00
|
|
|
if(!this.api.access())
|
|
|
|
return false;
|
|
|
|
this.api.files(archive, function(result) {
|
|
|
|
var data = JSON.parse(result);
|
|
|
|
cb(data);
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
upload: function(options, done_cb, progress_cb) {
|
|
|
|
function wrap(cb) {
|
|
|
|
if(!cb)
|
|
|
|
return null;
|
|
|
|
return function(result) {
|
|
|
|
var data = JSON.parse(result);
|
2010-09-27 16:03:28 +00:00
|
|
|
cb(data);
|
2010-09-06 20:47:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.api.upload(JSON.stringify(options),
|
|
|
|
wrap(done_cb),
|
|
|
|
wrap(progress_cb));
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
parsePath: function(path) {
|
|
|
|
var folder = path.split('/');
|
|
|
|
folder.pop();
|
|
|
|
if(folder.length==0) {
|
|
|
|
folder.push("rootfolder");
|
|
|
|
}
|
|
|
|
//FIXME: this is also done on the backend but might require more sub options
|
|
|
|
if (folder[folder.length-1] == "Extras" || folder[folder.length-1] == "Versions")
|
|
|
|
folder.pop();
|
|
|
|
folder = folder.join('/');
|
|
|
|
return {
|
|
|
|
folder: folder,
|
|
|
|
name: path.substring(folder.length),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
loadVolumes: function() {
|
2010-09-10 09:58:59 +00:00
|
|
|
var _this = this;
|
2010-09-06 20:47:24 +00:00
|
|
|
Ox.print("load volumes");
|
|
|
|
var $section = new Ox.CollapsePanel({
|
|
|
|
id: 'volumes',
|
|
|
|
size: 'small',
|
|
|
|
title: 'Volumes'
|
|
|
|
});
|
2010-09-10 09:58:59 +00:00
|
|
|
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.$ui.sections.push($section);
|
|
|
|
pandora.local.volumes(function(data) {
|
2010-09-06 20:47:24 +00:00
|
|
|
Ox.print("got volumes", data);
|
2010-09-10 09:58:59 +00:00
|
|
|
var volumes = 0;
|
2010-09-06 20:47:24 +00:00
|
|
|
$.each(data, function(name, info) {
|
2010-09-10 09:58:59 +00:00
|
|
|
volumes ++;
|
2010-09-06 20:47:24 +00:00
|
|
|
Ox.print("add volume", name, info);
|
|
|
|
var status = info.available?"online":"offline";
|
|
|
|
var $line = $('<div>').css({ height: '20px' }).append(
|
|
|
|
$('<div>').css({ float: 'left', width: '16px', height: '16px', margin: '1px'}).append(
|
|
|
|
$('<img>').attr({ src: 'static/oxjs/build/png/ox.ui.modern/iconFind.png' })
|
|
|
|
.css({
|
|
|
|
width: '16px', height: '16px',
|
|
|
|
border: 0, background: 'rgb(64, 64, 64)',
|
|
|
|
WebkitBorderRadius: '2px' })
|
|
|
|
)
|
|
|
|
).append(
|
|
|
|
$('<div>').css({ float: 'left', width: '122px', height: '14px', margin: '2px' }).html(name)
|
|
|
|
).append(
|
|
|
|
$('<div>').css({ float: 'left', width: '40px', height: '14px', margin: '2px', textAlign: 'right' }).html(status)
|
|
|
|
);
|
|
|
|
$line.click(function() {
|
|
|
|
Ox.print("get files", name);
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.local.constructFileList(name);
|
2010-09-06 20:47:24 +00:00
|
|
|
});
|
|
|
|
$section.$content.append($line);
|
|
|
|
});
|
2010-09-10 09:58:59 +00:00
|
|
|
|
|
|
|
add_button = new Ox.Button({
|
|
|
|
id: 'add_volume',
|
|
|
|
title: 'add',
|
|
|
|
width: 32
|
|
|
|
}).bindEvent('click', function(event, data) {
|
|
|
|
if(_this.api.setLocation("Volume "+(volumes+1))) _this.loadVolumes();
|
|
|
|
});
|
|
|
|
var update_button = new Ox.Button({
|
|
|
|
id: 'update_archive',
|
|
|
|
title: 'update',
|
|
|
|
width: 48
|
|
|
|
}).bindEvent('click', function(event, data) {
|
|
|
|
update_button.options({disabled: true});
|
|
|
|
_this.api.update(function() {
|
|
|
|
update_button.options({disabled: false});
|
|
|
|
})
|
|
|
|
});
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.$ui.lists.replaceWith(pandora.constructLists());
|
2010-09-10 09:58:59 +00:00
|
|
|
$section.find('.OxBar').append($('<div>')
|
|
|
|
.css({'text-align': 'right', 'margin': '2px'})
|
|
|
|
.append(update_button.$element)
|
|
|
|
.append(add_button.$element)
|
|
|
|
);
|
2010-09-06 20:47:24 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
uploadVideos: function(ids, done, progress, total) {
|
|
|
|
var _this = this;
|
|
|
|
if(typeof(total) == 'undefined')
|
|
|
|
total = ids.length;
|
|
|
|
|
|
|
|
if(ids.length>0) {
|
|
|
|
var oshash = ids.pop();
|
|
|
|
this.uploadVideo(oshash,
|
|
|
|
function(data) {
|
|
|
|
if(ids.length>0) {
|
|
|
|
Ox.print('more files in queue, calling again', ids, total);
|
|
|
|
_this.uploadVideos(ids, done, progress, total);
|
|
|
|
} else { //FIXME: should keep info about all uploads
|
|
|
|
done(data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
data.progress = data.progress/total;
|
|
|
|
progress(data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
uploadVideo: function(oshash, done, progress) {
|
|
|
|
Ox.print('upload', oshash);
|
2010-12-22 14:11:38 +00:00
|
|
|
var url = pandora.local.absolute_url('/api/');
|
|
|
|
pandora.local.upload({
|
2010-09-06 20:47:24 +00:00
|
|
|
url: url,
|
|
|
|
data: {action: 'upload', oshash: oshash},
|
|
|
|
oshash: oshash,
|
|
|
|
action: 'frames'
|
|
|
|
},
|
|
|
|
function(result) {
|
|
|
|
Ox.print(result);
|
|
|
|
//FIXME: check result before posting video
|
|
|
|
profile = '96p.webm';
|
2010-12-22 14:11:38 +00:00
|
|
|
var url = pandora.local.absolute_url('/api/upload/') + '?profile=' + profile + '&oshash=' + oshash;
|
|
|
|
pandora.local.upload(
|
2010-09-06 20:47:24 +00:00
|
|
|
{
|
|
|
|
oshash: oshash,
|
|
|
|
action: 'video',
|
|
|
|
profile: profile,
|
|
|
|
url: url
|
|
|
|
},
|
|
|
|
done,
|
|
|
|
progress
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2010-09-17 21:06:01 +00:00
|
|
|
uploadFile: function(oshash) {
|
|
|
|
Ox.print('upload file', oshash);
|
2010-12-22 14:11:38 +00:00
|
|
|
var url = pandora.local.absolute_url('/api/');
|
|
|
|
pandora.local.upload({
|
2010-09-17 21:06:01 +00:00
|
|
|
url: url,
|
|
|
|
data: {action: 'upload', oshash: oshash},
|
|
|
|
oshash: oshash,
|
|
|
|
action: 'file'
|
|
|
|
},
|
|
|
|
function(result) {
|
|
|
|
Ox.print(result);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2010-09-10 09:58:59 +00:00
|
|
|
cancel: function(oshash) {
|
|
|
|
Ox.print('this function needs to be implemented: cancel ', oshash);
|
|
|
|
},
|
2010-09-06 20:47:24 +00:00
|
|
|
constructFileList: function(name) {
|
2010-09-10 09:58:59 +00:00
|
|
|
var _this = this,
|
|
|
|
$list = new Ox.TextList({
|
2010-09-06 20:47:24 +00:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
align: "left",
|
|
|
|
id: "id",
|
|
|
|
operator: "+",
|
|
|
|
title: "ID",
|
|
|
|
unique: true,
|
|
|
|
visible: false,
|
|
|
|
width: 120
|
|
|
|
},
|
|
|
|
{
|
|
|
|
align: "left",
|
|
|
|
id: "path",
|
|
|
|
operator: "+",
|
|
|
|
title: "path",
|
|
|
|
unique: false,
|
|
|
|
visible: true,
|
|
|
|
width: 600
|
|
|
|
},
|
|
|
|
{
|
|
|
|
align: "left",
|
|
|
|
id: "files",
|
|
|
|
operator: "+",
|
|
|
|
title: "files",
|
|
|
|
visible: true,
|
|
|
|
width: 80
|
|
|
|
},
|
|
|
|
{
|
|
|
|
align: "left",
|
|
|
|
id: "status",
|
|
|
|
operator: "+",
|
|
|
|
title: "status",
|
|
|
|
unique: false,
|
|
|
|
visible: true,
|
|
|
|
width:120
|
|
|
|
},
|
|
|
|
],
|
|
|
|
id: "volume",
|
2010-09-14 14:10:37 +00:00
|
|
|
request: function(options, callback) {
|
2010-09-06 20:47:24 +00:00
|
|
|
Ox.print("options, volumes", options)
|
|
|
|
if(!options.range) {
|
2010-09-14 14:10:37 +00:00
|
|
|
callback({
|
2010-09-06 20:47:24 +00:00
|
|
|
data: {
|
|
|
|
items: 58
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.local.files(name, function(result) {
|
2010-09-08 17:14:01 +00:00
|
|
|
var fileInfo = result.info;
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.api.update({
|
2010-09-06 20:47:24 +00:00
|
|
|
'volume': name, 'files': result.files
|
|
|
|
}, function(result) {
|
|
|
|
var videos = {};
|
2010-09-08 17:14:01 +00:00
|
|
|
function parseResult(result) {
|
2010-09-17 21:06:01 +00:00
|
|
|
//extract and upload requested videos
|
2010-09-08 17:14:01 +00:00
|
|
|
$.each(result.data.data, function(i, oshash) {
|
|
|
|
$.each(folder_ids, function(i, ids) {
|
|
|
|
if($.inArray(oshash, ids) > -1) {
|
|
|
|
if(!videos[i]) {
|
|
|
|
videos[i] = [];
|
|
|
|
var button = new Ox.Button({
|
|
|
|
id: 'upload_' + oshash,
|
|
|
|
title: 'Upload',
|
|
|
|
width: 48
|
|
|
|
}).bindEvent('click', function(fid) { return function(event, data) {
|
|
|
|
Ox.print(videos[fid]);
|
2010-09-10 09:58:59 +00:00
|
|
|
$($('#'+fid).find('.OxCell')[1]).html(function(fid) {
|
|
|
|
var button = new Ox.Button({
|
|
|
|
title: 'Cancel',
|
|
|
|
width: 48
|
|
|
|
}).bindEvent('click', function(event, data) {
|
|
|
|
$.each(videos[fid], function(i, oshash) {
|
|
|
|
_this.cancel(oshash);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return button.$element;
|
|
|
|
}(fid));
|
2010-09-08 17:14:01 +00:00
|
|
|
//$($('#'+fid).find('.OxCell')[2]).html('extracting data...');
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.local.uploadVideos(
|
2010-09-08 17:14:01 +00:00
|
|
|
videos[fid],
|
|
|
|
function(data) {
|
|
|
|
$($('#'+fid).find('.OxCell')[2]).html('done');
|
|
|
|
},
|
2010-09-10 09:58:59 +00:00
|
|
|
function(data) {
|
|
|
|
$($('#'+fid).find('.OxCell')[2]).html(parseInt(data.progress*100));
|
2010-09-08 17:14:01 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}}(i));
|
|
|
|
$($('#'+i).find('.OxCell')[2]).html(button.$element);
|
|
|
|
$('#'+i).css({'font-weight': 'bold'});
|
|
|
|
}
|
|
|
|
videos[i].push(oshash);
|
|
|
|
//add some double click callback here to trigger video upload
|
|
|
|
return false;
|
2010-09-06 20:47:24 +00:00
|
|
|
}
|
2010-09-08 17:14:01 +00:00
|
|
|
});
|
|
|
|
});
|
2010-09-17 21:06:01 +00:00
|
|
|
//upload requested files
|
|
|
|
$.each(result.data.file, function(i, oshash) {
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.local.uploadFile(oshash);
|
2010-09-17 21:06:01 +00:00
|
|
|
});
|
2010-09-08 17:14:01 +00:00
|
|
|
};
|
|
|
|
if (result.data.info.length>0) {
|
|
|
|
var post = {'info': {}};
|
|
|
|
$.each(result.data.info, function(i, oshash) {
|
|
|
|
if(fileInfo[oshash]) {
|
|
|
|
post.info[oshash] = fileInfo[oshash];
|
2010-09-06 20:47:24 +00:00
|
|
|
}
|
|
|
|
});
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.api.update(post, function(result) {
|
2010-09-08 17:14:01 +00:00
|
|
|
parseResult(result);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
parseResult(result);
|
|
|
|
}
|
|
|
|
|
2010-09-06 20:47:24 +00:00
|
|
|
});
|
|
|
|
var data = {
|
|
|
|
items: []
|
|
|
|
}
|
|
|
|
var folder_ids = {};
|
|
|
|
var folders = {};
|
|
|
|
$.each(result.files, function(i, file) {
|
2010-12-22 14:11:38 +00:00
|
|
|
var f = pandora.local.parsePath(file.path);
|
2010-09-06 20:47:24 +00:00
|
|
|
if(!folders[f.folder]) {
|
|
|
|
folders[f.folder] = {
|
|
|
|
id: file.oshash,
|
|
|
|
path: f.folder,
|
|
|
|
files: 0,
|
|
|
|
status:'ok',
|
|
|
|
ids: []
|
|
|
|
};
|
|
|
|
folder_ids[file.oshash] = [];
|
|
|
|
}
|
|
|
|
folders[f.folder].files++;
|
|
|
|
folder_ids[folders[f.folder].id].push(file.oshash);
|
|
|
|
});
|
|
|
|
var j = 1;
|
|
|
|
$.each(folders, function(i, folder) {
|
|
|
|
data.items.push(folder);
|
|
|
|
});
|
|
|
|
r = {
|
|
|
|
data: data,
|
|
|
|
}
|
|
|
|
Ox.print(r);
|
2010-09-14 14:10:37 +00:00
|
|
|
callback(r);
|
2010-09-06 20:47:24 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sort: [
|
|
|
|
{
|
|
|
|
key: "path",
|
|
|
|
operator: "+"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.$ui.contentPanel.replace(1, $list);
|
2010-09-06 20:47:24 +00:00
|
|
|
},
|
|
|
|
absolute_url: function (url) {
|
|
|
|
var base = document.location.href;
|
|
|
|
if (url.substring(0, 1) == '/') {
|
2010-09-18 15:16:45 +00:00
|
|
|
base = document.location.protocol + '//' + document.location.hostname;
|
|
|
|
if(document.location.port) base += ':'+document.location.port
|
|
|
|
url = base + url;
|
2010-09-06 20:47:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(base.substring(base.length-1) == '/')
|
|
|
|
url = base + url;
|
|
|
|
else
|
|
|
|
url = base + '/' + url;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
};
|
2010-12-22 14:11:38 +00:00
|
|
|
pandora.local.loadVolumes();
|
2010-09-06 20:47:24 +00:00
|
|
|
});
|