1 | /* SaveBedConfigCommand.as */
|
---|
2 |
|
---|
3 | package gov.va.med.edp.command.config
|
---|
4 | {
|
---|
5 | import com.adobe.cairngorm.commands.ICommand;
|
---|
6 | import com.adobe.cairngorm.control.CairngormEvent;
|
---|
7 |
|
---|
8 | import gov.va.med.edp.business.config.SaveBedConfigDelegate;
|
---|
9 | import gov.va.med.edp.command.AbstractResponderCommand;
|
---|
10 | import gov.va.med.edp.factory.SessionFactory;
|
---|
11 | import gov.va.med.edp.factory.TrackingFactory;
|
---|
12 | import gov.va.med.edp.model.TrackingModelLocator;
|
---|
13 | import gov.va.med.edp.vo.RoomBedVO;
|
---|
14 | import gov.va.med.edp.widget.InfoDialog;
|
---|
15 |
|
---|
16 | import mx.collections.ArrayCollection;
|
---|
17 | import mx.rpc.IResponder;
|
---|
18 | import mx.rpc.events.FaultEvent;
|
---|
19 | import mx.rpc.events.ResultEvent;
|
---|
20 |
|
---|
21 | public class SaveBedConfigCommand extends AbstractResponderCommand implements ICommand, IResponder
|
---|
22 | {
|
---|
23 | private var model:TrackingModelLocator = TrackingModelLocator.getInstance();
|
---|
24 |
|
---|
25 | public function execute(event:CairngormEvent): void
|
---|
26 | {
|
---|
27 | // clear filter so we don't miss any changes that might be hidden
|
---|
28 | var bedFilter: Function = model.config.beds.filterFunction;
|
---|
29 | if (bedFilter != null) {
|
---|
30 | model.config.beds.filterFunction = null;
|
---|
31 | model.config.beds.refresh();
|
---|
32 | }
|
---|
33 |
|
---|
34 | // set the sequence based on the visible order in the datagrid
|
---|
35 | var i: int;
|
---|
36 | var seq: int;
|
---|
37 | var bed: RoomBedVO;
|
---|
38 | for (i=0; i<model.config.beds.length; i++) {
|
---|
39 | seq = (i+1)*10;
|
---|
40 | bed = model.config.beds[i] as RoomBedVO;
|
---|
41 | if (bed.sequence != seq) {
|
---|
42 | bed.sequence = seq;
|
---|
43 | bed.changed = true;
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | // create a collection of the changed entries
|
---|
48 | var saveBeds: ArrayCollection = new ArrayCollection();
|
---|
49 | for (i=0; i<model.config.beds.length; i++) {
|
---|
50 | bed = model.config.beds[i] as RoomBedVO;
|
---|
51 | if (bed.changed) {
|
---|
52 | saveBeds.addItem(bed);
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | // reset filter to previous setting now that beds have been saved
|
---|
57 | if (bedFilter != null) {
|
---|
58 | model.config.beds.filterFunction = bedFilter;
|
---|
59 | model.config.beds.refresh();
|
---|
60 | }
|
---|
61 |
|
---|
62 | // now save the changed entries
|
---|
63 | model.config.bedLoaded = false;
|
---|
64 | var delegate: SaveBedConfigDelegate = new SaveBedConfigDelegate(this);
|
---|
65 | delegate.saveBedConfig(saveBeds, model.logArea, model.config.bedToken);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public override function result(data:Object):void
|
---|
69 | {
|
---|
70 | var xml:XML = ResultEvent(data).result as XML;
|
---|
71 | if ((xml.save.@status == "ok") || (xml.save.@status == "collide")) {
|
---|
72 | model.config.beds =
|
---|
73 | TrackingFactory.buildRoomBedListFromXML(xml.beds.bed);
|
---|
74 | model.config.defaultRoomList =
|
---|
75 | SessionFactory.buildLookupListFromXML(xml.defaultRoomList.item);
|
---|
76 | model.config.bedToken = xml.bedToken;
|
---|
77 | model.config.bedMods = false;
|
---|
78 | model.config.bedLoaded = true;
|
---|
79 |
|
---|
80 | if (xml.save.@status == "ok") {
|
---|
81 | InfoDialog.show("New room/bed configuration saved.");
|
---|
82 | } else {
|
---|
83 | InfoDialog.show("Save failed: " + xml.save);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | if (xml.save.@status == "fail") {
|
---|
88 | InfoDialog.show("Save failed: " + xml.save);
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | protected override function getFaultMessage(faultEvent:FaultEvent):String {
|
---|
93 | return "Error saving configuration for rooms / beds: " + super.getFaultMessage(faultEvent);
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|