openmedialibrary/static/js/listDialog.js

129 lines
4.5 KiB
JavaScript
Raw Normal View History

2014-05-04 19:26:43 +02: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',
2016-01-13 13:50:03 +05:30
style: 'squared',
2014-05-04 19:26:43 +02:00
title: Ox._('Duplicate List...')
})
.bindEvent({
click: function() {
that.close();
oml.addList(list);
}
})
] : []).concat(Ox.startsWith(list, ':') && list != '' ? [
Ox.Button({
id: 'delete',
2016-01-13 13:50:03 +05:30
style: 'squared',
2014-05-04 19:26:43 +02:00
title: Ox._('Delete List...')
})
.bindEvent({
click: function() {
that.close();
2014-05-14 11:57:11 +02:00
oml.ui.deleteListDialog().open();
2014-05-04 19:26:43 +02:00
}
})
] : []).concat([
{},
Ox.Button({
id: 'done',
2016-01-13 13:50:03 +05:30
style: 'squared',
2014-05-04 19:26:43 +02:00
title: Ox._('Done')
})
.bindEvent({
click: function() {
that.close();
}
})
]),
closeButton: true,
content: Ox.LoadingScreen().start(),
2014-05-14 11:57:11 +02:00
height: 264,
2016-01-08 14:20:08 +05:30
title: Ox.encodeHTMLEntities(getTitle(list)),
2014-05-04 19:26:43 +02:00
width: 648 + Ox.UI.SCROLLBAR_SIZE
});
oml.api.getLists(function(result) {
2014-05-13 01:43:27 +02:00
var lists = result.data.lists.filter(function(list) {
2014-05-25 16:05:26 +02:00
return list.user == '';
2014-05-13 01:43:27 +02:00
}),
2014-05-04 19:26:43 +02: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-19 01:24:04 +02:00
var value = oml.getValidName(
data.value || Ox._('Untitled'),
listNames.filter(function(listName) {
return listName != listData.name;
})
);
2016-01-08 15:47:38 +05:30
that.options({
title: Ox.encodeHTMLEntities(getTitle(':' + value))
});
2014-05-04 19:26:43 +02:00
$nameInput.value(value);
2014-05-17 16:42:46 +02:00
// FIXME: UGLY
listNames[listNames.indexOf(listData.name)] = value;
2014-05-25 22:59:03 +02:00
listData.id = ':' + value;
2014-05-17 16:42:46 +02:00
listData.name = value;
2014-05-25 22:59:03 +02:00
listData.title = value;
2014-05-19 17:00:33 +02:00
// ...
2014-05-04 19:26:43 +02:00
oml.api.editList({
2014-05-17 16:42:46 +02:00
id: ui._list,
2014-05-04 19:26:43 +02:00
name: value
}, function(result) {
2014-05-17 16:42:46 +02:00
oml.$ui.folders.updateOwnLists(function() {
2014-05-04 19:26:43 +02:00
oml.UI.set({
find: {
conditions: [{
key: 'list',
operator: '==',
value: ':' + value
}],
operator: '&'
}
2014-05-25 22:59:03 +02:00
}/*, false*/); // FIXME: ui._lists still outdated
2014-05-04 19:26:43 +02:00
});
});
}
})
2014-05-14 11:57:11 +02:00
.appendTo($content),
$findForm;
if (listData.type == 'smart') {
$findForm = oml.ui.findForm(listData)
.css({marginTop: '8px'})
2014-05-04 19:26:43 +02:00
.appendTo($content);
2014-05-14 11:57:11 +02:00
}
that.options({content: $content});
2014-05-19 01:24:04 +02:00
$nameInput.focusInput(true);
2014-05-04 19:26:43 +02:00
});
2014-05-17 16:42:46 +02:00
function getTitle(list) {
return Ox._('List {0}', [
list == '' ? Ox._('All Libraries')
: list
.replace(/^:/, oml.user.preferences.username + ':')
.replace(/:$/, Ox._(':Library'))
]);
}
2014-05-04 19:26:43 +02:00
return that;
2014-05-19 17:00:33 +02:00
};