2011-07-29 18:37:11 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-11-05 17:04:10 +00:00
|
|
|
'use strict';
|
2011-09-18 21:46:37 +00:00
|
|
|
pandora.ui.info = function() {
|
2011-10-29 17:46:46 +00:00
|
|
|
|
2011-09-30 10:33:45 +00:00
|
|
|
var ui = pandora.user.ui,
|
2011-09-18 21:18:05 +00:00
|
|
|
view = getView(),
|
2011-09-30 10:33:45 +00:00
|
|
|
|
2011-09-18 21:18:05 +00:00
|
|
|
that = Ox.Element()
|
|
|
|
.css({overflowX: 'hidden', overflowY: 'auto'})
|
|
|
|
.bindEvent({
|
|
|
|
toggle: function(data) {
|
|
|
|
pandora.UI.set({showInfo: !data.collapsed});
|
2011-09-30 10:33:45 +00:00
|
|
|
},
|
|
|
|
pandora_find: function() {
|
|
|
|
if (pandora.user.ui._list != pandora.UI.getPrevious('_list')) {
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pandora_item: updateInfo,
|
2011-10-13 10:12:00 +00:00
|
|
|
pandora_listselection: updateInfo,
|
2011-11-07 20:08:58 +00:00
|
|
|
pandora_listview: function(data) {
|
|
|
|
if (!pandora.isClipView(data.value) && pandora.isClipView(data.previousValue)) {
|
|
|
|
updateInfo();
|
|
|
|
}
|
|
|
|
}
|
2011-08-18 07:54:46 +00:00
|
|
|
});
|
2011-09-30 10:33:45 +00:00
|
|
|
|
|
|
|
//pandora.$ui.leftPanel && resize();
|
|
|
|
|
|
|
|
updateInfo();
|
|
|
|
|
|
|
|
function getId() {
|
|
|
|
return ui.item || (
|
|
|
|
ui.listSelection.length
|
|
|
|
? ui.listSelection[ui.listSelection.length - 1]
|
|
|
|
: null
|
|
|
|
);
|
2011-09-18 21:18:05 +00:00
|
|
|
}
|
2011-09-30 10:33:45 +00:00
|
|
|
|
2011-09-18 21:18:05 +00:00
|
|
|
function getView() {
|
2011-09-30 10:33:45 +00:00
|
|
|
return !getId() ? 'list'
|
|
|
|
: !ui.item && pandora.isClipView() ? 'poster'
|
2011-09-18 21:18:05 +00:00
|
|
|
: 'video';
|
|
|
|
}
|
2011-09-30 10:33:45 +00:00
|
|
|
|
|
|
|
function resizeInfo() {
|
2011-10-29 13:50:40 +00:00
|
|
|
var height = pandora.getInfoHeight(true);
|
2011-10-29 14:17:43 +00:00
|
|
|
pandora.$ui.leftPanel.size(2, height);
|
|
|
|
pandora.resizeFolders();
|
|
|
|
!ui.showInfo && pandora.$ui.leftPanel.css({bottom: -height + 'px'});
|
2011-09-30 10:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateInfo() {
|
|
|
|
var id = getId(),
|
|
|
|
previousView = view;
|
2011-10-29 17:46:46 +00:00
|
|
|
view = getView();
|
2011-09-30 10:33:45 +00:00
|
|
|
if (view == 'list') {
|
2011-11-07 20:20:18 +00:00
|
|
|
pandora.$ui.listInfo && pandora.$ui.listInfo.remove();
|
2011-10-22 16:07:05 +00:00
|
|
|
that.empty().append(pandora.$ui.listInfo = pandora.ui.listInfo());
|
2011-09-30 10:33:45 +00:00
|
|
|
previousView == 'video' && resizeInfo();
|
|
|
|
} else if (view == 'poster') {
|
|
|
|
pandora.api.get({id: id, keys: ['director', 'posterRatio', 'title']}, function(result) {
|
|
|
|
var ratio = result.data.posterRatio,
|
2011-10-29 13:50:40 +00:00
|
|
|
height = pandora.getInfoHeight(true);
|
2011-11-07 20:20:18 +00:00
|
|
|
pandora.$ui.posterInfo && pandora.$ui.posterInfo.remove();
|
2011-09-30 10:33:45 +00:00
|
|
|
that.empty().append(
|
|
|
|
pandora.$ui.posterInfo = pandora.ui.posterInfo(Ox.extend(result.data, {id: id}))
|
|
|
|
);
|
|
|
|
previousView == 'video' && resizeInfo();
|
|
|
|
});
|
|
|
|
} else if (view == 'video') {
|
2011-10-23 22:03:41 +00:00
|
|
|
pandora.api.get({
|
|
|
|
id: id,
|
|
|
|
keys: ['duration', 'rendered', 'videoRatio']
|
|
|
|
}, function(result) {
|
|
|
|
if (result.data && result.data.rendered) {
|
2011-11-04 22:14:13 +00:00
|
|
|
pandora.$ui.videoPreview && pandora.$ui.videoPreview.remove();
|
2011-11-07 20:20:18 +00:00
|
|
|
that.empty().append(
|
|
|
|
pandora.$ui.videoPreview = pandora.ui.videoPreview({
|
|
|
|
duration: result.data.duration,
|
|
|
|
frameRatio: result.data.videoRatio,
|
|
|
|
height: pandora.getInfoHeight(true),
|
|
|
|
id: id,
|
|
|
|
width: ui.sidebarSize
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function(data) {
|
|
|
|
pandora.UI.set(
|
|
|
|
'videoPoints.' + id,
|
|
|
|
{'in': 0, out: 0, position: data.position}
|
|
|
|
);
|
|
|
|
if (ui.item && ['video', 'timeline'].indexOf(ui.itemView) > -1) {
|
|
|
|
pandora.$ui[
|
|
|
|
ui.itemView == 'video' ? 'player' : 'editor'
|
|
|
|
].options({
|
|
|
|
position: data.position
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
pandora.UI.set({
|
|
|
|
item: id,
|
|
|
|
itemView: ui.videoView
|
|
|
|
});
|
|
|
|
}
|
2011-09-30 10:33:45 +00:00
|
|
|
}
|
2011-11-07 20:20:18 +00:00
|
|
|
})
|
|
|
|
);
|
2011-09-30 10:33:45 +00:00
|
|
|
previousView != 'video' && resizeInfo();
|
|
|
|
}
|
|
|
|
});
|
2011-08-18 07:54:46 +00:00
|
|
|
}
|
2011-09-18 21:18:05 +00:00
|
|
|
}
|
2011-09-30 10:33:45 +00:00
|
|
|
|
2011-09-18 21:18:05 +00:00
|
|
|
that.resizeInfo = function() {
|
2011-09-30 10:33:45 +00:00
|
|
|
var view = getView();
|
2011-09-18 21:18:05 +00:00
|
|
|
if (view == 'list') {
|
2011-11-06 11:51:04 +00:00
|
|
|
pandora.$ui.listInfo.resizeInfo();
|
2011-09-18 21:18:05 +00:00
|
|
|
} else if (view == 'poster') {
|
2011-11-06 11:51:04 +00:00
|
|
|
pandora.$ui.posterInfo.resizeInfo();
|
2011-09-18 21:18:05 +00:00
|
|
|
} else if (view == 'video') {
|
|
|
|
pandora.$ui.videoPreview.options({
|
2011-10-29 13:50:40 +00:00
|
|
|
height: pandora.getInfoHeight(true),
|
2011-09-30 10:33:45 +00:00
|
|
|
width: ui.sidebarSize
|
2011-09-29 17:25:04 +00:00
|
|
|
});
|
2011-09-18 21:18:05 +00:00
|
|
|
}
|
|
|
|
};
|
2011-09-30 10:33:45 +00:00
|
|
|
|
2011-11-06 11:51:04 +00:00
|
|
|
that.updateListInfo = function() {
|
|
|
|
getView() == 'list' && that.empty().append(
|
|
|
|
pandora.$ui.listInfo = pandora.ui.listInfo()
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2011-09-18 21:18:05 +00:00
|
|
|
return that;
|
2011-09-30 10:33:45 +00:00
|
|
|
|
2011-09-18 21:18:05 +00:00
|
|
|
};
|
|
|
|
|
2011-10-22 16:07:05 +00:00
|
|
|
pandora.ui.listInfo = function() {
|
|
|
|
|
|
|
|
var list = pandora.user.ui._list,
|
2011-11-06 12:33:34 +00:00
|
|
|
editable = list.split(':')[0] == pandora.user.username,
|
2011-10-22 16:07:05 +00:00
|
|
|
that = $('<div>').css({padding: '16px', textAlign: 'center'}),
|
2011-11-03 17:11:10 +00:00
|
|
|
$icon = Ox.Element({
|
|
|
|
element: '<img>',
|
2011-11-06 12:33:34 +00:00
|
|
|
tooltip: editable ? 'Doubleclick to edit icon' : '',
|
2011-11-03 17:11:10 +00:00
|
|
|
})
|
2011-10-22 16:07:05 +00:00
|
|
|
.attr({
|
|
|
|
src: list
|
|
|
|
? '/list/' + list + '/icon256.jpg?' + Ox.uid()
|
|
|
|
: '/static/png/icon256.png'
|
|
|
|
})
|
|
|
|
.css(getIconCSS())
|
2011-11-06 11:51:04 +00:00
|
|
|
.appendTo(that),
|
|
|
|
$title, $description;
|
2011-10-05 17:35:16 +00:00
|
|
|
|
2011-11-06 12:33:34 +00:00
|
|
|
editable && $icon.bindEvent({
|
2011-11-08 09:46:30 +00:00
|
|
|
doubleclick: editIcon
|
2011-11-06 12:33:34 +00:00
|
|
|
});
|
|
|
|
|
2011-11-03 17:11:10 +00:00
|
|
|
that.append($('<div>').css({height: '16px'}));
|
|
|
|
|
2011-10-05 17:35:16 +00:00
|
|
|
//fixme: allow editing
|
|
|
|
//pandora.api.editList({id: list, description: 'foobbar'}, callback)
|
|
|
|
//pandora.api.editPage({name: 'allItems', body: 'foobar'}, callback)
|
2011-10-22 16:07:05 +00:00
|
|
|
if (list) {
|
2011-10-05 17:35:16 +00:00
|
|
|
pandora.api.findLists({
|
2011-11-06 14:09:39 +00:00
|
|
|
query: {conditions: [{key: 'id', value: list, operator: '=='}]},
|
2011-11-03 17:11:10 +00:00
|
|
|
keys: ['description', 'name', 'user']
|
2011-10-05 17:35:16 +00:00
|
|
|
}, function(result) {
|
2011-10-22 16:07:05 +00:00
|
|
|
if (result.data.items.length) {
|
2011-11-06 12:33:34 +00:00
|
|
|
var item = result.data.items[0],
|
|
|
|
editable = item.user == pandora.user.username;
|
2011-10-22 16:07:05 +00:00
|
|
|
that.append(
|
2011-11-06 11:51:04 +00:00
|
|
|
$title = Ox.Editable({
|
2011-11-06 12:33:34 +00:00
|
|
|
editable: editable,
|
2011-11-03 17:11:10 +00:00
|
|
|
format: function(value) {
|
2011-11-06 11:51:04 +00:00
|
|
|
return Ox.encodeHTML(item.user + ': ' + value)
|
2011-11-03 17:11:10 +00:00
|
|
|
},
|
2011-11-06 12:33:34 +00:00
|
|
|
tooltip: editable ? 'Doubleclick to edit title' : '',
|
2011-11-03 17:11:10 +00:00
|
|
|
value: item.name,
|
|
|
|
width: pandora.user.ui.sidebarSize - 32
|
|
|
|
})
|
|
|
|
.css({fontWeight: 'bold', textAlign: 'center'})
|
2011-11-06 11:51:04 +00:00
|
|
|
.bindEvent({
|
2011-11-06 12:26:56 +00:00
|
|
|
edit: function() {
|
|
|
|
$title.options({
|
|
|
|
width: that.width()
|
|
|
|
});
|
|
|
|
},
|
2011-11-06 11:51:04 +00:00
|
|
|
submit: function(data) {
|
|
|
|
if (data.value != item.name) {
|
|
|
|
pandora.api.editList({
|
|
|
|
id: list,
|
|
|
|
name: data.value
|
|
|
|
}, function(result) {
|
|
|
|
if (result.data.id != list) {
|
|
|
|
pandora.renameList(list, result.data.id, result.data.name);
|
|
|
|
list = result.data.id;
|
|
|
|
item.name = result.data.name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2011-10-22 16:07:05 +00:00
|
|
|
).append(
|
2011-11-03 17:11:10 +00:00
|
|
|
$('<div>').css({height: '8px'})
|
|
|
|
).append(
|
2011-11-06 11:51:04 +00:00
|
|
|
$description = Ox.Editable({
|
2011-11-03 17:11:10 +00:00
|
|
|
format: function(value) {
|
2011-11-06 11:51:04 +00:00
|
|
|
return '<div style="color: rgb(128, 128, 128); text-align: center">'
|
|
|
|
+ value + '</div>';
|
2011-11-03 17:11:10 +00:00
|
|
|
},
|
2011-11-06 12:33:34 +00:00
|
|
|
editable: editable,
|
2011-11-06 11:51:04 +00:00
|
|
|
height: pandora.user.ui.sidebarSize - 32,
|
2011-11-06 12:33:34 +00:00
|
|
|
placeholder: editable
|
2011-11-06 11:51:04 +00:00
|
|
|
? '<div style="color: rgb(128, 128, 128); text-align: center">No description</span>'
|
|
|
|
: '',
|
2011-11-06 12:33:34 +00:00
|
|
|
tooltip: editable ? 'Doubleclick to edit description' : '',
|
2011-11-03 17:11:10 +00:00
|
|
|
type: 'textarea',
|
|
|
|
value: item.description,
|
|
|
|
width: pandora.user.ui.sidebarSize - 32
|
|
|
|
})
|
2011-11-06 11:51:04 +00:00
|
|
|
.css({textAlign: 'center'})
|
|
|
|
.bindEvent({
|
2011-11-06 12:26:56 +00:00
|
|
|
edit: function() {
|
|
|
|
// scrollbars may appear
|
|
|
|
setTimeout(function() {
|
|
|
|
var width = that.width();
|
|
|
|
$description.options({
|
|
|
|
height: width,
|
|
|
|
width: width
|
|
|
|
});
|
|
|
|
}, 25);
|
|
|
|
},
|
2011-11-06 11:51:04 +00:00
|
|
|
submit: function(data) {
|
|
|
|
if (data.value != item.description) {
|
|
|
|
pandora.api.editList({
|
|
|
|
id: list,
|
|
|
|
description: data.value
|
|
|
|
}, function(result) {
|
|
|
|
item.description = result.data.description;
|
2011-11-06 14:09:39 +00:00
|
|
|
Ox.Request.clearCache('findLists');
|
2011-11-06 11:51:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2011-10-22 16:07:05 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
that.append(
|
|
|
|
$('<div>')
|
2011-11-03 17:11:10 +00:00
|
|
|
.css({paddingTop: '16px'})
|
2011-10-22 16:07:05 +00:00
|
|
|
.html('List not found')
|
|
|
|
);
|
|
|
|
}
|
2011-10-05 17:35:16 +00:00
|
|
|
});
|
2011-10-22 16:07:05 +00:00
|
|
|
} else {
|
|
|
|
that.append(
|
|
|
|
$('<div>')
|
2011-11-06 11:51:04 +00:00
|
|
|
.css({fontWeight: 'bold'})
|
2011-10-22 16:07:05 +00:00
|
|
|
.html('All ' + pandora.site.itemName.plural)
|
|
|
|
);
|
2011-10-05 17:35:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 09:46:30 +00:00
|
|
|
function editIcon() {
|
|
|
|
// timeout is needed since if the icon is clicked before the list
|
|
|
|
// folders have loaded, the list dialog cannot get the list data yet.
|
|
|
|
if (pandora.getListData().id) {
|
|
|
|
pandora.$ui.listDialog = pandora.ui.listDialog('icon').open();
|
|
|
|
} else {
|
|
|
|
setTimeout(editIcon, 250);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-18 21:18:05 +00:00
|
|
|
function getIconCSS() {
|
|
|
|
var size = Math.round(pandora.user.ui.sidebarSize / 2);
|
2011-09-29 17:25:04 +00:00
|
|
|
return {
|
|
|
|
width: size + 'px',
|
|
|
|
height: size + 'px',
|
2011-11-03 17:11:10 +00:00
|
|
|
borderRadius: Math.round(size / 4) + 'px',
|
2011-09-29 17:25:04 +00:00
|
|
|
};
|
2011-09-18 21:18:05 +00:00
|
|
|
}
|
2011-11-06 11:51:04 +00:00
|
|
|
that.resizeInfo = function() {
|
2011-11-06 12:26:56 +00:00
|
|
|
var width = that.width();
|
2011-09-18 21:18:05 +00:00
|
|
|
$icon.css(getIconCSS());
|
2011-11-06 22:08:22 +00:00
|
|
|
$title && $title.options({
|
2011-11-06 12:26:56 +00:00
|
|
|
width: width
|
2011-11-06 11:51:04 +00:00
|
|
|
});
|
2011-11-06 22:08:22 +00:00
|
|
|
$description && $description.options({
|
2011-11-06 12:26:56 +00:00
|
|
|
height: width,
|
|
|
|
width: width
|
2011-11-06 11:51:04 +00:00
|
|
|
});
|
2011-10-05 17:35:16 +00:00
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2011-09-18 21:18:05 +00:00
|
|
|
pandora.ui.posterInfo = function(data) {
|
|
|
|
var $poster = $('<img>')
|
|
|
|
.attr({src: '/' + data.id + '/poster512.jpg'})
|
|
|
|
.css(getPosterCSS()),
|
|
|
|
$text = $('<div>')
|
|
|
|
.css({
|
|
|
|
width: pandora.user.ui.sidebarSize - 8 + 'px',
|
|
|
|
height: '12px',
|
|
|
|
padding: '2px 4px 2px 4px',
|
|
|
|
fontSize: '9px',
|
|
|
|
textAlign: 'center',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
overflow: 'hidden'
|
|
|
|
})
|
|
|
|
.html(
|
|
|
|
data.title + (
|
2011-12-30 08:00:38 +00:00
|
|
|
Ox.len(data.director) ? ' (' + data.director.join(', ') + ')' : ''
|
2011-09-18 21:18:05 +00:00
|
|
|
)
|
2011-09-30 10:33:45 +00:00
|
|
|
),
|
2011-09-18 21:18:05 +00:00
|
|
|
that = Ox.SplitPanel({
|
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
element: $('<div>').append($poster)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: Ox.Bar({size: 16}).append($text),
|
|
|
|
size: 16
|
|
|
|
}
|
|
|
|
],
|
|
|
|
orientation: 'vertical'
|
|
|
|
});
|
|
|
|
function getPosterCSS() {
|
|
|
|
var css = {},
|
|
|
|
ratio = pandora.user.ui.sidebarSize / (pandora.user.ui.sidebarSize - 16);
|
|
|
|
if (data.posterRatio < ratio) {
|
|
|
|
css.height = pandora.user.ui.sidebarSize - 16;
|
|
|
|
css.width = Math.round(css.height * data.posterRatio);
|
|
|
|
css.marginLeft = Math.floor((pandora.user.ui.sidebarSize - css.width) / 2);
|
|
|
|
} else {
|
|
|
|
css.width = pandora.user.ui.sizebarSize;
|
|
|
|
css.height = Math.round(css.width / data.posterRatio);
|
|
|
|
css.marginTop = Math.floor((pandora.user.ui.sidebarSize - 16 - css.height) / 2);
|
|
|
|
}
|
|
|
|
return Ox.map(css, function(value) {
|
|
|
|
return value + 'px';
|
|
|
|
});
|
|
|
|
}
|
2011-11-06 11:51:04 +00:00
|
|
|
that.resizeInfo = function() {
|
2011-09-18 21:18:05 +00:00
|
|
|
$poster.css(getPosterCSS());
|
|
|
|
$text.css({width: pandora.user.ui.sidebarSize - 8 + 'px'})
|
|
|
|
}
|
|
|
|
return that;
|
|
|
|
};
|