1 | /* SaveConfigColorsCommand.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.SaveConfigColorsDelegate;
|
---|
9 | import gov.va.med.edp.command.AbstractResponderCommand;
|
---|
10 | import gov.va.med.edp.model.TrackingModelLocator;
|
---|
11 | import gov.va.med.edp.vo.ColorMapVO;
|
---|
12 | import gov.va.med.edp.vo.ColorMatchVO;
|
---|
13 | import gov.va.med.edp.widget.InfoDialog;
|
---|
14 | import gov.va.med.edp.util.BoardTools;
|
---|
15 |
|
---|
16 | import mx.rpc.IResponder;
|
---|
17 | import mx.rpc.events.FaultEvent;
|
---|
18 | import mx.rpc.events.ResultEvent;
|
---|
19 |
|
---|
20 | public class SaveConfigColorsCommand extends AbstractResponderCommand implements ICommand, IResponder
|
---|
21 | {
|
---|
22 | private var model:TrackingModelLocator = TrackingModelLocator.getInstance();
|
---|
23 |
|
---|
24 | public function execute(event:CairngormEvent):void
|
---|
25 | {
|
---|
26 | var delegate: SaveConfigColorsDelegate = new SaveConfigColorsDelegate(this);
|
---|
27 |
|
---|
28 | var xml: XML = <colorSpec />;
|
---|
29 | for each (var map: ColorMapVO in model.config.colorMaps) {
|
---|
30 | var colors: XML = <colors />;
|
---|
31 | colors.@id = map.id;
|
---|
32 | colors.@type = map.type;
|
---|
33 | for each (var match: ColorMatchVO in map.matches) {
|
---|
34 | var node: XML = <map />;
|
---|
35 | node.@att = match.attribute;
|
---|
36 | node.@val = match.value;
|
---|
37 | node.@clr = match.color.toString();
|
---|
38 | colors.appendChild(node);
|
---|
39 | }
|
---|
40 | xml.appendChild(colors);
|
---|
41 | }
|
---|
42 | model.config.colorLoaded = false;
|
---|
43 | delegate.saveConfigColors(model.logArea, xml, model.config.colorToken);
|
---|
44 | }
|
---|
45 |
|
---|
46 | public override function result(data:Object):void
|
---|
47 | {
|
---|
48 | var xml:XML = ResultEvent(data).result as XML;
|
---|
49 | if ((xml.save.@status == "ok") || (xml.save.@status == "collide")) {
|
---|
50 | BoardTools.applyColorSpec(xml.colorSpec.colors, model.config.colorMaps);
|
---|
51 | model.config.colorToken = xml.colorToken;
|
---|
52 | model.config.colorMods = false;
|
---|
53 | model.config.colorLoaded = true;
|
---|
54 |
|
---|
55 | if (xml.save.@status == "ok") {
|
---|
56 | InfoDialog.show("New board colors saved.");
|
---|
57 | } else {
|
---|
58 | InfoDialog.show("Save failed: " + xml.save);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | if (xml.save.@status == "fail") {
|
---|
63 | InfoDialog.show("Save failed: " + xml.save);
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected override function getFaultMessage(faultEvent:FaultEvent):String {
|
---|
68 | return "Error saving configuration for colors: " + super.getFaultMessage(faultEvent);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|