-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathItemController.j
More file actions
134 lines (111 loc) · 3.83 KB
/
Copy pathItemController.j
File metadata and controls
134 lines (111 loc) · 3.83 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
@implementation ItemController : CPObject
{
LocationController locationController;
Item activeItem @accessors;
ItemView itemView;
}
- (id)initWithItemView:(CPView)aView locationController:(id)aController
{
self = [super init];
if (self)
{
itemView = aView;
[itemView setItemController:self];
locationController = aController;
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshItem:) name:ItemAttachmentsDidChangeNotification object:nil];
}
return self;
}
- (void)refreshItem:(CPNotification)aNote
{
var object = [aNote object];
if (object === activeItem)
{
[itemView.attachmentsCollectionView reloadContent];
[locationController refreshItemData];
}
}
- (void)setItem:(Item)anItem
{
activeItem = anItem;
[itemView setItem:activeItem];
}
- (void)saveIfNeeded
{
if ([itemView isEditing])
[self itemDidEndEditing:[itemView itemForEditingValues]];
}
- (void)itemDidEndEditing:(Item)newItem
{
var //index = activeItem,//[[[locationView itemTableView] selectedRowIndexes] firstIndex],
//item = [location items][index],
copiedObject = [activeItem copy];
[activeItem setName:[newItem name]];
[activeItem setMake:[newItem make]];
[activeItem setModel:[newItem model]];
[activeItem setPrice:[newItem price]];
[activeItem setNotes:[newItem notes]];
[activeItem setDateAcquired:[newItem dateAcquired]];
[activeItem setTags:[newItem tags]];
[activeItem setExtras:[newItem extras]];
//[[locationView collectionView] reloadContent];
//[[locationView itemTableView] reloadData];
[locationController refreshItemData]
// register the undo
var dict = [CPDictionary dictionaryWithObjects:[activeItem, copiedObject] forKeys:[@"oldItem", @"newItem"]];
[[[CPApp delegate] undoManager] registerUndoWithTarget:[locationController location] selector:@selector(replaceItemWithItem:) object:dict];
}
/*- (void)enterEditMode:(BOOL)aFlag
{
[itemView enterEditMode:YES];
}*/
/*- (void)fileUpload:(DCFileUpload)anUpload didReceiveResponse:(CPString)aString
{
alert();
var data = JSON.parse(aString),
item = [[ItemAttachment alloc] init];
[item setName:data.name];
[item setType:data.type];
[item setData:data.data];
[[locationView itemView] addAttachment:item fromUpload:anUpload];
[[locationView itemTableView] reloadData];
}*/
- (void)fileDropUploadController:(DCFileDropController)theController setState:(BOOL)visible
{
/*if (visible)
[dropCover draggingEntered:nil]
else
[dropCover draggingExited:nil];*/
}
- (DCFileUploadManager)newUploadManager:(DCFileUploadController)aController
{
// create new attachment object
var newAttachment = [[ItemAttachment alloc] init],
// create new upload manager
manager = [[DCFileUploadManager alloc] init];
// assign upload manager to the attachment object
[newAttachment setName:@"Uploading..."];
[newAttachment setUploadManager:manager];
[manager setDelegate:newAttachment];
// add new attachment object to collectionview
var allAttachments = [activeItem attachments];
[allAttachments addObject:newAttachment];
// [itemView.attachmentsCollectionView setContent:allAttachments];
[itemView.attachmentsCollectionView reloadContent];
// profit?
return manager;
}
- (void)managerDidUpload:(DCFileUploadManager)anUpload
{
//var attachment = [anUpload delegate];
//currentItem = [locationController currentItem];
// add this to the item object now that we know it was successful
//[itemController addAttachment:attachment];
[locationController refreshItemData];
}
- (void)addAttachment:(id)anAttachment
{
[activeItem addAttachment:anAttachment];
[locationController refreshItemData];
}
@end