Created
January 19, 2012 15:38
-
-
Save ruprict/1640642 to your computer and use it in GitHub Desktop.
Tag hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Tag = Model.subclass(function (data) { | |
//HACK | |
if (data.owner !== null){ | |
this.mapping = { | |
owner: Model.mapping.object(data.ownerType) | |
} | |
if (data.owner.__ko_mapping__) { | |
data.owner = ko.mapping.toJS(data.owner); | |
} | |
}; | |
// END HACK | |
var objectFromCache = Model.call(this, 'tag', data); | |
if (objectFromCache) return objectFromCache; | |
this.initObservables({ | |
name: '', | |
owner:'', | |
ownerType: null, | |
postsCount: null | |
}); | |
this.objURL = ko.dependentObservable(function () { | |
if (this.owner() === null || this.owner() === "") return; // TODO: Why is this happening? | |
return App.sharedApp.objURL(this.ownerType(), this.owner().id()); | |
}, this); | |
if (data.owner === null) return; | |
this.score = ko.dependentObservable(function() { | |
var own = this.owner(); | |
if (!own) return; | |
if (this.ownerType() === "Event" && own.final() && own.team1Score()) { | |
var str = own.team1Score() + ":" + own.team2Score(); | |
return str; | |
} | |
return; | |
}, this); | |
this.displayName = ko.dependentObservable(function() { | |
var nm, | |
own = this.owner; | |
return this.name(); | |
}, this); | |
}); | |
Tag.prototype.apiResourceURL = function () { | |
return '/tags/'+ this.context() + ':' + this.name() + '.json'; | |
}; | |
Tag.prototype.mapping = { | |
owner: Model.mapping.object('User') | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment