pandora/static/js/pandora/filesView.js

505 lines
16 KiB
JavaScript
Raw Normal View History

2011-07-29 18:37:11 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-06-16 17:40:31 +00:00
2011-11-05 17:04:10 +00:00
'use strict';
pandora.ui.filesView = function(options, self) {
2011-06-16 17:40:31 +00:00
var self = self || {},
2011-06-19 17:49:25 +00:00
that = Ox.Element({}, self)
2011-06-16 17:40:31 +00:00
.defaults({
id: ''
})
.options(options || {});
2011-10-27 11:19:38 +00:00
self.wasChecked = false;
self.numberOfItems = 0;
2011-06-16 17:40:31 +00:00
self.selected = [];
2011-06-19 17:49:25 +00:00
self.$toolbar = Ox.Bar({
2011-06-16 17:40:31 +00:00
size: 24
});
/*
self.$userSelect = Ox.Select({
items: [
{id: 'admin', title: 'Admin', disabled: true},
{id: 'j', title: 'User: j', checked: true},
{id: 'rlx', title: 'User: rlx'},
{},
{id: 'admin', title: 'Staff', disabled: true},
{},
{id: 'admin', title: 'Member', disabled: true}
]
2011-06-16 17:40:31 +00:00
})
.css({
float: 'left',
width: '128px',
2011-06-16 17:40:31 +00:00
margin: '4px'
})
.appendTo(self.$toolbar);
*/
self.$deleteButton = Ox.Button({
disabled: false,
title: 'Delete ' + pandora.site.itemName.singular,
width: 116
})
.css({
float: 'right',
margin: '4px'
})
.appendTo(self.$toolbar)
.bindEvent({
click: deleteItem
});
2011-10-23 16:19:47 +00:00
self.$ignoreButton = Ox.Button({
2011-06-16 17:40:31 +00:00
disabled: 'true',
2011-10-23 16:19:47 +00:00
title: 'Ignore Selected Files...'
2011-06-16 17:40:31 +00:00
})
.css({
float: 'right',
margin: '4px'
})
2011-10-23 16:19:47 +00:00
.appendTo(self.$toolbar)
.bindEvent({
click: function() {
var data = {
ids: self.selected,
ignore: true
};
pandora.api.editFiles(data, function(result) {
Ox.Request.clearCache();
self.$filesList.reloadList();
});
}
});
2011-06-16 17:40:31 +00:00
2011-06-19 17:49:25 +00:00
self.$filesList = Ox.TextList({
2011-06-16 17:40:31 +00:00
columns: [
2011-10-18 20:06:01 +00:00
{
2011-10-23 11:57:52 +00:00
clickable: function(data) {
return true;
},
2011-10-18 20:06:01 +00:00
format: function(value, data) {
return $('<img>')
.attr({
src: data.wanted ? Ox.UI.getImageURL('symbolStar') :
Ox.UI.getImageURL('symbolCheck')
})
.css({
width: '10px',
height: '10px',
padding: '3px',
opacity: (value || data.wanted) ? 1 : 0
});
},
id: 'selected',
operator: '-',
2012-01-16 13:41:05 +00:00
title: 'Status',
titleImage: 'check',
2011-10-23 11:57:52 +00:00
tooltip: function (data) {
return data.instances.filter(function(i) {return i.ignore; }).length > 0
? 'Use this file'
: 'Dont use this file';
},
2011-10-18 20:06:01 +00:00
visible: true,
width: 16
},
2011-06-16 17:40:31 +00:00
{
align: 'left',
id: 'users',
operator: '+',
title: 'Users',
visible: true,
2011-10-18 20:06:01 +00:00
width: 50
2011-06-16 17:40:31 +00:00
},
{
align: 'left',
id: 'path',
2011-06-16 17:40:31 +00:00
operator: '+',
title: 'Path',
2011-06-16 17:40:31 +00:00
visible: true,
width: 480
2011-06-16 17:40:31 +00:00
},
{
align: 'left',
id: 'type',
operator: '+',
title: 'Type',
visible: true,
width: 60
},
{
align: 'right',
id: 'part',
operator: '+',
title: 'Part',
visible: true,
width: 60
},
{
align: 'right',
format: {type: 'value', args: ['B']},
2011-10-29 17:46:46 +00:00
id: 'size',
2011-06-16 17:40:31 +00:00
operator: '-',
title: 'Size',
visible: true,
width: 90
},
{
align: 'right',
format: {type: 'resolution', args: ['px']},
id: 'resolution',
operator: '-',
title: 'Resolution',
visible: true,
width: 90
},
{
align: 'right',
format: {type: 'duration', args: [0, 'short']},
id: 'duration',
operator: '-',
title: 'Duration',
visible: true,
width: 90
},
{
align: 'left',
2011-06-27 13:39:35 +00:00
id: 'id',
2011-06-16 17:40:31 +00:00
operator: '+',
2011-06-27 13:39:35 +00:00
title: 'ID',
2011-06-16 17:40:31 +00:00
unique: true,
visible: false,
width: 120
},
{
align: 'left',
id: 'instances',
operator: '+',
title: 'Instances',
visible: false,
width: 120
}
],
columnsMovable: true,
columnsRemovable: true,
columnsResizable: true,
columnsVisible: true,
id: 'files',
items: function(data, callback) {
pandora.api.findFiles(Ox.extend(data, {
2011-06-16 17:40:31 +00:00
query: {
conditions: [{
key: 'id',
value: self.options.id,
2011-10-18 20:06:01 +00:00
operator: '=='
2011-06-16 17:40:31 +00:00
}]
}
}), callback);
},
2012-01-19 11:57:47 +00:00
keys: ['wanted', 'instances'],
2011-06-16 17:40:31 +00:00
scrollbarVisible: true,
sort: [{key: 'path', operator: '+'}]
2011-06-16 17:40:31 +00:00
})
.bindEvent({
2011-10-23 11:57:52 +00:00
click: function(data) {
if (data.key == 'selected') {
var ignored = self.$filesList.value(data.id, 'instances')
.filter(function(i) {return i.ignore; }).length > 0;
pandora.api.editFile({
id: data.id,
ignore: !ignored
}, function(result) {
Ox.Request.clearCache();
self.$filesList.reloadList();
});
}
},
2012-01-15 15:05:37 +00:00
'delete': function(data) {
var ids = data.ids.filter(function(id) {
return self.$filesList.value(id, 'instances').length == 0;
});
if(ids.length>0 && pandora.user.level == 'admin') {
Ox.print('delete', ids);
pandora.api.removeFiles({
ids: ids
}, function(result) {
Ox.Request.clearCache();
self.$filesList.reloadList();
});
}
},
2011-10-27 11:19:38 +00:00
init: function(data) {
self.numberOfItems = data.items;
},
2011-06-16 17:40:31 +00:00
open: openFiles,
2011-10-23 11:57:52 +00:00
select: selectFiles,
2011-06-16 17:40:31 +00:00
});
self.$instancesList = Ox.TextList({
columns: [
{
align: 'left',
id: 'user',
operator: '+',
title: 'User',
visible: true,
width: 120
},
{
align: 'left',
id: 'volume',
operator: '+',
title: 'Volume',
visible: true,
width: 120
},
{
align: 'left',
id: 'path',
2011-06-16 17:40:31 +00:00
operator: '+',
title: 'Path',
2011-06-16 17:40:31 +00:00
visible: true,
width: 480
2011-06-16 17:40:31 +00:00
},
],
columnsMovable: true,
columnsRemovable: true,
columnsResizable: true,
columnsVisible: true,
id: 'files',
items: [],
scrollbarVisible: true,
sort: [{key: 'user', operator: '+'}]
});
self.$movieLabel = Ox.Label({
textAlign: 'center',
title: 'Move Selected Files to Another Movie',
width: 240
})
.css({margin: '8px'});
['title', 'director', 'year', 'id'].forEach(function(key) {
self['$' + key + 'Input'] = Ox.Input({
clear: true,
id: key,
label: key == 'id' ? 'ID' : Ox.toTitleCase(key),
labelWidth: 64,
width: 240
})
.bindEvent({
change: function(data) {
var conditions;
if (data.value.length) {
2011-10-18 20:06:01 +00:00
/*
2011-06-16 17:40:31 +00:00
if (key == 'id') {
2011-10-18 20:06:01 +00:00
conditions = [{key: 'id', value: data.value, operator: '=='}]
2011-06-16 17:40:31 +00:00
} else {
conditions = Ox.map(['title', 'director', 'year'], function(key) {
2011-12-21 15:34:28 +00:00
var value = self['$' + key + 'Input'].value()
2011-06-16 17:40:31 +00:00
return value.length ? {key: key, value: value, operator: '='} : null;
2011-10-18 20:06:01 +00:00
});
2011-06-16 17:40:31 +00:00
}
pandora.api.find({
keys: ['title', 'director', 'year', 'id'],
query: {
conditions: conditions,
operator: '&'
},
range: [0, 2]
}, function(result) {
2011-10-18 20:06:01 +00:00
*/
conditions = {};
Ox.map(['id', 'title', 'director', 'year'], function(key) {
2011-12-21 15:34:28 +00:00
var value = self['$' + key + 'Input'].value();
2011-10-18 20:06:01 +00:00
if(value.length) {
2011-11-22 11:56:09 +00:00
conditions[key] = key == 'director' ? value.split(', ') : value;
2011-10-18 20:06:01 +00:00
}
});
pandora.api.findId(conditions, function(result) {
2011-06-16 17:40:31 +00:00
var length = result.data.items.length;
if (length == 0) {
if (key != 'id') {
2011-12-21 15:34:28 +00:00
self.$idInput.value('');
2011-06-16 17:40:31 +00:00
}
} else if (result.data.items.length == 1) {
['title', 'director', 'year', 'id'].forEach(function(key) {
2011-12-21 15:34:28 +00:00
self['$' + key + 'Input'].value(
key == 'director'
2011-06-16 17:40:31 +00:00
? result.data.items[0][key].join(', ')
: result.data.items[0][key]
2011-12-21 15:34:28 +00:00
);
2011-06-16 17:40:31 +00:00
});
} else {
2011-12-21 15:34:28 +00:00
self.$idInput.value('');
2011-06-16 17:40:31 +00:00
}
2011-10-18 20:06:01 +00:00
});
2011-06-16 17:40:31 +00:00
}
}
});
});
self.$checkbox = Ox.Checkbox({
id: 'go',
2011-10-27 11:19:38 +00:00
title: 'Switch to this '
+ pandora.site.itemName.singular.toLowerCase()
+ ' after moving files',
2011-12-22 18:30:03 +00:00
value: false,
2011-06-16 17:40:31 +00:00
width: 240
});
self.$movieForm = Ox.Form({
items: [
self.$titleInput,
self.$directorInput,
self.$yearInput,
self.$idInput,
self.$checkbox
],
width: 240
})
.css({margin: '8px'});
self.$clearButton = Ox.Button({
title: 'Clear Form',
width: 116
})
.css({margin: '0 4px 4px 8px'})
.bindEvent({
click: function() {
['title', 'director', 'year', 'id'].forEach(function(key) {
2011-12-21 15:34:28 +00:00
self['$' + key + 'Input'].value('');
2011-06-16 17:40:31 +00:00
});
}
});
self.$moveButton = Ox.Button({
disabled: true,
title: 'Move Files',
width: 116
})
.css({margin: '0 4px 4px 4px'})
.bindEvent({
2011-10-27 11:19:38 +00:00
click: moveFiles
2011-06-16 17:40:31 +00:00
});
2011-06-16 17:40:31 +00:00
self.$moviePanel = Ox.Element()
.append(self.$movieLabel)
.append(self.$movieForm)
.append(self.$clearButton)
.append(self.$moveButton);
that.$element = Ox.SplitPanel({
elements: [
{
element: Ox.SplitPanel({
elements: [
{
element: self.$toolbar,
size: 24
},
{
element: self.$filesList
},
{
element: self.$instancesList,
size: 80
}
],
orientation: 'vertical'
})
},
{
collapsible: true,
element: self.$moviePanel,
size: 256
}
],
orientation: 'horizontal'
});
function deleteItem(data) {
pandora.api.get({
id: pandora.user.ui.item,
keys: ['id', 'title']
},function(result) {
pandora.ui.deleteItemDialog(result.data).open();
});
}
2011-10-27 11:19:38 +00:00
function moveFiles(data) {
var data = {
ids: self.selected,
itemId: self.$idInput.value()
};
['title', 'director', 'year'].forEach(function(key) {
data[key] = self['$' + key + 'Input'].value();
});
pandora.api.moveFiles(data, function(result) {
2011-11-22 16:49:38 +00:00
if(pandora.user.ui.item == self.options.id && pandora.user.ui.itemView == 'files') {
2011-11-22 21:58:02 +00:00
Ox.Request.clearCache(); // fixme: remove
2011-11-22 16:49:38 +00:00
if (self.$checkbox.value()) {
pandora.UI.set({item: result.data.itemId});
} else {
Ox.Log('', 'moved', self.selected, result.data.itemId);
self.$filesList.reloadList();
self.$instancesList.reloadList();
}
2011-10-27 11:19:38 +00:00
}
});
}
2011-09-17 17:40:15 +00:00
function openFiles(data) {
data.ids.length == 1 && pandora.api.parsePath({
path: self.$filesList.value(data.ids[0], 'path')
}, function(result) {
['title', 'director', 'year'].forEach(function(key) {
if (result.data[key]) {
2011-12-21 15:34:28 +00:00
self['$' + key + 'Input'].value(
key == 'director'
2011-10-27 09:33:25 +00:00
? result.data[key].join(', ')
: result.data[key]
2011-12-21 15:34:28 +00:00
);
}
});
updateForm();
2011-10-18 20:06:01 +00:00
self.$titleInput.triggerEvent('change', {value: result.data['title']});
});
2011-06-16 17:40:31 +00:00
}
function selectFiles(data) {
self.selected = data.ids;
self.$instancesList.options({
items: data.ids.length == 1
? self.$filesList.value(data.ids[0], 'instances') : []
});
updateForm();
}
function updateForm() {
2011-10-27 11:19:38 +00:00
if (self.selected.length == self.numberOfItems) {
2011-12-22 18:30:03 +00:00
self.wasChecked = self.$checkbox.value();
2011-10-27 11:19:38 +00:00
self.$checkbox.options({
2011-12-22 18:30:03 +00:00
disabled: true,
value: true
2011-10-27 11:19:38 +00:00
});
} else {
self.$checkbox.options({
2011-12-22 18:30:03 +00:00
disabled: false,
value: self.wasChecked
2011-10-27 11:19:38 +00:00
});
}
2011-06-16 17:40:31 +00:00
self.$moveButton.options({
2011-10-27 11:19:38 +00:00
disabled: self.selected.length == 0
2011-06-16 17:40:31 +00:00
});
2011-10-23 16:19:47 +00:00
self.$ignoreButton.options({
2011-10-27 11:19:38 +00:00
disabled: self.selected.length == 0
2011-10-23 16:19:47 +00:00
});
2011-06-16 17:40:31 +00:00
}
return that;
};