add user.name, list fixes

This commit is contained in:
j 2014-05-25 14:16:04 +02:00
parent ed2b7cebfc
commit 98d1725d19
15 changed files with 180 additions and 203 deletions

View File

@ -240,6 +240,7 @@ class Changelog(db.Model):
def action_editusername(self, user, timestamp, username): def action_editusername(self, user, timestamp, username):
user.info['username'] = username user.info['username'] = username
user.update_name()
user.save() user.save()
return True return True

View File

@ -7,6 +7,7 @@ from user.models import List, User
def create_default_lists(user_id=None): def create_default_lists(user_id=None):
user_id = user_id or settings.USER_ID user_id = user_id or settings.USER_ID
user = User.get_or_create(user_id) user = User.get_or_create(user_id)
user.update_name()
for list in settings.config['lists']: for list in settings.config['lists']:
l = List.get(user_id, list['title']) l = List.get(user_id, list['title'])
if not l: if not l:

View File

@ -58,6 +58,10 @@ def setPreferences(data):
} }
''' '''
update_dict(settings.preferences, data) update_dict(settings.preferences, data)
if 'username' in data:
u = state.user()
u.update_name()
u.save()
return settings.preferences return settings.preferences
actions.register(setPreferences) actions.register(setPreferences)
@ -102,7 +106,7 @@ def getLists(data):
'items': Item.query.count(), 'items': Item.query.count(),
'name': 'Libraries', 'name': 'Libraries',
'type': 'libraries', 'type': 'libraries',
'user': '', 'user': None,
}) })
for u in models.User.query.filter((models.User.peered==True)|(models.User.id==settings.USER_ID)): for u in models.User.query.filter((models.User.peered==True)|(models.User.id==settings.USER_ID)):
lists += u.lists_json() lists += u.lists_json()
@ -245,7 +249,11 @@ def editUser(data):
''' '''
if 'nickname' in data: if 'nickname' in data:
p = models.User.get_or_create(data['id']) p = models.User.get_or_create(data['id'])
p.set_nickname(data['nickname']) if data['nickname']:
p.info['nickname'] = data['nickname']
elif 'nickname' in p.info:
del p.info['nickname']
p.update_name()
p.save() p.save()
return {} return {}
actions.register(editUser, cache=False) actions.register(editUser, cache=False)

View File

