1 | package clarin.cmdi.componentregistry.services { |
---|
2 | import clarin.cmdi.componentregistry.browser.BrowserColumns; |
---|
3 | import clarin.cmdi.componentregistry.common.ItemDescription; |
---|
4 | |
---|
5 | import mx.collections.ArrayCollection; |
---|
6 | import mx.rpc.events.ResultEvent; |
---|
7 | import flash.events.Event; |
---|
8 | |
---|
9 | |
---|
10 | [Event(name="profilesLoaded", type="flash.events.Event")] |
---|
11 | public class ProfileListService extends BrowserService { |
---|
12 | |
---|
13 | private static var _instance:ProfileListService = new ProfileListService(); |
---|
14 | private static var _userSpaceInstance:ProfileListService = new ProfileListService(true); |
---|
15 | |
---|
16 | public static const PROFILES_LOADED:String = "profilesLoaded"; |
---|
17 | |
---|
18 | public function ProfileListService(userSpace:Boolean=false) { |
---|
19 | super(Config.instance.profileListUrl, userSpace); |
---|
20 | } |
---|
21 | |
---|
22 | override protected function result(resultEvent:ResultEvent):void { |
---|
23 | var resultXml:XML = resultEvent.result as XML; |
---|
24 | var nodes:XMLList = resultXml.profileDescription; |
---|
25 | var tempArray:ArrayCollection = new ArrayCollection(); |
---|
26 | for each (var node:XML in nodes) { |
---|
27 | var item:ItemDescription = new ItemDescription(); |
---|
28 | item.createProfile(node, userSpace); |
---|
29 | tempArray.addItem(item); |
---|
30 | } |
---|
31 | tempArray.sort = BrowserColumns.getInitialSortForProfiles(); |
---|
32 | tempArray.refresh(); |
---|
33 | setItemDescriptions(new ArrayCollection(tempArray.toArray())); |
---|
34 | trace(itemDescriptions.length + " profiles are loaded"); |
---|
35 | dispatchEvent(new Event(PROFILES_LOADED)); |
---|
36 | //super.result(resultEvent); |
---|
37 | } |
---|
38 | |
---|
39 | public static function getInstance(userSpace:Boolean):ProfileListService { |
---|
40 | if (userSpace) { |
---|
41 | return _userSpaceInstance; |
---|
42 | } else { |
---|
43 | return _instance; |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | public static function findDescription(profileId:String):ItemDescription { |
---|
48 | var result:ItemDescription = getInstance(true).lookUpDescription(profileId); |
---|
49 | if (result == null) { |
---|
50 | result = getInstance(false).lookUpDescription(profileId); |
---|
51 | } |
---|
52 | return result |
---|
53 | } |
---|
54 | |
---|
55 | } |
---|
56 | } |
---|