Skip to content

Instantly share code, notes, and snippets.

@justinpeterman
Created July 20, 2011 07:58
Show Gist options
  • Save justinpeterman/1094548 to your computer and use it in GitHub Desktop.
Save justinpeterman/1094548 to your computer and use it in GitHub Desktop.
Nested Records
Authoring = SC.Application.create(
store: SC.Store.create().from(SC.Record.fixtures)
}) ;
Authoring.LibraryFile = SC.Record.extend({
name: SC.Record.attr(String),
path: SC.Record.attr(String),
size: SC.Record.attr(Number),
type: SC.Record.attr(String),
checksum: SC.Record.attr(String),
cdn: SC.Record.attr(Boolean)
});
Authoring.libraryFileController = SC.ArrayController.create({
contentBinding: 'Authoring.libraryController.content.files'
}) ;
sc_require('models/library_model');
//sc_require('models/file_model'); add here?
Authoring.Library.FIXTURES = [
{
user_id : 1,
name : "Justin",
files : [
{
guid : 0,
name : "photo1.png",
path : "some/path",
size : 26,
type : "image/png",
checksum : "",
cdn : false
},
{
guid : 1,
name : "photo2.png",
path : "some/path",
size : 14,
type : "image/png",
checksum : "",
cdn : false
},
{
guid : 2,
name : "photo3.png",
path : "some/path",
size : 12,
type : "image/png",
checksum : "",
cdn : false
},
{
guid : 3,
name : "photo4.png",
path : "some/path",
size : 4,
type : "image/png",
checksum : "",
cdn : false
},
{
guid : 4,
name : "photo5.png",
path : "some/path",
size : 18,
type : "image/png",
checksum : "",
cdn : false
},
{
guid : 5,
name : "photo6.png",
path : "some/path",
size : 12,
type : "image/png",
checksum : "",
cdn : false
}
]
}
];
Authoring.libraryController = SC.ObjectController.create({
content: null
});
Authoring.Library = SC.Record.extend({
name: SC.Record.attr(String),
user_id: SC.Record.attr(Number),
files: SC.Record.toMany('Authoring.LibraryFile', { nested: true })
});
SC.ScrollView.design({
layout: { top: 140 },
contentView: SC.ListView.design({
layout: { top: 0 },
classNames: 'library-list',
actOnSelect: YES,
showAlternatingRows: YES,
rowHeight: 24,
contentBinding: "Authoring.libraryFileController",
selectionBinding: "Authoring.libraryFileController.selection",
contentValueKey: "name",
action: "fileClicked"
})
})
// call to statechart action
Authoring.libraryController.set('content', Authoring.store.find(Authoring.Library));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment