Skip to content

Instantly share code, notes, and snippets.

@skizzybiz
Created May 13, 2011 15:58
Show Gist options
  • Save skizzybiz/970797 to your computer and use it in GitHub Desktop.
Save skizzybiz/970797 to your computer and use it in GitHub Desktop.
Report Approval/Nomination
Authoring.groupedNominationsController = SC.TreeController.create({
content: null,
selection: null,
treeItemIsGrouped: YES,
setNominations: function(nominations) {
var group, osVersion, osVersions, root;
root = SC.Object.create({
treeItemChildren: []
treeItemIsExpanded: YES
});
osVersions = {};
osVersion = group = null;
nominations.forEach(function(nomination) {
osVersion = nomination.get('osVersion');
if (osVersions[osVersion]) {
group = osVersions[osVersion];
} else {
group = SC.Object.create({
treeItemChildren: [],
treeItemIsExpanded: YES
label: osVersion
});
root.treeItemChildren.push(group);
osVersions[osVersion] = group;
}
group.treeItemChildren.push(SC.Object.create({
treeItemChildren: null,
label: nomination.get('reportTemplate').get('name'),
record: nomination
}));
});
this.set('content', root);
}
});
Authoring.main = function() {
var nominations, templates;
Authoring.myReports = Authoring.getPath('Pages.reportApproval.mainPane').append();
nominations = Authoring.store.find(Authoring.Nomination);
nominations.addObserver('status', this, function() {
if (nominations.get('status') !== SC.Record.READY_CLEAN) return;
c = Authoring.groupedNominationsController;
c.setNominations(nominations);
c.selectObject(c.get('firstSelectableObject'));
});
};
window.main = function() {
return Authoring.main();
};
// ...
contentView: SC.SourceListView.design({
contentBinding: 'Authoring.groupedNominationsController.arrangedObjects',
selectionBinding: 'Authoring.groupedNominationsController.selection',
contentValueKey: 'label',
rowHeight: 21,
canEditContent: NO,
canDeleteContent: NO
})
Authoring.reportTemplateController = SC.ObjectController.create({
// This line is the trouble maker: it causes the browser to lock up in an infinite loop
// treeNodeBinding: SC.Binding.single('Authoring.groupedNominationsController.selection')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment