-
Notifications
You must be signed in to change notification settings - Fork 3
/
ItemView.j
1497 lines (1190 loc) · 56.4 KB
/
ItemView.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@implementation ItemView : CPView
{
int MINHEIGHT;
id locationController @accessors;
id itemController @accessors;
BOOL isEditing @accessors;
ItemContentView itemContentView;
CPScrollView scrollView;
MainItemView mainItemImage;
CPTextField nameField @accessors;
CPTextField makeField;
CPTextField modelField;
CPTextField priceField;
CPTextField serialField;
DatePicker dateAcquiredField;
CPButton clearDateButton;
CPTextField dateAcquiredTextField;
NATokenFieldView tagsField;
CPTextField tagsUnedited;
CPTextField notesLabel;
CPArray tagsArray;
CPTextField notesField;
CPDictionary extrasLabels;
CPDictionary extrasFields;
CPDictionary removeExtraFieldButtons;
CPButton addExtraFieldButton;
NAMenu _completionMenu;
CPView noItemView;
CPTextField newFieldPrompt;
CPButton createNewFieldButton;
CPScrollView attachmentsScrollView;
CPCollectionView attachmentsCollectionView;
DCFileUpload mainImageUpload @accessors;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self)
{
MINHEIGHT = aFrame.size.height - 100;
[self setBackgroundColor:[CPColor colorWithHexString:"f4f4f4"]];
tagsArray = [ ];
scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0,0,aFrame.size.width,aFrame.size.height - 90)];
itemContentView = [[ItemContentView alloc] initWithFrame:CGRectMake(0,0,aFrame.size.width - 20, aFrame.size.height - 100)];
[scrollView setHasHorizontalScroller:NO];
[scrollView setAutohidesScrollers:YES];
[scrollView setDocumentView:itemContentView];
[self addSubview:scrollView];
[[DCFileUploadManager sharedManager] setDelegate:itemController];
mainItemImage = [[MainItemView alloc] initWithFrame:CGRectMake(aFrame.size.width - 160, 10, 145, 145)];
[mainItemImage setController:self];
[itemContentView addSubview:mainItemImage];
var nameLabel = [ItemView customLabelWithFrame:CGRectMake(15, 24, 65, 28)];
[nameLabel setStringValue:"Name: "];
[nameLabel sizeToFit];
[itemContentView addSubview:nameLabel];
nameField = [ItemView ItemViewTextField];
[nameField setFrame:CGRectMake(CGRectGetMaxX([nameLabel frame]) + 5, 15, 275, 35)];
[nameField setFont:[CPFont systemFontOfSize:24]];
[itemContentView addSubview:nameField];
var makeLabel = [ItemView customLabelWithFrame:CGRectMake(15, 64, 65, 28)];
[makeLabel setStringValue:"Make: "];
[makeLabel sizeToFit];
[itemContentView addSubview:makeLabel];
makeField = [ItemView ItemViewTextField];
[makeField setFrame:CGRectMake(CGRectGetMaxX([nameLabel frame]) + 5, 60, 275, 28)];
[makeField setFont:[CPFont systemFontOfSize:13]];
[nameField setNextKeyView:makeField];
[nameField setNextResponder:makeField];
[itemContentView addSubview:makeField];
var modelLabel = [ItemView customLabelWithFrame:CGRectMake(15, 124, 100, 28)];
[modelLabel setStringValue:"Model: "];
[itemContentView addSubview:modelLabel];
modelField = [ItemView ItemViewTextField];
[modelField setFrame:CGRectMake(115, 120, 275, 28)];
[modelField setFont:[CPFont systemFontOfSize:13]];
[itemContentView addSubview:modelField];
var priceLabel = [ItemView customLabelWithFrame:CGRectMake(15, 154, 100, 28)];
[priceLabel setStringValue:"Price: "];
[itemContentView addSubview:priceLabel];
priceField = [ItemView ItemViewTextField];
[priceField setFrame:CGRectMake(115, 150, 275, 28)];
[priceField setFont:[CPFont systemFontOfSize:13]];
[itemContentView addSubview:priceField];
var serialLabel = [ItemView customLabelWithFrame:CGRectMake(15, 184, 100, 28)];
[serialLabel setStringValue:"Serial Number: "];
[itemContentView addSubview:serialLabel];
serialField = [ItemView ItemViewTextField];
[serialField setFrame:CGRectMake(115, 180, 275, 28)];
[serialField setFont:[CPFont systemFontOfSize:13]];
[itemContentView addSubview:serialField];
var dateAcquiredLabel = [ItemView customLabelWithFrame:CGRectMake(15, 214, 100, 28)];
[dateAcquiredLabel setStringValue:"Date Acquired: "];
[itemContentView addSubview:dateAcquiredLabel];
dateAcquiredField = [[DatePicker alloc] initWithFrame:CGRectMake(115, 210, 215, 28)];
[dateAcquiredField displayPreset:1];
clearDateButton = [[CPButton alloc] initWithFrame:CGRectMake(340, 213, 50, 24)];
[clearDateButton setTitle:"Clear"];
[clearDateButton setTarget:self];
[clearDateButton setAction:@selector(clearDate:)];
// [itemContentView addSubview:dateAcquiredField];
dateAcquiredTextField = [[CPTextField alloc] initWithFrame:CGRectMake(115, 214, 275, 28)];
[itemContentView addSubview:dateAcquiredTextField];
var tagsLabel = [ItemView customLabelWithFrame:CGRectMake(15, 244, 100, 28)];
[tagsLabel setStringValue:"Tags: "];
[itemContentView addSubview:tagsLabel];
tagsField = [[NATokenTextView alloc] initWithFrame:CGRectMake(115, 240, 275, 28)];
[tagsField setValue:[CPColor colorWithWhite:0.6 alpha:1.0] forThemeAttribute:@"text-color" inState:CPTextFieldStatePlaceholder];
[tagsField setValue:CGInsetMakeZero() forThemeAttribute:@"bezel-inset" inState:CPThemeStateNormal];
[tagsField setValue:CGInsetMake(-1.0, 10.0, 0.0, 10.0) forThemeAttribute:@"content-inset" inState:CPThemeStateNormal];
var bundle = [CPBundle mainBundle],
textFieldBackgroundImage = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-0.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-1.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-2.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-3.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-5.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-6.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-7.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-8.png"] size:CGSizeMake(11.0, 9.0)]
]]],
textFieldFocusedBackground = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-0.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-1.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-2.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-3.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-5.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-6.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-7.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-8.png"] size:CGSizeMake(11.0, 9.0)]
]]];
[tagsField setValue:textFieldBackgroundImage forThemeAttribute:@"bezel-color" inState:CPThemeStateBezeled];
[tagsField setValue:textFieldFocusedBackground forThemeAttribute:@"bezel-color" inState:CPThemeStateBezeled|CPThemeStateEditing];
[tagsField setDelegate:self];
// [itemContentView addSubview:tagsField];
tagsUnedited = [[AutoExpandingTextField alloc] initWithFrame:CGRectMake(115, 240, 275, 28)];
[tagsUnedited setValue:CGInsetMake(7.0, 10.0, 2.0, 10.0) forThemeAttribute:@"content-inset"];
[tagsUnedited setLineBreakMode:CPLineBreakByWordWrapping];
[itemContentView addSubview:tagsUnedited];
notesLabel = [ItemView customLabelWithFrame:CGRectMake(15, 274, 100, 28)];
[notesLabel setStringValue:"Notes: "];
[itemContentView addSubview:notesLabel];
notesField = [[AutoExpandingTextField alloc] init];//[LocationEditView customMultiLineTextField];
[notesField setFrame:CGRectMake(115, 270, 275, 50)];
[notesField setTextColor:[CPColor blackColor]];
[notesField setEditable:NO];
[notesField setBezeled:NO];
[notesField setFont:[CPFont systemFontOfSize:13]];
[notesField setDelegate:self];
[notesField setValue:[CPColor colorWithWhite:0.6 alpha:1.0] forThemeAttribute:@"text-color" inState:CPTextFieldStatePlaceholder];
[notesField setValue:CGInsetMakeZero() forThemeAttribute:@"bezel-inset" inState:CPThemeStateNormal];
[notesField setValue:CGInsetMake(5.0, 10.0, 0.0, 10.0) forThemeAttribute:@"content-inset" inState:CPThemeStateNormal];
[notesField setValue:textFieldBackgroundImage forThemeAttribute:@"bezel-color" inState:CPThemeStateBezeled];
[itemContentView addSubview:notesField];
extrasLabels = [CPDictionary dictionary];
extrasFields = [CPDictionary dictionary];
removeExtraFieldButtons = [CPDictionary dictionary];
addExtraFieldButton = [[CPButton alloc] initWithFrame:CGRectMake(17, 216, 12, 12)];
[addExtraFieldButton setImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"AddButton.png"] size:CGSizeMake(12,12)]];
[addExtraFieldButton setAlternateImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"AddButtonP.png"] size:CGSizeMake(12,12)]];
[addExtraFieldButton setBordered:NO];
[addExtraFieldButton setTarget:self];
[addExtraFieldButton setAction:@selector(promptAddExtraField:)];
attachmentsScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, aFrame.size.height - 90, aFrame.size.width - 20, 90)];
// [attachmentsScrollView setBackgroundColor:[CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"Attachments/CollectionGradientBG.png"] size:CGSizeMake(484, 7)]]];
[attachmentsScrollView setHasVerticalScroller:NO];
[attachmentsScrollView setAutohidesScrollers:YES];
[attachmentsScrollView setVerticalLineScroll:0.0001];
[attachmentsScrollView setHorizontalScroller:[LocationController customHorizontalScroller]];
[attachmentsScrollView setAutoresizingMask:CPViewWidthSizable|CPViewMinYMargin];
attachmentsCollectionView = [[DropUploadCollectionView alloc] initWithFrame:CGRectMake(0, 0, aFrame.size.width - 20, 90)];
var item = [[CPCollectionViewItem alloc] init];
[item setView:[AttachmentCell new]];
[attachmentsCollectionView setMinItemSize:CGSizeMake(80, 85)];
[attachmentsCollectionView setMaxItemSize:CGSizeMake(80, 85)];
[attachmentsCollectionView setVerticalMargin:5];
[attachmentsCollectionView setDelegate:self];
[attachmentsCollectionView setItemPrototype:item];
[attachmentsCollectionView setMaxNumberOfRows:1];
[attachmentsCollectionView setAutoresizingMask:CPViewWidthSizable];
// [attachmentsCollectionView setBackgroundColor:[CPColor colorWithHexString:@"EEEEEE"]];
// [attachmentsCollectionView setAllowsMultipleSelection:YES];
// [attachmentsCollectionView setContent:["123", "456", "789", "123", "456", "789", "123", "456", "789", "123", "456", "789", "123", "456", "789", "123", "456", "end"]];
// activate the view as a drop zone for uploads
//Collection view drop view
//dropCover = [[RLCollectionViewDropCover alloc] initWithFrame:CGRectMake(0, aFrame.size.height - 90, aFrame.size.width, 75)];
//[dropCover setHidden:YES];
// we timeout because the itemController isn't set until after this view is created
window.setTimeout(function(){
var fileDropUploadController = [[DCFileDropController alloc] initWithView:attachmentsCollectionView
dropDelegate:itemController
//uploadURL:[CPURL URLWithString:@"http://localhost:8888/upload.php"]
uploadURL:[CPURL URLWithString:@"http://timetableapp.com/TestingEnviro/Iguana/upload.php"]
uploadManager:[DCFileUploadManager sharedManager]];
[fileDropUploadController setValidFileTypes:["png","gif","jpg", "pdf"]];
},0);
[attachmentsScrollView setDocumentView:attachmentsCollectionView];
var shadowView = [[CPView alloc] initWithFrame:CGRectMake(0, aFrame.size.height - 90, aFrame.size.width, 11)];
[shadowView setBackgroundColor:[CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"Attachments/CollectionShadow.png"] size:CGSizeMake(52,11)]]];
[shadowView setAutoresizingMask:CPViewWidthSizable|CPViewMinYMargin];
[self addSubview:attachmentsScrollView];
[self addSubview:shadowView];
noItemView = nil;
[self setItem:nil];
}
return self;
}
- (void)setLocationController:(id)aController
{
locationController = aController;
[[DCFileUploadManager sharedManager] setDelegate:itemController];
}
- (void)setWidth:(int)aWidth
{
var height = [itemContentView frame].size.height;
[itemContentView setFrameSize:CGSizeMake(aWidth, height)];
}
- (void)setupEditViewsWithItem:(Item)anItem
{
var itemExtras = [anItem extras],
keys = [itemExtras allKeys],
y = CGRectGetMaxY([notesField frame]) + 3,
i = 0;
for (; i < [keys count]; i++)
{
var key = keys[i],
value = [itemExtras valueForKey:key];
// create the label
var label = [ItemView customLabelWithFrame:CGRectMake(15, y + 4, 100, 28)];
[label setStringValue:key + ": "];
[extrasLabels setValue:label forKey:key];
[itemContentView addSubview:label];
// create the field
var field = [ItemView ItemViewTextField];
[field setFrame:CGRectMake(115, y, 275, 28)];
[field setFont:[CPFont systemFontOfSize:13]];
[field setStringValue:value];
[extrasFields setValue:field forKey:key];
[itemContentView addSubview:field];
var button = [[CPButton alloc] initWithFrame:CGRectMake(3, y + 4, 12,12)],
bundle = [CPBundle mainBundle];
[button setImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"MinusButton.png"] size:CGSizeMake(12,12)]];
[button setAlternateImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"MinusButtonP.png"] size:CGSizeMake(12,12)]];
[button setBordered:NO];
[button setTarget:self];
[button setAction:@selector(removeField:)];
[button setTag:key];
[removeExtraFieldButtons setValue:button forKey:key];
y += 30;
}
/* [nameField setNextResponder:makeField];
[makeField setNextResponder:nameField];
[nameField setNextKeyView:makeField];
[makeField setNextKeyView:nameField];*/
}
- (void)moveExtrasIntoPlace
{
var keys = [extrasLabels allKeys],
y = CGRectGetMaxY([notesField frame]) + 3,
i = 0;
for (; i < [keys count]; i++)
{
// move the label
[itemContentView addSubview:[extrasLabels valueForKey:keys[i]]];
[[extrasLabels valueForKey:keys[i]] setFrameOrigin:CGPointMake(15, y + 4)];
// move the field
[itemContentView addSubview:[extrasFields valueForKey:keys[i]]];
[[extrasFields valueForKey:keys[i]] setFrameOrigin:CGPointMake(115, y)];
// move the remove button
[itemContentView addSubview:[removeExtraFieldButtons valueForKey:keys[i]]];
[[removeExtraFieldButtons valueForKey:keys[i]] setFrameOrigin:CGPointMake(3, y + 7)];
// reset Y
y += 30;
}
[addExtraFieldButton setFrameOrigin:CGPointMake(3, y)];
// set the size of the whole view...
// but I need to put it in a scrollview first... duh.
var size = [itemContentView bounds].size;
[itemContentView setFrameSize:CGSizeMake(size.width, MAX(MINHEIGHT, y + 30))];
}
- (void)setExtrasToEdit:(BOOL)aFlag
{
var keys = [extrasFields allKeys];
i = 0;
for (; i < [keys count]; i++)
{
// move the field
[[extrasFields valueForKey:keys[i]] setEditable:aFlag];
[[extrasFields valueForKey:keys[i]] setBezeled:aFlag];
if (aFlag)
[itemContentView addSubview:[removeExtraFieldButtons valueForKey:keys[i]]];
else
[[removeExtraFieldButtons valueForKey:keys[i]] removeFromSuperview];
}
}
- (void)removeAllExtras
{
var keys = [extrasLabels allKeys],
i = 0;
for (; i < [keys count]; i++)
{
// remove the label
[[extrasLabels valueForKey:keys[i]] removeFromSuperview];
// remove the field
[[extrasFields valueForKey:keys[i]] removeFromSuperview];
// remove the remove button
[[removeExtraFieldButtons valueForKey:keys[i]] removeFromSuperview];
}
// empty the dicts
[extrasLabels removeAllObjects];
[extrasFields removeAllObjects];
[removeExtraFieldButtons removeAllObjects];
}
- (void)promptAddExtraField:(id)sender
{
var removeLocationSheet = [[CPWindow alloc] initWithContentRect:CGRectMake(0,0,300,120) styleMask:CPDocModalWindowMask],
contentView = [removeLocationSheet contentView],
header = [CPTextField labelWithTitle:@"Add Item Field: "];
[header setFrame:CGRectMake(15,10, 200, 25)];
[header setFont:[CPFont boldSystemFontOfSize:15]];
[header sizeToFit];
[contentView addSubview:header];
createNewFieldButton = [[CPButton alloc] initWithFrame:CGRectMake(183, 80, 100, 24)];
newFieldPrompt = [[CPTextField alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY([header frame]) + 5, 270, 28)];
[newFieldPrompt setEditable:YES];
[newFieldPrompt setBezeled:YES];
[newFieldPrompt setTarget:createNewFieldButton];
[newFieldPrompt setAction:@selector(performClick:)];
[newFieldPrompt setDelegate:self];
[contentView addSubview:newFieldPrompt];
[createNewFieldButton setTitle:@"Create"];
[createNewFieldButton setTag:0];
[createNewFieldButton setTarget:self];
[createNewFieldButton setAction:@selector(closeSheet:)];
[createNewFieldButton setEnabled:NO];
[contentView addSubview:createNewFieldButton];
[removeLocationSheet setDefaultButton:createNewFieldButton];
var cancelButton = [[CPButton alloc] initWithFrame:CGRectMake(73, 80, 100, 24)];
[cancelButton setTag:-1];
[cancelButton setTitle:@"Cancel"];
[cancelButton setTarget:self];
[cancelButton setAction:@selector(closeSheet:)];
[contentView addSubview:cancelButton];
[CPApp beginSheet:removeLocationSheet modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) contextInfo:nil];
[removeLocationSheet makeFirstResponder:newFieldPrompt];
}
- (void)removeField:(id)sender
{
var key = [sender tag];
[[extrasLabels valueForKey:key] removeFromSuperview];
[[extrasFields valueForKey:key] removeFromSuperview];
[[removeExtraFieldButtons valueForKey:key] removeFromSuperview];
[extrasLabels removeObjectForKey:key];
[extrasFields removeObjectForKey:key];
[removeExtraFieldButtons removeObjectForKey:key];
[self moveExtrasIntoPlace];
}
- (void)setItem:(Item)anItem
{
// remove extras from the previous item
[self removeAllExtras];
if (!anItem)
{
if (!noItemView)
{
// make one
noItemView = [[CPView alloc] initWithFrame:[self bounds]];
[noItemView setBackgroundColor:[CPColor colorWithHexString:@"f4f4f4"]];
[noItemView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
var label = [CPTextField new];
[label setStringValue:"No Item Selected"];
[label setFont:[CPFont systemFontOfSize:22]];
[label setTextColor:[CPColor colorWithHexString:"727272"]];
[label setTextShadowColor:[CPColor whiteColor]];
[label setTextShadowOffset:CGSizeMake(0,2)];
[label sizeToFit];
[label setCenter:CGPointMake(CGRectGetMidX([self bounds]), CGRectGetMidY([self bounds]) - 50)];
[label setAutoresizingMask:CPViewMinXMargin | CPViewMinYMargin | CPViewMaxXMargin | CPViewMaxYMargin];
[noItemView addSubview:label];
}
var locationView = [locationController locationView];
[[locationView editButton] setHidden:YES];
[[locationView deleteButton] setHidden:YES];
[[locationView uploadButton] setHidden:YES];
[self addSubview:noItemView];
return;
}
var locationView = [locationController locationView];
[[locationView editButton] setHidden:NO];
[[locationView deleteButton] setHidden:NO];
[[locationView uploadButton] setHidden:NO];
[noItemView removeFromSuperview];
[nameField setStringValue:[anItem name]];
[makeField setStringValue:[anItem make]];
[modelField setStringValue:[anItem model]];
[priceField setStringValue:[anItem price]];
[serialField setStringValue:[anItem serial]];
[dateAcquiredField setDate:[[anItem dateAcquired] copy]];
[dateAcquiredTextField setStringValue:[[anItem dateAcquired] longStringDate]];
[tagsField setTokens:[anItem tags]];
[tagsUnedited setStringValue:[[anItem tags] componentsJoinedByString:", "]];
[notesField setStringValue:[anItem notes]];
[attachmentsCollectionView setContent:[anItem attachments]];
// if we don't do this then it doesn't work right... hell if I know why
window.setTimeout(function(){
[tagsUnedited sizeToFit];
if ([tagsUnedited frame].size.height < 28)
[tagsUnedited setFrameSize:CGSizeMake([tagsUnedited frame].size.width, 28)];
[notesField sizeToFit];
if (CGRectGetHeight([notesField frame]) < 50)
[notesField setFrameSize:CGSizeMake([notesField frame].size.width, 50)];
[self setupEditViewsWithItem:anItem];
[self moveExtrasIntoPlace];
[self setExtrasToEdit:isEditing];
},0);
}
- (CPDictionary)extrasForEditingItem
{
var dict = [CPDictionary dictionary],
keys = [extrasFields allKeys],
values = [extrasFields allValues],
i = 0;
for (; i < [keys count]; i++)
[dict setValue:[values[i] stringValue] forKey:keys[i]];
return dict;
}
- (void)toggleEditMode:(id)sender
{
[self enterEditMode:!isEditing];
if (!isEditing)
{
// construct new item to send
[itemController itemDidEndEditing:[self itemForEditingValues]];
}
}
- (Item)itemForEditingValues
{
var item = [[Item alloc] initWithName:[nameField stringValue]];
[item setMake:[makeField stringValue]];
[item setModel:[modelField stringValue]];
[item setNotes:[notesField stringValue]];
[item setDateAcquired:[dateAcquiredField date]];
[item setPrice:[priceField stringValue]];
tagsArray = [tagsField tokens];
[item setTags:tagsArray];
[item setExtras:[self extrasForEditingItem]];
return item;
}
- (void)enterEditMode:(BOOL)aFlag
{
isEditing = aFlag;
[nameField setEditable:aFlag];
[nameField setBezeled:aFlag];
[makeField setEditable:aFlag];
[makeField setBezeled:aFlag];
[makeField setEditable:aFlag];
[makeField setBezeled:aFlag];
[modelField setEditable:aFlag];
[modelField setBezeled:aFlag];
[priceField setEditable:aFlag];
[priceField setBezeled:aFlag];
[serialField setEditable:aFlag];
[serialField setBezeled:aFlag];
[notesField setEditable:aFlag];
[notesField setBezeled:aFlag];
if (isEditing)
{
[dateAcquiredTextField removeFromSuperview];
[itemContentView addSubview:dateAcquiredField];
[itemContentView addSubview:clearDateButton];
[itemContentView addSubview:addExtraFieldButton];
[tagsField setFrame:[tagsUnedited frame]];
[tagsUnedited removeFromSuperview];
[itemContentView addSubview:tagsField];
[self tokenTextViewFrameSizeDidChange:tagsField];
//[[[locationController locationView] editButton] setTitle:"Done"];
//[[[locationController locationView] editButton] setValue:[CPColor colorWithCalibratedRed:0.0/255.0 green:108.0/255.0 blue:152.0/255.0 alpha:1.0] forThemeAttribute:@"text-color"];
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"editbutton-selected.png"] size:CGSizeMake(18,18)];
[[[locationController locationView] editButton] setImage:image];
}
else
{
[addExtraFieldButton removeFromSuperview];
[dateAcquiredField removeFromSuperview];
[clearDateButton removeFromSuperview];
var date = [[dateAcquiredField date] longStringDate];
[dateAcquiredTextField setStringValue:date];
[itemContentView addSubview:dateAcquiredTextField];
[tagsUnedited setFrame:[tagsField frame]];
[tagsField removeFromSuperview];
tagsArray = [tagsField tokens];
[tagsUnedited setStringValue:[tagsArray componentsJoinedByString:", "]];
[itemContentView addSubview:tagsUnedited];
[self tokenTextViewFrameSizeDidChange:tagsUnedited];
//[[[locationController locationView] editButton] setTitle:"Edit"];
//[[[locationController locationView] editButton] setValue:[CPColor colorWithCalibratedWhite:79.0 / 255.0 alpha:1.0] forThemeAttribute:"text-color"];
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"editbutton.png"] size:CGSizeMake(18,18)];
[[[locationController locationView] editButton] setImage:image];
}
[self setExtrasToEdit:aFlag];
}
- (void)clearDate:(id)sender
{
[dateAcquiredTextField setStringValue:""];
[dateAcquiredField setDate:nil];
}
- (void)closeSheet:(id)sender
{
[CPApp endSheet:[sender window] returnCode:[sender tag]];
}
- (void)didEndSheet:(CPWindow)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo
{
[sheet orderOut:self];
switch (returnCode)
{
case 0: // create new extra
var key = [[newFieldPrompt stringValue] capitalizedString],
label = [ItemView customLabelWithFrame:CGRectMake(15, 10, 100, 28)];
// just in case they slip by... :) (generally by hitting enter too quickly)
if ([extrasLabels containsKey:key])
{
alert("Sorry, You cannot have two extras with the same name.");
return;
}
if (!key)
{
alert("Sorry, You must enter a name for the new extra.");
return;
}
[label setStringValue:key + ": "];
[extrasLabels setValue:label forKey:key];
[itemContentView addSubview:label];
// create the field
var field = [ItemView ItemViewTextField];
[field setFrame:CGRectMake(115, 10, 275, 28)];
[field setFont:[CPFont systemFontOfSize:13]];
[field setBezeled:YES];
[field setEditable:YES];
[extrasFields setValue:field forKey:key];
[itemContentView addSubview:field];
var button = [[CPButton alloc] initWithFrame:CGRectMake(3, 10, 12,12)],
bundle = [CPBundle mainBundle];
[button setImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"MinusButton.png"] size:CGSizeMake(12,12)]];
[button setAlternateImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"MinusButtonP.png"] size:CGSizeMake(12,12)]];
[button setBordered:NO];
[button setTarget:self];
[button setAction:@selector(removeField:)];
[button setTag:key];
[removeExtraFieldButtons setValue:button forKey:key];
[self moveExtrasIntoPlace];
[[self window] makeFirstResponder:field];
var clip = [scrollView contentView];
[clip scrollToPoint:CGPointMake(0, [clip bounds].size.height)];
[scrollView reflectScrolledClipView:clip];
break;
}
[newFieldPrompt setStringValue:""];
}
- (void)controlTextDidChange:(CPNotification)aNote
{
var field = [aNote object];
if (field === newFieldPrompt)
{
// check to see if this field already exists
var value = [[field stringValue] capitalizedString];
[createNewFieldButton setEnabled:(value && ![extrasLabels containsKey:value])];
}
else if (field === notesField)
{
[field sizeToFit];
if (CGRectGetHeight([field frame]) < 50)
[field setFrameSize:CGSizeMake([field frame].size.width, 50)];
[self moveExtrasIntoPlace];
}
}
- (void)tokenTextViewFrameSizeDidChange:(id)sender
{
var newY = CGRectGetMaxY([sender frame]) + 4;
[notesLabel setFrameOrigin:CGPointMake(15, newY + 2)];
[notesField setFrameOrigin:CGPointMake(115, newY)];
[self moveExtrasIntoPlace];
}
/*- (CPString)tokenTextViewCompletionForToken:(id)sender {
if(sender == tagsField) {
if(_completionMenu) {
var selectedTag = [_completionMenu selectedItem];
if(selectedTag == nil)
return nil;
return [selectedTag.tag getName];
}
}
return nil;
}
- (void)tokenTextViewResignFirstResponder:(id)sender {
if(sender == tagsField) {
if(_completionMenu) {
[_completionMenu orderOut:self];
}
}
}
- (void)tokenTextViewCurrentTokenOriginDidChange:(id)sender {
if(sender == tagsField) {
if(!_completionMenu)
return;
var point = [tagsField currentTokenOrigin];
point = [sender convertPoint:point toView:nil];
point.y += 21;
[_completionMenu setFrameOrigin:point];
}
}
- (void)tokenTextViewCurrentTokenDidChange:(id)sender {
if(sender == tagsField) {
if(!_completionMenu) {
_completionMenu = [[NAMenu alloc] init];
_completionContent = [[self class] availableTags];
[_completionMenu setContent:_completionContent];
}
var stringValue = [tagsField currentTokenStringValue];
if([stringValue length] > 0) {
var tags = [[self class] availableTags];//NAModelTag search:stringValue into:[astor.tags array]];
[_completionContent removeAllObjects];
var i, tag, count = [tags count];
if(count > 10)
count = 10;
for(i = 0; i < count; ++i) {
tag = [tags objectAtIndex:i];
[_completionContent addObject:{ 'name' : tag, 'tag' : tag }];
}
[_completionMenu reloadContent];
if([_completionContent count] > 0) {
[_completionMenu orderFront:self];
}
else {
[_completionMenu orderOut:self];
}
}
else {
[_completionMenu orderOut:self];
}
}
}*/
- (CPArray)collectionView:(CPCollectionView)aCollectionView dragTypesForItemsAtIndexes:(CPIndexSet)indices
{
//if ([[aCollectionView content][[indices firstIndex]] type] === "image")
return ["ItemImageAttachment"];
}
- (CPData)collectionView:(CPCollectionView)aCollectionView dataForItemsAtIndexes:(CPIndexSet)indices forType:(CPString)aType
{
return [CPKeyedArchiver archivedDataWithRootObject:indices];
}
- (BOOL)collectionView:(CPCollectionView)aView shouldDeleteItemsAtIndexes:(CPIndexSet)indicies
{
return YES;
//return NO;
}
- (void)collectionView:(CPCollectionView)aView didDoubleClickOnItemAtIndex:(int)anIndex
{
var item = [aView content][anIndex],
//itemView = ;[[aView items][anIndex] view],
itemFrame = [aView frameForItemAtIndex:anIndex];//[itemView frame];
//convert frame to window
itemFrame = [aView convertRect:itemFrame toView:nil];
var window = [[CPWindow alloc] initWithContentRect:itemFrame styleMask:CPTitledWindowMask|CPHUDBackgroundWindowMask|CPResizableWindowMask|CPClosableWindowMask];
[window setTitle:[item name]];
// FIX ME: here we need to store the size of the media so we have syncronous access to it
/*var image = [[CPImage alloc] initWithContentsOfFile:[item data]],
imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0, 0, 900, 550)],
scroll = [[CPScrollView alloc] initWithFrame:CGRectMake(0,0,900,550)],
hud = [CPTheme themeNamed:@"Aristo-HUD"];
[[scroll verticalScroller] setTheme:hud];
[[scroll horizontalScroller] setTheme:hud];
[scroll setDocumentView:imageView];
// [scroll setAutoresizingMask:CPViewHeightSizable|CPViewWidthSizable];
[imageView setImage:image];
[imageView setImageScaling:CPScaleNone];
// create some buttons
var fullScreenButton = [[CPButton alloc] initWithFrame:CGRectMake(425, 575, 75, 24)];
[fullScreenButton setTitle:@"Fullscreen"];
[fullScreenButton setTheme:hud];
[fullScreenButton setTarget:imageView];
[fullScreenButton setAction:@selector(enterFullScreenMode)];
var contentView = [window contentView];
[contentView addSubview:fullScreenButton];
[contentView addSubview:scroll];*/
mediaView = [[MediaView alloc] initWithFrame:CGRectMake(0,0,900,650)];
[mediaView setMedia:item forItem:[itemController activeItem]];
[window setContentView:mediaView];
[window makeKeyAndOrderFront:self];
[window makeFirstResponder:mediaView];
var containerSize = [CPPlatform isBrowser] ? [[window platformWindow] contentBounds].size : [[self screen] visibleFrame].size,
point = CGPointMake((containerSize.width - 900) / 2.0, (containerSize.height - 650) / 2.0),
size = [[aView window] frame].size,
newFrame = CGRectMake(point.x, point.y, 900, 650);
[window setFrame:newFrame display:YES animate:YES];
}
+ (CPTextField)ItemViewTextField
{
var textfield = [LocationEditView customTextField];
[textfield setFont:[CPFont systemFontOfSize:13]];
[textfield setValue:CGInsetMake(0.0, 10.0, 0.0, 10.0) forThemeAttribute:@"content-inset" inState:CPThemeStateNormal];
[textfield setValue:CGInsetMake(1.0, 10.0, 0.0, 10.0) forThemeAttribute:@"content-inset" inState:CPThemeStateEditing];
[textfield setBezeled:NO];
[textfield setEditable:NO];
return textfield;
}
+ (CPTextField)customLabelWithFrame:(CGRect)aRect
{
var textfield = [[CPTextField alloc] initWithFrame:aRect];
[textfield setTextColor:[CPColor colorWithHexString:"666666"]];
[textfield setFont:[CPFont boldSystemFontOfSize:12]];
[textfield setAlignment:CPRightTextAlignment];
return textfield;
}
@end
@implementation AutoExpandingTextField : LPMultiLineTextField
{
}
- (void)setFrameHeightToFit
{
var element = document.getElementsByTagName("textarea"),
aSize = nil;
for(var i=0; i < element.length; i++)
{
if(element[i] === document.activeElement)
{
//FitToContent(element[i], 200000);
var aDOMElement = element[i],
adjustedHeight = aDOMElement.clientHeight;
adjustedHeight = MAX(aDOMElement.scrollHeight, adjustedHeight);
if(adjustedHeight > aDOMElement.clientHeight)
aDOMElement.style.height = adjustedHeight + "px";
var height = parseInt(aDOMElement.style.height);
aSize = CGSizeMake(CGRectGetWidth([self bounds]), height + 14);
}
}
[super setFrameSize:aSize];
}
- (void)sizeToFit
{
var width = CGRectGetWidth([self bounds]),
heightDiv = document.createElement("div"),
lineBreaks = [self stringValue].lastIndexOf("\n") + 1;
heightDiv.style.width = (width - [self currentValueForThemeAttribute:@"content-inset"].left - [self currentValueForThemeAttribute:@"content-inset"].right) + "px";
heightDiv.style.font = [[self font] cssString];
heightDiv.innerHTML = [self stringValue].replace(/\n/gi,"<br />");
heightDiv.style.zindex = -200;
//heightDiv.style.position = "absolute";
//heightDiv.style.top = "-2000px";
//heightDiv.style.left = "-2000px";
document.body.appendChild(heightDiv);
var height = heightDiv.offsetHeight + [self currentValueForThemeAttribute:@"content-inset"].top + [self currentValueForThemeAttribute:@"content-inset"].bottom + 16;
document.body.removeChild(heightDiv);
//height += (lineBreaks)*2.5;
[self setFrameSize:CGSizeMake(width, height)];
}
@end
@implementation ItemContentView : CPView
-(void)drawRect:(id)aRect
{
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextSetStrokeColor(context, [CPColor colorWithHexString:@"CCCCCC"]);
var points = [
CGPointMake(15, 100.5),
CGPointMake(388, 100.5)
];
CGContextStrokeLineSegments(context, points, 2);
}
@end
@implementation RLProgressIndicator : CPProgressIndicator
- (void)updateBackgroundColor
{
[self setBackgroundColor:[CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"Attachments/upload-background.png"] size:CGSizeMake(47,7)]]];
[self drawBar];
}
- (void)drawBar
{
if (_style == CPProgressIndicatorSpinningStyle)
return;
if (!_barView)
{
_barView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 1.0, 0.0, 5.0)];
[self addSubview:_barView];
}
var bundle = [CPBundle mainBundle];
[_barView setBackgroundColor:[CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"Attachments/upload-bar-0.png"] size:CGSizeMake(3,5)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"Attachments/upload-bar-1.png"] size:CGSizeMake(1,5)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"Attachments/upload-bar-2.png"] size:CGSizeMake(3,5)]
]
isVertical:NO]]];
var width = CGRectGetWidth([self bounds]),
barWidth = width * ((_doubleValue - _minValue) / (_maxValue - _minValue));
if (barWidth > 0.0 && barWidth < 4.0)
barWidth = 4.0;
[_barView setFrameSize:CGSizeMake(barWidth, 5.0)];
}
@end
@implementation AttachmentCell : CPView
{
CPTextField name;
CPImageView image;