Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Created September 7, 2010 20:17
Show Gist options
  • Save joegaudet/569016 to your computer and use it in GitHub Desktop.
Save joegaudet/569016 to your computer and use it in GitHub Desktop.
// ==========================================================================
// Project: DarkHorse - The PC Browser targeted face of the Matygo Web App
// Copyright: ©2010 Matygo Educational Incorporated
// ==========================================================================
/*globals DarkHorse */
/** @class
(Document your Model here)
@extends SC.Record
@version 0.1
*/
sc_require('models/comment');
DarkHorse.FeedItem = SC.Record.extend(
/** @scope DarkHorse.FeedItem.prototype */ {
sourceName: SC.Record.attr(String),
sourceType: SC.Record.attr(String),
sourceGuid: SC.Record.attr(String),
source: function(){
var sourceModel = null;
var retval = null;
switch(this.get('sourceType')){
case 'Course': sourceModel = DarkHorse.Course; break;
}
if(sourceModel){
retval = DarkHorse.store.find(sourceModel,this.get('sourceGuid'));
}
return retval;
}.property(),
// slug line
subject: SC.Record.attr(String),
// content
content: SC.Record.attr(String),
publishedOn: SC.Record.attr(SC.DateTime),
exampleView: function(){
var retval = DarkHorse.SchoolFeedItem;
switch(this.get('sourceType')){
case 'School': retval = DarkHorse.SchoolFeedItem; break;
case 'Course': retval = DarkHorse.CourseFeedItem; break;
case 'Person': retval = DarkHorse.PersonFeedItem; break;
case 'Matygo': retval = DarkHorse.MatygoFeedItem; break;
}
return retval;
}.property(),
icon:function(){
var retval = static_url('resources/images/icons/matygo-icon-64.png');
switch(this.get('sourceType')){
case 'School': retval = static_url('resources/images/icons/school-icon-64.png'); break;
case 'Course': retval = static_url('resources/images/icons/course-icon-64.png'); break;
case 'Person': retval = static_url('resources/images/icons/person-icon-64.png'); break;
}
return retval;
}.property(),
showSourceText: function() {
return "goto " + this.get('sourceType').toLowerCase();
}.property(),
sourceLine: function(){
return this.get('sourceName') + " : " + this.get('publishedOn').toFormattedString("%a - %b %d, %i:%M");
}.property(),
// --------------------------------------------------------
// Relationships
//
comments: SC.Record.toMany("DarkHorse.Comment",{
inverse: "feedItem",
isMaster: YES
}),
findComments: function(){
DarkHorse.store.find(this.get('commentsQuery'));
},
commentsQuery: function(){
return SC.Query.create({
isCommentsQuery: YES, // quack like a duck
recordType: DarkHorse.Comment,
conditions: 'feedItem = {feedItem}',
parameteres: {feedItem:this}
});
}.property().cacheable(),
commentsUserQuery: function(){
return SC.Query.create({
isCommentsUserQuery: YES, // quack like a duck
recordType: DarkHorse.User,
parameteres: {feedItem:this}
});
}.property().cacheable()
}) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment