').css({ float: 'left', width: '122px', height: '14px', margin: '2px' }).html(name)
- ).append(
- $('
').css({ float: 'left', width: '40px', height: '14px', margin: '2px', textAlign: 'right' }).html(status)
- );
- $line.click(function() {
- Ox.print("get files", name);
- pandora.local.constructFileList(name);
- });
- $section.$content.append($line);
- });
-
- add_button = new Ox.Button({
- id: 'add_volume',
- title: 'add',
- width: 32
- }).bindEvent('click', function(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(data) {
- update_button.options({disabled: true});
- _this.api.update(function() {
- update_button.options({disabled: false});
- })
- });
- pandora.$ui.lists.replaceWith(pandora.constructLists());
- $section.find('.OxBar').append($('
')
- .css({'text-align': 'right', 'margin': '2px'})
- .append(update_button.$element)
- .append(add_button.$element)
- );
- });
- },
- 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);
- var url = pandora.local.absolute_url('/api/');
- pandora.local.upload({
- 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';
- var url = pandora.local.absolute_url('/api/upload/') + '?profile=' + profile + '&oshash=' + oshash;
- pandora.local.upload(
- {
- oshash: oshash,
- action: 'video',
- profile: profile,
- url: url
- },
- done,
- progress
- );
- }
- );
- },
- uploadFile: function(oshash) {
- Ox.print('upload file', oshash);
- var url = pandora.local.absolute_url('/api/');
- pandora.local.upload({
- url: url,
- data: {action: 'upload', oshash: oshash},
- oshash: oshash,
- action: 'file'
- },
- function(result) {
- Ox.print(result);
- }
- );
- },
- cancel: function(oshash) {
- Ox.print('this function needs to be implemented: cancel ', oshash);
- },
- constructFileList: function(name) {
- var _this = this,
- $list = new Ox.TextList({
- 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",
- request: function(options, callback) {
- Ox.print("options, volumes", options)
- if(!options.range) {
- callback({
- data: {
- items: 58
- }
- });
- } else {
- pandora.local.files(name, function(result) {
- var fileInfo = result.info;
- pandora.api.update({
- 'volume': name, 'files': result.files
- }, function(result) {
- var videos = {};
- function parseResult(result) {
- //extract and upload requested videos
- result.data.data.forEach(function(oshash) {
- folder_ids.forEach(function(ids, i) {
- if (ids.indexOf(oshash) > -1) {
- if (!videos[i]) {
- videos[i] = [];
- var button = new Ox.Button({
- id: 'upload_' + oshash,
- title: 'Upload',
- width: 48
- }).bindEvent('click', function(fid) { return function(data) {
- Ox.print(videos[fid]);
- $($('#'+fid).find('.OxCell')[1]).html(function(fid) {
- var button = new Ox.Button({
- title: 'Cancel',
- width: 48
- }).bindEvent('click', function(data) {
- videos[fid].forEach(function(oshash) {
- _this.cancel(oshash);
- });
- });
- return button.$element;
- }(fid));
- //$($('#'+fid).find('.OxCell')[2]).html('extracting data...');
- pandora.local.uploadVideos(
- videos[fid],
- function(data) {
- $($('#'+fid).find('.OxCell')[2]).html('done');
- },
- function(data) {
- $($('#'+fid).find('.OxCell')[2]).html(parseInt(data.progress*100));
- }
- );
- }}(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;
- }
- });
- });
- //upload requested files
- result.data.file.forEach(function(oshash) {
- pandora.local.uploadFile(oshash);
- });
- };
- if (result.data.info.length>0) {
- var post = {'info': {}};
- result.data.info.forEach(function(oshash) {
- if(fileInfo[oshash]) {
- post.info[oshash] = fileInfo[oshash];
- }
- });
- pandora.api.update(post, function(result) {
- parseResult(result);
- });
- } else {
- parseResult(result);
- }
-
- });
- var data = {
- items: []
- }
- var folder_ids = {};
- var folders = {};
- result.files.forEach(function(file) {
- var f = pandora.local.parsePath(file.path);
- 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;
- folders.forEach(function(folder) {
- data.items.push(folder);
- });
- r = {
- data: data,
- }
- Ox.print(r);
- callback(r);
-
- });
- }
- },
- sort: [
- {
- key: "path",
- operator: "+"
- }
- ]
- });
- pandora.$ui.contentPanel.replace(1, $list);
- },
- absolute_url: function (url) {
- var base = document.location.href;
- if (url.substring(0, 1) == '/') {
- base = document.location.protocol + '//' + document.location.hostname;
- if(document.location.port) base += ':'+document.location.port
- url = base + url;
- }
- else {
- if(base.substring(base.length-1) == '/')
- url = base + url;
- else
- url = base + '/' + url;
- }
- return url;
- },
- };
- pandora.local.loadVolumes();
-});