Skip to content

Instantly share code, notes, and snippets.

@lprhodes
Created March 15, 2011 05:33
Show Gist options
  • Save lprhodes/870351 to your computer and use it in GitHub Desktop.
Save lprhodes/870351 to your computer and use it in GitHub Desktop.
A more clean but still broken version
/*
* AppController.j
* blah
*
* Created by You on March 15, 2011.
* Copyright 2011, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
CPArray questions;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
tableViewScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(20, 50, 650, CGRectGetHeight([[theWindow contentView] bounds])-80)];
[tableViewScrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[tableViewScrollView setAutohidesScrollers:NO];
tableView = [[CPTableView alloc] initWithFrame:[[theWindow contentView] bounds]];
[tableView setUsesAlternatingRowBackgroundColors:YES];
[tableView setAllowsMultipleSelection:YES];
[tableView setDataSource:self];
[tableView setDelegate:self];
var column = [[CPTableColumn alloc] initWithIdentifier:@"Name"];
[column setWidth:180];
[[column headerView] setStringValue:@"Reference"];
[tableView addTableColumn:column];
var column = [[CPTableColumn alloc] initWithIdentifier:@"Question"];
[column setWidth:300];
[[column headerView] setStringValue:@"Question"];
var dataView = [column dataView];
[dataView setLineBreakMode:CPLineBreakByWordWrapping];
[column setDataView:dataView];
[tableView addTableColumn:column];
var column = [[CPTableColumn alloc] initWithIdentifier:@"AnswerType"];
[[column headerView] setStringValue:@"Type"];
[tableView addTableColumn:column];
[tableViewScrollView setDocumentView:tableView];
[[theWindow contentView] addSubview:tableViewScrollView];
[theWindow orderFront:self];
[self setData];
}
- (int)numberOfRowsInTableView:(CPTableView)aTableView
{
return [questions count];
}
- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aTableColumn row:(int)aRow
{
var question = questions[aRow];//[questions objectForKey:[CPNumber numberWithInt:aRow]];
return question[[aTableColumn identifier]];//[question objectForKey:[aTableColumn identifier]];
}
- (float)tableView:(CPTableView)aTableView heightOfRow:(int)aRow
{
var question = questions[aRow];//[questions objectForKey:[CPNumber numberWithInt:aRow]];
var questionText = question.Question;//[question objectForKey:@"Question"];
var size = [questionText sizeWithFont:[CPFont systemFontOfSize:14] inWidth:300];
return size.height + 30;
}
- (void)setData
{
var request = [CPURLRequest requestWithURL:"questions.html"];
var connection = [[CPURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]
}
- (void)connection:(CPURLConnection)connection didReceiveData:(CPString)sData
{
questions = JSON.parse(sData);
[tableView reloadData];
}
- (void)connection:(CPJSONPConnection)aConnection didFailWithError:(CPString)error {
alert(error); //a network error occurred
}
@end
[{"ID":"31","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"32","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"33","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"34","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"35","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"36","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"37","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"38","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"39","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"40","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"41","Name":"New Question","Question":"This is my question and it's quite a bit longer than the others","AnswerType":"1","SurveyID":"2"},{"ID":"42","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"43","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"44","Name":"New Question","Question":"New Question","AnswerType":"1","SurveyID":"2"},{"ID":"56","Name":"My Question","Question":"What is..?","AnswerType":"1","SurveyID":"2"},{"ID":"57","Name":"My Question","Question":"What is..?","AnswerType":"1","SurveyID":"2"},{"ID":"58","Name":"My Question","Question":"What is..?","AnswerType":"1","SurveyID":"2"},{"ID":"59","Name":"My Question","Question":"What is..?","AnswerType":"1","SurveyID":"2"},{"ID":"60","Name":"My Question","Question":"What is..?","AnswerType":"1","SurveyID":"2"},{"ID":"61","Name":"My Question","Question":"What is..?","AnswerType":"1","SurveyID":"2"},{"ID":"62","Name":"My Question","Question":"What is..?","AnswerType":"1","SurveyID":"2"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment