source: ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/CommentListService.as @ 1706

Last change on this file since 1706 was 1706, checked in by twagoo, 12 years ago

Implemented posting comments (still fails on the server but start of UI + service is there)

File size: 1.6 KB
Line 
1package clarin.cmdi.componentregistry.services {
2        import clarin.cmdi.componentregistry.common.Comment;
3        import clarin.cmdi.componentregistry.common.ItemDescription;
4       
5        import com.adobe.net.URI;
6       
7        import mx.collections.ArrayCollection;
8        import mx.rpc.events.ResultEvent;
9       
10        [Event(name="CommentsLoaded", type="flash.events.Event")]
11        public class CommentListService extends ComponentRegistryService {
12                public static const COMMENTS_LOADED:String = "CommentsLoaded";
13                ;
14                private var userSpace:Boolean;
15               
16                /**
17                 * Typed ArrayCollection publicly available for outside code to bind to and watch.
18                 */
19                [Bindable]
20                [ArrayElementType("Comment")]
21                public var comments:ArrayCollection;
22               
23                public function CommentListService(itemDescription:ItemDescription, userSpace:Boolean) {
24                        var url:String;
25                        if(itemDescription.isProfile){
26                                url = Config.instance.getProfileCommentsPath(itemDescription.id);
27                        } else{
28                                url = Config.instance.getComponentCommentsPath(itemDescription.id);
29                        }
30                        super(url);
31                       
32                        this.userSpace = userSpace;
33                }
34               
35                override protected function initServiceUrl(url:URI):void{
36                        if (userSpace) {
37                                url.setQueryValue(Config.PARAM_USERSPACE, "true");
38                        }
39                }
40               
41                override protected function result(resultEvent:ResultEvent):void {
42                        var resultXml:XML = resultEvent.result as XML;
43                        var nodes:XMLList = resultXml.comment;
44                       
45                        comments = new ArrayCollection();
46                        for each (var node:XML in nodes) {
47                                var comment:Comment = new Comment();
48                                comment.create(node);
49                                comments.addItem(comment);
50                        }
51                        comments.refresh();
52                        dispatchEvent(new Event(COMMENTS_LOADED));
53                }
54        }
55}
Note: See TracBrowser for help on using the repository browser.