hackedteam/rcs-console

View on GitHub
src/it/ht/rcs/console/entities/view/HandleForm.mxml

Summary

Maintainability
Test Coverage
<?xml version="1.0" encoding="utf-8"?>
<utils:TitleWindowSaveCancel 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:utils="it.ht.rcs.console.utils.*"
                             creationComplete="init()" save="onSave(event)"
                             title="{entity.type=='virtual' ? R.get('ADD_URL') : R.get('ADD_HANDLE')}">

  <fx:Script>
    <![CDATA[
      import it.ht.rcs.console.entities.controller.EntityManager;
      import it.ht.rcs.console.entities.model.Entity;
      import it.ht.rcs.console.entities.model.Handle;
      import it.ht.rcs.console.events.SaveEvent;
      import it.ht.rcs.console.operation.model.Operation;
      import it.ht.rcs.console.utils.AlertPopUp;
      
      import locale.R;
      
      import mx.collections.ArrayCollection;
      import mx.events.CloseEvent;
      import mx.rpc.events.ResultEvent;
      
      [Bindable] public var entity:Entity;
      
      private function init():void
      {
        saveButton.enabled=false;
      }
      
      private function onSave(event:SaveEvent):void
      {
        doSave();
        close();  
      }

      private function doSave():void
      {
       var type:String=entity.type=='virtual' ? 'url' : typeCb.selectedItem
       EntityManager.instance.addHandle(entity._id, handle.text, handleName.text, type, function(e:ResultEvent):void { close(); dispatchEvent(new Event("update"))});
      }
      
      private function onChange():void
      {
        if(handle.text=="")
        {
          saveButton.enabled=false;
        }
        else
        {
          saveButton.enabled=true;
        }
      }
      
    ]]>
  </fx:Script>

  <s:Form width="100%" defaultButton="{saveButton}">
    <s:FormItem label="{entity.type=='virtual'?'Url' : 'Account'}">
      <s:TextInput id="handle" width="250"  change="onChange()"/>
    </s:FormItem>
    <s:FormItem label="{R.get('NAME')}">
      <s:TextInput id="handleName" width="250"/>
    </s:FormItem>
    <s:FormItem label="{R.get('TYPE')}" visible="{entity.type!='virtual'}" includeInLayout="{entity.type!='virtual'}">
      <s:ComboBox selectedIndex="4" id="typeCb" >
        <s:dataProvider>
          <s:ArrayList>
            <fx:String>Bbm</fx:String>
            <fx:String>Facebook</fx:String>
            <fx:String>Linkedin</fx:String>   
            <fx:String>Mail</fx:String>   
            <fx:String>Messages</fx:String>   
            <fx:String>Skype</fx:String>
            <fx:String>Phone</fx:String>
            <fx:String>Telegram</fx:String>
            <fx:String>Twitter</fx:String>
            <fx:String>Viber</fx:String>
            <fx:String>Whatsapp</fx:String>
          </s:ArrayList>
        </s:dataProvider>
      </s:ComboBox>
    </s:FormItem>
  
  </s:Form>
  
</utils:TitleWindowSaveCancel>