pandora/static/js/usersDialog.js

1029 lines
39 KiB
JavaScript
Raw Normal View History

// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-11-05 17:04:10 +00:00
'use strict';
pandora.ui.usersDialog = function() {
2011-10-03 09:31:20 +00:00
2012-03-21 13:07:19 +00:00
var browsers = [
2013-07-30 17:03:27 +00:00
'Camino', 'Chrome Frame', 'Chrome', 'Chromium', 'Epiphany',
2012-10-27 19:35:20 +00:00
'Firefox', 'Internet Explorer', 'Konqueror', 'Nokia Browser',
'Opera', 'Safari', 'WebKit'
2012-03-21 13:07:19 +00:00
],
dialogHeight = Math.round((window.innerHeight - 48) * 0.9),
2011-12-18 09:27:15 +00:00
dialogWidth = Math.round(window.innerWidth * 0.9),
formWidth = 256,
2011-10-03 09:31:20 +00:00
numberOfUsers = 0,
2012-03-21 13:07:19 +00:00
systems = [
2012-10-27 16:57:28 +00:00
'Android', 'BlackBerry', 'BSD', 'iOS', 'Java', 'Linux', 'Mac OS X',
2013-07-30 17:03:27 +00:00
'Nokia', 'PlayStation', 'RIM Tablet OS', 'Unix', 'Wii',
'Windows Phone', 'Windows'
2012-03-21 13:07:19 +00:00
],
2012-05-24 08:22:56 +00:00
userLevels = pandora.site.userLevels.map(function(userLevel) {
return Ox.toTitleCase(userLevel);
}).concat(['Robot']),
2011-10-03 09:31:20 +00:00
$reloadButton = Ox.Button({
disabled: true,
title: 'redo',
2013-05-09 10:13:58 +00:00
tooltip: Ox._('Reload'),
type: 'image'
})
.css({float: 'left', margin: '4px 2px 4px 4px'})
.bindEvent({
click: function() {
$reloadButton.options({disabled: true});
Ox.Request.clearCache('findUsers');
$list.reloadList(true);
}
}),
$guestsCheckbox = Ox.Checkbox({
2013-05-09 10:13:58 +00:00
title: Ox._('Include Guests'),
value: false
})
2013-04-26 09:11:17 +00:00
.css({float: 'left', margin: '4px 2px'})
.bindEvent({
change: function(data) {
data.value
? $robotsCheckbox.show()
: $robotsCheckbox.hide().options({value: false});
updateList();
}
}),
$robotsCheckbox = Ox.Checkbox({
2013-05-09 10:13:58 +00:00
title: Ox._('Include Robots'),
value: false
})
2013-04-26 09:11:17 +00:00
.css({float: 'left', margin: '4px 2px'})
.hide()
.bindEvent({
change: updateList
}),
2011-10-03 09:31:20 +00:00
$findSelect = Ox.Select({
items: [
2013-05-09 10:13:58 +00:00
{id: 'all', title: Ox._('Find: All')},
{id: 'username', title: Ox._('Find: Username')},
2014-09-30 12:26:14 +00:00
{id: 'email', title: Ox._('Find: E-Mail Address')},
{id: 'group', title: Ox._('Find: Group')}
2011-10-03 09:31:20 +00:00
],
overlap: 'right',
type: 'image'
})
.bindEvent({
change: function(data) {
$findInput.value() && updateList();
2013-03-24 09:39:43 +00:00
$findInput.options({placeholder: data.title});
2011-10-03 09:31:20 +00:00
}
}),
$findInput = Ox.Input({
changeOnKeypress: true,
clear: true,
2013-07-17 10:25:01 +00:00
placeholder: Ox._('Find: All'),
2011-10-03 09:31:20 +00:00
width: 192
})
.bindEvent({
change: updateList
2011-10-03 09:31:20 +00:00
}),
$findElement = Ox.FormElementGroup({
elements: [
$findSelect,
$findInput
]
})
.css({float: 'right', margin: '4px'}),
2012-06-27 07:41:39 +00:00
$list = Ox.TableList({
2011-10-03 09:31:20 +00:00
columns: [
{
format: function(value, data) {
2011-10-03 09:31:20 +00:00
return $('<img>')
.attr({
2014-09-26 12:30:51 +00:00
src: Ox.UI.getImageURL('symbolCheck')
2011-10-03 09:31:20 +00:00
})
.css({
width: '10px',
height: '10px',
padding: '3px',
opacity: value || [
'guest', 'robot'
].indexOf(data.level) > -1 ? 0 : 1
2011-10-03 09:31:20 +00:00
});
},
id: 'disabled',
operator: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('Enabled'),
2011-12-18 09:27:15 +00:00
titleImage: 'check',
2011-10-03 09:31:20 +00:00
visible: true,
width: 16
},
2012-04-19 14:26:52 +00:00
{
format: function(value) {
return $('<img>')
.attr({
2014-09-26 12:30:51 +00:00
src: Ox.UI.getImageURL('symbolMail')
2012-04-19 14:26:52 +00:00
})
.css({
width: '10px',
height: '10px',
padding: '3px',
opacity: +value
});
},
id: 'newsletter',
2013-05-09 10:13:58 +00:00
title: Ox._('Newsletter'),
2012-04-19 14:26:52 +00:00
titleImage: 'mail',
operator: '-',
visible: true,
width: 16
},
{
format: function(value, data) {
return '<span style="opacity: ' + (
data.disabled ? 0.5 : 1
) + '">' + Ox.encodeHTMLEntities(value) + '</span>';
},
id: 'username',
operator: '+',
removable: false,
2013-05-09 10:13:58 +00:00
title: Ox._('Username'),
visible: true,
width: 128
},
{
format: function(value, data) {
return '<span style="opacity: ' + (
data.disabled ? 0.5 : 1
) + '">' + value + '</span>';
},
id: 'email',
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('E-Mail Address'),
visible: true,
width: 192
},
{
align: 'center',
format: function(value) {
return Ox.Theme.formatColorLevel(
userLevels.indexOf(Ox.toTitleCase(value)),
userLevels,
[0, 300]
);
},
id: 'level',
operator: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('Level'),
type: 'label',
visible: true,
2014-03-04 19:37:15 +00:00
width: 80
},
{
format: function(value) {
return value ? Ox.Element({
2012-03-21 13:07:19 +00:00
element: '<img>',
tooltip: value
})
.attr({
src: Ox.getFlagByGeoname(value, 16)
2012-03-21 13:07:19 +00:00
})
.css({
width: '14px',
height: '14px',
borderRadius: '4px',
marginLeft: '-3px',
marginTop: 0
}) : '';
2012-03-21 13:07:19 +00:00
},
id: 'location',
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('Location'),
2012-03-21 13:07:19 +00:00
titleImage: 'flag',
visible: true,
width: 16
},
{
format: function(value) {
2012-03-21 14:01:18 +00:00
var system;
Ox.forEach(systems, function(s) {
if (new RegExp('^' + s).test(value)) {
system = s;
2012-07-04 11:40:37 +00:00
return false;
2012-03-21 13:07:19 +00:00
}
});
2012-03-21 14:01:18 +00:00
return system ? Ox.Element({
2012-03-21 13:07:19 +00:00
element: '<img>',
tooltip: value
2012-03-27 10:29:32 +00:00
.replace(/BSD \((.+)\)/, '$1')
.replace(/Linux \((.+)\)/, '$1')
.replace(/Unix \((.+)\)/, '$1')
.replace(/Windows (NT \d+\.\d+) \((.+)\)/, 'Windows $2 ($1)')
2012-03-21 13:07:19 +00:00
})
.attr({
2014-09-26 12:41:53 +00:00
src: Ox.UI.PATH + 'png/system'
2012-03-21 14:01:18 +00:00
+ system.replace(/ /g, '') + '128.png'
2012-03-21 13:07:19 +00:00
})
.css({
width: '14px',
height: '14px',
marginLeft: '-3px',
marginTop: 0
}) : '';
},
2012-03-21 14:01:18 +00:00
id: 'system',
2012-03-21 13:07:19 +00:00
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('System'),
2012-04-16 09:22:56 +00:00
titleImage: 'square',
2012-03-21 13:07:19 +00:00
visible: true,
2012-03-21 14:01:18 +00:00
width: 16
2012-03-21 13:07:19 +00:00
},
{
format: function(value) {
2012-03-21 14:01:18 +00:00
var browser;
Ox.forEach(browsers, function(b) {
if (new RegExp('^' + b).test(value)) {
browser = b;
2012-07-04 11:40:37 +00:00
return false;
2012-03-21 13:07:19 +00:00
}
});
2012-03-21 14:01:18 +00:00
return browser ? Ox.Element({
2012-03-21 13:07:19 +00:00
element: '<img>',
tooltip: value
})
.attr({
2014-09-26 12:41:53 +00:00
src: Ox.UI.PATH + 'png/browser'
2012-03-21 14:01:18 +00:00
+ browser.replace(/ /g, '') + '128.png'
2012-03-21 13:07:19 +00:00
})
.css({
width: '14px',
height: '14px',
marginLeft: '-3px',
marginTop: 0
}) : '';
},
2012-03-21 14:01:18 +00:00
id: 'browser',
2012-03-21 13:07:19 +00:00
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('Browser'),
2012-04-16 09:22:56 +00:00
titleImage: 'circle',
2012-03-21 13:07:19 +00:00
visible: true,
2012-03-21 14:01:18 +00:00
width: 16
2012-03-21 13:07:19 +00:00
},
2011-12-18 09:27:15 +00:00
{
align: 'right',
2011-12-18 09:27:15 +00:00
format: function(value) {
return Ox.formatNumber(value);
2011-12-18 09:27:15 +00:00
},
2011-10-03 09:31:20 +00:00
id: 'timesseen',
operator: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('Times Seen'),
2011-10-03 09:31:20 +00:00
visible: true,
width: 80
2011-10-03 09:31:20 +00:00
},
{
align: 'right',
2011-10-03 11:37:46 +00:00
format: function(value) {
2012-10-31 23:54:09 +00:00
return Ox.formatDate(value, '%F %T');
2011-10-03 11:37:46 +00:00
},
2011-10-03 09:31:20 +00:00
id: 'firstseen',
operator: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('First Seen'),
2011-10-03 09:31:20 +00:00
visible: true,
width: 144
2011-10-03 09:31:20 +00:00
},
{
align: 'right',
2011-10-03 11:37:46 +00:00
format: function(value) {
2012-10-31 23:54:09 +00:00
return Ox.formatDate(value, '%F %T');
2011-10-03 11:37:46 +00:00
},
2011-10-03 09:31:20 +00:00
id: 'lastseen',
operator: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('Last Seen'),
2011-10-03 09:31:20 +00:00
visible: true,
width: 144
2011-10-03 09:31:20 +00:00
},
{
align: 'right',
format: function(value, data) {
return ['guest', 'robot'].indexOf(data.level) > -1
? '' : value;
},
id: 'numberoflists',
operator: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('Lists'),
visible: true,
width: 64
},
{
id: 'groups',
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('Groups'),
visible: true,
width: 64
},
2011-10-03 09:31:20 +00:00
{
id: 'screensize',
align: 'right',
operator: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('Screen Size'),
2011-10-03 09:31:20 +00:00
visible: true,
width: 80
2011-10-03 09:31:20 +00:00
},
{
align: 'right',
id: 'windowsize',
operator: '-',
2013-05-09 10:13:58 +00:00
title: Ox._('Window Size'),
2011-10-03 09:31:20 +00:00
visible: true,
width: 80
2011-10-03 09:31:20 +00:00
},
2011-12-03 16:17:07 +00:00
{
2012-03-21 13:07:19 +00:00
align: 'right',
id: 'ip',
2011-12-03 16:17:07 +00:00
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('IP Address'),
2011-12-03 16:17:07 +00:00
visible: true,
width: 128
2011-12-03 16:17:07 +00:00
},
2011-10-03 09:31:20 +00:00
{
id: 'useragent',
2011-10-03 16:38:07 +00:00
operator: '+',
2013-05-09 10:13:58 +00:00
title: Ox._('User Agent'),
2011-10-03 09:31:20 +00:00
visible: true,
width: 768
2011-10-03 09:31:20 +00:00
}
],
columnsRemovable: true,
columnsVisible: true,
2012-06-20 10:47:15 +00:00
items: pandora.api.findUsers,
query: {
conditions: [
{key: 'level', value: 'guest', operator: '!='},
{key: 'level', value: 'robot', operator: '!='}
],
operator: '&'
},
2012-01-13 09:47:18 +00:00
keys: ['notes', 'groups'],
2011-12-18 09:27:15 +00:00
max: -1,
2011-10-03 09:31:20 +00:00
scrollbarVisible: true,
sort: [{key: 'lastseen', operator: '-'}],
unique: 'id'
2011-10-03 09:31:20 +00:00
})
.bindEvent({
init: function(data) {
numberOfUsers = data.users;
$status.html(
2011-11-07 14:46:16 +00:00
Ox.formatNumber(data.items)
+ ' user' + (data.items == 1 ? '' : 's')
+ (
$guestsCheckbox.value()
? ' (' + Ox.formatNumber(data.users) + ' registered, '
+ Ox.formatNumber(data.guests) + ' guest'
+ (data.guests == 1 ? '' : 's')
+ (
$robotsCheckbox.value()
? ', '
+ Ox.formatNumber(data.robots) + ' robot'
+ (data.robots == 1 ? '' : 's')
: ''
) + ')'
: ''
)
);
2011-10-03 09:31:20 +00:00
},
load: function() {
$reloadButton.options({disabled: false});
},
2011-12-18 09:27:15 +00:00
select: selectUsers
2011-10-03 09:31:20 +00:00
}),
2011-12-18 09:27:15 +00:00
$formButton = Ox.ButtonGroup({
buttons: [
2011-10-03 01:46:19 +00:00
{
2011-12-18 09:27:15 +00:00
id: 'edit',
selected: true,
title: 'edit',
2013-05-09 10:13:58 +00:00
tooltip: Ox._('Edit')
},
2011-10-03 01:46:19 +00:00
{
2011-12-18 09:27:15 +00:00
id: 'mail',
title: 'mail',
2013-05-09 10:13:58 +00:00
tooltip: Ox._('Mail')
2011-12-18 09:27:15 +00:00
}
],
selectable: true,
type: 'image'
})
.css({float: 'left', margin: '4px 2px 4px 4px'})
2011-12-18 09:27:15 +00:00
.bindEvent({
change: selectForm
}),
$formLabel = Ox.Label({
textAlign: 'center',
title: Ox._('No user selected'),
width: 192
})
.css({float: 'left', margin: '4px 2px'}),
$deselectButton = Ox.Button({
disabled: true,
title: 'close',
tooltip: Ox._('Done'),
type: 'image'
})
.css({float: 'left', margin: '4px 4px 4px 2px'})
.bindEvent({
click: function() {
$list.options({selected: []});
selectUsers({ids: []});
}
}),
2013-03-24 09:39:43 +00:00
$form = Ox.Element(),
2011-12-18 09:27:15 +00:00
$editForm,
$sendButton = Ox.Button({
disabled: true,
id: 'send',
2013-05-09 10:13:58 +00:00
title: Ox._('Send'),
width: 64
})
.bindEvent({
click: sendMail
}),
2011-12-18 09:27:15 +00:00
$mailForm = renderMailForm(),
$content = Ox.SplitPanel({
elements: [
{
element: Ox.SplitPanel({
elements: [
{
element: Ox.Bar({size: 24})
.append($reloadButton)
2011-12-18 09:27:15 +00:00
.append($guestsCheckbox)
.append($robotsCheckbox)
2011-12-18 09:27:15 +00:00
.append($findElement),
size: 24
},
{
element: $list
}
],
orientation: 'vertical'
})
},
{
element: Ox.SplitPanel({
2011-10-03 01:46:19 +00:00
elements: [
{
element: Ox.Bar({size: 24})
.append($formButton)
2011-12-18 09:27:15 +00:00
.append($formLabel)
.append($deselectButton),
2011-10-03 01:46:19 +00:00
size: 24
},
{
2011-12-18 09:27:15 +00:00
element: $form
2011-10-03 01:46:19 +00:00
}
],
orientation: 'vertical'
2011-12-18 09:27:15 +00:00
})
.bindEvent({
resize: setWidth
2011-10-03 01:46:19 +00:00
}),
2011-12-18 09:27:15 +00:00
resizable: true,
resize: [256, 384, 512],
size: 256
}
],
orientation: 'horizontal'
}),
that = Ox.Dialog({
buttons: [
Ox.Button({
id: 'statistics',
2013-05-09 10:13:58 +00:00
title: Ox._('Statistics...')
}).bindEvent({
click: function() {
that.close();
pandora.$ui.statisticsDialog = pandora.ui.statisticsDialog().open();
}
}),
{},
2011-12-18 09:27:15 +00:00
Ox.Button({
title: Ox._('Export E-Mail Addresses...')
2011-12-18 09:27:15 +00:00
})
.css({margin: '4px 4px 4px 0'})
.bindEvent({
click: function() {
var $button = this;
$button.options({disabled: true});
getEmailAddresses(function(items) {
pandora.ui.exportDialog({
data: items.filter(function(item) {
return item.email;
}).map(function(item) {
return Ox.encodeHTMLEntities(item.username)
+ ' <' + item.email + '>';
}).join(', '),
title: Ox._('E-Mail Addresses')
}).open();
$button.options({disabled: false});
2011-12-18 09:27:15 +00:00
});
}
}),
Ox.Button({
id: 'done',
2013-05-09 10:13:58 +00:00
title: Ox._('Done'),
2011-12-18 09:27:15 +00:00
width: 48
}).bindEvent({
click: function() {
that.close();
}
})
2011-10-03 01:46:19 +00:00
],
2011-12-18 09:27:15 +00:00
closeButton: true,
content: $content,
height: dialogHeight,
maximizeButton: true,
minHeight: 256,
minWidth: 512,
padding: 0,
removeOnClose: true,
2013-05-09 10:13:58 +00:00
title: Ox._('Manage Users'),
2011-12-18 09:27:15 +00:00
width: dialogWidth
})
.bindEvent({
resize: setHeight
2011-10-03 01:46:19 +00:00
}),
$status = $('<div>')
.css({
position: 'absolute',
top: '4px',
left: '128px',
right: '384px',
bottom: '4px',
paddingTop: '2px',
fontSize: '9px',
textAlign: 'center'
})
2012-05-22 13:15:16 +00:00
.appendTo(that.find('.OxButtonsbar'));
that.superClose = that.close;
that.close = function() {
Ox.Request.clearCache('findUsers');
that.superClose();
};
function getEmailAddresses(callback) {
pandora.api.findUsers({
query: {conditions: [
{key: 'level', value: 'guest', operator: '!='},
{key: 'level', value: 'robot', operator: '!='}
], operator: '&'},
keys: ['id', 'username', 'email'],
range: [0, 1000000],
sort: [{key: 'username', operator: '+'}]
}, function(result) {
var selected = $list.options('selected');
callback(result.data.items.filter(function(user) {
return !selected.length || Ox.contains(selected, user.id);
}).map(function(user) {
return {username: user.username, email: user.email};
}));
});
}
2011-12-18 09:27:15 +00:00
function getFormItemById(id) {
var ret;
Ox.forEach((
$formButton.value() == 'edit' ? $editForm : $mailForm
).options('items'), function($item) {
if ($item.options('id') == id) {
ret = $item;
2012-07-04 11:40:37 +00:00
return false;
2011-12-18 09:27:15 +00:00
}
});
return ret;
};
function getTo(callback) {
pandora.api.findUsers({
query: {conditions: [
{key: 'level', value: 'guest', operator: '!='},
{key: 'level', value: 'robot', operator: '!='}
], operator: '&'},
keys: ['id', 'username', 'newsletter'],
range: [0, numberOfUsers],
sort: [{key: 'username', operator: '+'}]
}, function(result) {
var selected = $list.options('selected');
callback(result.data.items.filter(function(user) {
return selected.indexOf(user.id) > -1
&& ($mailForm.values().include == 'users' || user.newsletter);
}).map(function(user) {
return user.username;
}));
2011-12-18 09:27:15 +00:00
});
}
2011-10-03 09:31:20 +00:00
2011-12-18 09:27:15 +00:00
function renderEditForm() {
var user = $list.value($list.options('selected')[0]),
$groupsLabel;
2011-10-03 09:31:20 +00:00
return Ox.Form({
2011-12-18 09:27:15 +00:00
items: [
Ox.Checkbox({
id: 'status',
2013-05-10 14:54:30 +00:00
label: Ox._('Status'),
2011-12-18 09:27:15 +00:00
labelWidth: 80,
2013-05-10 14:54:30 +00:00
title: !user.disabled ? Ox._('Enabled') : Ox._('Disabled'),
2011-12-22 15:48:48 +00:00
value: !user.disabled,
2011-12-18 09:27:15 +00:00
width: formWidth - 16
})
.bindEvent({
change: function(data) {
this.options({
2013-05-10 14:54:30 +00:00
title: this.options('title') == Ox._('Enabled')
? Ox._('Disabled') : Ox._('Enabled')
2011-12-18 09:27:15 +00:00
});
}
}),
Ox.Input({
id: 'username',
2013-05-10 14:54:30 +00:00
label: Ox._('Username'),
2011-12-18 09:27:15 +00:00
labelWidth: 80,
value: user.username,
width: formWidth - 16
})
.bindEvent({
submit: function(data) {
}
}),
Ox.Input({
id: 'email',
2013-05-10 14:54:30 +00:00
label: Ox._('E-Mail'),
2011-12-18 09:27:15 +00:00
labelWidth: 80,
value: user.email,
width: formWidth - 16
})
.bindEvent({
submit: function(data) {
2011-10-03 15:01:47 +00:00
2011-12-18 09:27:15 +00:00
}
}),
Ox.Select({
id: 'level',
2012-05-22 15:07:34 +00:00
items: pandora.site.userLevels.slice(1).map(function(level) {
return {
2011-12-18 09:27:15 +00:00
id: level,
title: Ox.toTitleCase(level)
2012-05-22 15:07:34 +00:00
};
2011-12-18 09:27:15 +00:00
}),
2013-05-10 14:54:30 +00:00
label: Ox._('Level'),
2011-12-18 09:27:15 +00:00
labelWidth: 80,
2011-12-22 15:48:48 +00:00
value: user.level,
2011-12-18 09:27:15 +00:00
width: formWidth - 16
}),
Ox.Checkbox({
id: 'newsletter',
2013-05-10 14:54:30 +00:00
label: Ox._('Newsletter'),
2011-10-03 15:01:47 +00:00
labelWidth: 80,
2013-05-10 14:54:30 +00:00
title: user.newsletter ? Ox._('Subscribed') : Ox._('Unsubscribed'),
2011-12-22 15:48:48 +00:00
value: user.newsletter,
2011-12-18 09:27:15 +00:00
width: formWidth - 16
})
.bindEvent({
change: function(data) {
this.options({
2013-05-10 14:54:30 +00:00
title: this.options('title') == Ox._('Subscribed')
? Ox._('Unsubscribed') : Ox._('Subscribed')
2011-12-18 09:27:15 +00:00
});
}
}),
Ox.FormElementGroup({
elements: [
Ox.Label({
overlap: 'right',
textAlign: 'right',
title: Ox._('Groups'),
width: 80
}),
Ox.FormElementGroup({
elements: [
$groupsLabel = Ox.Label({
title: user.groups ? user.groups.join(', ') : '',
width: formWidth - 112
}),
Ox.Button({
overlap: 'left',
title: 'edit',
tooltip: Ox._('Edit Groups'),
type: 'image'
})
.bindEvent({
click: function() {
pandora.$ui.groupsDialog = pandora.ui.groupsDialog({
id: user.id,
name: user.username,
type: 'user'
})
.bindEvent({
groups: function(data) {
var groups = data.groups.join(', ');
$list.value(user.id, 'groups', groups);
$groupsLabel.options({title: groups});
}
})
.open();
}
})
],
float: 'right'
})
],
float: 'left'
}),
2011-12-18 09:27:15 +00:00
Ox.Input({
height: dialogHeight - 184,
2011-12-18 09:27:15 +00:00
id: 'notes',
2013-05-10 14:54:30 +00:00
placeholder: Ox._('Notes'),
2011-12-18 09:27:15 +00:00
type: 'textarea',
value: user.notes,
width: formWidth - 16
})
],
width: 240
})
.css({margin: '8px'})
.bindEvent({
change: function(event) {
var data = {id: user.id}, key, value;
if (event.id == 'status') {
2011-12-21 15:34:28 +00:00
data.disabled = !event.data.value;
2011-12-18 09:27:15 +00:00
} else if (event.id == 'level') {
2011-12-21 15:34:28 +00:00
data.level = event.data.value;
2011-12-18 09:27:15 +00:00
} else if (event.id == 'newsletter') {
2011-12-21 15:34:28 +00:00
data.newsletter = event.data.value;
2011-12-18 09:27:15 +00:00
} else {
data[event.id] = event.data.value;
}
if (event.id == 'status') {
$list.value(user.id, 'disabled', data.disabled);
} else {
$list.value(user.id, event.id, data[event.id]);
}
2011-12-18 09:27:15 +00:00
pandora.api.editUser(data, function(result) {
Ox.Request.clearCache('findUsers');
});
}
});
}
function renderMailForm() {
return Ox.Form({
items: [
Ox.Input({
disabled: true,
id: 'from',
2013-05-10 15:15:07 +00:00
label: Ox._('From'),
2011-12-18 09:27:15 +00:00
labelWidth: 80,
value: pandora.site.site.name + ' <' + pandora.site.site.email.contact + '>',
width: formWidth - 16
}),
Ox.Input({
disabled: true,
id: 'to',
2013-05-10 14:54:30 +00:00
label: Ox._('To'),
2011-12-18 09:27:15 +00:00
labelWidth: 80,
value: '',
width: formWidth - 16
}),
Ox.Select({
id: 'include',
items: [
2013-05-09 10:13:58 +00:00
{id: 'users', title: Ox._('All users')},
{id: 'subscribers', title: Ox._('Subscribers only')},
2011-12-18 09:27:15 +00:00
],
2013-05-10 14:54:30 +00:00
label: Ox._('Include'),
2011-12-18 09:27:15 +00:00
labelWidth: 80,
width: formWidth - 16
})
.bindEvent({
change: function() {
setTo(setSend);
2011-12-18 09:27:15 +00:00
}
2011-10-03 09:31:20 +00:00
}),
2011-12-18 09:27:15 +00:00
Ox.Input({
id: 'subject',
2013-05-10 14:54:30 +00:00
label: Ox._('Subject'),
2011-12-18 09:27:15 +00:00
labelWidth: 80,
value: pandora.site.site.email.prefix + ' ',
width: formWidth - 16
})
.bindEvent({
change: setSend
2011-10-03 09:31:20 +00:00
}),
2011-12-18 09:27:15 +00:00
Ox.Input({
height: dialogHeight - 208,
id: 'message',
2013-05-10 14:54:30 +00:00
placeholder: Ox._('Message'),
2011-10-03 09:31:20 +00:00
type: 'textarea',
2011-12-18 09:27:15 +00:00
value: '\n\n' + pandora.site.site.email.footer,
width: formWidth - 16
2011-10-03 09:31:20 +00:00
})
2011-12-18 09:27:15 +00:00
.bindEvent({
change: setSend
}),
2011-12-20 07:20:23 +00:00
Ox.MenuButton({
2011-12-18 09:27:15 +00:00
id: 'insert',
items: [
2013-05-09 10:13:58 +00:00
{id: 'username', title: Ox._('Username')},
2013-05-20 19:14:57 +00:00
{id: 'email', title: Ox._('E-Mail Address')},
2011-12-18 09:27:15 +00:00
],
2013-05-09 10:13:58 +00:00
title: Ox._('Insert...'),
2011-12-18 09:27:15 +00:00
width: formWidth - 16
})
.bindEvent({
click: function(data) {
var $input = getFormItemById('message'),
textarea = $input.find('textarea')[0],
2011-12-21 15:34:28 +00:00
value = $input.value();
$input.value(
2012-05-24 09:56:52 +00:00
value.slice(0, textarea.selectionStart)
2011-12-21 15:34:28 +00:00
+ '{' + data.id + '}'
2012-05-24 09:56:52 +00:00
+ value.slice(textarea.selectionEnd)
2011-12-21 15:34:28 +00:00
)
2011-12-18 09:27:15 +00:00
.focusInput(textarea.selectionStart + data.id.length + 2);
}
}),
Ox.Checkbox({
id: 'receipt',
2013-05-09 10:13:58 +00:00
title: Ox._('Send a receipt to {0}', [pandora.user.email]),
2011-12-22 15:48:48 +00:00
value: false,
2011-12-18 09:27:15 +00:00
width: formWidth - 16
}),
$sendButton
2011-12-18 09:27:15 +00:00
],
width: formWidth - 16
})
.css({margin: '8px', textAlign: 'right'});
}
function selectForm(data) {
var selected;
2011-12-21 15:34:28 +00:00
if (data.value == 'edit') {
2011-12-18 09:27:15 +00:00
$mailForm.detach();
selected = $list.options('selected');
if (selected.length == 1 && ['guest', 'robot'].indexOf(selected[0].level) == -1) {
2011-12-18 09:27:15 +00:00
$form.append($editForm = renderEditForm());
}
} else {
setTo(setSend);
2011-12-18 09:27:15 +00:00
setWidth();
$editForm && $editForm.remove();
$form.append($mailForm);
}
}
function selectUsers(data) {
var users = data.ids.map(function(id) {
2011-12-18 09:27:15 +00:00
return $list.value(id);
});
setLabel();
$deselectButton.options({disabled: data.ids.length == 0});
2011-12-18 09:27:15 +00:00
if ($formButton.value() == 'edit') {
$form.empty();
if (
data.ids.length == 1
&& ['guest', 'robot'].indexOf(users[0].level) == -1
) {
$form.append($editForm = renderEditForm());
2011-12-18 09:27:15 +00:00
}
} else {
setTo(setSend);
2011-12-18 09:27:15 +00:00
}
}
function sendMail() {
2013-05-09 10:13:58 +00:00
$sendButton.options({title: Ox._('Sending'), disabled: true});
getTo(function(to) {
pandora.api.mail({
to: to,
subject: getFormItemById('subject').value(),
message: getFormItemById('message').value(),
receipt: getFormItemById('receipt').value()
}, function(result) {
var $dialog = pandora.ui.iconDialog({
buttons: [
Ox.Button({
id: 'close',
title: Ox._('Close')
})
.bindEvent({
click: function() {
$dialog.close();
}
})
],
content: result.status.code == 200
? Ox._('Your message has been sent.')
: Ox._('Your message could not be sent. Please try again.'),
keys: {enter: 'close', escape: 'close'},
title: result.status.code == 200
? Ox._('Message Sent')
: Ox._('Application Error')
}).open();
$sendButton.options({title: Ox._('Send'), disabled: false});
});
2011-12-18 09:27:15 +00:00
});
}
function setHeight(data) {
2011-12-21 15:34:28 +00:00
var form = $formButton.value(),
2011-12-18 09:27:15 +00:00
$item = getFormItemById(form == 'edit' ? 'notes' : 'message');
dialogHeight = data.height;
$item && $item.options({
height: dialogHeight - (form == 'edit' ? 160 : 208)
});
}
function setLabel() {
var users = $list.options('selected').map(function(id) {
return $list.value(id);
}),
2013-05-09 10:13:58 +00:00
title = users.length == 0 ? Ox._('No user selected')
2011-12-18 09:27:15 +00:00
: users.length == 1 ? (
['guest', 'robot'].indexOf(users[0].level) > -1
? Ox.toTitleCase(users[0].level)
: Ox.encodeHTMLEntities(users[0].username)
+ ' &lt;' + users[0].email + '&gt;'
2011-12-18 09:27:15 +00:00
)
2013-05-09 10:13:58 +00:00
: Ox._('{0} users selected', [users.length]);
2011-12-18 09:27:15 +00:00
$formLabel.options({title: title});
}
function setSend() {
getFormItemById('send').options({
2013-05-09 10:13:58 +00:00
disabled: getFormItemById('to').value() == Ox._('No recipients')
2011-12-21 15:34:28 +00:00
|| getFormItemById('subject').value() === ''
|| getFormItemById('message').value() === ''
2011-12-18 09:27:15 +00:00
});
}
function setTo(callback) {
getTo(function(to) {
var recipients = to.length;
$mailForm.values({
to: Ox.formatCount(recipients, 'recipient').replace('no', 'No')
});
callback();
2011-12-18 09:27:15 +00:00
});
}
function setWidth() {
var $form = $formButton.value() == 'edit' ? $editForm : $mailForm;
2011-12-18 09:27:15 +00:00
formWidth = $content.size(1);
$formLabel.options({width: formWidth - 64});
$form && $form.options('items').forEach(function($item) {
2011-12-18 09:27:15 +00:00
if ($item.options('id') != 'send') {
$item.options({width: formWidth - 16});
}
});
$status.css({right: formWidth + 128 + 'px'});
2011-10-03 09:31:20 +00:00
}
function updateList() {
var guests = $guestsCheckbox.value(),
robots = $robotsCheckbox.value(),
key = $findSelect.value(),
value = $findInput.value(),
query = {
conditions: value
2012-05-24 08:22:56 +00:00
? [].concat(
2014-09-30 12:26:14 +00:00
Ox.contains(['username', 'all'], key) ? [{key: 'username', value: value, operator: '='}] : [],
Ox.contains(['email', 'all'], key) ? [{key: 'email', value: value, operator: '='}] : [],
Ox.contains(['group', 'all'], key) ? [{key: 'group', value: value, operator: '='}] : []
)
2012-05-24 08:22:56 +00:00
: [].concat(
!guests ? [{key: 'level', value: 'guest', operator: '!='}] : [],
!robots ? [{key: 'level', value: 'robot', operator: '!='}] : []
),
operator: key == 'all' && value ? '|' : '&'
2011-10-03 09:31:20 +00:00
};
2013-03-24 09:39:43 +00:00
$list.options({query: query});
2011-10-03 09:31:20 +00:00
}
return that;
2011-10-03 09:31:20 +00:00
};