forked from 0x2620/pandora
update account and preferences dialogs
This commit is contained in:
parent
3ac27ac27a
commit
fbed9b12cc
4 changed files with 114 additions and 50 deletions
|
@ -14,6 +14,13 @@ pandora.UI = (function() {
|
|||
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
|
||||
// key foo.bar.baz sets pandora.user.ui.foo.bar.baz
|
||||
// val null removes a key
|
||||
|
|
|
@ -1,51 +1,69 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
||||
|
||||
pandora.autovalidateCode = function(value, blur, callback) {
|
||||
value = value.toUpperCase().split('').map(function(v) {
|
||||
return /[0-9A-Z]/.test(v) ? v : null;
|
||||
}).join('');
|
||||
callback(value);
|
||||
value = value.split('').map(function(v) {
|
||||
return /[A-Z]/.test(v) ? v : null;
|
||||
}).join('').substr(0, 16);
|
||||
callback({valid: value.length == 16, value: value});
|
||||
};
|
||||
|
||||
pandora.autovalidateEmail = function(value, blur, callback) {
|
||||
value = value.toLowerCase().split('').map(function(v, i) {
|
||||
return /[0-9a-z\.\+\-_@]/.test(v) ? v : null;
|
||||
}).join('');
|
||||
callback(value);
|
||||
}).join('').substr(0, 255);
|
||||
callback({valid: Ox.isValidEmail(value), value: value});
|
||||
};
|
||||
|
||||
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;
|
||||
value = value.split('').map(function(v, i) {
|
||||
if (new RegExp('[0-9' + Ox.regexp.letters + '\\(\\)' + ((i == 0 || (i == length - 1 && blur)) ? '' : ' \-') + ']', 'i').test(v)) {
|
||||
return v;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
value = value.toLowerCase().split('').map(function(v, i) {
|
||||
return /\s/.test(v) && (i == 0 || (i == length - 1 && blur)) ? null : v;
|
||||
}).join('');
|
||||
[' ', ' -', '- ', '--', '\\(\\(', '\\)\\(', '\\)\\)'].forEach(function(v) {
|
||||
//Ox.print(v, v[0], v[0] == '\\')
|
||||
while (value.indexOf(v) > -1) {
|
||||
value = value.replace(new RegExp(v, 'g'), v[0] + (v[0] == '\\' ? v[1] : ''));
|
||||
}
|
||||
});
|
||||
callback(value);
|
||||
value = value.replace(/\s+/g, ' ').substr(0, 255);
|
||||
callback({valid: !!value.length, value: value});
|
||||
};
|
||||
|
||||
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;
|
||||
value = value.toLowerCase().split('').map(function(v, i) {
|
||||
if (new RegExp('[0-9a-z' + ((i == 0 || (i == length - 1 && blur)) ? '' : '\-_') + ']').test(v)) {
|
||||
return v;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return /\s/.test(v) && (i == 0 || (i == length - 1 && blur)) ? null : v;
|
||||
}).join('');
|
||||
['--', '-_', '_-', '__'].forEach(function(v) {
|
||||
while (value.indexOf(v) > -1) {
|
||||
value = value.replace(new RegExp(v, 'g'), v[0]);
|
||||
}
|
||||
value = value.replace(/\s+/g, ' ').substr(0, 255);
|
||||
callback({valid: !!value.length, value: value});
|
||||
};
|
||||
|
||||
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) {
|
||||
|
@ -56,7 +74,7 @@ pandora.validateUser = function(key, existing) {
|
|||
valid ? pandora.api.findUser({
|
||||
key: key,
|
||||
value: value,
|
||||
operator: '='
|
||||
operator: '=='
|
||||
}, function(result) {
|
||||
var valid = existing == !!result.data.users.length;
|
||||
//Ox.print(existing, result.data.users)
|
||||
|
|
|
@ -215,12 +215,7 @@ pandora.ui.accountForm = function(action, value) {
|
|||
label: 'New Password',
|
||||
labelWidth: 120,
|
||||
type: 'password',
|
||||
validate: function(value, callback) {
|
||||
callback({
|
||||
message: 'Missing password',
|
||||
valid: value.length > 0
|
||||
});
|
||||
},
|
||||
validate: pandora.validateNewPassword,
|
||||
width: 320
|
||||
});
|
||||
} else if (type == 'newUsername') {
|
||||
|
@ -282,10 +277,12 @@ pandora.ui.accountForm = function(action, value) {
|
|||
change: function(data) {
|
||||
var selected = data.selected[0].id;
|
||||
pandora.$ui.usernameOrEmailInput.options({
|
||||
autovalidate: selected == 'username' ? pandora.autovalidateUsername : autovalidateEmail,
|
||||
validate: validateUser(selected, true),
|
||||
autovalidate: selected == 'username'
|
||||
? pandora.autovalidateUsername : pandora.autovalidateEmail,
|
||||
validate: pandora.validateUser(selected, true),
|
||||
value: ''
|
||||
}).focus();
|
||||
pandora.$ui.accountDialog.disableButton('submitReset');
|
||||
}
|
||||
}),
|
||||
pandora.$ui.usernameOrEmailInput = Ox.Input({
|
||||
|
|
|
@ -26,24 +26,66 @@ pandora.ui.preferencesDialog = function() {
|
|||
width: 320
|
||||
}),
|
||||
Ox.Input({
|
||||
autovalidate: /.+/,
|
||||
id: 'password',
|
||||
label: 'New Passowrd',
|
||||
label: 'New Password',
|
||||
labelWidth: 120,
|
||||
type: 'password',
|
||||
validate: pandora.validateNewPassword,
|
||||
width: 320
|
||||
})
|
||||
.bindEvent({
|
||||
validate: function(data) {
|
||||
data.valid && pandora.api.editPreferences({password: data.value});
|
||||
}
|
||||
}),
|
||||
Ox.Input({
|
||||
autovalidate: pandora.autovalidateEmail,
|
||||
id: 'email',
|
||||
label: 'E-Mail Address',
|
||||
labelWidth: 120,
|
||||
validate: pandora.validateNewEmail,
|
||||
value: pandora.user.email,
|
||||
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'})
|
||||
.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 {
|
||||
$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({
|
||||
elements: [
|
||||
|
|
Loading…
Reference in a new issue