pandora/static/js/namesDialog.js

192 lines
6.4 KiB
JavaScript
Raw Normal View History

2011-10-11 11:29:05 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-11-05 17:04:10 +00:00
'use strict';
2011-10-11 11:29:05 +00:00
pandora.ui.namesDialog = function() {
// FIXME: add cache invalidation
2011-10-11 11:29:05 +00:00
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,
$findInput = Ox.Input({
changeOnKeypress: true,
clear: true,
placeholder: 'Find',
2011-10-11 11:29:05 +00:00
width: 192
})
.css({float: 'right', margin: '4px'})
2011-10-11 11:29:05 +00:00
.bindEvent({
change: function(data) {
var query = {
conditions: [
{key: 'name', value: data.value, operator: '='},
{key: 'sortname', value: data.value, operator: '='}
],
operator: '|'
};
$list.options({
2012-06-20 10:47:15 +00:00
query: query,
2011-10-29 17:46:46 +00:00
});
2011-10-11 11:29:05 +00:00
}
}),
2012-06-27 07:41:39 +00:00
$list = Ox.TableList({
2011-10-11 11:29:05 +00:00
columns: [
{
id: 'id',
2013-05-09 10:13:58 +00:00
title: Ox._('ID'),
2011-10-11 11:29:05 +00:00
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,
2013-05-09 10:13:58 +00:00
title: Ox._('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
},
{
2011-10-11 16:01:33 +00:00
editable: true,
id: 'sortname',
2011-10-11 11:29:05 +00:00
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('Sort Name'),
tooltip: Ox._('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: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('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
},
],
columnsVisible: true,
items: pandora.api.findNames,
max: 1,
scrollbarVisible: true,
sort: [{key: 'sortname', operator: '+'}],
unique: 'id'
2011-10-11 11:29:05 +00:00
})
.bindEvent({
init: function(data) {
numberOfNames = data.items;
2013-07-17 10:25:01 +00:00
$status.html(Ox.formatCount(numberOfNames, 'name'));
2011-10-11 11:29:05 +00:00
},
open: function(data) {
2012-05-22 13:15:16 +00:00
$list.find('.OxItem.OxSelected > .OxCell.OxColumnSortname')
.trigger('mousedown')
.trigger('mouseup');
},
select: function(data) {
$findButton.options({disabled: !data.ids.length});
},
2011-10-11 16:01:33 +00:00
submit: function(data) {
Ox.Request.clearCache('findNames');
2011-10-11 16:01:33 +00:00
pandora.api.editName({
id: data.id,
2011-10-11 16:58:12 +00:00
sortname: data.value
2011-10-11 16:01:33 +00:00
});
2011-10-11 11:29:05 +00:00
}
}),
$findButton = Ox.Button({
disabled: true,
2013-05-09 10:13:58 +00:00
title: Ox._('Find'),
2012-05-26 15:46:24 +00:00
width: 48
}).bindEvent({
click: function() {
that.close();
2013-07-14 15:36:49 +00:00
pandora.UI.set({find: {
conditions: [{
key: 'name',
value: $list.value($list.options('selected'), 'name'),
operator: '='
}],
operator: '&'
2013-07-14 15:36:49 +00:00
}});
2012-06-11 08:50:03 +00:00
pandora.$ui.findElement.updateElement();
}
}),
2011-10-29 17:46:46 +00:00
2011-10-11 11:29:05 +00:00
that = Ox.Dialog({
buttons: [
Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('Manage Titles...')
}).bindEvent({
click: function() {
that.close();
(pandora.$ui.titlesDialog || (
pandora.$ui.titlesDialog = pandora.ui.titlesDialog()
)).open();
}
}),
{},
$findButton,
Ox.Button({
2013-05-09 10:13:58 +00:00
title: Ox._('Done'),
width: 48
}).bindEvent({
click: function() {
that.close();
}
})
2011-10-11 11:29:05 +00:00
],
closeButton: true,
content: Ox.SplitPanel({
elements: [
{
element: Ox.Bar({size: 24})
.append($status)
.append(
$findInput
),
size: 24
},
{
element: $list
}
],
orientation: 'vertical'
}),
height: height,
maximizeButton: true,
minHeight: 256,
minWidth: 512,
padding: 0,
2013-05-09 10:13:58 +00:00
title: Ox._('Manage Names'),
width: width
})
.bindEvent({
resizeend: function(data) {
var width = (data.width - 64 - Ox.UI.SCROLLBAR_SIZE) / 2;
[
{id: 'name', width: Math.ceil(width)},
{id: 'sortname', width: Math.floor(width)}
].forEach(function(column) {
$list.resizeColumn(column.id, column.width);
});
}
2011-10-11 11:29:05 +00:00
}),
$status = $('<div>')
.css({
position: 'absolute',
top: '4px',
left: '128px',
right: '128px',
bottom: '4px',
paddingTop: '2px',
fontSize: '9px',
textAlign: 'center'
})
.appendTo(that.find('.OxButtonsbar'));
2011-10-11 11:29:05 +00:00
return that;
};