rename user

This commit is contained in:
j 2014-05-25 16:05:26 +02:00
parent f28e3816ff
commit 19292fb940
6 changed files with 43 additions and 16 deletions

View file

@ -306,8 +306,9 @@ oml.ui.folders = function() {
}); });
}; };
that.updateUser = function(id, name) {s that.updateUser = function(index) {
// ... oml.$ui.folder[index].options({title: ui._users[index].name})
return that;
}; };
oml.bindEvent({ oml.bindEvent({

View file

@ -12,6 +12,9 @@ oml.ui.info = function() {
overflowY: 'auto' overflowY: 'auto'
}) })
.bindEvent({ .bindEvent({
toggle: function(data) {
oml.UI.set({showInfo: !data.collapsed});
},
oml_item: function() { oml_item: function() {
that.updateElement(); that.updateElement();
}, },

View file

@ -282,7 +282,7 @@ oml.ui.infoView = function(identifyData) {
click: function() { click: function() {
data.mediastate = 'unavailable'; data.mediastate = 'unavailable';
that.updateElement(data, $data); that.updateElement(data, $data);
oml.api.cancelDownload({id: ui.item}, function() { oml.api.cancelDownloads({ids: [ui.item]}, function() {
that.updateElement(ui.item, $data); that.updateElement(ui.item, $data);
}); });
} }

View file

@ -49,7 +49,7 @@ oml.ui.listDialog = function() {
oml.api.getLists(function(result) { oml.api.getLists(function(result) {
var lists = result.data.lists.filter(function(list) { var lists = result.data.lists.filter(function(list) {
return list.user == oml.user.preferences.username; return list.user == '';
}), }),
listData = Ox.getObjectById(lists, list), listData = Ox.getObjectById(lists, list),
listNames = lists.map(function(list) { listNames = lists.map(function(list) {

View file

@ -270,6 +270,7 @@ oml.ui.usersDialog = function() {
nickname: data.value nickname: data.value
}, function(result) { }, function(result) {
Ox.print('EDIT USER', result.data, folder); Ox.print('EDIT USER', result.data, folder);
oml.renameUser(result.data)
// FIXME: ugly // FIXME: ugly
Ox.forEach($lists, function($list) { Ox.forEach($lists, function($list) {
var selected = $list.options('selected'); var selected = $list.options('selected');

View file

@ -305,8 +305,7 @@ oml.enableDragAndDrop = function($list, canMove) {
}), }),
drag = {}, drag = {},
scrollInterval, scrollInterval,
ui = oml.user.ui, ui = oml.user.ui;
username = oml.user.preferences.username;
$list.bindEvent({ $list.bindEvent({
draganddropstart: function(data) { draganddropstart: function(data) {
@ -326,8 +325,8 @@ oml.enableDragAndDrop = function($list, canMove) {
drag.targets[id] = Ox.extend(data, { drag.targets[id] = Ox.extend(data, {
editable: data.editable || ( editable: data.editable || (
data.type == 'library' data.type == 'library'
&& drag.source.user != username && drag.source.user != ''
&& data.user == username && data.user == ''
), ),
selected: data.id == ui._list selected: data.id == ui._list
}, data); }, data);
@ -467,14 +466,14 @@ oml.enableDragAndDrop = function($list, canMove) {
function getTitle() { function getTitle() {
var image, text, var image, text,
actionText = drag.action == 'copy' ? ( actionText = drag.action == 'copy' ? (
drag.source.user == username ? 'copy' : 'download' drag.source.user == '' ? 'copy' : 'download'
) : 'move', ) : 'move',
itemText = Ox.isString(drag.item) itemText = Ox.isString(drag.item)
? '"' + Ox.encodeHTMLEntities(Ox.truncate(drag.item, 32)) + '"' ? '"' + Ox.encodeHTMLEntities(Ox.truncate(drag.item, 32)) + '"'
: Ox._('{0} books', [drag.item]), : Ox._('{0} books', [drag.item]),
targetText; targetText;
if (drag.action == 'move') { if (drag.action == 'move') {
if (drag.source.user != username) { if (drag.source.user != '') {
text = Ox._('You can only remove books<br>from your own lists.'); text = Ox._('You can only remove books<br>from your own lists.');
} else if (drag.source.type == 'library') { } else if (drag.source.type == 'library') {
text = Ox._('You cannot move books<br>out of your library.'); text = Ox._('You cannot move books<br>out of your library.');
@ -488,8 +487,8 @@ oml.enableDragAndDrop = function($list, canMove) {
if ( if (
( (
drag.target.type == 'library' drag.target.type == 'library'
&& drag.source.user == username && drag.source.user == ''
&& drag.target.user == username && drag.target.user == ''
) )
|| drag.target.selected || drag.target.selected
) { ) {
@ -497,7 +496,7 @@ oml.enableDragAndDrop = function($list, canMove) {
Ox._(itemText[0] == '"' ? '' : 'These ') + itemText, Ox._(itemText[0] == '"' ? '' : 'These ') + itemText,
targetText targetText
]); ]);
} else if (drag.target.user != username) { } else if (drag.target.user != '') {
text = Ox._( text = Ox._(
'You can only {0} books<br>to your own {1}.', 'You can only {0} books<br>to your own {1}.',
[actionText, drag.target.type == 'library' ? 'library' : 'lists'] [actionText, drag.target.type == 'library' ? 'library' : 'lists']
@ -510,7 +509,7 @@ oml.enableDragAndDrop = function($list, canMove) {
image = 'symbolClose' image = 'symbolClose'
} else { } else {
image = drag.action == 'copy' ? ( image = drag.action == 'copy' ? (
drag.source.user == username ? 'symbolAdd' : 'symbolDownload' drag.source.user == '' ? 'symbolAdd' : 'symbolDownload'
) : 'symbolRemove', ) : 'symbolRemove',
text = Ox._(Ox.toTitleCase(actionText)) + ' ' + ( text = Ox._(Ox.toTitleCase(actionText)) + ' ' + (
Ox.isString(drag.item) Ox.isString(drag.item)
@ -519,7 +518,7 @@ oml.enableDragAndDrop = function($list, canMove) {
) + '<br>' + ( ) + '<br>' + (
drag.target && drag.target.editable && !drag.target.selected drag.target && drag.target.editable && !drag.target.selected
? Ox._('to {0}.', [targetText]) ? Ox._('to {0}.', [targetText])
: drag.source.user == username : drag.source.user == ''
? Ox._('to {0} list.', [ui._list == ':' ? 'a' : 'another']) ? Ox._('to {0} list.', [ui._list == ':' ? 'a' : 'another'])
: Ox._('to your library or to one of your lists.') : Ox._('to your library or to one of your lists.')
); );
@ -799,7 +798,7 @@ oml.getLists = function(callback) {
list.name = list.type == 'libraries' ? Ox._('Libraries') list.name = list.type == 'libraries' ? Ox._('Libraries')
: list.type == 'library' ? Ox._('Library') : list.name; : list.type == 'library' ? Ox._('Library') : list.name;
return Ox.extend(list, { return Ox.extend(list, {
editable: list.user == username && list.type == 'static', editable: list.user == '' && list.type == 'static',
own: list.user == '', own: list.user == '',
title: (list.user ? list.user + ': ' : '') + list.name title: (list.user ? list.user + ': ' : '') + list.name
}); });
@ -890,6 +889,29 @@ oml.reloadList = function() {
oml.$ui.list.updateElement(); oml.$ui.list.updateElement();
}; };
oml.renameUser = function(data) {
var ui = oml.user.ui,
index = Ox.getIndexById(ui._users, data.id),
name = ui._users[index].name,
set = {};
ui._users[index].name = data.name;
ui._users[index].nickname = data.nickname;
oml.$ui.folders.updateUser(index);
set['showFolder.' + data.name] = ui.showFolder[name];
set['showFolder.' + name] = null;
Ox.forEach(ui.lists, function(value, key) {
var split = key.split(':'),
username = split[0],
listname = split.slice(1).join(':');
if (username == name) {
set['lists.' + data.name + ':' + listname] = value;
set['lists.' + key] = null;
}
});
Ox.print('$$$ SET', set);
oml.UI.set(set, false);
};
oml.resizeFilters = function() { oml.resizeFilters = function() {
// ... // ...
}; };