1 | package clarin.cmdi.componentregistry.services { |
---|
2 | import com.adobe.net.URI; |
---|
3 | |
---|
4 | import mx.collections.ArrayCollection; |
---|
5 | |
---|
6 | import clarin.cmdi.componentregistry.common.Comment; |
---|
7 | import clarin.cmdi.componentregistry.common.ItemDescription; |
---|
8 | |
---|
9 | [Event(name="CommentsLoaded", type="flash.events.Event")] |
---|
10 | public class CommentListService extends ComponentRegistryService { |
---|
11 | public static const COMMENTS_LOADED:String = "CommentsLoaded"; |
---|
12 | private var itemDescription:ItemDescription; |
---|
13 | |
---|
14 | /** |
---|
15 | * Typed ArrayCollection publicly available for outside code to bind to and watch. |
---|
16 | */ |
---|
17 | [Bindable] |
---|
18 | [ArrayElementType("Comment")] |
---|
19 | public var comments:ArrayCollection; |
---|
20 | |
---|
21 | public function CommentListService(itemDescription:ItemDescription, userSpace:Boolean) { |
---|
22 | var url:String; |
---|
23 | if(itemDescription.isProfile){ |
---|
24 | url = Config.instance.getProfileCommentsPath(itemDescription.id); |
---|
25 | } else{ |
---|
26 | url = Config.instance.getComponentCommentsPath(itemDescription.id); |
---|
27 | } |
---|
28 | super(COMMENTS_LOADED, new URI(url)); |
---|
29 | |
---|
30 | this.itemDescription = itemDescription; |
---|
31 | this.userSpace = userSpace; |
---|
32 | } |
---|
33 | |
---|
34 | override protected function handleXmlResult(resultXml:XML):void{ |
---|
35 | var nodes:XMLList = resultXml.comment; |
---|
36 | |
---|
37 | comments = new ArrayCollection(); |
---|
38 | for each (var node:XML in nodes) { |
---|
39 | var comment:Comment = new Comment(); |
---|
40 | comment.create(node, itemDescription); |
---|
41 | comments.addItem(comment); |
---|
42 | } |
---|
43 | comments.refresh(); |
---|
44 | } |
---|
45 | } |
---|
46 | } |
---|