hackedteam/rcs-console

View on GitHub
src/it/ht/rcs/console/accounting/view/users/UserActionBar.mxml

Summary

Maintainability
Test Coverage
<?xml version="1.0" encoding="utf-8"?>
<actionbar:ActionBar xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx"
                     xmlns:actionbar="it.ht.rcs.console.main.actionbar.*">
  
  
  <s:Button label="{R.get('NEW_USER')}" click="onNewClick()" icon="@Embed('/img/NEW/newUser.png')"/>
  
  <s:Button label="{R.get('EDIT_USER')}" click="onEditClick()" enabled="{selectedObject != null}"
            icon="@Embed('/img/NEW/edit.png')"/>
  
  <s:Button label="{R.get('DELETE_USER')}" click="onDeleteClick()" enabled="{selectedObject != null &amp;&amp;
                                                                            (selectedObject as User)._id != Console.currentSession.user._id}"
            icon="@Embed('/img/NEW/delete_32.png')"/>
  
  <actionbar:Separator width="40"/>
  
  <s:Button label="{R.get('DISCONNECT_USER')}" click="onDisconnectClick()"
            enabled="{selectedObject != null &amp;&amp; selectedObject.session}"
            icon="@Embed('/img/NEW/logout_32.png')"/>
  
  <actionbar:Separator width="40"/>
  
  <s:Spacer width="100%"/>
  
  <s:ButtonBar dataProvider="{viewStack}" requireSelection="true"/>
  
  <s:TextInput id="searchInput" keyUp="onKeyUp(event)"/>
  
  
  <fx:Script>
    <![CDATA[
      import it.ht.rcs.console.accounting.controller.SessionManager;
      import it.ht.rcs.console.accounting.controller.UserManager;
      import it.ht.rcs.console.accounting.model.User;
      import it.ht.rcs.console.utils.AlertPopUp;
      
      import locale.R;
      
      import mx.events.CloseEvent;
      import mx.managers.PopUpManager;
      
      private function onNewClick():void
      {
        var popup:UserForm = PopUpManager.createPopUp(root, UserForm, true) as UserForm;
        popup.currentState = 'create';
        PopUpManager.centerPopUp(popup);
      }
      
      private function onEditClick():void
      {
        var popup:UserForm = PopUpManager.createPopUp(root, UserForm, true) as UserForm;
        popup.user = selectedObject as User;
        popup.currentState = 'edit';
        PopUpManager.centerPopUp(popup);
      }
      
      private function onDeleteClick():void
      {
        AlertPopUp.show(R.get('CONFIRM_USER_DELETION', [selectedObject.name]), R.get('CONFIRM'),
                        AlertPopUp.YES|AlertPopUp.NO, null,
                        function(e:CloseEvent):void {
                          if (e.detail == AlertPopUp.YES)
                            UserManager.instance.removeItem(selectedObject);
                        }, null, AlertPopUp.NO);
      }
      
      private function onKeyUp(event:KeyboardEvent):void
      {
        if (view != null) view.refresh();
      }
      
      private function onDisconnectClick():void
      {
        SessionManager.instance.disconnectUser(selectedObject as User);
      }
    ]]>
  </fx:Script>

</actionbar:ActionBar>