Skip to content

Instantly share code, notes, and snippets.

@thomaslang
Created August 11, 2009 09:57
Show Gist options
  • Save thomaslang/165728 to your computer and use it in GitHub Desktop.
Save thomaslang/165728 to your computer and use it in GitHub Desktop.
// my main.js ---------------------------------
BB.main = function main() {
var usersQuery = SC.Query.create({recordType: BB.User});
BB.set('usersQuery', usersQuery);
var users = BB.store.findAll(BB.get('usersQuery'));
BB.set('users', users);
BB.store.dataSource.loadAllDocs(BB.store);
//SC.RunLoop.begin();
BB.usersController.set('content', users);
//SC.RunLoop.end();
} ;
function main() { BB.main(); }
// my main_page.js ---------------------------------
BB.mainPage = SC.Page.design({
loginPane: SC.PanelPane.design({
layout: { width: 250, height: 180, centerX: 0, centerY: -100 },
isModal: NO,
contentView: SC.View.design({
childViews: 'title list start'.w(),
title: SC.LabelView.design({
layout: { top: 10, height: 18, left: 20, right: 20 },
value: 'Benutzer auswählen'
}),
list: SC.ScrollView.design({
layout: { left: 20, right: 20, top: 30, bottom: 50 },
hasHorizontalScroller: NO,
borderStyle: SC.BORDER_GRAY,
contentView: SC.ListView.design({
contentValueKey: 'name',
contentBinding: 'BB.usersController.arrangedObjects',
selectionBinding: 'BB.usersController.selection',
rowHeight: 21
})
}),
start: SC.ButtonView.design({
layout: { bottom: 13, height: 24, centerX: 0, width: 100 },
theme: 'capsule',
isDefault: YES,
title: "Start",
target: "BB",
action: "startApp"
})
})
})
// -- snip --
});
// inside my datasource ---------------------------------
loadAllDocsDidComplete: function(r, params) {
var docs, doc, l, i, dataHash, recordType, primaryKey;
var types = [];
var hashes = [];
var response = r.response();
if(response.kindOf ? response.kindOf(SC.Error) : false) {
this.requestDidError(r);
} else {
docs = response.rows;
l = docs.length;
for(i=0; i<l; i++) {
doc = docs[i];
recordType = SC.objectForPropertyPath(doc.key);
primaryKey = recordType ? recordType.prototype.primaryKey : 'guid';
dataHash = doc.value;
dataHash[primaryKey] = dataHash._id ;
hashes.push(dataHash);
types.push(recordType);
}
SC.RunLoop.begin();
params.store.loadRecords(types, hashes);
BB.goState('a',0);
SC.RunLoop.end();
}
},
// states ---------------------------------
goStateA0: function(){
BB.getPath('mainPage.loginPane').append();
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment