pandora/static/js/pandora/folderBrowserList.js

204 lines
8.7 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-05-25 19:42:45 +00:00
pandora.ui.folderBrowserList = function(id) {
2011-09-01 04:46:44 +00:00
// fixme: user and name are set to the same width here,
// but resizeFolders will set them to different widths
var columnWidth = (pandora.user.ui.sidebarSize - Ox.UI.SCROLLBAR_SIZE - 96) / 2,
2011-06-06 15:48:11 +00:00
i = Ox.getPositionById(pandora.site.sectionFolders[pandora.user.ui.section], id),
2011-06-19 17:49:25 +00:00
that = Ox.TextList({
2011-05-25 19:42:45 +00:00
columns: [
{
clickable: true,
format: function(value) {
return $('<img>').attr({
src: '/list/' + value + '/icon16.jpg'
}).css({
width: '14px',
height: '14px',
borderRadius: '4px',
margin: '0 0 0 -3px'
});
},
// FIXME: why does the above only work with clickable: true ??
/*
2011-05-25 19:42:45 +00:00
format: function() {
2011-09-01 07:00:35 +00:00
return $('<img>').attr({
src: Ox.UI.getImageURL('symbolIcon')
}).css({
width: '10px',
height: '10px',
2011-09-01 09:17:49 +00:00
padding: '3px'
2011-09-01 07:00:35 +00:00
});
2011-05-25 19:42:45 +00:00
},
*/
2011-05-25 19:42:45 +00:00
id: 'id',
2011-11-03 12:58:22 +00:00
titleImage: 'icon',
2011-05-25 19:42:45 +00:00
unique: true,
visible: true,
width: 16
},
{
id: 'user',
operator: '+',
title: 'User',
visible: true,
width: Math.floor(columnWidth)
},
{
id: 'name',
operator: '+',
title: 'List',
visible: true,
width: Math.ceil(columnWidth)
},
{
align: 'right',
id: 'items',
2011-09-01 04:46:44 +00:00
format: {type: 'number'},
2011-05-25 19:42:45 +00:00
operator: '-',
title: 'Items',
visible: true,
2011-09-01 04:46:44 +00:00
width: 48
2011-05-25 19:42:45 +00:00
},
{
clickable: function(data) {
2011-09-01 07:43:32 +00:00
return data.type == 'smart' || data.user == pandora.user.username;
2011-05-25 19:42:45 +00:00
},
format: function(value, data) {
2011-05-25 19:42:45 +00:00
return $('<img>')
.attr({
src: Ox.UI.getImageURL(value == 'static' ? 'symbolClick' : 'symbolFind')
2011-05-25 19:42:45 +00:00
})
.css({
width: '10px',
height: '10px',
2011-09-01 09:17:49 +00:00
padding: '3px',
opacity: data.user == pandora.user.username ? 1 : 0.25
2011-05-25 19:42:45 +00:00
});
},
id: 'type',
operator: '+',
2011-11-03 12:58:22 +00:00
titleImage: 'edit',
tooltip: function(data) {
return data.type == 'smart'
? (data.user == pandora.user.username ? 'Edit Query' : 'Show Query')
2011-09-01 07:43:32 +00:00
: (data.user == pandora.user.username ? 'Edit Default View' : 'Default View: ...');
},
2011-05-25 19:42:45 +00:00
visible: true,
width: 16
},
{
clickable: true,
format: function(value) {
return $('<img>')
.attr({
2011-08-09 17:07:24 +00:00
src: Ox.UI.getImageURL(
2011-09-01 04:46:44 +00:00
'symbol' + (id == 'favorite' ? 'Like' : 'Star')
2011-05-25 19:42:45 +00:00
)
})
.css({
width: '10px',
height: '10px',
2011-09-01 09:17:49 +00:00
padding: '3px',
opacity: id == 'favorite'
2011-09-01 07:00:35 +00:00
? (value ? 1 : 0.25)
: (value == 'featured' ? 1 : 0.25)
2011-05-25 19:42:45 +00:00
});
},
id: id == 'favorite' ? 'subscribed' : 'status',
operator: '+',
2011-11-03 12:58:22 +00:00
titleImage: id == 'favorite' ? 'like' : 'star',
tooltip: function(data) {
var checked = id == 'favorite' ? data.subscribed : data.status == 'featured';
return (checked ? 'Remove from' : 'Add to')
+ ' ' + Ox.toTitleCase(id) + ' Lists';
},
2011-05-25 19:42:45 +00:00
visible: true,
width: 16
}
2011-05-25 19:42:45 +00:00
],
columnsVisible: true,
items: function(data, callback) {
var query = id == 'favorite' ? {conditions: [
{key: 'status', value: 'public', operator: '='},
2011-09-28 17:32:03 +00:00
{key: 'user', value: pandora.user.username, operator: '!=='}
2011-09-01 07:00:35 +00:00
], operator: '&'} : {conditions: [
2011-09-28 17:32:03 +00:00
{key: 'status', value: 'private', operator: '!='}
2011-09-01 07:00:35 +00:00
], operator: ''};
return pandora.api.findLists(Ox.extend(data, {
2011-05-25 19:42:45 +00:00
query: query
}), callback);
},
// needed in order to determine if, when switching back
// from featured browser to featured folder, the selected
// not-featured list may be in the user's favorites folder
keys: id == 'featured' ? ['subscribed'] : [],
2011-05-25 19:42:45 +00:00
pageLength: 1000,
2011-09-28 00:10:26 +00:00
selected: pandora.getListData().folder == id ? [pandora.user.ui._list] : [],
2011-05-25 19:42:45 +00:00
sort: [
{key: 'name', operator: '+'}
]
})
.bindEvent({
2011-09-17 17:40:15 +00:00
click: function(data) {
2011-05-25 19:42:45 +00:00
if (data.key == 'type') {
2011-09-19 12:29:55 +00:00
/*
if (that.value(data.id, 'type') == 'smart') {
pandora.$ui.filterDialog = pandora.ui.filterDialog(that.value(data.id, 'query')).open();
}
*/
2011-05-25 19:42:45 +00:00
} else if (data.key == 'subscribed') {
var subscribed = that.value(data.id, 'subscribed');
pandora.api[subscribed ? 'unsubscribeFromList' : 'subscribeToList']({
id: data.id,
}, function(result) {
that.value(data.id, 'subscribed', !subscribed);
});
} else if (data.key == 'status') {
pandora.api.editList({
id: data.id,
status: that.value(data.id, 'status') == 'featured' ? 'public' : 'featured'
}, function(result) {
2011-11-04 15:54:42 +00:00
Ox.Log('', 'result', result)
2011-06-06 15:48:11 +00:00
if (result.data.user == pandora.user.username || result.data.subscribed) {
2011-05-25 19:42:45 +00:00
Ox.Request.clearCache(); // fixme: remove
2011-06-06 15:48:11 +00:00
pandora.$ui.folderList[
result.data.user == pandora.user.username ? 'personal' : 'favorite'
2011-05-25 19:42:45 +00:00
].reloadList();
}
that.value(data.id, 'status', result.data.status);
});
}
},
2011-09-17 17:40:15 +00:00
init: function(data) {
2011-06-06 15:48:11 +00:00
pandora.site.sectionFolders[pandora.user.ui.section][i].items = data.items;
pandora.$ui.folder[i].$content.css({
2011-05-25 19:42:45 +00:00
height: 40 + data.items * 16 + 'px'
});
2011-06-06 15:48:11 +00:00
pandora.$ui.folderList[id].css({
2011-05-25 19:42:45 +00:00
height: 16 + data.items * 16 + 'px'
});
pandora.resizeFolders();
},
2011-09-17 17:40:15 +00:00
paste: function(data) {
2011-06-06 15:48:11 +00:00
pandora.$ui.list.triggerEvent('paste', data);
2011-05-25 19:42:45 +00:00
},
2011-09-17 17:40:15 +00:00
select: function(data) {
2011-05-25 19:42:45 +00:00
// fixme: duplicated
2011-09-28 00:10:26 +00:00
var list = data.ids.length ? data.ids[0] : '';
if (list) {
Ox.forEach(pandora.$ui.folderList, function($list, id_) {
2011-05-25 19:42:45 +00:00
id != id_ && $list.options('selected', []);
});
}
2011-09-28 00:10:26 +00:00
pandora.UI.set({
find: {
conditions: list ? [
{key: 'list', value: data.ids[0], operator: '=='}
] : [],
operator: '&'
}
});
2011-05-25 19:42:45 +00:00
}
});
return that;
2011-09-17 17:40:15 +00:00
};