This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
VBXMessageAttribute.m
109 lines (88 loc) · 3.38 KB
/
VBXMessageAttribute.m
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
104
105
106
107
108
109
/**
* "The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
* The Original Code is OpenVBX, released February 18, 2011.
* The Initial Developer of the Original Code is Twilio Inc.
* Portions created by Twilio Inc. are Copyright (C) 2010.
* All Rights Reserved.
* Contributor(s):
**/
#import "VBXMessageAttribute.h"
#import "VBXMessageDetail.h"
#import "VBXTicketStatus.h"
@implementation VBXMessageAttribute
+ (VBXMessageAttribute *)assignedUserAttributeForMessage:(VBXMessageDetail *)detail name:(NSString *)name {
VBXMessageAttribute *attribute = [[VBXMessageAttribute new] autorelease];
attribute.messageDetail = detail;
attribute.key = @"assigned";
attribute.name = name;
attribute.options = detail.activeUsers;
attribute.valueGetter = @selector(assignedUser);
attribute.valueSetter = @selector(setAssignedUser:);
attribute.titleSelector = @selector(fullName);
attribute.detailSelector = @selector(email);
attribute.keySelector = @selector(key);
return attribute;
}
+ (VBXMessageAttribute *)ticketStatusAttributeForMessage:(VBXMessageDetail *)detail name:(NSString *)name {
VBXMessageAttribute *attribute = [[VBXMessageAttribute new] autorelease];
attribute.messageDetail = detail;
attribute.key = @"ticket_status";
attribute.name = name;
attribute.options = [NSArray arrayWithObjects:
[VBXTicketStatus ticketStatusWithValue:@"open"],
[VBXTicketStatus ticketStatusWithValue:@"closed"],
[VBXTicketStatus ticketStatusWithValue:@"pending"],
nil];
attribute.valueGetter = @selector(ticketStatus);
attribute.valueSetter = @selector(setTicketStatus:);
attribute.titleSelector = @selector(title);
attribute.keySelector = @selector(key);
return attribute;
}
@synthesize messageDetail = _messageDetail;
@synthesize key = _key;
@synthesize name = _name;
@synthesize options = _options;
@synthesize valueGetter = _valueGetter;
@synthesize valueSetter = _valueSetter;
@synthesize pendingValue = _pendingValue;
@synthesize titleSelector = _titleSelector;
@synthesize detailSelector = _detailSelector;
@synthesize keySelector = _keySelector;
- (void)dealloc {
self.messageDetail = nil;
self.key = nil;
self.name = nil;
self.options = nil;
self.pendingValue = nil;
[super dealloc];
}
- (id)value {
return [_messageDetail performSelector:_valueGetter];
}
- (void)setValue:(id)value {
[_messageDetail performSelector:_valueSetter withObject:value];
}
- (NSInteger)selectedIndex {
return [_options indexOfObject:self.value];
}
- (BOOL)hasDetail {
return _detailSelector != NULL;
}
- (NSString *)titleForValue:(id)value {
return [value performSelector:_titleSelector];
}
- (NSString *)detailForValue:(id)value {
return self.hasDetail? [value performSelector:_detailSelector] : nil;
}
- (NSString *)keyForValue:(id)value {
return [value performSelector:_keySelector];
}
@end