hackedteam/rcs-console

View on GitHub
src/it/ht/rcs/console/alerting/view/LogsActionBar.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('DELETE')}"
                        click="onDeleteClick()"
                        enabled="{selectedObjects!=null &amp;&amp;  selectedObjects.length>0}"
                        icon="@Embed('/img/NEW/delete_32.png')"/>

    <s:Button label="{R.get('DELETE_ALL')}"
                        click="onDeleteAllClick()"
                        enabled="{view &amp;&amp; view.length > 0  &amp;&amp; (parent.parent as AlertingSection).alerts.selectedItem}"
                        icon="@Embed('/img/NEW/delete_all.png')"/>
    <actionbar:Separator/>
    <s:Button label="{R.get('JUMP_TO_EVIDENCE')}"
                        enabled="{selectedObjects.length==1 &amp;&amp;  new VectorCollection(selectedObjects).getItemAt(0).entities.length==0}"
                        icon="@Embed('/img/NEW/jumpToEvidence.png')"
                        click="jumpToEvidence()"/>
    <s:Button label="{R.get('JUMP_TO_ENTITY')}"
                        enabled="{selectedObjects.length==1 &amp;&amp; new VectorCollection(selectedObjects).getItemAt(0).entities.length==1}"
                        icon="@Embed('/img/NEW/jumpToEntities.png')"
                        click="jumpToEntity()"/>
    <s:Button label="{R.get('JUMP_TO_LINK')}"
                        enabled="{selectedObjects.length==1 &amp;&amp; new VectorCollection(selectedObjects).getItemAt(0).entities.length==2}"
                        icon="@Embed('/img/NEW/jumpToLink.png')"
                        click="jumpToLink()"/>


    <fx:Script>
        <![CDATA[
      import it.ht.rcs.console.alert.controller.AlertManager;
      import it.ht.rcs.console.alert.model.Alert;
      import it.ht.rcs.console.alert.model.AlertLog;
      import it.ht.rcs.console.events.SectionEvent;
      import it.ht.rcs.console.search.controller.SearchManager;
      import it.ht.rcs.console.utils.AlertPopUp;
      
      import locale.R;
      
      import mx.core.FlexGlobals;
      import mx.events.CloseEvent;
      import mx.managers.CursorManager;
      
      import org.apache.flex.collections.VectorCollection;

            public var section:AlertingSection;

            [Bindable]
            public var selectedObjects:Vector.<Object>=null;
            [Bindable]
            public var selectedIndices:Vector.<int>=null;


            private function jumpToEvidence():void
            {
                if (selectedObjects == null)
                    return;
                var log:AlertLog=selectedObjects[0] as AlertLog;
                var se:SectionEvent=new SectionEvent(SectionEvent.CHANGE_SECTION);
                se.section=SectionEvent.OPERATIONS;
                se.subsection='evidence';
                se.item=SearchManager.instance.getItem(log.path.getItemAt(log.path.length - 1) as String);

                if (log.evidence.length > 0)
                {
                    se.evidenceIds=log.evidence.source;
                }

                FlexGlobals.topLevelApplication.dispatchEvent(se);
                CursorManager.setBusyCursor()
            }

            private function jumpToLink():void
            {
                if (selectedObjects == null)
                    return;
                var log:AlertLog=selectedObjects[0] as AlertLog;
                var se:SectionEvent=new SectionEvent(SectionEvent.CHANGE_SECTION);
                se.section=SectionEvent.INTELLIGENCE;
                se.subsection='links';
                se.info=[log.entities.getItemAt(0), log.entities.getItemAt(1)]
                se.item=SearchManager.instance.getItem(log.path.getItemAt(0) as String);

                FlexGlobals.topLevelApplication.dispatchEvent(se);
                CursorManager.setBusyCursor()
            }

            private function jumpToEntity():void
            {
                if (selectedObjects == null)
                    return;
                var log:AlertLog=selectedObjects[0] as AlertLog;
                var se:SectionEvent=new SectionEvent(SectionEvent.CHANGE_SECTION);
                se.section=SectionEvent.INTELLIGENCE;
                se.subsection='links';
                se.info=[log.entities.getItemAt(0)]
                se.item=SearchManager.instance.getItem(log.path.getItemAt(log.path.length - 1) as String);

                FlexGlobals.topLevelApplication.dispatchEvent(se);
                CursorManager.setBusyCursor()
            }

            private function onDeleteClick():void
            {
                var alert:Alert=section.alertBar.selectedObject as Alert;

                for (var i:int=0; i < selectedObjects.length; i++)
                {

                    var l:int=alert.logs.getItemIndex(selectedObjects[i] as AlertLog);
                    trace((selectedObjects[i] as AlertLog)._id)
                    alert.logs.removeItemAt(l);

                }
                section.alerts.selectedItem=null;
                section.alertBar.selectedObject=null;
                section.logs.dataProvider=null;     
                section.logs.selectedItem=null;
                section.logBar.selectedObject=null;
                section.logBar.selectedObjects=null;
                section.logBar.selectedIndices=null;

                /* if there are no more items, invalidate the arraycollection to avoid displaying the 0 counter */
                if (alert.logs.length == 0)
                    alert.logs=null;
            }

            private function onDeleteAllClick():void
            {
                var alert:Alert=(parent.parent as AlertingSection).alerts.selectedItem as Alert;

                AlertPopUp.show(R.get('CONFIRM_ALERT_LOG_DELETION'), R.get('CONFIRM'), AlertPopUp.YES | AlertPopUp.NO, null, function(e:CloseEvent):void
                {
                    if (e.detail == AlertPopUp.YES)
                    {
                        /* if null is passed, delete all the logs */
                        alert.logs.removeAll();
                        /* to avoid displaying the 0 counter */
                        alert.logs=null;
                        section.alerts.selectedItem=null;
                        section.alertBar.selectedObject=null;
                    }
                }, null, AlertPopUp.NO);
            }
        ]]>
    </fx:Script>

</actionbar:ActionBar>