Skip to content

Instantly share code, notes, and snippets.

@jlebrech
Created January 10, 2011 16:37
Show Gist options
  • Save jlebrech/773009 to your computer and use it in GitHub Desktop.
Save jlebrech/773009 to your computer and use it in GitHub Desktop.
@import <Foundation/CPObject.j>
@implementation TasksView : CPView
{
id _delegate @accessors(property=delegate);
CPScrollView scrollView;
CPTableView dataTable;
CPArray dataset;
}
- (id)initWithFrame:(CPRect)frame
{
self = [super initWithFrame:frame];
if (self){
var dataset = [CPArray alloc];
// create the CPTableView
dataTable = [[CPTableView alloc] initWithFrame:[self bounds]];
[dataTable setAutoresizingMask:CPViewHeightSizable ];
scrollView = [[CPScrollView alloc] initWithFrame:[self bounds]];
[scrollView setAutoresizingMask: CPViewWidthSizable | CPViewHeightSizable];
[scrollView setAutohidesScrollers:YES];
[scrollView setDocumentView:dataTable];
[dataTable setUsesAlternatingRowBackgroundColors:YES];
//[projectsTable setAlternatingRowBackgroundColors:[CPArray arrayWithObjects:[CPColor whiteColor],[CPColor redColor]]];
//var headerColor = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"button-bezel-center.png"]]];
//[[projectsTable cornerView] setBackgroundColor:headerColor];
// add the first column
var column = [[CPTableColumn alloc] initWithIdentifier:@"Name"];
[[column headerView] setStringValue:"Task Title"];
//[[column headerView] setBackgroundColor:headerColor];
[column setWidth:450.0];
[dataTable addTableColumn:column];
[dataTable setDataSource:self];
[self addSubview:scrollView];
}
return self;
}
- (void)getProjectTasks:(int)projectId
{
var request = [CPURLRequest requestWithURL:"/listtasks/"+projectId] ;
var dataConnection = [CPURLConnection connectionWithRequest:request delegate:self];
}
- (id)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row
{
if ([tableColumn identifier]===@"Name")
return dataset[row]["name"];
else
return @"foo";
}
// CPTableView datasource methods
- (int)numberOfRowsInTableView:(CPTableView)tableView
{
return dataset.length;
}
- (void)connection:(CPURLConnection) connection didReceiveData:(CPString)data
{
//This method is called when a connection receives a response. in a
//multi-part request, this method will (eventually) be called multiple times,
//once for each part in the response.
dataset = JSON.parse(data);
[dataTable reloadData];
if ([_delegate respondsToSelector:@selector(didFinishLoadingTasks:)])
[_delegate didFinishLoadingTasks];
}
- (void)connection:(CPURLConnection)connection didFailWithError:(CPString)error
{
//This method is called if the request fails for any reason.
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment