(js) No 404 images with contacts chips

pull/186/head
Francis Lachapelle 2015-12-17 23:34:25 -05:00
parent f496f2b28f
commit 904c2f071a
3 changed files with 13 additions and 7 deletions

View File

@ -8,12 +8,12 @@
* @memberof SOGo.Common * @memberof SOGo.Common
* @param {string} email * @param {string} email
* @param {number} [size] - the size of the image * @param {number} [size] - the size of the image
* @param {string} alternate avatar to use * @param {string} alternate avatar to use (none, identicon, monsterid, wavatar, retro)
* @ngInject * @ngInject
*/ */
function Gravatar() { function Gravatar() {
return function(email, size, alternate_avatar) { return function(email, size, alternate_avatar, options) {
var x, y, hash, s = size; var x, y, hash, s = size, a = alternate_avatar;
if (!email) { if (!email) {
return ''; return '';
} }
@ -28,8 +28,12 @@
} }
hash = email.md5(); hash = email.md5();
if (alternate_avatar == "none") if (!a || a == "none") {
alternate_avatar = "404"; if (options && options.no_404)
alternate_avatar = "mm"; // mystery man alternative
else
alternate_avatar = "404";
}
return 'https://www.gravatar.com/avatar/' + hash + '?s=' + s + '&d=' + alternate_avatar; return 'https://www.gravatar.com/avatar/' + hash + '?s=' + s + '&d=' + alternate_avatar;
}; };

View File

@ -110,7 +110,7 @@
if (!this.$$shortFormat) if (!this.$$shortFormat)
this.$$shortFormat = this.$shortFormat(); this.$$shortFormat = this.$shortFormat();
if (!this.$$image) if (!this.$$image)
this.$$image = this.image || User.$gravatar(this.c_email, 32, User.$alternateAvatar); this.$$image = this.image || User.$gravatar(this.c_email, 32, User.$alternateAvatar, {no_404: true});
// An empty attribute to trick md-autocomplete when adding users from the ACLs editor // An empty attribute to trick md-autocomplete when adding users from the ACLs editor
this.empty = ' '; this.empty = ' ';

View File

@ -49,6 +49,8 @@
if (Preferences.defaults.SOGoContactsCategories) { if (Preferences.defaults.SOGoContactsCategories) {
Card.$categories = Preferences.defaults.SOGoContactsCategories; Card.$categories = Preferences.defaults.SOGoContactsCategories;
} }
if (Preferences.defaults.SOGoAlternateAvatar)
Card.$alternateAvatar = Preferences.defaults.SOGoAlternateAvatar;
}); });
return Card; // return constructor return Card; // return constructor
@ -131,7 +133,7 @@
if (!this.$$email) if (!this.$$email)
this.$$email = this.$preferredEmail(partial); this.$$email = this.$preferredEmail(partial);
if (!this.$$image) if (!this.$$image)
this.$$image = this.image || Card.$gravatar(this.$preferredEmail(partial), 32); this.$$image = this.image || Card.$gravatar(this.$preferredEmail(partial), 32, Card.$alternateAvatar, {no_404: true});
this.selected = false; this.selected = false;
// An empty attribute to trick md-autocomplete when adding attendees from the appointment editor // An empty attribute to trick md-autocomplete when adding attendees from the appointment editor