Changeset 3918


Ignore:
Timestamp:
10/31/13 09:46:34 (11 years ago)
Author:
twagoo
Message:

Moved 'move to group' controls from InfoPage? to BrowserOverviewList?
Refs #431

Location:
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/BrowserOverviewList.mxml

    r3907 r3918  
    1616        <mx:Script>
    1717                <![CDATA[
     18                        import clarin.cmdi.componentregistry.common.Group;
    1819                        import clarin.cmdi.componentregistry.common.ItemDescription;
    1920                        import clarin.cmdi.componentregistry.common.components.BrowseContextMenu;
     
    2122                        import clarin.cmdi.componentregistry.common.components.RssDescriptionsContextMenu;
    2223                        import clarin.cmdi.componentregistry.services.Config;
    23                         import clarin.cmdi.componentregistry.common.StyleConstants;
    24                
    25                         import flash.events.ContextMenuEvent;
    26                         import flash.ui.ContextMenu;
    27                         import flash.ui.ContextMenuItem;
     24                        import clarin.cmdi.componentregistry.services.ListUserGroupsMembershipService;
     25                       
     26                        import mx.collections.ArrayCollection;
    2827                        import mx.controls.Alert;
    29                        
    30                         import mx.collections.ArrayCollection;
    31                         import mx.controls.Text;
    32                         import mx.core.UIComponent;
     28                        import mx.events.CloseEvent;
     29                        import mx.rpc.events.ResultEvent;
    3330                       
    3431                        private var defaultColor:Object;
     
    5047                        [Bindable]
    5148                        public var spaceSwitchEnabled:Boolean = false;
     49                       
     50                        [Bindable]
     51                        private var groups:ArrayCollection = new ArrayCollection();
     52                       
     53                        private static var currentSelectedGroup:String="";
     54                        private var previousSelectedIndex:int=0;
    5255                       
    5356                        public function set browserDataProvider(dataProvider:ArrayCollection):void {
     
    7679                        private function init():void{
    7780                                Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, onSpaceChanged);
     81
     82                                groups.addItem("Move to group...");
     83                                Config.instance.getListUserGroupsMembershipService().addEventListener(ListUserGroupsMembershipService.GROUPS_LOADED, onGroupsLoaded);
     84                                Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, updateGroupVisibility);
     85                                Config.instance.getListUserGroupsMembershipService().loadGroupsForUser();
     86                                addEventListener(GroupSelectionEvent.GROUP_SELECTED, onGroupSelected);
     87                               
    7888                                scrollToSelected();
    7989                        }
     
    8292                                createNewButton.visible = (!Config.instance.selectedGroup);
    8393                                createNewButton.includeInLayout = (!Config.instance.selectedGroup);
     94                                importButton.visible = (!Config.instance.selectedGroup);
     95                                importButton.includeInLayout = (!Config.instance.selectedGroup);
    8496                        }
    8597
     
    132144                        }
    133145                       
     146                       
     147                       
     148                        private function onGroupSelected(event:GroupSelectionEvent):void {
     149                                //Some handler already moved the group for us
     150                                if (event.groupWasMoved)
     151                                        return;
     152                                if (!event.getGroupId()){
     153                                        // we don't want items to be moved from groups into void, thus object this selection event
     154                                        event.stopPropagation();
     155                                        event.stopImmediatePropagation();
     156                                        event.preventDefault();
     157                                } else{
     158                                        var groupId:String = event.getGroupId();
     159                                        var itemId:String = currentSelectedItem.id;
     160                                        Alert.show("Items, once moved to a group, can not be moved back to your workspace. Do you want to move this item?", "Title", mx.controls.Alert.YES | mx.controls.Alert.NO, this, function (nestedCloseEvent:CloseEvent):void {
     161                                                if (nestedCloseEvent.detail == Alert.YES) {
     162                                                        Config.instance.getListGroupsOfItemService().transferOwnership(itemId, groupId, itemTransferToGroupComplete);
     163                                                }
     164                                        });
     165                                }
     166                                event.groupWasMoved = true;
     167                        }
     168                       
     169                        private function onMoveToGroupButtonClicked(event:Event):void {
     170                                currentSelectedGroup=groupBox.selectedItem.groupId;
     171                                var groupEvent:GroupSelectionEvent = new GroupSelectionEvent(groupBox.selectedItem.groupId, groupBox.selectedItem.label);
     172                                dispatchEvent(groupEvent);
     173                                // did someone object this selection?
     174                                if (groupEvent.isDefaultPrevented()){
     175                                        //e.preventDefault, stopPropagation and stopImmediatePropagation don't undo the selection so we have to do it manually here
     176                                        groupBox.selectedIndex = previousSelectedIndex;
     177                                } else{
     178                                        previousSelectedIndex = groupBox.selectedIndex;
     179                                }
     180                        }
     181                       
     182                        public function onGroupsLoaded(event:Event):void{
     183                                groups.removeAll();
     184                                groups.addItem({label:"Move to group...", space:null, groupId:null});
     185                               
     186                                for each (var group:Group in Config.instance.getListUserGroupsMembershipService().groups) {
     187                                        groups.addItem({label:group.name, space:Config.SPACE_USER, groupId:group.id});                                 
     188                                }
     189                                updateGroupVisibility(event);
     190                        }
     191                       
     192                       
     193                        private function updateGroupVisibility(event:Event):void{
     194                                var showGroups:Boolean = Config.instance.getListUserGroupsMembershipService().groups.length>0 && Config.instance.space != Config.SPACE_PUBLIC;
     195                                groupPanel.visible = showGroups;
     196                                groupBox.selectedIndex = 0;
     197                        }
     198                       
     199                        protected function itemTransferToGroupComplete(resultEvent:ResultEvent):void {
     200                                RegistryViewStack.showView(Config.VIEW_BROWSE, currentSelectedItem);
     201                        }
    134202                ]]>
    135203        </mx:Script>
     
    169237                                           enabled="{Config.instance.space != Config.SPACE_USER &amp;&amp; dataGrid.selectedItem != null}"
    170238                                           click="editItem()" />
    171                         <mx:Button label="Import"
     239                        <mx:Button id="importButton"
     240                                           label="Import"
    172241                                           toolTip="Import an item from a local file"
    173242                                           click="importItem()" />
     243                       
     244                        <mx:HBox id="groupPanel"
     245                                         visible="true"
     246                                         enabled="{Config.instance.space == Config.SPACE_USER &amp;&amp; dataGrid.selectedItem != null}"
     247                                         >
     248                                <mx:ComboBox id="groupBox"
     249                                                         dataProvider="{groups}"
     250                                                         />
     251                                <mx:Button id="moveToGroupBtn"
     252                                                   label="Move to group"
     253                                                   click="onMoveToGroupButtonClicked(event)"/>
     254                        </mx:HBox>
    174255                       
    175256                </mx:HBox>
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/browser/infoPage.mxml

    r3907 r3918  
    44                 xmlns:common="clarin.cmdi.componentregistry.common.*"
    55                 xmlns:browser="clarin.cmdi.componentregistry.browser.*"
    6                  creationComplete="init()"
    76                 >
    8 
     7       
    98        <mx:Metadata>
    109                [Event(name="groupSelected", type="clarin.cmdi.componentregistry.browser.GroupSelectionEvent")]
     
    2423                                                        dataProvider="{infoViewStack}"/>
    2524               
    26                 <mx:HBox id="groupPanel" visible="true">
    27                         <mx:ComboBox id="groupBox"
    28                                          dataProvider="{groups}"
    29                                          />
    30                         <mx:Button id="moveToGroupBtn"
    31                                    label="Move to group"
    32                                    click="onMoveToGroupButtonClicked(event)"/>
    33                 </mx:HBox>
    3425        </mx:HBox>
    3526
     
    6051        <mx:Script>
    6152                <![CDATA[
    62                         import clarin.cmdi.componentregistry.common.Group;
    6353                        import clarin.cmdi.componentregistry.common.ItemDescription;
    64                         import clarin.cmdi.componentregistry.common.components.RegistryViewStack;
    65                         import clarin.cmdi.componentregistry.services.CommentListService;
    6654                        import clarin.cmdi.componentregistry.services.Config;
    67                         import clarin.cmdi.componentregistry.services.ListUserGroupsMembershipService;
    6855                       
    69                         import mx.collections.ArrayCollection;
    70                         import mx.controls.Alert;
    71                         import mx.events.CloseEvent;
    72                         import mx.events.FlexEvent;
    7356                        import mx.events.IndexChangedEvent;
    74                         import mx.messaging.SubscriptionInfo;
    75                         import mx.rpc.events.ResultEvent;
    76                        
    77                         private static var currentSelectedGroup:String="";
    78                         private var previousSelectedIndex:int=0;
     57
    7958
    8059                        [Bindable]
    8160                        private var _itemDescription:ItemDescription;
    82                         [Bindable]
    83                         private var groups:ArrayCollection = new ArrayCollection();
    84                        
    85                         public function init():void{
    86                                 groups.addItem("Move to group...");
    87                                 Config.instance.getListUserGroupsMembershipService().addEventListener(ListUserGroupsMembershipService.GROUPS_LOADED, onGroupsLoaded);
    88                                 Config.instance.addEventListener(Config.USER_SPACE_TOGGLE_EVENT, updateGroupVisibility);
    89                                 Config.instance.getListUserGroupsMembershipService().loadGroupsForUser();
    90                                 addEventListener(GroupSelectionEvent.GROUP_SELECTED, onGroupSelected);
    91                         }
    92 
    93                         private function onGroupSelected(event:GroupSelectionEvent):void {
    94                                 //Some handler already moved the group for us
    95                                 if (event.groupWasMoved)
    96                                         return;
    97                                 if (!event.getGroupId()){
    98                                         // we don't want items to be moved from groups into void, thus object this selection event
    99                                         event.stopPropagation();
    100                                         event.stopImmediatePropagation();
    101                                         event.preventDefault();
    102                                 } else{
    103                                         var groupId:String = event.getGroupId();
    104                                         var itemId:String = _itemDescription.id;
    105                                         Alert.show("Items, once moved to a group, can not be moved back to your workspace. Do you want to move this item?", "Title", mx.controls.Alert.YES | mx.controls.Alert.NO, this, function (nestedCloseEvent:CloseEvent):void {
    106                                                 if (nestedCloseEvent.detail == Alert.YES) {
    107                                                         Config.instance.getListGroupsOfItemService().transferOwnership(itemId, groupId, itemTransferToGroupComplete);
    108                                                 }
    109                                         });
    110                                 }
    111                                 event.groupWasMoved = true;
    112                         }
    113 
    114                         private function onMoveToGroupButtonClicked(event:Event):void {
    115                                 currentSelectedGroup=groupBox.selectedItem.groupId;
    116                                 var groupEvent:GroupSelectionEvent = new GroupSelectionEvent(groupBox.selectedItem.groupId, groupBox.selectedItem.label);
    117                                 dispatchEvent(groupEvent);
    118                                 // did someone object this selection?
    119                                 if (groupEvent.isDefaultPrevented()){
    120                                         //e.preventDefault, stopPropagation and stopImmediatePropagation don't undo the selection so we have to do it manually here
    121                                         groupBox.selectedIndex = previousSelectedIndex;
    122                                 } else{
    123                                         previousSelectedIndex = groupBox.selectedIndex;
    124                                 }
    125                         }
    126                        
    127                        
    128                        
    129                         public function onGroupsLoaded(event:Event):void{
    130                                 groups.removeAll();
    131                                 groups.addItem({label:"Move to group...", space:null, groupId:null});
    132                                
    133                                 for each (var group:Group in Config.instance.getListUserGroupsMembershipService().groups) {
    134                                         groups.addItem({label:group.name, space:Config.SPACE_USER, groupId:group.id});                                 
    135                                 }
    136                                 updateGroupVisibility(event);
    137                         }
    138                        
    139                        
    140                         private function updateGroupVisibility(event:Event):void{
    141                                 var showGroups:Boolean = Config.instance.getListUserGroupsMembershipService().groups.length>0 && Config.instance.space != Config.SPACE_PUBLIC;
    142                                 groupPanel.visible = showGroups;
    143                                 groupBox.selectedIndex = 0;
    144                         }
    14561
    14662
     
    17894                        }
    17995
    180                         protected function itemTransferToGroupComplete(resultEvent:ResultEvent):void {
    181                                 RegistryViewStack.showView(Config.VIEW_BROWSE, _itemDescription);
    182                         }
    183 
    18496                ]]>
    18597        </mx:Script>
Note: See TracChangeset for help on using the changeset viewer.