openmedialibrary/static/js/listDialog.js

124 lines
4.2 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
oml.ui.listDialog = function() {
var ui = oml.user.ui,
list = ui._list,
that = Ox.Dialog({
buttons: [].concat(list && !Ox.endsWith(list, ':') ? [
Ox.Button({
id: 'duplicate',
title: Ox._('Duplicate List...')
})
.bindEvent({
click: function() {
that.close();
oml.addList(list);
}
})
] : []).concat(Ox.startsWith(list, ':') && list != '' ? [
Ox.Button({
id: 'delete',
title: Ox._('Delete List...')
})
.bindEvent({
click: function() {
that.close();
2014-05-14 09:57:11 +00:00
oml.ui.deleteListDialog().open();
2014-05-04 17:26:43 +00:00
}
})
] : []).concat([
{},
Ox.Button({
id: 'done',
title: Ox._('Done')
})
.bindEvent({
click: function() {
that.close();
}
})
]),
closeButton: true,
content: Ox.LoadingScreen().start(),
2014-05-14 09:57:11 +00:00
height: 264,
2014-05-17 14:42:46 +00:00
title: getTitle(list),
2014-05-04 17:26:43 +00:00
width: 648 + Ox.UI.SCROLLBAR_SIZE
});
oml.api.getLists(function(result) {
2014-05-12 23:43:27 +00:00
var lists = result.data.lists.filter(function(list) {
2014-05-25 14:05:26 +00:00
return list.user == '';
2014-05-12 23:43:27 +00:00
}),
2014-05-04 17:26:43 +00:00
listData = Ox.getObjectById(lists, list),
listNames = lists.map(function(list) {
return list.name;
}),
$content = Ox.Element()
.css({margin: '16px'}),
$nameInput = Ox.Input({
label: Ox._('Name'),
labelWidth: 128,
value: listData.name,
width: 616
})
.bindEvent({
change: function(data) {
2014-05-18 23:24:04 +00:00
var value = oml.getValidName(
data.value || Ox._('Untitled'),
listNames.filter(function(listName) {
return listName != listData.name;
})
);
2014-05-17 14:42:46 +00:00
that.options({title: getTitle(':' + value)})
2014-05-04 17:26:43 +00:00
$nameInput.value(value);
2014-05-17 14:42:46 +00:00
// FIXME: UGLY
listNames[listNames.indexOf(listData.name)] = value;
2014-05-25 20:59:03 +00:00
listData.id = ':' + value;
2014-05-17 14:42:46 +00:00
listData.name = value;
2014-05-25 20:59:03 +00:00
listData.title = value;
2014-05-19 15:00:33 +00:00
// ...
2014-05-04 17:26:43 +00:00
oml.api.editList({
2014-05-17 14:42:46 +00:00
id: ui._list,
2014-05-04 17:26:43 +00:00
name: value
}, function(result) {
2014-05-17 14:42:46 +00:00
oml.$ui.folders.updateOwnLists(function() {
2014-05-04 17:26:43 +00:00
oml.UI.set({
find: {
conditions: [{
key: 'list',
operator: '==',
value: ':' + value
}],
operator: '&'
}
2014-05-25 20:59:03 +00:00
}/*, false*/); // FIXME: ui._lists still outdated
2014-05-04 17:26:43 +00:00
});
});
}
})
2014-05-14 09:57:11 +00:00
.appendTo($content),
$findForm;
if (listData.type == 'smart') {
$findForm = oml.ui.findForm(listData)
.css({marginTop: '8px'})
2014-05-04 17:26:43 +00:00
.appendTo($content);
2014-05-14 09:57:11 +00:00
}
that.options({content: $content});
2014-05-18 23:24:04 +00:00
$nameInput.focusInput(true);
2014-05-04 17:26:43 +00:00
});
2014-05-17 14:42:46 +00:00
function getTitle(list) {
return Ox._('List {0}', [
list == '' ? Ox._('All Libraries')
: list
.replace(/^:/, oml.user.preferences.username + ':')
.replace(/:$/, Ox._(':Library'))
]);
}
2014-05-04 17:26:43 +00:00
return that;
2014-05-19 15:00:33 +00:00
};