-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRequestPanelController.j
58 lines (49 loc) · 1.68 KB
/
RequestPanelController.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
// (c) 2010-2011 by Anton Korenyushkin
@import "PanelController.j"
@import "HTTPRequest.j"
@import "Alert.j"
@implementation RequestPanelController : PanelController
{
BOOL isProcessing;
CPString panelTitle;
}
- (void)requestWithMethod:(CPString)method
URL:(CPString)url
data:(JSObject)data
context:(JSObject)context
selector:(SEL)selector // private
{
if (isProcessing)
return;
isProcessing = YES;
panelTitle = [[self window] title];
[[self window] setTitle:"Processing..."];
var request = [[HTTPRequest alloc] initWithMethod:method URL:url target:self action:selector];
[request setFinishAction:@selector(didRequestFinished)];
[request setErrorMessageAction:@selector(didEndRequestErrorSheet:)];
[request setWindow:[self window]];
[request setContext:context];
[request send:data];
}
- (void)requestWithMethod:(CPString)method URL:(CPString)url data:(JSObject)data context:(JSObject)context // protected
{
[self requestWithMethod:method URL:url data:data context:context selector:@selector(didReceiveResponse:withContext:)];
}
- (void)requestWithMethod:(CPString)method URL:(CPString)url data:(JSObject)data // protected
{
[self requestWithMethod:method URL:url data:data context:nil selector:@selector(didReceiveResponse:)];
}
- (void)requestWithMethod:(CPString)method URL:(CPString)url // protected
{
[self requestWithMethod:method URL:url data:nil];
}
- (void)didRequestFinished // protected
{
isProcessing = NO;
[[self window] setTitle:panelTitle];
}
- (void)didEndRequestErrorSheet:(Alert)sender // protected
{
[self showWindow:nil];
}
@end