pandora/static/js/pandora/list.js

608 lines
26 KiB
JavaScript
Raw Normal View History

2011-07-29 18:37:11 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2012-02-03 09:15:38 +00:00
'use strict';
2011-07-29 18:37:11 +00:00
pandora.ui.list = function() {
2012-06-30 16:15:08 +00:00
var preview = false,
that,
view = pandora.user.ui.listView;
2011-05-25 19:42:45 +00:00
if (view == 'list') {
2012-06-27 07:41:39 +00:00
that = Ox.TableList({
2012-05-24 08:22:56 +00:00
columns: [].concat([{
2011-09-04 01:52:41 +00:00
align: 'center',
defaultWidth: 16,
format: function(value, data) {
var icon, width, height, margin, marginCSS, borderRadius;
if (pandora.user.ui.icons == 'posters') {
icon = 'poster';
width = value < 1 ? Math.round(14 * value / 2) * 2 : 14;
height = value < 1 ? 14 : Math.round(14 / value / 2) * 2;
margin = value < 1 ? Math.floor(7 - width / 2) - 3 : Math.floor(7 - height / 2);
marginCSS = value < 1 ? '0 0 0 ' + margin + 'px' : margin + 'px 0 0 -3px';
borderRadius = 0;
} else {
icon = 'icon';
width = 14;
height = 14;
marginCSS = '0 0 0 -3px';
borderRadius = '3px';
}
return $('<img>').css({
width: width - 2 + 'px',
height: height - 2 + 'px',
border: '1px solid rgb(48, 48, 48)',
borderRadius: '2px',
margin: marginCSS,
background: '-webkit-linear-gradient(top, rgb(32, 32, 32), rgb(0, 0, 0))'
}).load(function() {
$(this).css({
width: width + 'px',
height: height + 'px',
border: 0,
borderRadius: borderRadius
//background: 'transparent'
2012-01-09 12:17:55 +00:00
});
2011-09-04 01:52:41 +00:00
}).attr({
src: '/' + data.id + '/' + icon + '14.jpg'
});
},
id: 'posterRatio',
resizable: false,
2011-11-03 12:58:22 +00:00
title: 'Icon',
titleImage: pandora.user.ui.icons == 'posters' ? 'SetPoster' : 'Icon',
visible: pandora.user.ui.listColumns.indexOf('posterRatio') > -1,
2011-09-04 01:52:41 +00:00
width: 16
2012-05-22 15:07:34 +00:00
}], pandora.site.sortKeys.filter(function(key) {
return !key.capability
2012-05-22 15:07:34 +00:00
|| pandora.site.capabilities[key.capability][pandora.user.level];
}).map(function(key) {
var position = pandora.user.ui.listColumns.indexOf(key.id);
return {
align: ['string', 'text'].indexOf(
Ox.isArray(key.type) ? key.type[0]: key.type
) > -1 ? 'left' : key.type == 'list' ? 'center' : 'right',
defaultWidth: key.columnWidth,
format: key.format,
id: key.id,
operator: pandora.getSortOperator(key.id),
position: position,
removable: !key.columnRequired,
title: key.title,
type: key.type,
visible: position > -1,
width: pandora.user.ui.listColumnWidth[key.id] || key.columnWidth
};
})),
2011-05-25 19:42:45 +00:00
columnsMovable: true,
columnsRemovable: true,
columnsResizable: true,
columnsVisible: true,
2011-09-01 09:17:49 +00:00
draggable: true,
2011-05-25 19:42:45 +00:00
id: 'list',
items: function(data, callback) {
2011-11-04 15:54:42 +00:00
//Ox.Log('', 'data, pandora.Query.toObject', data, pandora.Query.toObject())
2011-08-24 06:32:59 +00:00
pandora.api.find(Ox.extend(data, {
query: pandora.user.ui.find
2011-05-25 19:42:45 +00:00
}), callback);
},
scrollbarVisible: true,
selected: pandora.user.ui.listSelection,
sort: pandora.user.ui.listSort,
unique: 'id'
2011-05-25 19:42:45 +00:00
})
.bindEvent({
2011-08-18 07:54:46 +00:00
columnchange: function(data) {
2011-06-27 13:39:35 +00:00
var columnWidth = {};
2011-09-26 16:46:31 +00:00
pandora.UI.set({listColumns: data.ids});
2011-05-25 19:42:45 +00:00
/*
data.ids.forEach(function(id) {
2011-10-29 17:46:46 +00:00
columnWidth[id] =
2011-09-26 16:46:31 +00:00
pandora.user.ui.lists[pandora.user.ui.list].columnWidth[id]
|| Ox.getObjectById(pandora.site.sortKeys, id).width
2011-05-25 19:42:45 +00:00
});
2011-09-26 16:46:31 +00:00
pandora.UI.set({listColumnWidth: columnWidth});
2011-05-25 19:42:45 +00:00
*/
},
2011-08-18 07:54:46 +00:00
columnresize: function(data) {
2011-09-26 16:46:31 +00:00
pandora.UI.set('listColumnWidth.' + data.id, data.width);
2011-05-25 19:42:45 +00:00
},
2011-08-18 07:54:46 +00:00
resize: function(data) { // this is the resize event of the split panel
2011-05-25 19:42:45 +00:00
that.size();
},
2011-08-18 07:54:46 +00:00
sort: function(data) {
2011-11-04 15:54:42 +00:00
Ox.Log('', '---- SORT ----', data)
pandora.UI.set({
listSort: [{key: data.key, operator: data.operator}]
});
2011-05-25 19:42:45 +00:00
}
});
2011-09-17 07:07:59 +00:00
} else if (view == 'grid') {
2011-06-19 17:49:25 +00:00
that = Ox.IconList({
borderRadius: pandora.user.ui.icons == 'posters' ? 0 : 16,
2011-08-07 20:25:33 +00:00
defaultRatio: pandora.user.ui.icons == 'posters' ? 5/8 : 1,
2011-09-01 09:17:49 +00:00
draggable: true,
2011-05-25 19:42:45 +00:00
id: 'list',
item: function(data, sort, size) {
var ui = pandora.user.ui,
ratio = ui.icons == 'posters'
? (ui.showSitePosters ? 5/8 : data.posterRatio) : 1,
url = '/' + data.id + '/' + (
ui.icons == 'posters'
? (ui.showSitePosters ? 'siteposter' : 'poster') : 'icon'
) + size + '.jpg',
format, info, sortKey = sort[0].key;
if (['title', 'director', 'random'].indexOf(sortKey) > -1) {
info = data['year'];
} else {
format = pandora.getSortKeyData(sortKey).format;
2011-10-26 14:52:23 +00:00
if (format) {
info = (
/^color/.test(format.type.toLowerCase()) ? Ox.Theme : Ox
)['format' + Ox.toTitleCase(format.type)].apply(
2012-05-24 08:22:56 +00:00
this, [data[sortKey]].concat(format.args || [])
2011-10-26 14:52:23 +00:00
);
} else {
info = data[sortKey];
}
}
2011-05-25 19:42:45 +00:00
size = size || 128;
return {
height: Math.round(ratio <= 1 ? size : size / ratio),
2011-08-06 18:00:15 +00:00
id: data.id,
info: info,
2011-05-25 19:42:45 +00:00
title: data.title + (data.director.length ? ' (' + data.director.join(', ') + ')' : ''),
url: url,
width: Math.round(ratio >= 1 ? size : size * ratio)
2011-05-25 19:42:45 +00:00
};
},
items: function(data, callback) {
2011-08-24 06:32:59 +00:00
pandora.api.find(Ox.extend(data, {
query: pandora.user.ui.find
2011-05-25 19:42:45 +00:00
}), callback);
},
2011-08-19 12:33:02 +00:00
keys: ['director', 'id', 'posterRatio', 'title', 'year'],
selected: pandora.user.ui.listSelection,
2011-05-25 19:42:45 +00:00
size: 128,
sort: pandora.user.ui.listSort,
2011-05-25 19:42:45 +00:00
unique: 'id'
})
.addClass('OxMedia');
2011-06-27 13:39:35 +00:00
} else if (view == 'info') {
2011-08-19 02:13:16 +00:00
that = Ox.Element().css({margin: '16px'}).html(view + ' results view still missing.');
} else if (view == 'clips') {
2011-10-17 15:13:37 +00:00
that = Ox.InfoList({
borderRadius: pandora.user.ui.icons == 'posters' ? 0 : 16,
defaultRatio: pandora.user.ui.icons == 'posters' ? 5/8 : 1,
draggable: true,
id: 'list',
item: function(data, sort, size) {
size = 128;
var ui = pandora.user.ui,
ratio = ui.icons == 'posters'
? (ui.showSitePosters ? 5/8 : data.posterRatio) : 1,
2011-10-17 15:13:37 +00:00
url = '/' + data.id + '/' + (
ui.icons == 'posters'
? (ui.showSitePosters ? 'siteposter' : 'poster') : 'icon'
2011-10-17 15:13:37 +00:00
) + size + '.jpg',
format, info, sortKey = sort[0].key;
if (['title', 'director'].indexOf(sortKey) > -1) {
info = data['year'];
} else {
format = pandora.getSortKeyData(sortKey).format;
2011-10-26 14:52:23 +00:00
if (format) {
info = (
/^color/.test(format.type.toLowerCase()) ? Ox.Theme : Ox
)['format' + Ox.toTitleCase(format.type)].apply(
2012-05-24 08:22:56 +00:00
this, [data[sortKey]].concat(format.args || [])
2011-10-26 14:52:23 +00:00
);
} else {
info = data[sortKey];
}
2011-10-17 15:13:37 +00:00
}
return {
icon: {
height: Math.round(ratio <= 1 ? size : size / ratio),
id: data.id,
info: info,
title: data.title + (data.director.length ? ' (' + data.director.join(', ') + ')' : ''),
url: url,
width: Math.round(ratio >= 1 ? size : size * ratio)
},
info: {
2011-10-19 10:47:33 +00:00
element: pandora.ui.itemClips,
2011-10-17 15:13:37 +00:00
id: data.id,
options: {
2011-10-19 16:40:52 +00:00
clips: data.clips,
2011-10-19 10:47:33 +00:00
duration: data.duration,
id: data.id,
ratio: data.videoRatio
2011-10-17 15:13:37 +00:00
}
}
};
},
items: function(data, callback) {
pandora.api.find(Ox.extend(data, {
query: pandora.user.ui.find,
2011-10-19 16:40:52 +00:00
clips: {
2011-10-20 12:58:21 +00:00
query: pandora.getClipsQuery(),
items: pandora.getClipsItems(),
2011-10-19 16:40:52 +00:00
keys: []
}
2011-10-17 15:13:37 +00:00
}), callback);
},
2011-10-19 16:40:52 +00:00
keys: ['clips', 'director', 'duration', 'id', 'posterRatio', 'title', 'videoRatio', 'year'],
2011-10-17 15:13:37 +00:00
selected: pandora.user.ui.listSelection,
size: 192,
sort: pandora.user.ui.listSort,
unique: 'id',
width: window.innerWidth
- pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1
- Ox.UI.SCROLLBAR_SIZE
2011-10-17 15:13:37 +00:00
})
.addClass('OxMedia')
2011-10-17 15:13:37 +00:00
.bindEvent({
key_left: function() {
// ...
},
key_right: function() {
// ...
}
});
2011-08-19 02:13:16 +00:00
} else if (view == 'timelines') {
that = Ox.InfoList({
2011-08-18 11:32:47 +00:00
borderRadius: pandora.user.ui.icons == 'posters' ? 0 : 16,
defaultRatio: pandora.user.ui.icons == 'posters' ? 5/8 : 1,
2011-10-17 11:25:55 +00:00
draggable: true,
2011-08-18 11:32:47 +00:00
id: 'list',
item: function(data, sort, size) {
2011-08-19 06:40:19 +00:00
size = 128;
2011-10-20 13:33:18 +00:00
var clipsQuery = pandora.getClipsQuery(),
isClipsQuery = !!clipsQuery.conditions.length,
ui = pandora.user.ui,
ratio = ui.icons == 'posters'
? (ui.showSitePosters ? 5/8 : data.posterRatio) : 1,
url = '/' + data.id + '/' + (
ui.icons == 'posters'
? (ui.showSitePosters ? 'siteposter' : 'poster') : 'icon'
) + size + '.jpg',
format, info, sortKey = sort[0].key;
if (['title', 'director'].indexOf(sortKey) > -1) {
info = data['year'];
} else {
format = pandora.getSortKeyData(sortKey).format;
if (format) {
info = (
/^color/.test(format.type.toLowerCase()) ? Ox.Theme : Ox
)['format' + Ox.toTitleCase(format.type)].apply(
2012-05-24 08:22:56 +00:00
this, [data[sortKey]].concat(format.args || [])
);
} else {
info = data[sortKey];
}
2011-10-17 15:13:37 +00:00
}
2011-08-18 11:32:47 +00:00
return {
2011-08-19 06:40:19 +00:00
icon: {
height: Math.round(ratio <= 1 ? size : size / ratio),
2011-08-19 06:40:19 +00:00
id: data.id,
info: info,
2011-08-19 06:40:19 +00:00
title: data.title + (data.director.length ? ' (' + data.director.join(', ') + ')' : ''),
url: url,
width: Math.round(ratio >= 1 ? size : size * ratio)
2011-08-19 06:40:19 +00:00
},
2012-05-19 13:46:52 +00:00
info: data.rendered ? {
2011-10-17 15:13:37 +00:00
css: {marginTop: '2px'},
2011-08-19 06:40:19 +00:00
element: Ox.BlockVideoTimeline,
2011-10-17 10:19:17 +00:00
events: {
position: function(event) {
2011-10-20 13:33:18 +00:00
if (pandora.user.ui.videoPoints[data.id]) {
pandora.UI.set('videoPoints.' + data.id + '.position', event.position);
} else {
pandora.UI.set('videoPoints.' + data.id, {'in': 0, out: 0, position: event.position});
}
// FIXME: we need a way to set the position
// once the video preview has loaded
pandora.$ui.videoPreview && pandora.$ui.videoPreview.options({
position: event.position
});
2011-10-17 10:19:17 +00:00
}
},
2011-08-19 06:40:19 +00:00
id: data.id,
options: {
duration: data.duration,
2011-10-20 13:33:18 +00:00
find: isClipsQuery ? clipsQuery.conditions[0].value : '',
getImageURL: function(type, i) {
2012-05-17 09:38:59 +00:00
return '/' + data.id + '/timeline' + type + '16p' + i + '.jpg';
2011-10-17 10:19:17 +00:00
},
position: pandora.user.ui.videoPoints[data.id]
2011-10-17 15:13:37 +00:00
? pandora.user.ui.videoPoints[data.id].position : 0,
2011-10-20 13:33:18 +00:00
results: isClipsQuery ? data.clips.map(function(clip) {
2011-10-20 12:58:21 +00:00
return {'in': clip['in'], out: clip.out};
}) : [],
2011-10-20 13:33:18 +00:00
subtitles: isClipsQuery ? data.clips.map(function(clip) {
2011-10-20 12:58:21 +00:00
return {'in': clip['in'], out: clip.out, text: clip.annotations[0].value};
}) : [],
type: pandora.user.ui.videoTimeline
2011-08-19 06:40:19 +00:00
}
2012-05-19 13:46:52 +00:00
} : {
css: {marginTop: '2px'},
element: Ox.Element,
id: data.id,
options: {}
2011-08-19 06:40:19 +00:00
}
2011-08-18 11:32:47 +00:00
};
},
items: function(data, callback) {
2011-10-20 13:33:18 +00:00
var clipsQuery = pandora.getClipsQuery(),
isClipsQuery = !!clipsQuery.conditions.length;
2011-10-20 12:58:21 +00:00
pandora.api.find(Ox.extend(data, Ox.extend({
query: pandora.user.ui.find
}, isClipsQuery ? {clips: {
query: clipsQuery,
items: 1000000,
keys: []
}} : {})), callback);
2011-08-18 11:32:47 +00:00
},
2012-05-19 13:46:52 +00:00
keys: ['clips', 'director', 'duration', 'id', 'posterRatio', 'rendered', 'title', 'year'],
selected: pandora.user.ui.listSelection,
2011-08-19 02:13:16 +00:00
size: 192,
sort: pandora.user.ui.listSort,
2011-08-18 11:32:47 +00:00
unique: 'id'
2011-10-17 15:13:37 +00:00
})
.bindEvent({
key_left: function() {
// ...
},
key_right: function() {
// ...
}
});
2011-06-27 13:39:35 +00:00
} else if (view == 'maps') {
that = Ox.Element().css({margin: '16px'}).html(view + ' results view still missing.');
} else if (view == 'calendars') {
that = Ox.Element().css({margin: '16px'}).html(view + ' results view still missing.');
2011-06-16 20:00:10 +00:00
} else if (view == 'clip') {
that = pandora.$ui.clipList = pandora.ui.clipList();
} else if (view == 'video') {
that = pandora.ui.clipPlayer();
} else if (['map', 'calendar'].indexOf(view) > -1) {
that = pandora.ui.navigationView(view);
2011-05-25 19:42:45 +00:00
}
2011-10-17 15:13:37 +00:00
if (['list', 'grid', 'clips', 'timelines'].indexOf(view) > -1) {
2011-09-03 23:04:48 +00:00
pandora.enableDragAndDrop(that, true);
that.bindEvent({
closepreview: function(data) {
pandora.$ui.previewDialog.close();
preview = false;
//delete pandora.$ui.previewDialog;
},
copy: function(data) {
Ox.Clipboard.copy({
items: data.ids,
2011-09-09 12:09:05 +00:00
text: data.ids.map(function(id) {
return pandora.$ui.list.value(id, 'title');
}).join('\n')
2011-09-03 23:04:48 +00:00
});
},
'delete': function(data) {
pandora.getListData().editable && pandora.api.removeListItems({
2011-09-28 00:10:26 +00:00
list: pandora.user.ui._list,
items: data.ids
}, function() {
pandora.UI.set({listSelection: []});
pandora.reloadList();
});
},
init: function(data) {
pandora.$ui.statusbar.set('total', data);
data = [];
pandora.site.totals.forEach(function(v) {
data[v.id] = 0;
});
pandora.$ui.statusbar.set('selected', data);
},
open: function(data) {
var set = {item: data.ids[0]};
if (data.isSpecialTarget) {
set.itemView = pandora.user.ui.videoView;
}
if (['accessed', 'timesaccessed'].indexOf(pandora.user.ui.listSort[0].key) > -1) {
Ox.Request.clearCache('find');
}
pandora.UI.set(set);
},
openpreview: function(data) {
2011-12-23 08:17:51 +00:00
if (data.ids.length) {
}
pandora.requests.preview && pandora.api.cancel(pandora.requests.preview);
pandora.requests.preview = pandora.api.find({
2011-12-23 08:17:51 +00:00
keys: ['director', 'id', 'posterRatio', 'title', 'year'],
query: {
conditions: data.ids.map(function(id) {
return {
key: 'id',
value: id,
2011-09-28 01:40:36 +00:00
operator: '=='
2011-11-11 17:17:06 +00:00
};
}),
operator: '|'
}
}, function(result) {
var item = result.data.items[0],
2012-02-21 20:44:35 +00:00
title = item.title + (
item.director ? ' (' + item.director.join(', ') + ')' : ''
) + (
item.year ? ' ' + item.year : ''
),
ratio = item.posterRatio,
windowWidth = window.innerWidth * 0.8,
windowHeight = window.innerHeight * 0.8,
windowRatio = windowWidth / windowHeight,
width = Math.round(ratio > windowRatio ? windowWidth : windowHeight * ratio),
height = Math.round(ratio < windowRatio ? windowHeight : windowWidth / ratio);
pandora.$ui.previewImage = $('<img>')
.attr({src: '/' + item.id + '/poster128.jpg'})
.css({width: width + 'px', height: height + 'px'})
$('<img>').load(function() {
pandora.$ui.previewImage.attr({src: $(this).attr('src')});
})
.attr({src: '/' + item.id + '/poster1024.jpg'});
if (!preview) {
if (!pandora.$ui.previewDialog) {
pandora.$ui.previewDialog = Ox.Dialog({
closeButton: true,
content: pandora.$ui.previewImage,
fixedRatio: true,
focus: false,
height: height,
maximizeButton: true,
title: title,
width: width
})
.bindEvent({
close: function() {
that.closePreview();
preview = false;
},
2011-09-17 17:40:15 +00:00
resize: function(data) {
pandora.$ui.previewImage.css({
2011-09-17 17:40:15 +00:00
width: data.width + 'px',
height: data.height + 'px'
});
}
})
.open();
} else {
2011-12-23 08:17:51 +00:00
pandora.$ui.previewDialog.options({
content: pandora.$ui.previewImage,
height: height,
title: title,
width: width
})
.open();
2011-05-25 19:42:45 +00:00
}
preview = true;
2011-08-08 07:48:13 +00:00
} else {
pandora.$ui.previewDialog.options({
2011-08-08 07:48:13 +00:00
content: pandora.$ui.previewImage,
2012-05-26 15:46:24 +00:00
title: title
2011-08-08 07:48:13 +00:00
})
.setSize(width, height);
2011-08-08 07:48:13 +00:00
}
});
},
paste: function(data) {
data.items && pandora.getListData().editable && pandora.api.addListItems({
2011-09-28 00:10:26 +00:00
list: pandora.user.ui._list,
items: data.items
}, pandora.reloadList);
},
select: function(data) {
2011-12-19 17:20:06 +00:00
var query;
pandora.UI.set('listSelection', data.ids);
if (data.ids.length) {
pandora.$ui.mainMenu.enableItem('copy');
pandora.$ui.mainMenu.enableItem('openmovie');
2011-05-25 19:42:45 +00:00
} else {
pandora.$ui.mainMenu.disableItem('copy');
2011-10-29 17:46:46 +00:00
pandora.$ui.mainMenu.disableItem('openmovie');
2011-05-25 19:42:45 +00:00
}
2011-12-23 08:17:51 +00:00
if (data.ids.length == 0) {
pandora.$ui.statusbar.set('selected', {items: 0});
2011-12-19 17:20:06 +00:00
} else {
2011-12-23 08:17:51 +00:00
if (Ox.isUndefined(data.rest)) {
query = {
conditions: data.ids.map(function(id) {
return {
key: 'id',
value: id,
operator: '=='
}
}),
operator: '|'
};
} else {
query = {
2012-05-24 08:22:56 +00:00
conditions: [pandora.user.ui.find].concat(
data.rest.map(function(id) {
return {
key: 'id',
value: id,
operator: '!='
};
})
),
2011-12-23 08:17:51 +00:00
operator: '&'
};
}
pandora.api.find({
query: query
}, function(result) {
pandora.$ui.statusbar.set('selected', result.data);
2011-12-23 08:17:51 +00:00
});
2011-12-19 17:20:06 +00:00
}
},
pandora_listselection: function(data) {
that.options({selected: data.value});
},
pandora_listsort: function(data) {
that.options({sort: data.value});
2011-05-25 19:42:45 +00:00
}
});
2011-10-29 17:46:46 +00:00
}
if (['list', 'grid', 'timelines'].indexOf(view) > -1) {
that.bindEvent({
pandora_icons: function(data) {
2011-11-03 12:58:22 +00:00
var src, previousSrc;
// fixme: doesn't update title icon, passes useless options
2011-11-03 12:58:22 +00:00
if (hasIcons()) {
if (pandora.user.ui.listView == 'list') {
src = Ox.UI.getImageURL(
data.value == 'posters' ? 'symbolSetPoster' : 'symbolIcon'
);
previousSrc = Ox.UI.getImageURL(
data.previousValue == 'posters' ? 'symbolSetPoster' : 'symbolIcon'
2012-05-22 13:15:16 +00:00
);
that.find('img[src="' + previousSrc + '"]').attr({src: src});
2011-11-03 12:58:22 +00:00
} else {
that.options({
borderRadius: data.value == 'posters' ? 0 : 16,
defaultRatio: data.value == 'posters' ? 5/8 : 1
});
}
that.reloadList(true);
}
},
pandora_showsiteposters: function() {
// fixme: should be disabled if ui.icons != 'posters'
hasIcons() && pandora.user.ui.icons == 'posters' && that.reloadList(true);
}
});
}
if (view == 'timelines') {
that.bindEvent({
pandora_videotimeline: function(data) {
that.reloadList(true);
}
});
}
function hasIcons() {
return (
pandora.user.ui.listView == 'list'
&& pandora.user.ui.listColumns.indexOf('posterRatio') > -1
) || ['grid', 'timelines'].indexOf(pandora.user.ui.listView) > -1;
}
2011-05-25 19:42:45 +00:00
return that;
2011-05-25 19:42:45 +00:00
};