import/lists/autocompleteFolder

This commit is contained in:
j 2014-05-19 01:24:04 +02:00
commit d6f350e5a1
42 changed files with 955 additions and 436 deletions

View file

@ -45,7 +45,6 @@ oml.ui.appPanel = function() {
oml.$ui.importExportDialog
&& oml.$ui.importExportDialog.is(':visible')
) {
Ox.print('AAAAAAAA')
oml.$ui.importExportDialog.select(page);
} else {
oml.$ui.importExportDialog = oml.ui.importExportDialog(page).open();
@ -56,6 +55,7 @@ oml.ui.appPanel = function() {
that.reload = function() {
Ox.Request.cancel();
Ox.Request.clearCache();
oml.unbindEvent();
oml.$ui.appPanel.remove();
oml.$ui.appPanel = oml.ui.appPanel().appendTo(Ox.$body);
return that;

View file

@ -16,7 +16,10 @@ oml.ui.backButton = function() {
})
.bindEvent({
click: function() {
oml.UI.set({item: ''});
oml.UI.set({
item: '',
itemView: 'info'
});
}
});

View file

@ -72,8 +72,10 @@ oml.ui.browser = function() {
unique: 'id'
})
.bindEvent({
open: function() {
oml.UI.set({itemView: 'book'});
open: function(data) {
if (that.value(data.ids[0], 'mediastate') == 'available') {
oml.UI.set({itemView: 'book'});
}
},
select: function(data) {
oml.UI.set({

View file

@ -27,7 +27,6 @@ oml.ui.deleteItemsDialog = function() {
}, function() {
oml.UI.set({listSelection: []});
Ox.Request.clearCache('find');
oml.$ui.folders.updateElement();
oml.$ui.list.updateElement();
});
});

View file

@ -62,7 +62,6 @@ oml.ui.filter = function(id) {
);
},
select: function(data) {
Ox.print('UI FILTER STATE', ui._filterState)
// fixme: cant index be an empty array, instead of -1?
// FIXME: this is still incorrect when deselecting a filter item
// makes a selected item in another filter disappear

View file

@ -59,7 +59,6 @@ oml.ui.filtersOuterPanel = function() {
},
oml_find: function() {
var previousUI = oml.UI.getPrevious();
Ox.print('WTF', ui, oml.user.ui, Object.keys(ui), Object.keys(previousUI));
ui._filterState.forEach(function(data, index) {
if (!Ox.isEqual(data.selected, previousUI._filterState[index].selected)) {
oml.$ui.filters[index].options(
@ -72,7 +71,6 @@ oml.ui.filtersOuterPanel = function() {
);
}
if (!Ox.isEqual(data.find, previousUI._filterState[index].find)) {
Ox.print('::::', index, 'UNEQUAL', data.find, previousUI._filterState[index].find)
if (!ui.showFilters) {
oml.$ui.filters[index].options({
_selected: data.selected

View file

@ -188,7 +188,6 @@ oml.ui.findElement = function() {
$select.superValue = $select.value;
$select.value = function(value) {
if (arguments.length == 1) {
Ox.print('I AM HERE')
$select.options({title: value == 'all' ? 'data' : value});
}
$select.superValue.apply($select, arguments);

View file

@ -2,8 +2,6 @@
oml.ui.findForm = function(list) {
//Ox.print('FIND FORM LIST QUERY', list.query);
var ui = oml.user.ui,
that = Ox.Element(),
@ -19,7 +17,7 @@ oml.ui.findForm = function(list) {
title: Ox._('List'),
type: 'item',
values: ui._lists.filter(function(list) {
return list.type != 'smart'
return Ox.contains(['library', 'static'], list.type);
}).map(function(list) {
return {id: list.id, title: list.title};
})

View file

@ -3,8 +3,10 @@
oml.ui.folders = function() {
var ui = oml.user.ui,
username = oml.user.preferences.username,
userIndex,
users,
$lists,
@ -28,6 +30,24 @@ oml.ui.folders = function() {
};
}
function getFolderList(list) {
var index = users.map(function(user) {
return user.nickname;
}).indexOf(list.user);
return list.id == '' ? oml.$ui.librariesList
: Ox.endsWith(list.id, ':') ? oml.$ui.libraryList[index]
: oml.$ui.folderList[index];
}
function getUsersAndLists(callback) {
oml.getUsers(function() {
users = arguments[0];
oml.getLists(function(lists) {
callback(users, lists);
});
});
}
function selectList() {
var split = ui._list.split(':'),
index = userIndex[split[0] || oml.user.preferences.username],
@ -50,49 +70,44 @@ oml.ui.folders = function() {
$lists = [];
$lists.push(
oml.$ui.librariesList = oml.ui.folderList({
items: [
{
id: '',
name: Ox._('All Libraries'),
type: 'libraries',
items: -1
}
]
})
.bindEvent({
load: function() {
oml.api.find({query: getFind('')}, function(result) {
oml.$ui.librariesList.value('', 'items', result.data.items);
});
},
select: function() {
oml.UI.set({find: getFind('')});
oml.$ui.librariesList.options({selected: ['']});
},
selectnext: function() {
oml.UI.set(Ox.extend(
{find: getFind(':')},
'showFolder.' + oml.user.preferences.username,
true
));
},
})
.css({height: '16px'})
.appendTo(that)
);
oml.$ui.librariesList.$body.css({height: '16px'}); // FIXME!
oml.$ui.folder = [];
oml.$ui.libraryList = [];
oml.$ui.folderList = [];
oml.getUsersAndLists(function(users, lists) {
getUsersAndLists(function(users, lists) {
Ox.print('GOT USERS AND LISTS', users, lists);
userIndex = {};
$lists.push(
oml.$ui.librariesList = oml.ui.folderList({
items: [
{
id: '',
name: Ox._('All Libraries'),
type: 'libraries',
items: Ox.getObjectById(lists, '').items
}
]
})
.bindEvent({
select: function() {
oml.UI.set({find: getFind('')});
oml.$ui.librariesList.options({selected: ['']});
},
selectnext: function() {
oml.UI.set(Ox.extend(
{find: getFind(':')},
'showFolder.' + username,
true
));
},
})
.css({height: '16px'})
.appendTo(that)
);
oml.$ui.librariesList.$body.css({height: '16px'}); // FIXME!
users.forEach(function(user, index) {
var $content,
@ -107,11 +122,7 @@ oml.ui.folders = function() {
oml.$ui.folder[index] = Ox.CollapsePanel({
collapsed: false,
extras: [
oml.ui.statusIcon(
!oml.user.online && index ? 'unknown'
: user.online ? 'connected'
: 'disconnected'
),
oml.ui.statusIcon(user, index),
{},
Ox.Button({
style: 'symbol',
@ -162,7 +173,7 @@ oml.ui.folders = function() {
id: libraryId,
name: Ox._('Library'),
type: 'library',
items: -1
items: Ox.getObjectById(lists, libraryId).items
}
]
})
@ -170,15 +181,6 @@ oml.ui.folders = function() {
add: function() {
!index && oml.addList();
},
load: function() {
oml.api.find({
query: getFind(libraryId)
}, function(result) {
oml.$ui.libraryList[index].value(
libraryId, 'items', result.data.items
);
});
},
select: function(data) {
oml.UI.set({find: getFind(data.ids[0])});
},
@ -186,16 +188,20 @@ oml.ui.folders = function() {
oml.UI.set({find: getFind(items[0].id)});
},
selectprevious: function() {
var userId = !index ? null : users[index - 1].id,
set = {
find: getFind(
!index
? ''
: Ox.last(lists[userId]).id
)
};
if (userId) {
Ox.extend(set, 'showFolder.' + userId, true);
// FIXME: ugly
var set, user, userLists;
if (!index) {
set = {find: getFind('')};
} else {
user = users[index - 1].nickname;
userLists = lists.filter(function(list) {
return list.user == user;
});
set = {find: getFind(
!userLists.length ? (user == oml.user.preferences.username ? '' : user) + ':'
: Ox.last(userLists).id
)};
Ox.extend(set, 'showFolder.' + user, true);
}
oml.UI.set(set);
}
@ -219,14 +225,6 @@ oml.ui.folders = function() {
key_control_d: function() {
oml.addList(ui._list);
},
load: function() {
// FIXME: too much
items.forEach(function(item) {
oml.api.find({query: getFind(item.id)}, function(result) {
oml.$ui.folderList[index].value(item.id, 'items', result.data.items);
});
});
},
move: function(data) {
lists[user.id] = data.ids.map(function(listId) {
return Ox.getObjectById(items, listId);
@ -273,32 +271,53 @@ oml.ui.folders = function() {
};
that.updateItems = function() {
oml.getUsersAndLists(function(users, lists) {
Ox.Request.clearCache('find');
$lists.forEach(function($list) {
$list.reloadList();
that.updateItems = function(items) {
Ox.print('UPDATE ITEMS', items);
var $list;
if (arguments.length == 0) {
oml.getLists(function(lists) {
lists.forEach(function(list) {
$list = getFolderList(list);
if ($list) {
$list.value(list.id, 'items', list.items);
}
});
});
});
} else {
$list = $lists.filter(function($list) {
return $list.options('selected').length;
})[0];
if ($list && !Ox.isEmpty($list.value(ui._list))) {
$list.value(ui._list, 'items', items);
}
}
};
that.updateOwnLists = function(callback) {
oml.getUsersAndLists(function(users, lists) {
oml.getLists(function(lists) {
var items = lists.filter(function(list) {
return list.user == oml.user.preferences.username
&& list.type != 'library';
});
oml.$ui.folder[0].$content
.css({height: 16 + items.length * 16 + 'px'});
oml.$ui.folderList[0].options({
items: items
})
.css({height: items.length * 16 + 'px'})
.size();
oml.$ui.folder[0].$content
.css({height: 16 + items.length * 16 + 'px'});
callback && callback();
});
};
oml.bindEvent({
activity: function(data) {
if (data.activity == 'import') {
that.updateItems();
}
}
});
return that.updateElement();
};
};

View file

@ -34,6 +34,8 @@ oml.ui.identifyDialog = function(data) {
originalData = Ox.clone(data, true),
selected = data.mainid ? 'id' : 'title',
idValue, titleValue,
$idInputs, $idButtons = {},
@ -59,7 +61,7 @@ oml.ui.identifyDialog = function(data) {
$titlePanel = Ox.SplitPanel({
elements: [
{element: $titleForm, size: 96},
{element: renderResults([])}
{element: Ox.Element()}
],
orientation: 'vertical'
}),
@ -72,7 +74,7 @@ oml.ui.identifyDialog = function(data) {
{id: 'title', title: Ox._('Find by Title')}
],
selectable: true,
selected: 'id'
value: selected
})
.css({
width: '768px',
@ -81,7 +83,8 @@ oml.ui.identifyDialog = function(data) {
})
.bindEvent({
change: function(data) {
$innerPanel.options({selected: data.value});
selected = data.value;
$innerPanel.options({selected: selected});
}
})
.appendTo($bar),
@ -92,7 +95,7 @@ oml.ui.identifyDialog = function(data) {
{id: 'title', element: $titlePanel}
],
orientation: 'horizontal',
selected: 'id',
selected: selected,
size: 768
}),
@ -122,16 +125,16 @@ oml.ui.identifyDialog = function(data) {
})
.bindEvent({
click: function() {
Ox.print('$$$', idValue);
var edit = Ox.extend(
{id: data.id},
$innerPanel.options('selected') == 'id'
? idValue
? idValue || {mainid: ''}
: titleValue
);
that.options({content: Ox.LoadingScreen().start()});
that.disableButtons();
oml.api.edit(edit, function(result) {
Ox.print('EDITED', result.data);
that.close();
Ox.Request.clearCache('find');
oml.$ui.browser.reloadList(true);
@ -145,28 +148,36 @@ oml.ui.identifyDialog = function(data) {
content: $outerPanel,
fixedSize: true,
height: 384,
removeOnClose: true,
title: Ox._('Identify Book'),
width: 768
});
function disableButtons() {
Ox.forEach(selected == 'id' ? $idButtons : $titleButtons, function($button) {
$button.options({disabled: true});
});
}
function findMetadata(data) {
disableButtons();
$titlePanel.replaceElement(1, Ox.LoadingScreen().start());
oml.api.findMetadata(data, function(result) {
Ox.print('GOT RESULTS', result.data);
// FIXME: CONCAT HERE
var items = result.data.items.map(function(item, index) {
return Ox.extend({index: (index + 1).toString()}, item);
});
updateTitleButtons();
$titlePanel.replaceElement(1, renderResults(items));
});
}
function getMetadata(key, value) {
disableButtons();
$idPanel.replaceElement(1, Ox.LoadingScreen().start());
oml.api.getMetadata(Ox.extend({}, key, value), function(result) {
Ox.print('GOT RESULT', result.data);
$idForm = renderIdForm(result.data);
$idPreview = oml.ui.infoView(result.data);
$idPreview = Ox.isEmpty(data) ? Ox.Element() : oml.ui.infoView(result.data);
$idPanel
.replaceElement(0, $idForm)
.replaceElement(1, $idPreview);
@ -174,7 +185,6 @@ oml.ui.identifyDialog = function(data) {
}
function idInputValues(key, values) {
Ox.print('WTF,', $idInputs);
var $input = $idInputs[ids.map(function(id) {
return id.id;
}).indexOf(key)];
@ -190,30 +200,13 @@ oml.ui.identifyDialog = function(data) {
return values;
}
function titleInputValue(key, value) {
var $input = $titleInputs[keys.map(function(key) {
return key.id;
}).indexOf(key)];
if (Ox.isUndefined(value)) {
value = $input.value();
if (key == 'author') {
value = value ? value.split(', ') : [];
}
} else {
$input.value(
key == 'author' ? (value || []).join(', ') : value
);
}
return value;
}
function isEmpty(data) {
return Ox.every(data, Ox.isEmpty);
}
function isOriginal(data) {
return Ox.every(data, function(value, key) {
return value == originalData[key];
return Ox.every(Object.keys(data), function(key) {
return data[key] == originalData[key];
});
}
@ -268,7 +261,7 @@ oml.ui.identifyDialog = function(data) {
});
});
getMetadata(id.id, data.value, function() {
// ...
Ox.print('GOT METADATA');
updateIdButtons();
});
}
@ -335,15 +328,27 @@ oml.ui.identifyDialog = function(data) {
})
.bindEvent({
click: function() {
var key, value;
Ox.forEach(ids, function(id) {
var values = idInputValues(id.id);
if (values[0]) {
key = id.id;
value = values[1];
return false;
}
});
getMetadata(key, value, function() {
// ...
})
Ox.print('NOT IMPLEMENTED')
}
})
.appendTo($element);
updateIdButtons();
return $element;
}
function renderResults(items) {
Ox.print('LIST ITEMS::::', items);
var $list = Ox.TableList({
columns: [
{
@ -375,7 +380,6 @@ oml.ui.identifyDialog = function(data) {
select: function(data) {
var index = data.ids[0], mainid;
mainid = $list.value(index, 'mainid');
Ox.print('MAINID', mainid)
titleValue = Ox.extend({}, mainid, $list.value(index, mainid));
$results.replaceElement(1, Ox.LoadingScreen().start());
oml.api.getMetadata(titleValue, function(result) {
@ -476,6 +480,23 @@ oml.ui.identifyDialog = function(data) {
return $element;
}
function titleInputValue(key, value) {
var $input = $titleInputs[keys.map(function(key) {
return key.id;
}).indexOf(key)];
if (Ox.isUndefined(value)) {
value = $input.value();
if (key == 'author') {
value = value ? value.split(', ') : [];
}
} else {
$input.value(
key == 'author' ? (value || []).join(', ') : value
);
}
return value;
}
function updateIdButtons() {
var data = {}, empty, original;
ids.forEach(function(id) {
@ -486,7 +507,7 @@ oml.ui.identifyDialog = function(data) {
$idButtons.clear.options({disabled: empty});
$idButtons.reset.options({disabled: original});
$idButtons.find.options({disabled: empty});
that[original ? 'disableButton' : 'enableButton']('update');
that && that[original ? 'disableButton' : 'enableButton']('update');
}
function updateTitleButtons() {

View file

@ -50,8 +50,8 @@ oml.ui.importExportDialog = function(selected) {
that = Ox.Dialog({
buttons: [
Ox.Button({
id: 'close',
title: Ox._('Close')
id: 'hide',
title: Ox._('Hide')
})
.bindEvent({
click: function() {
@ -87,7 +87,7 @@ oml.ui.importExportDialog = function(selected) {
$status = {},
$progressButton = {};
oml.getUsersAndLists(function() {
oml.getLists(function() {
oml.api.getActivity(function(result) {
var isActive = !Ox.isEmpty(result.data),
activity = result.data.activity;
@ -98,7 +98,6 @@ oml.ui.importExportDialog = function(selected) {
progress: [0,42]
};
*/
Ox.print(result.data, '!!!!!!!!')
$innerPanel
.replaceElement(0,
activity == 'import' ? renderActivity(result.data)
@ -208,6 +207,12 @@ oml.ui.importExportDialog = function(selected) {
$form = Ox.Form({
items: selected == 'import' ? [
Ox.Input({
autocomplete: function(value, callback) {
oml.api.autocompleteFolder({path: value}, function(result) {
callback(result.data.items);
});
},
autocompleteSelect: true,
changeOnKeypress: true,
id: 'path',
label: 'Source Path',
@ -216,7 +221,7 @@ oml.ui.importExportDialog = function(selected) {
}),
Ox.SelectInput({
id: 'list',
inputValue: oml.validateName(Ox._('Untitled'), getListNames()),
inputValue: oml.getValidName(Ox._('Untitled'), getListNames()),
inputWidth: 224,
items: getListItems('import'),
label: 'Destination',
@ -229,8 +234,8 @@ oml.ui.importExportDialog = function(selected) {
Ox.Select({
id: 'mode',
items: [
{id: 'copy', title: Ox._('Copy files')},
{id: 'move', title: Ox._('Move files')}
{id: 'copy', title: Ox._('Copy (keep files in source path)')},
{id: 'move', title: Ox._('Move (delete files from source path)')}
],
label: Ox._('Import Mode'),
labelWidth: 128,
@ -255,10 +260,10 @@ oml.ui.importExportDialog = function(selected) {
Ox.Select({
id: 'mode',
items: [
{id: 'keep', title: Ox._('Keep existing files')},
{id: 'remove', title: Ox._('Remove existing files')}
{id: 'add', title: Ox._('Add (keep files in destination path)')},
{id: 'replace', title: Ox._('Replace (delete files from destination path)')}
],
label: Ox._('Import Mode'),
label: Ox._('Export Mode'),
labelWidth: 128,
width: 480
})
@ -268,15 +273,8 @@ oml.ui.importExportDialog = function(selected) {
.bindEvent({
change: function(data) {
var values = $form.values();
Ox.print('FORM CHANGE', data);
if (data.id == 'list') {
// FIXME: WRONG
if (data.data.value[0] != '') {
$form.values('list', oml.validateName(data.data.value, getListNames()))
}
}
$activityButton[selected].options({
disabled: !values.path //|| !values.list
disabled: !values.path
});
}
})
@ -310,7 +308,11 @@ oml.ui.importExportDialog = function(selected) {
})
.bindEvent({
click: function() {
var data = $form.values();
var data = $form.values(),
addList = data.list && !Ox.contains(
oml.getOwnListNames(),
data.list
);
$innerPanel.replaceElement(0,
renderActivity({
activity: 'import',
@ -319,13 +321,15 @@ oml.ui.importExportDialog = function(selected) {
})
);
$label['export'].show();
oml.api.import({
list: data.list, // FIXME: WRONG for Library
mode: data.mode,
path: data.path,
}, function() {
// ...
})
(addList ? oml.addList : Ox.noop)(false, false, data.list, function() {
oml.api.import({
list: data.list,
mode: data.mode,
path: data.path,
}, function() {
// ...
});
});
}
})
.appendTo($element);
@ -341,7 +345,6 @@ oml.ui.importExportDialog = function(selected) {
}
function setProgress(data) {
Ox.print('SET PROGRESS', data, $progress)
var progress = data.status ? 1
: !data.progress[0] || !data.progress[1] ? -1
: data.progress[0] / data.progress[1];
@ -379,7 +382,6 @@ oml.ui.importExportDialog = function(selected) {
oml.bindEvent({
activity: function(data) {
Ox.print('activity', arguments);
setProgress(data);
setStatus(data);
setButton(data);

View file

@ -321,6 +321,11 @@ oml.ui.infoView = function(identifyData) {
tooltip: isEditable ? oml.getEditTooltip() : '',
value: data.title || ''
})
.bindEvent({
submit: function(data) {
editMetadata('title', data.value);
}
})
.css({
fontSize: '13px',
fontWeight: 'bold'
@ -353,7 +358,9 @@ oml.ui.infoView = function(identifyData) {
fontWeight: 'bold'
})
.bindEvent({
// ...
submit: function(data) {
editMetadata('author', value.split(', '));
}
})
)
.appendTo($info);
@ -502,12 +509,13 @@ oml.ui.infoView = function(identifyData) {
// FIXME: identify dialog should call this too
function editMetadata(key, value) {
var edit;
Ox.print('EM', key, value, data[key])
if (value != data[key]) {
edit = Ox.extend({id: ui.item}, key, value);
oml.api.edit(edit, function(result) {
Ox.Request.clearCache('find');
oml.$ui.browser.reloadList();
that.updateElement(result.data, $data);
//that.updateElement(result.data, $info);
});
}
}

View file

@ -50,6 +50,14 @@ oml.ui.list = function() {
}
},
init: function(data) {
Ox.print('MAIN LIST INIT', data);
if (ui.find.conditions.length == 0 || (
ui.find.conditions.length == 1
&& ui.find.conditions[0].key == 'list'
&& ui.find.conditions[0].operator == '=='
)) {
oml.$ui.folders.updateItems(data.items);
}
oml.$ui.statusbar.set('total', data);
},
key_control_delete: function() {
@ -58,6 +66,15 @@ oml.ui.list = function() {
oml.ui.deleteItemsDialog().open();
}
},
key_shift_enter: function() {
var selected = that.options('selected');
if (selected.length) {
oml.UI.set({
item: selected[0],
itemView: 'book'
});
}
},
open: function(data) {
oml.UI.set({
item: data.ids[0],

View file

@ -65,14 +65,18 @@ oml.ui.listDialog = function() {
})
.bindEvent({
change: function(data) {
var value = oml.validateName(data.value, listNames);
var value = oml.getValidName(
data.value || Ox._('Untitled'),
listNames.filter(function(listName) {
return listName != listData.name;
})
);
that.options({title: getTitle(':' + value)})
$nameInput.value(value);
// FIXME: UGLY
listNames[listNames.indexOf(listData.name)] = value;
listData.name = value;
//
Ox.print(listData.name, 'LIST NAMES ???', listNames)
oml.api.editList({
id: ui._list,
name: value
@ -94,13 +98,13 @@ oml.ui.listDialog = function() {
})
.appendTo($content),
$findForm;
Ox.print('DEBUG:', list, listData)
if (listData.type == 'smart') {
$findForm = oml.ui.findForm(listData)
.css({marginTop: '8px'})
.appendTo($content);
}
that.options({content: $content});
$nameInput.focusInput(true);
});
function getTitle(list) {

View file

@ -19,7 +19,7 @@ oml.ui.openButton = function() {
oml.UI.set({item: ui.listSelection[0]});
},
oml_listselection: function() {
that.update();
that.updateElement();
}
});
@ -29,4 +29,4 @@ oml.ui.openButton = function() {
return that.updateElement();
};
};

View file

@ -12,7 +12,7 @@ oml.ui.preferencesDialog = function() {
title: '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 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.'
},
{
id: 'contact',
@ -25,12 +25,24 @@ oml.ui.preferencesDialog = function() {
{
id: 'libraryPath',
title: 'Library Path',
autocomplete: function(value, callback) {
oml.api.autocompleteFolder({path: value}, function(result) {
callback(result.data.items);
});
},
autocompleteSelect: true,
value: preferences.libraryPath,
help: 'The directory in which your "Books" folder is located. This is where your media files are stored. It can be on your local machine, but just as well on an external drive or networked volume.'
},
{
id: 'importPath',
title: 'Import Path',
autocomplete: function(value, callback) {
oml.api.autocompleteFolder({path: value}, function(result) {
callback(result.data.items);
});
},
autocompleteSelect: true,
value: preferences.importPath,
help: 'Any media files that you put in this folder will be added to your library. Once added, they will be removed from this folder.'
}
@ -376,6 +388,8 @@ oml.ui.preferencesDialog = function() {
width: 384
})
: Ox.Input({
autocomplete: item.autocomplete || null,
autocompleteSelect: item.autocompleteSelect || false,
label: Ox._(item.title),
labelWidth: 128,
placeholder: item.placeholder || '',
@ -415,6 +429,9 @@ oml.ui.preferencesDialog = function() {
change: function(data) {
var key = data.id,
value = data.data.value[0];
if (key == 'username') {
value = getValidName(value, [], ':');
}
if (key in oml.config.user.preferences) {
oml.Preferences.set(key, value);
} else {

View file

@ -26,6 +26,7 @@ oml.ui.rightPanel = function() {
oml.$ui.itemViewPanel.options({size: data.size});
},
oml_item: function(data) {
Ox.print('rightPanel, oml_item', data);
if (!!data.value != !!data.previousValue) {
that.options({selected: !ui.item ? 'list' : 'item'});
}
@ -34,4 +35,4 @@ oml.ui.rightPanel = function() {
return that;
};
};

View file

@ -1,18 +1,10 @@
'use strict';
oml.ui.statusIcon = function(status) {
oml.ui.statusIcon = function(user, index) {
// FIXME: not only '-webkit'
var color = {
connected: [[64, 255, 64], [0, 192, 0]],
disconnected: [[255, 64, 64], [192, 0, 0]],
transferring: [[64, 255, 255], [0, 192, 192]],
unknown: [[255, 255, 64], [192, 192, 0]]
}[status].map(function(rgb) {
return 'rgb(' + rgb.join(', ') + ')';
}).join(', '),
var status = getStatus(user),
that = Ox.Element({
tooltip: Ox._({
connected: 'Connected',
@ -24,7 +16,6 @@ oml.ui.statusIcon = function(status) {
width: '10px',
height: '10px',
margin: '3px',
background: '-webkit-linear-gradient(bottom, ' + color + ')',
borderRadius: '5px'
})
.append(
@ -33,11 +24,65 @@ oml.ui.statusIcon = function(status) {
width: '8px',
height: '8px',
margin: '1px',
background: '-webkit-linear-gradient(top, ' + color + ')',
borderRadius: '4px'
})
);
return that;
render();
};
if (user) {
var superRemove = that.remove;
that.remove = function() {
oml.unbindEvent({
status: update
})
superRemove();
};
oml.bindEvent({
status: update
});
}
function getStatus(data) {
return !oml.user.online && index ? 'unknown'
: data.online ? 'connected'
: 'disconnected';
}
function render() {
var color = {
connected: [[64, 255, 64], [0, 192, 0]],
disconnected: [[255, 64, 64], [192, 0, 0]],
transferring: [[64, 255, 255], [0, 192, 192]],
unknown: [[255, 255, 64], [192, 192, 0]]
}[status].map(function(rgb) {
return 'rgb(' + rgb.join(', ') + ')';
}).join(', ');
that.options({
tooltip: Ox._({
connected: 'Connected',
disconnected: 'Disconnected',
transferring: 'Transferring'
}[status])
}).css({
background: '-webkit-linear-gradient(bottom, ' + color + ')',
});
that.find('div').css({
background: '-webkit-linear-gradient(top, ' + color + ')',
});
}
function update(data) {
if (data.id == user.id) {
var newStatus = getStatus(data);
if (status != newStatus) {
status = newStatus;
render();
}
}
}
return that;
};

View file

@ -35,7 +35,9 @@ oml.ui.statusbar = function() {
});
function getText(data) {
return Ox.toTitleCase(Ox.formatCount(data.items, 'book'));
return Ox.toTitleCase(Ox.formatCount(data.items, 'book')) + (
data.items ? ', ' + Ox.formatValue(data.size, 'B') : ''
);
}
that.set = function(key, data) {

View file

@ -21,7 +21,7 @@ oml.ui.transfersDialog = function() {
visible: true,
width: id == 'title' ? 240
: id == 'transferadded' ? 144
: id == 'transferprogress' ? 80
: id == 'transferprogress' ? 80 - Ox.UI.SCROLLBAR_SIZE
: key.columnWidth
};
}),
@ -40,6 +40,7 @@ oml.ui.transfersDialog = function() {
}), callback);
},
keys: ['author'],
scrollbarVisible: true,
sort: [{key: 'transferprogress', operator: '-'}],
unique: 'id'
}),

View file

@ -38,7 +38,15 @@ oml.ui.usersDialog = function() {
width: 768
})
.bindEvent({
open: function() {
oml.bindEvent({
peering: peering,
});
},
close: function() {
oml.unbindEvent({
peering: peering,
});
if (ui.page == 'users') {
oml.UI.set({page: ''});
}
@ -112,6 +120,10 @@ oml.ui.usersDialog = function() {
.appendTo($users);
});
var peering = Ox.throttle(function() {
updateUsers();
}, 1000);
function renderSectionList(folder) {
var $list = Ox.TableList({
@ -254,11 +266,15 @@ oml.ui.usersDialog = function() {
})
.bindEvent({
change: function(data) {
var value = oml.validateName(
data.value,
users.map(function(user) {
return user.nickname;
})
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({
@ -447,9 +463,7 @@ oml.ui.usersDialog = function() {
columns: [
{
format: function(value, data) {
return oml.ui.statusIcon(
value ? 'connected' : 'disconnected'
)
return oml.ui.statusIcon(data)
.css({
margin: '2px 3px 3px 0'
});
@ -581,7 +595,6 @@ oml.ui.usersDialog = function() {
});
}
that.updateElement = function() {
that.options({

View file

@ -1,8 +1,10 @@
oml.addList = function() {
// addList(isSmart, isFrom) or addList(list) [=dupicate]
// addList(isSmart, isFrom[, name[, callback]])
// or addList(list) [=duplicate]
var args = arguments,
isDuplicate = args.length == 1,
isSmart, isFrom, list, listData, data,
isSmart, isFrom, name, callback,
list, listData, data,
username = oml.user.preferences.username;
Ox.Request.clearCache('getLists');
oml.api.getLists(function(result) {
@ -16,8 +18,10 @@ oml.addList = function() {
if (!isDuplicate) {
isSmart = args[0];
isFrom = args[1];
name = args[2] || Ox._('Untitled');
callback = args[3];
data = {
name: oml.validateName(Ox._('Untitled'), listNames),
name: oml.getValidName(name, listNames),
type: !isSmart ? 'static' : 'smart'
};
if (!isSmart) {
@ -36,7 +40,7 @@ oml.addList = function() {
list = args[0];
listData = Ox.getObjectById(Ox.flatten(Ox.values(lists)), list);
data = Ox.extend({
name: oml.validateName(listData.name, listNames),
name: oml.getValidName(listData.name, listNames),
type: listData.type
}, listData.query ? {
query: listData.query
@ -74,26 +78,32 @@ oml.addList = function() {
$folderList = oml.$ui.folderList[0];
oml.$ui.folder[0].options({collapsed: false}); // FIXME: SET UI!
// FIXME: DOESN'T WORK
$folderList
.bindEventOnce({
load: function() {
$folderList
.gainFocus()
.options({selected: [list]});
oml.UI.set({
find: {
conditions: [{
key: 'list',
operator: '==',
value: list
}],
operator: '&'
}
});
oml.$ui.listDialog = oml.ui.listDialog().open();
}
});
if (
!oml.$ui.importExportDialog
|| !oml.$ui.importExportDialog.is(':visible')
) {
$folderList
.bindEventOnce({
load: function() {
$folderList
.gainFocus()
.options({selected: [list]});
oml.UI.set({
find: {
conditions: [{
key: 'list',
operator: '==',
value: list
}],
operator: '&'
}
});
oml.$ui.listDialog = oml.ui.listDialog().open();
}
});
}
oml.$ui.folders.updateOwnLists();
callback && callback();
});
}
};
@ -267,7 +277,6 @@ oml.enableDragAndDrop = function($list, canMove) {
$list.bindEvent({
draganddropstart: function(data) {
Ox.print('DND START', data);
var $lists = oml.$ui.libraryList.concat(oml.$ui.folderList);
drag.action = 'copy';
drag.ids = $list.options('selected');
@ -732,7 +741,6 @@ oml.getListData = function(list) {
oml.getListFoldersHeight = function() {
var ui = oml.user.ui;
return Object.keys(ui.showFolder).reduce(function(value, id, index) {
Ox.print('WTF WTF', index)
var items = oml.$ui.folderList[index].options('items').length;
return value + 16 + ui.showFolder[id] * (1 + items) * 16;
}, 16);
@ -748,6 +756,35 @@ oml.getListFoldersWidth = function() {
);
};
oml.getLists = function(callback) {
var ui = oml.user.ui;
Ox.Request.clearCache('getLists');
oml.api.getLists(function(result) {
var username = oml.user.preferences.username;
ui._lists = result.data.lists.map(function(list) {
// FIXME: 'editable' is notoriously vague
list.name = list.type == 'libraries' ? Ox._('Libraries')
: list.type == 'library' ? Ox._('Library') : list.name;
return Ox.extend(list, {
editable: list.user == username && list.type == 'static',
own: list.user == username,
title: (list.user ? list.user + ': ' : '') + list.name
});
});
callback(ui._lists);
});
};
oml.getOwnListNames = function() {
var ui = oml.user.ui,
username = oml.user.preferences.username;
return ui._lists.filter(function(list) {
return list.user == username;
}).filter(function(list) {
return list.name;
});
}
oml.getPageTitle = function(stateOrURL) {
var page = Ox.getObjectById(
oml.config.pages,
@ -765,6 +802,22 @@ oml.getSortOperator = function(key) {
) ? '+' : '-';
};
oml.getUsers = function(callback) {
var users = [{
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: '',
@ -811,12 +864,30 @@ oml.getUsersAndLists = function(callback) {
oml.$ui.mainMenu.updateElement();
}
ui._lists = lists;
Ox.print('UI._LISTS', JSON.stringify(ui._lists));
Ox.print('GOT LISTS ::::', lists);
callback(users, lists);
});
})
};
oml.getValidName = function(value, names, chars) {
var index = 1, length = 256, suffix;
if (chars) {
value = value.replace(
new RegExp('[' + Ox.escapeRegExp(chars) + ']', 'g'),
''
);
}
value = Ox.clean(Ox.clean(value).slice(0, length));
names = names || [];
while (Ox.contains(names, value)) {
suffix = ' [' + (++index) + ']';
value = value.replace(/ \[\d+\]$/, '')
.slice(0, length - suffix.length) + suffix;
};
return value;
};
oml.hasDialogOrScreen = function() {
return !!$('.OxDialog:visible').length
|| !!$('.OxFullscreen').length
@ -834,7 +905,6 @@ oml.resizeFilters = function() {
oml.resizeListFolders = function() {
// FIXME: does this have to be here?
Ox.print('RESIZING LIST FOLDERS', 'WIDTH', oml.getListFoldersWidth(), 'HEIGHT', oml.getListFoldersHeight())
var width = oml.getListFoldersWidth(),
columnWidth = width - 58;
oml.$ui.librariesList
@ -842,7 +912,6 @@ oml.resizeListFolders = function() {
.resizeColumn('name', columnWidth);
Ox.forEach(oml.$ui.folder, function($folder, index) {
$folder.css({width: width + 'px'});
Ox.print('SHOULD BE:', width);
oml.$ui.libraryList[index]
.css({width: width + 'px'})
.resizeColumn('name', columnWidth);
@ -881,18 +950,6 @@ oml.updateFilterMenus = function() {
});
};
oml.validateName = function(value, names) {
var index = 1, length = 256, suffix;
value = Ox.clean(Ox.clean(value).slice(0, length));
names = names || [];
while (Ox.contains(names, value)) {
suffix = ' [' + (++index) + ']';
value = value.replace(/ \[\d+\]$/, '')
.slice(0, length - suffix.length) + suffix;
};
return value;
};
oml.validatePublicKey = function(value) {
return /^[A-Za-z0-9+\/]{43}$/.test(value);
};