update account and preferences dialogs

This commit is contained in:
rolux 2011-10-22 14:50:53 +00:00
parent 3ac27ac27a
commit fbed9b12cc
4 changed files with 114 additions and 50 deletions

View file

@ -14,6 +14,13 @@ pandora.UI = (function() {
return !key ? self.previousUI : self.previousUI[key]; return !key ? self.previousUI : self.previousUI[key];
}; };
that.reset = function() {
pandora.user.ui = pandora.site.user.ui;
pandora.user.ui._list = pandora.getListsState(pandora.user.ui.find);
pandora.user.ui._groupsState = pandora.getGroupsState(pandora.user.ui.find);
pandora.user.ui._findState = pandora.getFindState(pandora.user.ui.find);
};
// sets pandora.user.ui.key to val // sets pandora.user.ui.key to val
// key foo.bar.baz sets pandora.user.ui.foo.bar.baz // key foo.bar.baz sets pandora.user.ui.foo.bar.baz
// val null removes a key // val null removes a key

View file

@ -1,51 +1,69 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript // vim: et:ts=4:sw=4:sts=4:ft=javascript
pandora.autovalidateCode = function(value, blur, callback) { pandora.autovalidateCode = function(value, blur, callback) {
value = value.toUpperCase().split('').map(function(v) { value = value.split('').map(function(v) {
return /[0-9A-Z]/.test(v) ? v : null; return /[A-Z]/.test(v) ? v : null;
}).join(''); }).join('').substr(0, 16);
callback(value); callback({valid: value.length == 16, value: value});
}; };
pandora.autovalidateEmail = function(value, blur, callback) { pandora.autovalidateEmail = function(value, blur, callback) {
value = value.toLowerCase().split('').map(function(v, i) { value = value.toLowerCase().split('').map(function(v, i) {
return /[0-9a-z\.\+\-_@]/.test(v) ? v : null; return /[0-9a-z\.\+\-_@]/.test(v) ? v : null;
}).join(''); }).join('').substr(0, 255);
callback(value); callback({valid: Ox.isValidEmail(value), value: value});
}; };
pandora.autovalidateListname = function(value, blur, callback) { pandora.autovalidateListname = function(value, blur, callback) {
// A valid listname consists of 1 to 255 unicode characters,
// without leading, trailing or consecutive spaces
var length = value.length; var length = value.length;
value = value.split('').map(function(v, i) { value = value.toLowerCase().split('').map(function(v, i) {
if (new RegExp('[0-9' + Ox.regexp.letters + '\\(\\)' + ((i == 0 || (i == length - 1 && blur)) ? '' : ' \-') + ']', 'i').test(v)) { return /\s/.test(v) && (i == 0 || (i == length - 1 && blur)) ? null : v;
return v;
} else {
return null;
}
}).join(''); }).join('');
[' ', ' -', '- ', '--', '\\(\\(', '\\)\\(', '\\)\\)'].forEach(function(v) { value = value.replace(/\s+/g, ' ').substr(0, 255);
//Ox.print(v, v[0], v[0] == '\\') callback({valid: !!value.length, value: value});
while (value.indexOf(v) > -1) {
value = value.replace(new RegExp(v, 'g'), v[0] + (v[0] == '\\' ? v[1] : ''));
}
});
callback(value);
}; };
pandora.autovalidateUsername = function(value, blur, callback) { pandora.autovalidateUsername = function(value, blur, callback) {
// A valid username consists of 1 to 255 unicode characters,
// without leading, trailing or consecutive spaces
var length = value.length; var length = value.length;
value = value.toLowerCase().split('').map(function(v, i) { value = value.toLowerCase().split('').map(function(v, i) {
if (new RegExp('[0-9a-z' + ((i == 0 || (i == length - 1 && blur)) ? '' : '\-_') + ']').test(v)) { return /\s/.test(v) && (i == 0 || (i == length - 1 && blur)) ? null : v;
return v;
} else {
return null;
}
}).join(''); }).join('');
['--', '-_', '_-', '__'].forEach(function(v) { value = value.replace(/\s+/g, ' ').substr(0, 255);
while (value.indexOf(v) > -1) { callback({valid: !!value.length, value: value});
value = value.replace(new RegExp(v, 'g'), v[0]); };
}
pandora.validateNewEmail = function(value, callback) {
value == pandora.user.email ? callback({
message: '',
valid: true,
value: value
}) : Ox.isValidEmail(value) ? pandora.api.findUser({
key: 'email',
value: value,
operator: '=='
}, function(result) {
callback({
message: 'E-mail address already exists',
valid: !result.data.users.length,
value: value
});
}) : callback({
message: (!value.length ? 'Missing' : 'Invalid') + ' e-mail address',
valid: false,
value: value
});
};
pandora.validateNewPassword = function(value, callback) {
callback({
message: 'Missing password',
valid: value.length > 0,
value: value
}); });
callback(value);
}; };
pandora.validateUser = function(key, existing) { pandora.validateUser = function(key, existing) {
@ -56,7 +74,7 @@ pandora.validateUser = function(key, existing) {
valid ? pandora.api.findUser({ valid ? pandora.api.findUser({
key: key, key: key,
value: value, value: value,
operator: '=' operator: '=='
}, function(result) { }, function(result) {
var valid = existing == !!result.data.users.length; var valid = existing == !!result.data.users.length;
//Ox.print(existing, result.data.users) //Ox.print(existing, result.data.users)

View file

@ -215,12 +215,7 @@ pandora.ui.accountForm = function(action, value) {
label: 'New Password', label: 'New Password',
labelWidth: 120, labelWidth: 120,
type: 'password', type: 'password',
validate: function(value, callback) { validate: pandora.validateNewPassword,
callback({
message: 'Missing password',
valid: value.length > 0
});
},
width: 320 width: 320
}); });
} else if (type == 'newUsername') { } else if (type == 'newUsername') {
@ -282,10 +277,12 @@ pandora.ui.accountForm = function(action, value) {
change: function(data) { change: function(data) {
var selected = data.selected[0].id; var selected = data.selected[0].id;
pandora.$ui.usernameOrEmailInput.options({ pandora.$ui.usernameOrEmailInput.options({
autovalidate: selected == 'username' ? pandora.autovalidateUsername : autovalidateEmail, autovalidate: selected == 'username'
validate: validateUser(selected, true), ? pandora.autovalidateUsername : pandora.autovalidateEmail,
validate: pandora.validateUser(selected, true),
value: '' value: ''
}).focus(); }).focus();
pandora.$ui.accountDialog.disableButton('submitReset');
} }
}), }),
pandora.$ui.usernameOrEmailInput = Ox.Input({ pandora.$ui.usernameOrEmailInput = Ox.Input({

View file

@ -26,24 +26,66 @@ pandora.ui.preferencesDialog = function() {
width: 320 width: 320
}), }),
Ox.Input({ Ox.Input({
autovalidate: /.+/,
id: 'password', id: 'password',
label: 'New Passowrd', label: 'New Password',
labelWidth: 120, labelWidth: 120,
type: 'password', type: 'password',
validate: pandora.validateNewPassword,
width: 320 width: 320
})
.bindEvent({
validate: function(data) {
data.valid && pandora.api.editPreferences({password: data.value});
}
}), }),
Ox.Input({ Ox.Input({
autovalidate: pandora.autovalidateEmail,
id: 'email', id: 'email',
label: 'E-Mail Address', label: 'E-Mail Address',
labelWidth: 120, labelWidth: 120,
validate: pandora.validateNewEmail,
value: pandora.user.email, value: pandora.user.email,
width: 320 width: 320
}) })
.bindEvent({
validate: function(data) {
if (data.valid && data.value != pandora.user.email) {
pandora.user.email = data.value;
pandora.api.editPreferences({email: data.value});
}
}
})
] ]
}) })
.css({position: 'absolute', left: '96px', top: '16px'}) .css({position: 'absolute', left: '96px', top: '16px'})
.bindEvent({
change: function(data) {
return;
var preferences = {};
preferences[data.id] = data.data.value;
pandora.api.editPreferences(preferences, function(result) {
if (data.id == 'email') {
pandora.user.email = data.data.value;
}
});
}
})
); );
} else { } else {
$content.append(
Ox.Button({
title: 'Reset UI Settings',
width: 150
})
.bindEvent({
click: function() {
pandora.UI.reset();
pandora.$ui.appPanel.reload();
}
})
.css({position: 'absolute', left: '96px', top: '16px'})
);
/* /*
content.append(Ox.FormElementGroup({ content.append(Ox.FormElementGroup({
elements: [ elements: [