cablegates/static/js/pandora/ui/foldersList.js

342 lines
14 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.folderList = function(id) {
2011-06-06 15:48:11 +00:00
var i = Ox.getPositionById(pandora.site.sectionFolders[pandora.user.ui.section], id),
2011-05-25 19:42:45 +00:00
that;
2011-09-01 04:46:44 +00:00
if (pandora.user.ui.section == 'items') {
var columns, items;
2011-09-01 07:00:35 +00:00
if (id != 'volumes') {
2011-09-01 04:46:44 +00:00
columns = [
2011-05-25 19:42:45 +00:00
{
format: function() {
2011-09-01 04:46:44 +00:00
return $('<img>').attr({
2011-09-01 07:00:35 +00:00
src: Ox.UI.getImageURL('symbolIcon')
2011-09-01 04:46:44 +00:00
}).css({
width: '10px',
height: '10px',
2011-09-01 09:17:49 +00:00
padding: '3px'
2011-09-01 04:46:44 +00:00
});
},
id: 'user',
operator: '+',
visible: true,
width: 16
},
{
2011-09-01 07:00:35 +00:00
format: function(value) {
return value.split('/').join(': ');
},
id: 'id',
2011-09-01 04:46:44 +00:00
operator: '+',
unique: true,
2011-09-01 07:00:35 +00:00
visible: id == 'favorite',
// fixme: user and name are set to the same width here,
// but resizeFolders will set them to different widths
width: pandora.user.ui.sidebarWidth - 96
},
{
editable: function(data) {
return data.user == pandora.user.username;
},
id: 'name',
input: {
autovalidate: pandora.ui.autovalidateListname
},
operator: '+',
2011-09-01 07:43:32 +00:00
tooltip: id == 'personal' ? 'Edit Title' : '',
2011-09-01 07:00:35 +00:00
visible: id != 'favorite',
2011-09-01 04:46:44 +00:00
width: pandora.user.ui.sidebarWidth - 96
},
{
align: 'right',
id: 'items',
format: {type: 'number'},
operator: '-',
visible: true,
width: 48
},
{
clickable: function(data) {
2011-09-01 07:43:32 +00:00
return data.type == 'smart' || data.user == pandora.user.username;
2011-09-01 04:46:44 +00:00
},
format: function(value, data) {
2011-05-25 19:42:45 +00:00
return $('<img>')
.attr({
2011-09-01 07:00:35 +00:00
src: Ox.UI.getImageURL(value == 'static' ? 'symbolClick' : 'symbolFind')
2011-05-25 19:42:45 +00:00
})
2011-09-01 04:46:44 +00:00
.css({
width: '10px',
height: '10px',
2011-09-01 09:17:49 +00:00
padding: '3px',
2011-09-01 07:00:35 +00:00
opacity: data.user == pandora.user.username ? 1 : 0.25
2011-09-01 04:46:44 +00:00
});
2011-05-25 19:42:45 +00:00
},
2011-09-01 07:00:35 +00:00
id: 'type',
2011-05-25 19:42:45 +00:00
operator: '+',
2011-09-01 04:46:44 +00:00
tooltip: function(data) {
2011-09-01 07:00:35 +00:00
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-09-01 04:46:44 +00:00
},
2011-05-25 19:42:45 +00:00
visible: true,
width: 16
},
{
2011-09-01 07:00:35 +00:00
clickable: id == 'personal',
format: function(value) {
var symbols = {personal: 'Publish', favorite: 'Like', featured: 'Star'};
2011-09-01 04:46:44 +00:00
return $('<img>')
.attr({
2011-09-01 07:00:35 +00:00
src: Ox.UI.getImageURL(
'symbol' + symbols[id]
)
2011-09-01 04:46:44 +00:00
})
.css({
width: '10px',
height: '10px',
2011-09-01 09:17:49 +00:00
padding: '3px',
2011-09-01 07:00:35 +00:00
opacity: value == 'private' ? 0.25 : 1
})
2011-09-01 04:46:44 +00:00
},
2011-09-01 07:00:35 +00:00
id: 'status',
2011-05-25 19:42:45 +00:00
operator: '+',
2011-09-01 07:00:35 +00:00
tooltip: id == 'personal' ? function(data) {
return data.status == 'private' ? 'Make Public' : 'Make Private';
} : null,
2011-05-25 19:42:45 +00:00
visible: true,
2011-09-01 04:46:44 +00:00
width: 16
2011-05-25 19:42:45 +00:00
}
2011-09-01 04:46:44 +00:00
];
items = function(data, callback) {
2011-09-01 07:00:35 +00:00
var query;
if (id == 'personal') {
query = {conditions: [
{key: 'user', value: pandora.user.username, operator: '='},
{key: 'status', value: 'featured', operator: '!'}
], operator: '&'};
} else if (id == 'favorite') {
query = {conditions: [
{key: 'subscribed', value: true, operator: '='},
{key: 'status', value: 'featured', operator: '!'},
], operator: '&'};
} else if (id == 'featured') {
query = {conditions: [{key: 'status', value: 'featured', operator: '='}], operator: '&'};
2011-05-25 19:42:45 +00:00
}
2011-09-01 07:00:35 +00:00
return pandora.api.findLists(Ox.extend(data, {
query: query
}), callback);
2011-09-01 04:46:44 +00:00
};
} else {
columns = [
2011-05-25 19:42:45 +00:00
{
format: function() {
return $('<img>').attr({
2011-09-01 07:00:35 +00:00
src: Ox.UI.getImageURL('symbolVolume')
2011-09-01 04:46:44 +00:00
}).css({
width: '10px',
height: '10px',
2011-09-01 09:17:49 +00:00
padding: '3px'
2011-09-01 04:46:44 +00:00
});
2011-05-25 19:42:45 +00:00
},
id: 'user',
operator: '+',
visible: true,
width: 16
},
{
2011-09-01 07:00:35 +00:00
editable: true,
2011-05-25 19:42:45 +00:00
id: 'name',
operator: '+',
2011-09-01 07:00:35 +00:00
tooltip: 'Edit Title',
unique: true,
visible: true,
2011-09-01 04:46:44 +00:00
width: pandora.user.ui.sidebarWidth - 96
2011-05-25 19:42:45 +00:00
},
{
align: 'right',
id: 'items',
2011-09-01 04:46:44 +00:00
format: {type: 'number'},
2011-05-25 19:42:45 +00:00
operator: '-',
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:00:35 +00:00
return data.mounted;
2011-05-25 19:42:45 +00:00
},
format: function(value, data) {
2011-05-25 19:42:45 +00:00
return $('<img>')
.attr({
2011-09-01 07:00:35 +00:00
src: Ox.UI.getImageURL(data.mounted ? 'symbolSync' : 'symbolEdit')
2011-05-25 19:42:45 +00:00
})
.css({
width: '10px',
height: '10px',
2011-09-01 09:17:49 +00:00
padding: '3px'
2011-05-25 19:42:45 +00:00
});
},
2011-09-01 07:00:35 +00:00
id: 'path',
2011-05-25 19:42:45 +00:00
operator: '+',
tooltip: function(data) {
2011-09-01 07:00:35 +00:00
return data.mounted ? 'Scan Volume' : 'Edit Path';
},
2011-05-25 19:42:45 +00:00
visible: true,
width: 16
},
{
2011-09-01 07:00:35 +00:00
clickable: true,
format: function(value, data) {
2011-05-25 19:42:45 +00:00
return $('<img>')
.attr({
2011-09-01 07:00:35 +00:00
src: Ox.UI.getImageURL('symbolMount')
2011-05-25 19:42:45 +00:00
})
.css({
width: '10px',
height: '10px',
padding: '3px 2px 1px 2px',
2011-09-01 07:00:35 +00:00
opacity: data.mounted ? 1 : 0.25
});
2011-05-25 19:42:45 +00:00
},
2011-09-01 07:00:35 +00:00
id: 'mounted',
2011-05-25 19:42:45 +00:00
operator: '+',
2011-09-01 07:00:35 +00:00
tooltip: function(data) {
return data.mounted ? 'Unmount Volume' : 'Mount Volume';
},
2011-05-25 19:42:45 +00:00
visible: true,
width: 16
}
2011-09-01 04:46:44 +00:00
];
items = function(data, callback) {
2011-09-01 07:00:35 +00:00
var volumes = pandora.user.volumes || [
{"name": "Movies A-M", "path": "/Volumes/Movies A-M", "items": 1234},
{"name": "Movies N-Z", "path": "/Volumes/Movies N-Z", "items": 987}
];
if (!data.keys) {
data = {items: volumes.length};
} else {
data = {items: volumes.map(function(volume) {
return Ox.extend({id: volume.name, user: pandora.user.username, mounted: volume.name == 'Movies A-M'}, volume);
})};
2011-05-25 19:42:45 +00:00
}
2011-09-01 07:00:35 +00:00
// fixme: ridiculous (we're binding to init too late)
setTimeout(function() {
callback({data: data});
}, 1000);
2011-09-01 04:46:44 +00:00
};
}
that = Ox.TextList({
columns: columns,
items: items,
2011-05-25 19:42:45 +00:00
max: 1,
min: 0,
pageLength: 1000,
2011-09-01 04:46:44 +00:00
sort: [{key: 'position', operator: '+'}],
sortable: id != 'featured' || pandora.user.level == 'admin'
2011-05-25 19:42:45 +00:00
})
.css({
left: 0,
top: 0,
2011-06-06 15:48:11 +00:00
width: pandora.user.ui.sidebarWidth + 'px',
2011-05-25 19:42:45 +00:00
})
.bindEvent({
click: function(event, data) {
2011-06-06 15:48:11 +00:00
var $list = pandora.$ui.folderList[id];
2011-05-25 19:42:45 +00:00
if (data.key == 'type') {
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
2011-05-25 19:42:45 +00:00
} else if (data.key == 'status') {
pandora.api.editList({
id: data.id,
status: $list.value(data.id, data.key) == 'private' ? 'public' : 'private'
}, function(result) {
$list.value(result.data.id, 'status', result.data.status);
});
2011-09-01 04:46:44 +00:00
} else if (data.key == 'path') {
} else if (data.key == 'mounted') {
alert(JSON.stringify(data));
2011-05-25 19:42:45 +00:00
}
},
'delete': function(event, data) {
2011-06-06 15:48:11 +00:00
var $list = pandora.$ui.folderList[id];
pandora.URL.set('?find=');
2011-05-25 19:42:45 +00:00
$list.options({selected: []});
if (id == 'personal') {
pandora.api.removeList({
id: data.ids[0]
}, function(result) {
pandora.UI.set(['lists', data.ids[0]].join('|'), null);
2011-05-25 19:42:45 +00:00
Ox.Request.clearCache(); // fixme: remove
$list.reloadList();
});
} else if (id == 'favorite') {
pandora.api.unsubscribeFromList({
id: data.ids[0]
}, function(result) {
Ox.Request.clearCache(); // fixme: remove
$list.reloadList();
});
2011-06-06 15:48:11 +00:00
} else if (id == 'featured' && pandora.user.level == 'admin') {
2011-05-25 19:42:45 +00:00
pandora.api.editList({
id: data.ids[0],
status: 'public'
}, function(result) {
// fixme: duplicated
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();
}
$list.reloadList();
});
}
},
init: function(event, 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: 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: data.items * 16 + 'px'
});
pandora.resizeFolders();
},
move: function(event, data) {
/*
data.ids.forEach(function(id, pos) {
2011-06-06 15:48:11 +00:00
pandora.user.ui.lists[id].position = pos;
2011-05-25 19:42:45 +00:00
});
*/
pandora.api.sortLists({
section: id,
ids: data.ids
});
},
paste: function(event, data) {
2011-06-06 15:48:11 +00:00
pandora.$ui.list.triggerEvent('paste', data);
2011-05-25 19:42:45 +00:00
},
select: function(event, data) {
if (data.ids.length) {
2011-06-06 15:48:11 +00:00
$.each(pandora.$ui.folderList, function(id_, $list) {
2011-05-25 19:42:45 +00:00
id != id_ && $list.options('selected', []);
})
2011-09-01 04:46:44 +00:00
pandora.URL.set('?find=' + (id == 'volumes' ? 'volume' : 'list') + ':' + data.ids[0]);
2011-05-25 19:42:45 +00:00
} else {
pandora.URL.set('?find=');
}
},
submit: function(event, data) {
data_ = {id: data.id};
data_[data.key] = data.value;
pandora.api.editList(data_, function(result) {
if (result.data.id != data.id) {
2011-06-06 15:48:11 +00:00
pandora.$ui.folderList[id].value(data.id, 'name', result.data.name);
pandora.$ui.folderList[id].value(data.id, 'id', result.data.id);
2011-05-25 19:42:45 +00:00
pandora.URL.set('?find=list:' + result.data.id);
}
});
}
});
}
return that;
};