wejsv2old-plugin-cdp-profile
Version:
We.js plugin wejsv2old-plugin-cdp-profile
65 lines (52 loc) • 1.75 kB
JavaScript
$( document ).ready(function (){
App.UserIndexController = Ember.ObjectController.extend({
relatosProxy: function () {
return Ember.ArrayProxy.createWithMixins(Ember.SortableMixin, {
sortProperties: ['createdAt'],
sortAscending: false,
content: this.get('relatos')
});
}.property('relatos'),
currentUser: function (){
return App.get('currentUser');
}.property('App.currentUser'),
comunidadesProxy: function (){
return this.get('comunidades').map(function (comunidade) {
comunidade.bgdImg = 'background-image: url(' + comunidade.logo + ')';
return comunidade;
})
}.property('comunidades.[]'),
compatibilityClass: function (){
if ( !this.get('compatibility') ) {
return 'p00';
}
return 'p' + this.get('compatibility');
}.property('compatibility'),
compatibility: function (){
var compAux = 0;
if ( !App.get('currentUser') || this.get('ownProfile') ) {
return compAux;
}
var cUserInterests = App.get('currentUser.interests');
var cUserInterestsAjd = App.get('currentUser.interestsAjd');
var userInterests = this.get('user.interests');
var userInterestsAjd = this.get('user.interestsAjd');
if ( cUserInterestsAjd ) {
cUserInterestsAjd.forEach(function (intAjd, i, arr){
if ( userInterests.isAny('id', intAjd.id) ) {
return compAux++;
}
});
}
if ( cUserInterests ) {
cUserInterests.forEach(function (intAjd, i, arr){
if ( userInterestsAjd.isAny('id', intAjd.id) ) {
return compAux++;
}
});
}
var total = userInterests.get('length') + userInterestsAjd.get('length');
return Math.round( ( compAux / total ) * 100 ) || 0;
}.property('user', 'App.currentUser')
});
});