1 | /* RefreshLogSelectorCommand.as */
|
---|
2 |
|
---|
3 | package gov.va.med.edp.command
|
---|
4 | {
|
---|
5 | import com.adobe.cairngorm.commands.ICommand;
|
---|
6 | import com.adobe.cairngorm.control.CairngormEvent;
|
---|
7 |
|
---|
8 | import gov.va.med.edp.business.RefreshLogSelectorDelegate;
|
---|
9 | import gov.va.med.edp.factory.TrackingFactory;
|
---|
10 | import gov.va.med.edp.model.TrackingModelLocator;
|
---|
11 | import gov.va.med.edp.util.Vista;
|
---|
12 |
|
---|
13 | import mx.collections.ArrayCollection;
|
---|
14 | import mx.collections.Sort;
|
---|
15 | import mx.collections.SortField;
|
---|
16 | import mx.rpc.IResponder;
|
---|
17 | import mx.rpc.events.FaultEvent;
|
---|
18 | import mx.rpc.events.ResultEvent;
|
---|
19 |
|
---|
20 | public class RefreshLogSelectorCommand 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:RefreshLogSelectorDelegate = new RefreshLogSelectorDelegate(this);
|
---|
27 | delegate.refreshLogSelector(model.logArea, model.logEntryList.token);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public override function result(data:Object):void
|
---|
31 | {
|
---|
32 | var xml:XML = ResultEvent(data).result as XML;
|
---|
33 |
|
---|
34 | //DONOT refresh if the Dirty flags is true. This is because the ChangeWatcher keeps different
|
---|
35 | //components in sync but if the user is still editing and the referesh comes in the components get
|
---|
36 | //out of sync..
|
---|
37 | //ALSO only refresh the list if it has changed
|
---|
38 | if (!model.logEdit.dirty && xml.logEntries.@status == "new"){
|
---|
39 | model.logEntryList.entries =
|
---|
40 | new ArrayCollection(TrackingFactory.buildLogSelectorListFromXML(xml.logEntries.log));
|
---|
41 | model.logEntryList.token = xml.logEntries.@token;
|
---|
42 |
|
---|
43 | // sort based on previous settings
|
---|
44 | if (model.logEntryList.sortField.length > 0) {
|
---|
45 | var sort:Sort = new Sort();
|
---|
46 | sort.fields = [new SortField(model.logEntryList.sortField, true, model.logEntryList.sortDescending)];
|
---|
47 | model.logEntryList.entries.sort = sort;
|
---|
48 | model.logEntryList.entries.refresh();
|
---|
49 | }
|
---|
50 | // now that it is sorted, reset the selected index (must set initial -1 to fire bindings)
|
---|
51 | model.logEntryList.selectedIndex = -1;
|
---|
52 | model.logEntryList.selectedIndex =
|
---|
53 | Vista.locateIndex(model.logEntryList.entries, model.logEntryList.selectedID, "id");
|
---|
54 | // if the ID is no longer in the list, the entry must be closed
|
---|
55 | if ((model.logEntryList.selectedIndex == -1) && (model.logEntryList.selectedID > 0)) {
|
---|
56 | model.logEdit.resetEntry();
|
---|
57 | model.logEdit.message = "The selected entry has been closed.";
|
---|
58 | model.logEntryViewState = TrackingModelLocator.VIEW_EDIT_MESSAGE;
|
---|
59 | //from AutoSave: model.editorViewState = TrackingModelLocator.VIEW_EDIT_MESSAGE;
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | protected override function getFaultMessage(faultEvent:FaultEvent):String {
|
---|
65 | return "Refresh Log Selector failed: " + super.getFaultMessage(faultEvent);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|