pandora/static/js/pandora/ui/namesDialog.js

166 lines
5 KiB
JavaScript
Raw Normal View History

2011-10-11 11:29:05 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
pandora.ui.namesDialog = function() {
var height = Math.round((window.innerHeight - 48) * 0.9),
2011-10-11 16:01:33 +00:00
width = 576 + Ox.UI.SCROLLBAR_SIZE,
2011-10-11 11:29:05 +00:00
numberOfNames = 0,
$status = Ox.Label({
title: 'Loading...'
})
.css({float: 'left', margin: '4px'}),
$findSelect = Ox.Select({
items: [
{id: 'all', title: 'Find: All'}
],
overlap: 'right',
type: 'image'
})
.bindEvent({
change: function(data) {
var key = data.selected[0].id,
value = $findInput.value();
value && updateList(key, value);
$findInput.options({
placeholder: data.selected[0].title
});
}
}),
$findInput = Ox.Input({
changeOnKeypress: true,
clear: true,
placeholder: 'Find: All',
width: 192
})
.bindEvent({
change: function(data) {
var key = $findSelect.value(),
value = data.value;
updateList(key, value);
}
}),
$findElement = Ox.FormElementGroup({
elements: [
$findSelect,
$findInput
]
})
.css({float: 'right', margin: '4px'}),
$list = Ox.TextList({
columns: [
{
id: 'id',
title: 'ID',
unique: true,
visible: false,
2011-10-11 16:01:33 +00:00
width: 0
2011-10-11 11:29:05 +00:00
},
{
id: 'name',
operator: '+',
removable: false,
title: 'Name',
visible: true,
2011-10-11 16:01:33 +00:00
width: 256
2011-10-11 11:29:05 +00:00
},
{
2011-10-11 16:01:33 +00:00
editable: true,
id: 'sortname',
2011-10-11 11:29:05 +00:00
operator: '+',
title: 'Sort Name',
2011-10-11 16:01:33 +00:00
tooltip: 'Edit Sort Name',
2011-10-11 11:29:05 +00:00
visible: true,
2011-10-11 16:01:33 +00:00
width: 256
2011-10-11 11:29:05 +00:00
},
{
id: 'numberofnames',
align: 'right',
operator: '-',
2011-10-11 16:01:33 +00:00
title: 'Names',
2011-10-11 11:29:05 +00:00
visible: true,
2011-10-11 16:01:33 +00:00
width: 64
2011-10-11 11:29:05 +00:00
},
],
columnsRemovable: true,
columnsVisible: true,
items: pandora.api.findNames,
max: 1,
scrollbarVisible: true,
2011-10-11 16:01:33 +00:00
sort: [{key: 'sortname', operator: '+'}]
2011-10-11 11:29:05 +00:00
})
.bindEvent({
init: function(data) {
numberOfNames = data.items;
$status.options({
title: Ox.formatNumber(numberOfNames)
+ ' name' + (numberOfNames == 1 ? '' : 's')
});
},
2011-10-11 16:01:33 +00:00
submit: function(data) {
pandora.api.editName({
id: data.id,
sortname: data.sortname
});
2011-10-11 11:29:05 +00:00
}
}),
that = Ox.Dialog({
buttons: [
Ox.Button({
id: 'done',
title: 'Done'
}).bindEvent({
click: function() {
that.close();
}
})
],
closeButton: true,
content: Ox.SplitPanel({
elements: [
{
2011-10-11 16:01:33 +00:00
element: Ox.Bar({size: 24})
.append($status)
.append(
$findElement
),
size: 24
2011-10-11 11:29:05 +00:00
},
{
2011-10-11 16:01:33 +00:00
element: $list
2011-10-11 11:29:05 +00:00
}
],
2011-10-11 16:01:33 +00:00
orientation: 'vertical'
2011-10-11 11:29:05 +00:00
}),
height: height,
maximizeButton: true,
minHeight: 256,
minWidth: 512,
padding: 0,
title: 'Manage Names',
width: width
});
function updateList(key, value) {
var query = {
conditions: [{key: 'name', value: value, operator: '='}],
operator: '&'
};
$list.options({
items: function(data, callback) {
return pandora.api.findNames(Ox.extend(data, {
query: query
}), callback);
}
});
}
return that;
};