hackedteam/rcs-console

View on GitHub
src/it/ht/rcs/console/operations/view/BaseListRenderer.mxml

Summary

Maintainability
Test Coverage
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:mx="library://ns.adobe.com/flex/mx"
                autoDrawBackground="true" doubleClickEnabled="true" click="onClick(event)">
  
  <fx:Script>
    <![CDATA[
      import it.ht.rcs.console.agent.model.Agent;
      import it.ht.rcs.console.dashboard.view.renderer.Icons;
      import it.ht.rcs.console.entities.model.Entity;
      import it.ht.rcs.console.entities.view.EntitiesSection;
      import it.ht.rcs.console.operation.model.Operation;
      import it.ht.rcs.console.target.model.Target;
      
      [Embed(source='/img/NEW/operation.png')]
      private static const operationIcon:Class;
      
      [Embed(source='/img/NEW/operationEntity.png')]
      private static const operationEntityIcon:Class;
      
      [Embed(source='/img/NEW/target.png')]
      private static const targetIcon:Class;
      
      [Embed(source='/img/NEW/device/compass.png')]
      private static const compassIcon:Class;
      
      [Embed(source='/img/NEW/device/soldier.png')]
      private static const soldierIcon:Class;
      
      [Embed(source='/img/NEW/evidence_50.png')]
      private static const evidenceIcon:Class;
      
      [Embed(source='/img/NEW/filesystem_50.png')]
      private static const fsIcon:Class;
      
      [Embed(source='/img/NEW/info_50.png')]
      private static const infoIcon:Class;
      
      [Embed(source='/img/NEW/config_50.png')]
      private static const configIcon:Class;
      
      [Embed(source='/img/NEW/filetransfer_50.png')]
      private static const fileTransferIcon:Class;
      
      [Embed(source='/img/NEW/commands_50.png')]
      private static const commandsIcon:Class;
      
      [Embed(source='/img/NEW/ipaddresses_50.png')]
      private static const ipaddressesIcon:Class;
      
      [Embed(source='/img/NEW/star_50.png')]
      private static const entityIcon:Class;
      
      [Embed(source='/img/NEW/entity_people_50.png')]
      private static const entityPeopleIcon:Class;
      
      [Embed(source='/img/NEW/entity_location_50.png')]
      private static const entityLocationIcon:Class;
      
      [Embed(source='/img/NEW/bookmark_50.png')]
      private static const entityVirtualIcon:Class;
      
      [Embed(source='/img/NEW/entity_target_50.png')]
      private static const entityTargetIcon:Class;
      
      override public function set data(value:Object):void
      {
        super.data = value;
        this.enabled=true;
        bottomLabel.text = data ? data.name : '';
        iconType.source = data ? getTypeIcon() : null;
        
        alpha = data && data.hasOwnProperty('status') && data.status && data.status.toLowerCase() == 'closed' ? .5 : 1;
        
        if (data && data.hasOwnProperty('demo') && data.demo)
          iconType.filters = [glow_demo];
        else if (data && data.hasOwnProperty('scout') && data.scout)
          iconType.filters = null;
        else
          iconType.filters = null;
        
        var operationSection:OperationsSection=(this.owner as BaseList).section as OperationsSection;
        if(operationSection)
        {
          var stateManager:OperationsSectionStateManager=operationSection.stateManager as OperationsSectionStateManager;
          if(stateManager.selectedAgent)
          {
          
            if(
              (stateManager.selectedAgent.level=="scout") 
              && (
                (data is Object && data.customType == 'filesystem') || 
                (data is Object && data.customType == 'filetransfer') || 
                (data is Object && data.customType == 'commands')
              )
             
            )
            {
              this.enabled=false;
            }
            
            else if(
              (stateManager.selectedAgent.level=="soldier" ) 
              && (
                (data is Object && data.customType == 'commands')
              )
              
            )
            {
              this.enabled=false;
            }
            
          }
         
        }
      
      }
      
      private function getTypeIcon():Class
      {
        var list:BaseList =owner as BaseList;
       
        if (data is Operation)
        {
          if(list.section is EntitiesSection) return operationEntityIcon;
          else return operationIcon;
        }
        else if (data is Target)
          return targetIcon;
        else if (data is Agent && data._kind == 'agent')
          return data.platform ? Icons[data.type + '_' + data.platform] : Icons['agent_' + data.type];
        else if (data is Agent && data._kind == 'factory')
          return Icons['agent_' + data.type];
        else if (data is Entity && data.type=="target")
          return entityTargetIcon;
        else if (data is Entity && data.type=="person")
          return entityPeopleIcon;
        else if (data is Entity && data.type=="position")
          return entityLocationIcon;
        else if (data is Entity && data.type=="virtual")
          return entityVirtualIcon;
        else if (data is Entity && data.type=="group")
          return null;
        // see addCustomTypes() in stateManager
        else if (data is Object && data.customType == 'evidence')
          return evidenceIcon;
        else if (data is Object && data.customType == 'filesystem')
          return fsIcon;
        else if (data is Object && data.customType == 'info')
          return infoIcon;
        else if (data is Object && data.customType == 'configlist')
          return configIcon;
        else if (data is Object && data.customType == 'filetransfer')
          return fileTransferIcon;
        else if (data is Object && data.customType == 'commands')
          return commandsIcon;
        else if (data is Object && data.customType == 'ipaddresses')
          return ipaddressesIcon;
        
        return null;
      }
      
      private function onClick(e:MouseEvent):void
      {
      e.stopImmediatePropagation()
      }
    ]]>
  </fx:Script>
  
  <fx:Declarations>
    <s:GlowFilter id="glow_scout" color="#00FF00" blurX="8" blurY="8" strength="2"/>
    <s:GlowFilter id="glow_demo" color="#5C8FFF" blurX="8" blurY="8" strength="2"/>
    <s:GlowFilter id="glow_special" color="0x3082c4" blurX="8" blurY="8" strength="2"/>
  </fx:Declarations>
  <s:Group width="100%" horizontalCenter="0">
    <s:Image id="iconType" top="5" horizontalCenter="0"/>
    <s:Image source="{compassIcon}" x="54" y="25" visible="{data &amp;&amp; data.hasOwnProperty('level') &amp;&amp; data.level=='scout' &amp;&amp; data._kind=='agent'}" />
    <s:Image source="{soldierIcon}" x="54" y="25" visible="{data &amp;&amp; data.hasOwnProperty('level') &amp;&amp; data.level=='soldier'}"/>
  </s:Group>
 
  
  <s:Label id="bottomLabel" top="62" width="110" horizontalCenter="0" paddingBottom="5"
           textAlign="center" maxDisplayedLines="2" fontFamily="Myriad" fontSize="12" fontWeight="normal"/>
  
  
  
</s:ItemRenderer>