hackedteam/rcs-console

View on GitHub
src/it/ht/rcs/console/operations/view/evidences/advanced/viewers/Photo.mxml

Summary

Maintainability
Test Coverage
<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer 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:viewers="it.ht.rcs.console.operations.view.evidences.advanced.viewers.*"
                                     xmlns:maps="it.ht.rcs.console.maps.*"
                                     xmlns:tags="it.ht.rcs.console.operations.view.evidences.advanced.viewers.tags.*"
                                     height="100%"
                                     width="100%"
                                     borderColor="0xCCCCCC"
                                     backgroundColor="0xFFFFFF"
                                     backgroundAlpha="1"
                   creationPolicy="all"
                                     creationComplete="init()">

    <s:states>
        <s:State name="image"/>
        <s:State name="position"/>
    </s:states>

    <s:layout>
        <s:VerticalLayout paddingBottom="10"
                                            paddingLeft="10"
                                            paddingRight="10"
                                            paddingTop="10"/>
    </s:layout>


    <fx:Script>
        <![CDATA[
            import flashx.textLayout.conversion.TextConverter;

            import it.ht.rcs.console.DB;
            import it.ht.rcs.console.evidence.controller.EvidenceManager;
            import it.ht.rcs.console.evidence.model.Evidence;
            import it.ht.rcs.console.evidence.model.Tag;
            import it.ht.rcs.console.monitor.controller.LicenseManager;
            import it.ht.rcs.console.operations.view.evidences.EvidenceAdvancedViewer;
            import it.ht.rcs.console.operations.view.evidences.EvidencesView;

            import locale.R;

            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
      
      public var target:String;

            private var _evidence:Evidence;
      
            private var loader:URLLoader=new URLLoader();

            [Embed(source="/img/NEW/eyeIcon.png")]
            [Bindable]
            public var eyeIcon:Class;

            [Embed(source="/img/NEW/positionIcon.png")]
            [Bindable]
            public var positionIcon:Class;

            [Bindable]
            private var _url:String;

            [Bindable]
            private var tags:String;

            [Bindable]
            public var idVisible:Boolean;

            [Bindable]
            public function set evidence(value:Evidence):void
            {
                _evidence=value;
                target=EvidenceManager.instance.evidenceFilter.target;

                if (evidence.data._grid != null)
                {
                    if (DB.instance.demo)
                    {
                        _url="grid/" + evidence.data._grid;
                    }
                    else
                    {
                        _url=DB.hostAutocomplete(Console.currentSession.server) + "grid/" + evidence.data._grid + "?target_id=" + encodeURIComponent(target);
                    }
                    init()
                }

                tags="";
                if (evidence.data.tags && evidence.data.tags.length)
                {
                    for (var i:int=0; i < evidence.data.tags.length; i++)
                    {
                        var tag:Tag=evidence.data.tags.getItemAt(i) as Tag
            tags+=tag.type+": "+tag.name+" ("+tag.handle+")"+ "<BR>"
                    }
                }
        tagsPanel.visible=evidence.data.tags.length>0
        if (tagsPanel.visible)
        {
          tagsPanel.currentState="expanded";
          //tagsPanel.details=tags;
        }
            }

            public function get evidence():Evidence
            {
                return _evidence;
            }

            private function init():void
            {
                currentState="image" 
                target=EvidenceManager.instance.evidenceFilter.target;
                imageViewer.url=_url;
            }

            private function switchView():void
            {
                if (currentState == "image")
                {
                    currentState="position"

                    if (evidence.data.longitude && evidence.data.latitude)
                    {
                        mapViewer.visible=mapViewer.includeInLayout=true;
                        mapViewer.positions=new Vector.<Object>
                        mapViewer.positions.push(evidence)
                        mapViewer.update()
                    }
                    else
                    {
                        if (mapViewer)
                            mapViewer.visible=mapViewer.includeInLayout=false;
                    }

                }
                else
                {
                    currentState="image"

                }
            }

            public function reset():void
            {
                imageViewer.reset()
            }
        ]]>
    </fx:Script>
    <s:RichText id="idTxt"
                            width="100%"
                            textFlow="{TextConverter.importToFlow('&lt;b&gt;Id: &lt;/b&gt;'+evidence._id, TextConverter.TEXT_FIELD_HTML_FORMAT)}"
                            fontSize="12"
                            visible="{idVisible}"
                            includeInLayout="{idVisible}"/>
    <s:Line width="100%"
                    visible="{idVisible}"
                    includeInLayout="{idVisible}">
        <s:stroke>
            <s:SolidColorStroke color="0xCCCCCC"/>
        </s:stroke>
    </s:Line>
    <s:HGroup width="100%"
                        verticalAlign="middle"
                        visible="{evidence.data.latitude &amp;&amp; evidence.data.longitude}"
                        includeInLayout="{evidence.data.latitude &amp;&amp; evidence.data.longitude}">
        <s:Spacer width="100%"/>
        <s:Image source="{currentState=='image'? positionIcon:eyeIcon}"
                         toolTip="{currentState=='image'?'Position':'Image'}"
                         click="switchView()"
                         id="switchBtn"
                         useHandCursor="true"
                         buttonMode="true"/>
    </s:HGroup>
    <s:Line width="100%"
                    visible="{evidence.data.latitude &amp;&amp; evidence.data.longitude}"
                    includeInLayout="{evidence.data.latitude &amp;&amp; evidence.data.longitude}">
        <s:stroke>
            <s:SolidColorStroke color="0xCCCCCC"/>
        </s:stroke>
    </s:Line>
    <s:Group width="100%"
                     height="100%">
        <viewers:ImageViewer id="imageViewer"
                                                 url="{_url}"
                                                 includeIn="image"/>
        <maps:MapViewer width="100%"
                                        height="100%"
                                        id="mapViewer"
                                        includeIn="position"/>
        <tags:TagsPanel id="tagsPanel"
                                        tags="{evidence.data.tags}"
                                        visible="{evidence.data.tags.length>0}"
                                        includeInLayout="{evidence.data.tags.length>0}"/>
    </s:Group>
</s:BorderContainer>