1 | package gov.va.med.edp.util
|
---|
2 | {
|
---|
3 | import flash.events.Event;
|
---|
4 |
|
---|
5 | import gov.va.med.edp.control.ChangeLogEntryFieldEvent;
|
---|
6 | import gov.va.med.edp.pt.demog.view.SelectPatientEvent;
|
---|
7 |
|
---|
8 | import mx.controls.ComboBox;
|
---|
9 | import mx.controls.TextInput;
|
---|
10 | import mx.events.CalendarLayoutChangeEvent;
|
---|
11 |
|
---|
12 | public class ChangeWatcher
|
---|
13 | {
|
---|
14 | public static function changeField(event: Event): void
|
---|
15 | {
|
---|
16 | var changeEvent: ChangeLogEntryFieldEvent =
|
---|
17 | new ChangeLogEntryFieldEvent(ChangeLogEntryFieldEvent.EVENT_CHANGE_LOG_ENTRY_FIELD);
|
---|
18 | changeEvent.field = event.currentTarget.id;
|
---|
19 | if (event.currentTarget is ComboBox) {
|
---|
20 | changeEvent.value = comboBoxValue(ComboBox(event.currentTarget));
|
---|
21 | changeEvent.label = comboBoxLabel(ComboBox(event.currentTarget));
|
---|
22 | changeEvent.reference = comboBoxRef(ComboBox(event.currentTarget));
|
---|
23 | }
|
---|
24 | if (event.currentTarget is TextInput) {
|
---|
25 | changeEvent.value = TextInput(event.currentTarget).text;
|
---|
26 | //changeEvent.value = (changeEvent.value == "") ? " " : changeEvent.value;
|
---|
27 | changeEvent.label = changeEvent.value;
|
---|
28 | }
|
---|
29 | if (event is SelectPatientEvent) {
|
---|
30 | changeEvent.value = SelectPatientEvent(event).patient;
|
---|
31 | changeEvent.field = "patient";
|
---|
32 | }
|
---|
33 | if (event is CalendarLayoutChangeEvent) {
|
---|
34 | changeEvent.value = CalendarLayoutChangeEvent(event).newDate;
|
---|
35 | changeEvent.field = event.currentTarget.id;
|
---|
36 | }
|
---|
37 | changeEvent.dispatch();
|
---|
38 | }
|
---|
39 |
|
---|
40 | private static function comboBoxValue(box: ComboBox): *
|
---|
41 | {
|
---|
42 | if (box.selectedItem == null) return -1;
|
---|
43 | return box.selectedItem.data;
|
---|
44 | }
|
---|
45 |
|
---|
46 | private static function comboBoxLabel(box: ComboBox): String
|
---|
47 | {
|
---|
48 | if (box.selectedItem == null) return "";
|
---|
49 | return box.selectedItem.label;
|
---|
50 | }
|
---|
51 |
|
---|
52 | private static function comboBoxRef(box: ComboBox): String
|
---|
53 | {
|
---|
54 | if (box.selectedItem == null) return "";
|
---|
55 | if (box.selectedItem.hasOwnProperty("reference")) {
|
---|
56 | return box.selectedItem.reference;
|
---|
57 | } else {
|
---|
58 | return "";
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|