New Bookmarks menu
[potlatch2.git] / net / systemeD / controls / DeletableListItemRenderer.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <!-- http://blog.flexexamples.com/2010/04/09/adding-a-delete-button-in-the-hovered-state-of-a-spark-list-control-item-renderer-in-flex-4/ -->
3 <s:ItemRenderer name="DeletableListItemRenderer"
4         xmlns:fx="http://ns.adobe.com/mxml/2009" 
5         xmlns:s="library://ns.adobe.com/flex/spark" 
6         xmlns:mx="library://ns.adobe.com/flex/mx" 
7         autoDrawBackground="true"
8         minHeight="24">
9     <s:states>
10         <s:State name="normal" />
11         <s:State name="hovered" />
12         <s:State name="selected" />
13     </s:states>
14  
15     <fx:Script>
16         <![CDATA[
17             import mx.controls.Alert;
18             import mx.events.CloseEvent;
19  
20             import spark.components.List;
21  
22             protected function button1_clickHandler(evt:MouseEvent):void {
23                 Alert.show(data.label,
24                         "Are you sure you want to delete this item?",
25                         Alert.YES|Alert.CANCEL,
26                         null,
27                         alrt_closeHandler);
28             }
29  
30             protected function alrt_closeHandler(evt:CloseEvent):void {
31                 switch (evt.detail) {
32                     case Alert.YES:
33                     case Alert.OK:
34                         Object(owner).dataProvider.removeItemAt(itemIndex);
35                         break;
36                     case Alert.CANCEL:
37                     case Alert.NO:
38                         Object(owner).selectedIndex = -1;
39                         break;
40                     default:
41                         break;
42                 }
43             }
44         ]]>
45     </fx:Script>
46  
47     <s:HGroup width="100%" height="100%"
48             verticalAlign="middle"
49             paddingLeft="2" paddingRight="2"
50             paddingTop="2" paddingBottom="2">
51         <s:Label id="lbl" text="{data.name}" width="100%" />
52         <s:Image id="btn" includeIn="hovered,selected" source="@Embed('../../../embedded/delete_small.svg')" click="button1_clickHandler(event)" />
53     </s:HGroup>
54  
55 </s:ItemRenderer>