hackedteam/rcs-console

View on GitHub
src/it/ht/rcs/console/main/Main.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"
         xmlns:main="it.ht.rcs.console.main.*"
         width="100%" height="100%" addedToStage="onAddedToStage()" creationComplete="init()"
         removedFromStage="onRemovedFromStage()">
  
  <fx:Script>
    <![CDATA[
      import it.ht.rcs.console.alert.controller.AlertManager;
      import it.ht.rcs.console.events.SectionEvent;
      import it.ht.rcs.console.history.HistoryManager;
      import it.ht.rcs.console.monitor.controller.LicenseManager;
      import it.ht.rcs.console.monitor.controller.MonitorManager;
      
      import mx.collections.ArrayList;
      import mx.core.FlexGlobals;
      
      [Bindable]
      private var mainSections:ArrayList;
      
      private function init():void
      {
       
        if (Console.currentSession.user.is_view_alerts())
        {
          AlertManager.instance.startCounters();
        }
        if (Console.currentSession.user.is_admin() || Console.currentSession.user.is_tech() || Console.currentSession.user.is_sys())
        {
          MonitorManager.instance.startCounters();
        }
        // if we are in "archve" mode, dashboard and alerting don't make any sense
     /*    if (LicenseManager.instance.archive) {
          // move backward to avoid problems with index after remove
          for (var i:int = mainSections.length - 1; i >= 0; i--) {
            var e:Object = mainSections.getItemAt(i);
            if (e.label == 'Alerting' || e.label == 'Dashboard')
              mainSections.removeItemAt(i);
          }
        } */
          
      }
      
      private function onAddedToStage():void
      {
        FlexGlobals.topLevelApplication.addEventListener(SectionEvent.CHANGE_SECTION, changeSection);
        mainSections = Initialization.instance.mainSections;
        HistoryManager.instance.sections=sections
        HistoryManager.instance.init()
      }
      
      private function onRemovedFromStage():void 
      {
        FlexGlobals.topLevelApplication.removeEventListener(SectionEvent.CHANGE_SECTION, changeSection);
      }
      
      private function changeSection(event:SectionEvent):void
      {
        /* change the state to the current section if it isn't in dirty state */
        //if (!(sections[sections.currentState] as Section).isDirty)
        //{
          sections.currentState = event.section;
          menu.bar.selectedItem = getSectionObject(event.section);
          /* check if the new section has an handler to manage the event */
          if (sections[event.section].hasOwnProperty('changeSection'))
            sections[event.section].changeSection(event);
        //}
      }
      
      private function getSectionObject(name:String):Object
      {
        for each (var section:Object in mainSections.source)
          if (section.label == name)
            return section;
        return null;
      }
    ]]>
  </fx:Script>
  
  <s:layout>
    <s:VerticalLayout gap="0" paddingBottom="10" paddingLeft="10" paddingRight="10"/>
  </s:layout>
  
  <main:MenuSection id="menu" sections="{mainSections}"/>
  
  <main:MenuSubSection subSections="{sections.selectedItem.subSections}"/>
  

  <main:Sections id="sections"/>

</s:Group>