1 | package clarin.cmdi.componentregistry.browser |
---|
2 | { |
---|
3 | import clarin.cmdi.componentregistry.common.Comment; |
---|
4 | import clarin.cmdi.componentregistry.services.DeleteService; |
---|
5 | |
---|
6 | import flash.events.MouseEvent; |
---|
7 | |
---|
8 | import mx.containers.HBox; |
---|
9 | import mx.containers.VBox; |
---|
10 | import mx.controls.Alert; |
---|
11 | import mx.controls.Button; |
---|
12 | import mx.controls.HRule; |
---|
13 | import mx.controls.Label; |
---|
14 | import mx.controls.Text; |
---|
15 | import mx.events.CloseEvent; |
---|
16 | |
---|
17 | public class CommentPanel extends VBox |
---|
18 | { |
---|
19 | private var userNameLabel:Label = new Label(); |
---|
20 | private var dateLabel:Label = new Label(); |
---|
21 | private var commentText:Text = new Text(); |
---|
22 | private var comment:Comment; |
---|
23 | |
---|
24 | public function CommentPanel(comment:Comment) |
---|
25 | { |
---|
26 | super(); |
---|
27 | this.comment = comment; |
---|
28 | |
---|
29 | initLayout(); |
---|
30 | setValues(); |
---|
31 | } |
---|
32 | |
---|
33 | private function initLayout():void{ |
---|
34 | this.width = 400; |
---|
35 | |
---|
36 | var header:HBox = new HBox(); |
---|
37 | header.percentWidth = 100; |
---|
38 | header.addChild(userNameLabel); |
---|
39 | header.addChild(dateLabel); |
---|
40 | |
---|
41 | userNameLabel.setStyle("fontWeight","bold"); |
---|
42 | userNameLabel.setStyle("textDecoration","underline"); |
---|
43 | userNameLabel.percentWidth = 70; |
---|
44 | dateLabel.setStyle("textAlign", "right"); |
---|
45 | dateLabel.setStyle("fontWeight","bold"); |
---|
46 | dateLabel.percentWidth = 30; |
---|
47 | |
---|
48 | addChild(header); |
---|
49 | |
---|
50 | commentText.percentWidth = 100; |
---|
51 | addChild(commentText); |
---|
52 | |
---|
53 | if(comment.canDelete) { |
---|
54 | var deleteButton:Button = new Button(); |
---|
55 | deleteButton.label = "Delete comment"; |
---|
56 | deleteButton.addEventListener(MouseEvent.CLICK, confirmDeleteHandler); |
---|
57 | addChild(deleteButton); |
---|
58 | } |
---|
59 | |
---|
60 | var rule:HRule = new HRule(); |
---|
61 | rule.percentWidth = 100; |
---|
62 | addChild(rule); |
---|
63 | } |
---|
64 | |
---|
65 | private function setValues():void{ |
---|
66 | userNameLabel.text = comment.userName; |
---|
67 | dateLabel.text = comment.commentDate; |
---|
68 | commentText.text = comment.comments; |
---|
69 | } |
---|
70 | |
---|
71 | private function confirmDeleteHandler(event:MouseEvent):void{ |
---|
72 | Alert.show("Are you sure you want to delete this comment?", "Delete comment", Alert.OK|Alert.CANCEL, this, deleteHandler); |
---|
73 | } |
---|
74 | |
---|
75 | private function deleteHandler(event:CloseEvent):void { |
---|
76 | if(event.detail == Alert.OK){ |
---|
77 | DeleteService.instance.deleteComment(comment); |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|