Merge pull request #5531 from acburdine/profile-fixes

Fixes the profile image uploader component
This commit is contained in:
Hannah Wolfe 2015-07-11 13:17:48 +01:00
commit 591467c47b
3 changed files with 12 additions and 7 deletions

View File

@ -51,8 +51,7 @@ export default Ember.Component.extend({
previewMaxWidth: size,
previewCrop: true,
maxNumberOfFiles: 1,
autoUpload: false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|svg?z)$/i
autoUpload: false
})
.on('fileuploadadd', Ember.run.bind(this, this.queueFile))
.on('fileuploadprocessalways', Ember.run.bind(this, this.triggerPreview));
@ -63,14 +62,17 @@ export default Ember.Component.extend({
},
queueFile: function (e, data) {
this.set('hasUploadedImage', true);
// send image data to controller
this.sendAction('setImage', data);
var fileName = data.files[0].name;
if ((/\.(gif|jpe?g|png|svg?z)$/i).test(fileName)) {
this.sendAction('setImage', data);
}
},
triggerPreview: function (e, data) {
var file = data.files[data.index];
if (file.preview) {
this.set('hasUploadedImage', true);
// necessary jQuery code because file.preview is a raw DOM object
// potential todo: rename 'gravatar-img' class in the CSS to be something
// that both the gravatar and the image preview can use that's not so confusing

View File

@ -47,7 +47,7 @@ export default Ember.Controller.extend(ValidationEngine, {
actions: {
setup: function () {
var self = this,
data = self.getProperties('blogTitle', 'name', 'email', 'password'),
data = self.getProperties('blogTitle', 'name', 'email', 'password', 'image'),
notifications = this.get('notifications');
this.toggleProperty('submitting');

View File

@ -14,7 +14,10 @@ var NewUserValidator = BaseValidator.extend({
email: function (model) {
var email = model.get('email');
if (!validator.isEmail(email)) {
if (validator.empty(email)) {
model.get('errors').add('email', 'Please enter an email.');
this.invalidate();
} else if (!validator.isEmail(email)) {
model.get('errors').add('email', 'Invalid Email.');
this.invalidate();
}