openmedialibrary/static/js/listDialog.js

107 lines
3.6 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-04 17:26:43 +00:00
title: Ox._('List – {0}', [
ui._list == '' ? Ox._('All Libraries')
: ui._list
.replace(/^:/, oml.user.preferences.username + ':')
.replace(/:$/, Ox._(':Library'))
]),
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) {
return list.user == oml.user.preferences.username;
}),
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) {
var value = oml.validateName(data.value, listNames);
$nameInput.value(value);
oml.api.editList({
id: list,
name: value
}, function(result) {
oml.updateLists(function() {
oml.UI.set({
find: {
conditions: [{
key: 'list',
operator: '==',
value: ':' + value
}],
operator: '&'
}
});
});
});
}
})
2014-05-14 09:57:11 +00:00
.appendTo($content),
$findForm;
Ox.print('DEBUG:', list, listData)
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-04 17:26:43 +00:00
});
return that;
};