@ -50,6 +50,11 @@ class User(db.Model):
db.session.add(self) db.session.add(self)
db.session.commit() db.session.commit()
@property
def name(self):
name = self.nickname if self.id != settings.USER_ID else ''
return name
def json(self): def json(self):
j = {} j = {}
if self.info: if self.info:
@ -59,7 +64,9 @@ class User(db.Model):
j['pending'] = self.pending j['pending'] = self.pending
j['peered'] = self.peered j['peered'] = self.peered
j['online'] = self.is_online() j['online'] = self.is_online()
j['nickname'] = self.nickname j['nickname'] = self.info.get('nickname')
j['username'] = self.info.get('username') if self.id != settings.USER_ID else settings.preferences['username']
j['name'] = self.name
return j return j
def is_online(self): def is_online(self):
@ -71,7 +78,7 @@ class User(db.Model):
'name': 'Library', 'name': 'Library',
'type': 'library', 'type': 'library',
'items': self.items.count(), 'items': self.items.count(),
'user': self.nickname if self.id != settings.USER_ID else settings.preferences['username'], 'user': self.name
}] + [l.json() for l in self.lists.order_by('index_')] }] + [l.json() for l in self.lists.order_by('index_')]
def update_peering(self, peered, username=None): def update_peering(self, peered, username=None):
@ -80,11 +87,7 @@ class User(db.Model):
self.pending = '' self.pending = ''
if username: if username:
self.info['username'] = username self.info['username'] = username
else: self.update_name()
username = self.info.get('username')
if not username:
username = 'anonymous'
self.set_nickname(username)
# FIXME: need to set peered to False to not trigger changelog event # FIXME: need to set peered to False to not trigger changelog event
# before other side receives acceptPeering request # before other side receives acceptPeering request
self.peered = False self.peered = False
@ -97,7 +100,7 @@ class User(db.Model):
else: else:
self.pending = '' self.pending = ''
self.peered = False self.peered = False
self.nickname = None self.update_name()
self.save() self.save()
List.query.filter_by(user_id=self.id).delete() List.query.filter_by(user_id=self.id).delete()
for i in self.items: for i in self.items:
@ -112,11 +115,15 @@ class User(db.Model):
Changelog.record(state.user(), 'removepeer', self.id) Changelog.record(state.user(), 'removepeer', self.id)
self.save() self.save()
def set_nickname(self, nickname): def update_name(self):
username = nickname if self.id == settings.USER_ID:
name = settings.preferences.get('username', 'anonymous')
else:
name = self.info.get('nickname') or self.info.get('username') or 'anonymous'
nickname = name
n = 2 n = 2
while self.query.filter_by(nickname=nickname).filter(User.id!=self.id).first(): while self.query.filter_by(nickname=nickname).filter(User.id!=self.id).first():
nickname = '%s [%d]' % (username, n) nickname = '%s [%d]' % (name, n)
n += 1 n += 1
self.nickname = nickname self.nickname = nickname
@ -261,7 +268,7 @@ class List(db.Model):
def json(self): def json(self):
r = { r = {
'id': self.public_id, 'id': self.public_id,
'user': self.user.nickname if self.user_id != settings.USER_ID else settings.preferences['username'], 'user': self.user.name,
'name': self.name, 'name': self.name,
'index': self.index_, 'index': self.index_,
'items': self.items_count(), 'items': self.items_count(),

View File

@ -59,6 +59,7 @@ oml.UI = (function() {
// and list may then change listSort and listView, // and list may then change listSort and listView,
// which we don't want to trigger, since find triggers // which we don't want to trigger, since find triggers
// (values we put in add will be changed, but won't trigger) // (values we put in add will be changed, but won't trigger)
// FIXME: ABOVE COMMENT DOES NOT APPLY
list = oml.getListState(args.find); list = oml.getListState(args.find);
ui._list = list; ui._list = list;
ui._filterState = oml.getFilterState(args.find); ui._filterState = oml.getFilterState(args.find);
@ -74,66 +75,65 @@ oml.UI = (function() {
// then for each setting that corresponds to a list setting // then for each setting that corresponds to a list setting
if (!ui.lists[list]) { if (!ui.lists[list]) {
// either add the default setting // either add the default setting
add[setting] = oml.config.user.ui[setting]; args[setting] = oml.config.user.ui[setting];
} else { } else {
// or the existing list setting // or the existing list setting
add[setting] = ui.lists[list][listSetting] args[setting] = ui.lists[list][listSetting];
} }
}); });
} else {
list = previousUI._list;
} }
// it is important to check for find first, so that } else {
// if find changes list, list is correct here list = previousUI._list;
item = args.item || ui.item; }
listView = add.listView || args.listView; // it is important to check for find first, so that
// if find changes list, list is correct here
item = args.item || ui.item;
listView = add.listView || args.listView;
if (!ui.lists[list]) { if (!ui.lists[list]) {
add['lists.' + that.encode(list)] = {}; add['lists.' + that.encode(list)] = {};
} }
Ox.forEach(listSettings, function(listSetting, setting) { Ox.forEach(listSettings, function(listSetting, setting) {
// for each setting that corresponds to a list setting // for each setting that corresponds to a list setting
// set that list setting to // set that list setting to
var key = 'lists.' + that.encode(list) + '.' + listSetting; var key = 'lists.' + that.encode(list) + '.' + listSetting;
if (setting in args) { if (setting in args) {
// the setting passed to UI.set // the setting passed to UI.set
add[key] = args[setting]; args[key] = args[setting];
} else if (setting in add) { } else if (setting in add) {
// or the setting changed via find // or the setting changed via find
add[key] = add[setting]; args[key] = add[setting];
} else if (!ui.lists[list]) { } else if (!ui.lists[list]) {
// or the default setting // or the default setting
add[key] = oml.config.user.ui[setting]; args[key] = oml.config.user.ui[setting];
}
});
if (args.item) {
// when switching to an item, update list selection
add['listSelection'] = [args.item];
add['lists.' + that.encode(list) + '.selection'] = [args.item];
if (
!args.itemView
&& ui.itemView == 'book'
&& !ui.mediaState[item]
&& !args['mediaState.' + item]
) {
// if the item view doesn't change, remains a media view,
// media state doesn't exist yet, and won't be set, add
// default media state
add['mediaState.' + item] = {position: 0, zoom: 1};
}
} }
});
if (args.item) {
// when switching to an item, update list selection
add['listSelection'] = [args.item];
add['lists.' + that.encode(list) + '.selection'] = [args.item];
if ( if (
args.itemView == 'book' !args.itemView
&& ui.itemView == 'book'
&& !ui.mediaState[item] && !ui.mediaState[item]
&& !args['mediaState.' + item] && !args['mediaState.' + item]
) { ) {
// when switching to a media view, media state doesn't exist // if the item view doesn't change, remains a media view,
// yet, and won't be set, add default media state // media state doesn't exist yet, and won't be set, add
// default media state
add['mediaState.' + item] = {position: 0, zoom: 1}; add['mediaState.' + item] = {position: 0, zoom: 1};
} }
}
if (
args.itemView == 'book'
&& !ui.mediaState[item]
&& !args['mediaState.' + item]
) {
// when switching to a media view, media state doesn't exist
// yet, and won't be set, add default media state
add['mediaState.' + item] = {position: 0, zoom: 1};
} }
// items in args trigger events, items in add do not // items in args trigger events, items in add do not

