forked from MCF/FileUpload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileUploadAppController.j
103 lines (80 loc) · 2.6 KB
/
FileUploadAppController.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* AppController.j
* FileUpload Test application.
*
* Created by Mike Fellows on April 28, 2010.
*/
@import <Foundation/CPObject.j>
@import <AppKit/CPWebView.j>
@import "FileUpload.j"
@implementation FileUploadAppController : CPObject
{
FileUploadTextDisplay statusDisplay;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero()
styleMask:CPBorderlessBridgeWindowMask];
var contentView = [theWindow contentView];
var urlString = "/file_upload";
var fileUploadButton = [[UploadButton alloc] initWithFrame:CGRectMake(10, 15, 100, 24)];
[fileUploadButton setTitle:"Upload File"];
[fileUploadButton setBordered:YES];
[fileUploadButton allowsMultipleFiles:YES];
[fileUploadButton setURL:urlString];
[fileUploadButton setDelegate:self];
[contentView addSubview:fileUploadButton];
var urlLabel = [[CPTextField alloc] initWithFrame:CGRectMake(10, 55, 500, 40)];
[urlLabel setFont:[CPFont boldSystemFontOfSize:16.0]];
[urlLabel setStringValue:"The Upload POST URL is: " + urlString];
[urlLabel sizeToFit];
[urlLabel setSelectable:YES];
[contentView addSubview:urlLabel];
statusDisplay = [[FileUploadTextDisplay alloc] initWithFrame:CGRectMake(10, 90, 500, 300)];
[contentView addSubview:statusDisplay];
[theWindow orderFront:self];
}
-(void) uploadButton:(UploadButton)button didChangeSelection:(CPArray)selection
{
[statusDisplay clearDisplay];
[statusDisplay appendString:"Selection has been made: " + selection];
[button submit];
}
-(void) uploadButton:(UploadButton)button didFailWithError:(CPString)anError
{
[statusDisplay appendString:"Upload failed with this error: " + anError];
}
-(void) uploadButton:(UploadButton)button didFinishUploadWithData:(CPString)response
{
[statusDisplay appendString:"Upload finished with this response: " + response];
[button resetSelection];
}
-(void) uploadButtonDidBeginUpload:(UploadButton)button
{
[statusDisplay appendString:"Upload has begun with selection: " + [button selection]];
}
@end
@implementation FileUploadTextDisplay: CPWebView
{
CPString currentString;
}
- (id)initWithFrame:(CPRect)aFrame
{
self = [super initWithFrame:aFrame];
if(self)
{
currentString = "";
}
return self;
}
- (void)appendString:(CPString)aString
{
currentString = currentString + "<pre>" + aString + "</pre>";
[self loadHTMLString: currentString];
}
-(void)clearDisplay
{
currentString = "";
[self loadHTMLString:""];
}
@end