View File

@ -3,7 +3,6 @@
oml.ui.folders = function() { oml.ui.folders = function() {
var ui = oml.user.ui, var ui = oml.user.ui,
username = oml.user.preferences.username,
userIndex, userIndex,
users, users,
@ -13,7 +12,6 @@ oml.ui.folders = function() {
that = Ox.Element() that = Ox.Element()
.css({ .css({
overflowX: 'hidden', overflowX: 'hidden',
//overflowY: 'auto',
}) })
.bindEvent({ .bindEvent({
oml_find: selectList, oml_find: selectList,
@ -35,7 +33,7 @@ oml.ui.folders = function() {
function getFolderList(list) { function getFolderList(list) {
var index = users.map(function(user) { var index = users.map(function(user) {
return user.nickname; return user.name;
}).indexOf(list.user); }).indexOf(list.user);
return list.id == '' ? oml.$ui.librariesList return list.id == '' ? oml.$ui.librariesList
: Ox.endsWith(list.id, ':') ? oml.$ui.libraryList[index] : Ox.endsWith(list.id, ':') ? oml.$ui.libraryList[index]
@ -43,8 +41,10 @@ oml.ui.folders = function() {
} }
function getUsersAndLists(callback) { function getUsersAndLists(callback) {
oml.getUsers(function() { oml.getUsers(function(users_) {
users = arguments[0]; users = users_.filter(function(user) {
return user.id == oml.user.id || user.peered;
});
oml.getLists(function(lists) { oml.getLists(function(lists) {
callback(users, lists); callback(users, lists);
}); });
@ -53,7 +53,7 @@ oml.ui.folders = function() {
function selectList() { function selectList() {
var split = ui._list.split(':'), var split = ui._list.split(':'),
index = userIndex[split[0] || oml.user.preferences.username], index = userIndex[split[0]],
list = split[1], list = split[1],
$selectedList = !ui._list ? oml.$ui.librariesList $selectedList = !ui._list ? oml.$ui.librariesList
: !list ? oml.$ui[!list ? 'libraryList' : 'folderList'][index] : !list ? oml.$ui[!list ? 'libraryList' : 'folderList'][index]
@ -84,14 +84,7 @@ oml.ui.folders = function() {
$lists.push( $lists.push(
oml.$ui.librariesList = oml.ui.folderList({ oml.$ui.librariesList = oml.ui.folderList({
items: [ items: [lists[0]]
{
id: '',
name: Ox._('All Libraries'),
type: 'libraries',
items: Ox.getObjectById(lists, '').items
}
]
}) })
.bindEvent({ .bindEvent({
select: function() { select: function() {
@ -101,7 +94,7 @@ oml.ui.folders = function() {
selectnext: function() { selectnext: function() {
oml.UI.set(Ox.extend( oml.UI.set(Ox.extend(
{find: getFind(':')}, {find: getFind(':')},
'showFolder.' + username, 'showFolder.',
true true
)); ));
}, },
@ -115,15 +108,15 @@ oml.ui.folders = function() {
var $content, var $content,
items = lists.filter(function(list) { items = lists.filter(function(list) {
return list.user == user.nickname return list.user === user.name
&& list.type != 'library'; && list.type != 'library';
}), }),
libraryId = (!index ? '' : user.nickname) + ':' libraryId = user.name + ':';
userIndex[user.nickname] = index; userIndex[user.name] = index;
oml.$ui.folder[index] = Ox.CollapsePanel({ oml.$ui.folder[index] = Ox.CollapsePanel({
collapsed: !ui.showFolder[user.nickname], collapsed: !ui.showFolder[user.name],
extras: [ extras: [
oml.ui.statusIcon(user, index), oml.ui.statusIcon(user, index),
{}, {},
@ -146,18 +139,22 @@ oml.ui.folders = function() {
} }
}) })
], ],
title: Ox.encodeHTMLEntities(user.nickname) title: Ox.encodeHTMLEntities(
!index
? oml.user.preferences.username || 'anonymous'
: user.name
)
}) })
.css({ .css({
width: ui.sidebarSize width: ui.sidebarSize
}) })
.bindEvent({ .bindEvent({
toggle: function(data) { toggle: function(data) {
oml.UI.set('showFolder.' + user.nickname, !data.collapsed); oml.UI.set('showFolder.' + user.name, !data.collapsed);
} }
}) })
.bindEvent( .bindEvent(
'oml_showfolder.' + user.nickname.toLowerCase(), 'oml_showfolder.' + user.name.toLowerCase(),
function(data) { function(data) {
oml.$ui.folder[index].options({collapsed: !data.value}); oml.$ui.folder[index].options({collapsed: !data.value});
} }
@ -171,14 +168,10 @@ oml.ui.folders = function() {
$lists.push( $lists.push(
oml.$ui.libraryList[index] = oml.ui.folderList({ oml.$ui.libraryList[index] = oml.ui.folderList({
items: [ items: lists.filter(function(list) {
{ return list.user == user.name
id: libraryId, && list.type == 'library';
name: Ox._('Library'), })
type: 'library',
items: Ox.getObjectById(lists, libraryId).items
}
]
}) })
.bindEvent({ .bindEvent({
add: function() { add: function() {
@ -196,12 +189,12 @@ oml.ui.folders = function() {
if (!index) { if (!index) {
set = {find: getFind('')}; set = {find: getFind('')};
} else { } else {
user = users[index - 1].nickname; user = users[index - 1].name;
userLists = lists.filter(function(list) { userLists = lists.filter(function(list) {
return list.user == user; return list.user == user;
}); });
set = {find: getFind( set = {find: getFind(
!userLists.length ? (user == oml.user.preferences.username ? '' : user) + ':' !userLists.length ? user + ':'
: Ox.last(userLists).id : Ox.last(userLists).id
)}; )};
Ox.extend(set, 'showFolder.' + user, true); Ox.extend(set, 'showFolder.' + user, true);
@ -248,8 +241,8 @@ oml.ui.folders = function() {
selectnext: function() { selectnext: function() {
if (index < users.length - 1) { if (index < users.length - 1) {
oml.UI.set(Ox.extend( oml.UI.set(Ox.extend(
{find: getFind(users[index + 1].nickname + ':')}, {find: getFind(users[index + 1].name + ':')},
'showFolder.' + users[index + 1].nickname, 'showFolder.' + users[index + 1].name,
true true
)); ));
} }
@ -299,8 +292,7 @@ oml.ui.folders = function() {
that.updateOwnLists = function(callback) { that.updateOwnLists = function(callback) {
oml.getLists(function(lists) { oml.getLists(function(lists) {
var items = lists.filter(function(list) { var items = lists.filter(function(list) {
return list.user == oml.user.preferences.username return list.user == '' && list.type != 'library';
&& list.type != 'library';
}); });
oml.$ui.folder[0].$content oml.$ui.folder[0].$content
.css({height: 16 + items.length * 16 + 'px'}); .css({height: 16 + items.length * 16 + 'px'});

View File

@ -8,6 +8,14 @@ oml.ui.infoView = function(identifyData) {
css = getCSS(iconSize, oml.config.iconRatio), css = getCSS(iconSize, oml.config.iconRatio),
ids = [
{key: 'isbn', url: 'https://google.com/search?q=ISBN+{0}'},
{key: 'asin', url: 'http://www.amazon.com/dp/{0}'},
{key: 'lccn', url: 'http://lccn.loc.gov/{0}'},
{key: 'oclc', url: 'https://www.worldcat.org/oclc/{0}'},
{key: 'olid', url: 'https://openlibrary.org/books/{0}'}
],
that = Ox.Element() that = Ox.Element()
.addClass('OxTextPage') .addClass('OxTextPage')
.css({overflowY: 'auto'}) .css({overflowY: 'auto'})
@ -132,14 +140,12 @@ oml.ui.infoView = function(identifyData) {
}), }),
data.mediastate == 'available' && data.primaryid data.mediastate == 'available' && data.primaryid
? Ox.Select({ ? Ox.Select({
items: Ox.flatten([ items: Ox.flatten(ids.map(function(id) {
'isbn', 'asin', 'lccn', 'oclc', 'olid' return (data[id.key] || []).map(function(value) {
].map(function(key) {
return (data[key] || []).map(function(value) {
return { return {
id: key + ':' + value, id: id.key + ':' + value,
title: '<b>' + Ox.getObjectById( title: '<b>' + Ox.getObjectById(
oml.config.itemKeys, key oml.config.itemKeys, id.key
).title + ':</b> ' + value ).title + ':</b> ' + value
}; };
}); });
@ -632,12 +638,10 @@ oml.ui.infoView = function(identifyData) {
renderIdentifyButton(data).appendTo($data); renderIdentifyButton(data).appendTo($data);
[ ids.forEach(function(id, index) {
'isbn', 'asin', 'lccn', 'oclc', 'olid'
].forEach(function(id, index) {
var title; var title;
if (data[id] && !Ox.isEmpty(data[id])) { if (data[id.key] && !Ox.isEmpty(data[id.key])) {
title = Ox.getObjectById(oml.config.itemKeys, id).title; title = Ox.getObjectById(oml.config.itemKeys, id.key).title;
$('<div>') $('<div>')
.css({ .css({
marginTop: (index == 0 ? 10 : 6) + 'px', marginTop: (index == 0 ? 10 : 6) + 'px',
@ -645,16 +649,17 @@ oml.ui.infoView = function(identifyData) {
}) })
.text(title) .text(title)
.appendTo($data); .appendTo($data);
Ox.makeArray(data[id]/*FIXME!*/).forEach(function(value) { Ox.makeArray(data[id.key]/*FIXME!*/).forEach(function(value) {
var isPrimary = data.primaryid[0] == id var isPrimary = data.primaryid[0] == id.key
&& data.primaryid[1] == value; && data.primaryid[1] == value;
value = Ox.encodeHTMLEntities(value);
Ox.Element({ Ox.Element({
tooltip: isPrimary ? 'Primary ID' : '' tooltip: isPrimary ? 'Primary ID' : ''
}) })
.html( .html(
Ox.encodeHTMLEntities(value) + ( '<a href="' + Ox.formatString(id.url, [value])
isPrimary ? ' (*)' : '' + '" target="_blank">' + value + '</a>'
) + (isPrimary ? ' (*)' : '')
) )
.appendTo($data); .appendTo($data);
}); });

View File

@ -113,7 +113,10 @@ oml.ui.list = function() {
oml.UI.set({listSelection: data.ids}); oml.UI.set({listSelection: data.ids});
}, },
oml_find: function() { oml_find: function() {
that.reloadList(); if (ui.listView == oml.UI.getPrevious().listView) {
Ox.print('NEW FIND, SAME LIST VIEW, RELOADING')
that.reloadList();
}
}, },
oml_item: function() { oml_item: function() {
if (!ui.item) { if (!ui.item) {
@ -123,10 +126,16 @@ oml.ui.list = function() {
} }
}, },
oml_listselection: function(data) { oml_listselection: function(data) {
that.options({selected: data.value}); if (ui._list == oml.UI.getPrevious()._list) {
that.options({selected: data.value});
}
}, },
oml_listsort: function(data) { oml_listsort: function(data) {
that.options({sort: data.value}); if (ui._list == oml.UI.getPrevious()._list) {
Ox.print('NEW LIST SORT, SAME LIST, SETTING SORT OPTION')
Ox.print('OLD:', that.options('sort'), 'NEW:', data.value);
that.options({sort: data.value});
}
}, },
oml_sidebarsize: function(data) { oml_sidebarsize: function(data) {
that.size(); that.size();

View File

@ -28,6 +28,7 @@ oml.ui.listInnerPanel = function() {
}) })
.bindEvent({ .bindEvent({
oml_listview: function() { oml_listview: function() {
Ox.print('LIST VIEW HAS CHANGED, REPLACING LIST')
that.replaceElement(1, oml.$ui.list = oml.ui.list()); that.replaceElement(1, oml.$ui.list = oml.ui.list());
}, },
oml_showfilters: function(data) { oml_showfilters: function(data) {

View File

@ -21,9 +21,16 @@ oml.ui.listViewButtons = function() {
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
oml.UI.set({listView: data.value}); oml.UI.set({listView: data.value});
},
oml_listview: function() {
that.updateElement();
} }
}); });
that.updateElement = function() {
return that.options({value: ui.listView});
};
return that; return that;
}; };

View File

@ -221,6 +221,15 @@ oml.ui.mainMenu = function() {
title: Ox._('Advanced Sort'), title: Ox._('Advanced Sort'),
keyboard: 'shift control s', keyboard: 'shift control s',
disabled: true disabled: true
},
{},
{
id: 'sorttitles',
title: Ox._('Sort Titles...')
},
{
id: 'sortnames',
title: Ox._('Sort Names...')
} }
] ]
}, },

View File

@ -11,7 +11,6 @@ oml.ui.preferencesDialog = function() {
id: 'username', id: 'username',
title: 'Username', title: 'Username',
value: preferences.username, value: preferences.username,
placeholder: 'anonymous',
help: 'Your username doesn\'t have to be your real name, and you can change it at any time. You can also leave it blank, in which case you will appear as "anonymous". Any characters other than colons and leading, trailing or consecutive spaces are okay.' help: 'Your username doesn\'t have to be your real name, and you can change it at any time. You can also leave it blank, in which case you will appear as "anonymous". Any characters other than colons and leading, trailing or consecutive spaces are okay.'
}, },
{ {
@ -430,7 +429,7 @@ oml.ui.preferencesDialog = function() {
var key = data.id, var key = data.id,
value = data.data.value[0]; value = data.data.value[0];
if (key == 'username') { if (key == 'username') {
value = getValidName(value, [], ':'); value = oml.getValidName(value, [], ':');
} }
if (key in oml.config.user.preferences) { if (key in oml.config.user.preferences) {
oml.Preferences.set(key, value); oml.Preferences.set(key, value);

View File

@ -238,7 +238,7 @@ oml.ui.usersDialog = function() {
disabled: true, disabled: true,
label: Ox._('Download Link'), label: Ox._('Download Link'),
labelWidth: 128, labelWidth: 128,
value: 'https://openmedialibrary.com/#download', value: 'http://openmedialibrary.com/#download',
width: 480 width: 480
}) })
.css({ .css({
@ -260,27 +260,16 @@ oml.ui.usersDialog = function() {
Ox.Input({ Ox.Input({
label: Ox._('Nickname'), label: Ox._('Nickname'),
labelWidth: 128, labelWidth: 128,
placeholder: 'anonymous', value: user.nickname,
value: user.nickname || user.username || '',
width: 480 width: 480
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var value = oml.getValidName(
data.value || 'anonymous',
// FIXME: WRONG
users.filter(function(user_) {
return user_.nickname != user.nickname;
}).map(function(u) {
return user_.nickname;
}),
':'
);
this.value(value);
oml.api.editUser({ oml.api.editUser({
id: user.id, id: user.id,
nickname: value nickname: data.value
}, function() { }, function(result) {
Ox.print('EDIT USER', result.data);
// ... // ...
}); });
} }
@ -331,8 +320,7 @@ oml.ui.usersDialog = function() {
disabled: true, disabled: true,
label: Ox._('Username'), label: Ox._('Username'),
labelWidth: 128, labelWidth: 128,
placeholder: 'anonymous', value: user.username,
value: user.username || '',
width: 480 width: 480
}) })
.css({ .css({
@ -474,11 +462,9 @@ oml.ui.usersDialog = function() {
}, },
{ {
format: function(value) { format: function(value) {
return value return Ox.encodeHTMLEntities(value);
? Ox.encodeHTMLEntities(value)
: '<span class="OxLight">anonymous</span>';
}, },
id: folder.id == 'peers' ? 'nickname' : 'username', id: 'name',
visible: true, visible: true,
width: 240 width: 240
} }
@ -533,14 +519,16 @@ oml.ui.usersDialog = function() {
} }
function updateUsers(callback) { function updateUsers(callback) {
Ox.Request.clearCache('getUsers'); Ox.Request.clearCache('getUsers');
oml.api.getUsers(function(result) { oml.api.getUsers(function(result) {
users = result.data.users; users = result.data.users;
peerIds = users.filter(function(user) { peerIds = users.filter(function(user) {
return user.peered; return user.peered;
}).map(function(user) { }).map(function(user) {
return user.id return user.id;
}); });
folders.forEach(function(folder) { folders.forEach(function(folder) {
folder.items = []; folder.items = [];
@ -595,14 +583,13 @@ oml.ui.usersDialog = function() {
}); });
} }
that.updateElement = function() {
that.updateElement = function() {
that.options({ that.options({
content: Ox.LoadingScreen().start() content: Ox.LoadingScreen().start()
}); });
updateUsers(); updateUsers();
return that; return that;
}; };
return that.updateElement(); return that.updateElement();

View File

@ -800,7 +800,7 @@ oml.getLists = function(callback) {
: 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 == username && list.type == 'static',
own: list.user == username, own: list.user == '',
title: (list.user ? list.user + ': ' : '') + list.name title: (list.user ? list.user + ': ' : '') + list.name
}); });
}); });
@ -836,71 +836,22 @@ oml.getSortOperator = function(key) {
}; };
oml.getUsers = function(callback) { oml.getUsers = function(callback) {
var users = [{ var ui = oml.user.ui,
id: oml.user.id,
nickname: oml.user.preferences.username,
online: oml.user.online
}];
oml.api.getUsers(function(result) {
users = users.concat(
result.data.users.filter(function(user) {
return user.peered;
})
);
callback(users);
});
}
oml.getUsersAndLists = function(callback) {
var lists = [{
id: '',
name: Ox._('All Libraries'),
type: 'libraries'
}],
ui = oml.user.ui,
username = oml.user.preferences.username,
users = [{ users = [{
id: oml.user.id, id: oml.user.id,
nickname: username, name: '',
online: oml.user.online online: oml.user.online
}]; }];
Ox.Request.clearCache('getUsers'); Ox.Request.clearCache('getUsers');
Ox.Request.clearCache('getLists');
oml.api.getUsers(function(result) { oml.api.getUsers(function(result) {
users = users.concat( users = users.concat(
result.data.users.filter(function(user) { result.data.users.filter(function(user) {
return user.peered; return user.peered;
}) })
); );
oml.api.getLists(function(result) { ui._users = users;
users.forEach(function(user) { callback(users);
lists = lists.concat([{ });
id: (user.nickname == username ? '' : user.nickname) + ':',
name: Ox._('Library'),
type: 'library',
user: user.nickname
}].concat(
result.data.lists.filter(function(list) {
return list.user == user.nickname;
})
));
});
lists = lists.map(function(list) {
// FIXME: 'editable' is notoriously vague
return Ox.extend(list, {
editable: list.user == username && list.type == 'static',
own: list.user == username,
title: (list.user ? list.user + ': ' : '') + list.name
});
})
if (!ui.lists) {
oml.$ui.mainMenu.updateElement();
}
ui._lists = lists;
Ox.print('GOT LISTS ::::', lists);
callback(users, lists);
});
})
}; };
oml.getValidName = function(value, names, chars) { oml.getValidName = function(value, names, chars) {

View File

@ -6,25 +6,25 @@ oml.ui.viewer = function() {
that = Ox.Element() that = Ox.Element()
.bindEvent({ .bindEvent({
oml_item: function(data) {
that.updateElement();
},
oml_itemview: function(data) { oml_itemview: function(data) {
that.updateElement(); if (ui.item != item && ui.itemView == 'book') {
that.updateElement(ui.item);
}
} }
}), }),
$iframe; $iframe, item;
that.updateElement = function() { that.updateElement = function() {
if (ui.item && ui.itemView == 'book') { item = ui.item;
if (item) {
$iframe = $iframe || Ox.Element('<iframe>').css({ $iframe = $iframe || Ox.Element('<iframe>').css({
width: '100%', width: '100%',
height: '100%', height: '100%',
border: 0 border: 0
}).appendTo(that); }).appendTo(that);
$iframe.attr({ $iframe.attr({
src: '/' + ui.item + '/reader/' src: '/' + item + '/reader/'
}); });
} }
return that; return that;