<?xml version="1.0" encoding="UTF-8"?>
<action-sequence> 
  <name>query1.xaction</name>
  <title>%title</title>
  <version>1</version>
  <logging-level>debug</logging-level>
  <documentation> 
    <author>James Dixon</author>  
    <help>just testing...</help>  
    <result-type>report</result-type>  
    <description>%description</description>  
    <icon>slicedice.png</icon> 
  </documentation>

  <inputs> 
    <region type="string-list"> 
      <default-value/>  
      <sources> 
        <request>region</request> 
      </sources> 
    </region>  
    <department type="string-list"> 
      <default-value/>  
      <sources> 
        <request>department</request> 
      </sources> 
    </department>  
    <position type="string-list"> 
      <default-value/>  
      <sources> 
        <request>position</request> 
      </sources> 
    </position>  
    <mdx type="string"> 
      <default-value/>  
      <sources> 
        <request>MDX</request> 
      </sources> 
    </mdx>  
    <mode type="string"> 
      <default-value/>  
      <sources> 
        <request>mode</request> 
      </sources> 
    </mode> 
  </inputs>

  <outputs> 
    <connection type="string"/>  
    <mdx type="string"/>  
    <options type="list"/>  
    <title type="string"/>  
    <url type="string"> 
      <destinations> 
        <response>redirect</response> 
      </destinations> 
    </url> 
  </outputs>

  <resources/>
  
  <actions> 
    <action-definition> 
      <component-name>JavascriptRule</component-name>
      <action-type>JavaScript</action-type>
      <action-inputs> 
        <region type="string"/>  
        <department type="string"/>  
        <position type="string"/> 
      </action-inputs>
      <action-outputs> 
        <regionSelects type="string"/>  
        <departmentSelects type="string"/>  
        <positionSelects type="string"/> 
      </action-outputs>
      <component-definition> 
        <script><![CDATA[function getSelects( baseStr, values ) {
    rtnStr = baseStr;
    if ( values == null ) {
        // Do nothing and the baseStr will be returned
    }
    else if ( typeof( values ) == "string" ) {
        rtnStr += values;
    }
    else {
        rtnStr = baseStr;
        if ( (values != null) && (values.length >= 1) ) {
            rtnStr += values[0];
            for ( i = 1; i < values.length; ++i ) {
                rtnStr += ", " + baseStr + values[i];
            }
        }
    }
java.lang.System.out.println( rtnStr );
    return( rtnStr );
}

regionSelects = getSelects( "[Region].[All Regions]", region );
departmentSelects = getSelects( "[Department].[All Departments]", department );
positionSelects = getSelects( "[Positions].[All Positions]", position );]]></script> 
      </component-definition> 
    </action-definition>
  
    <action-definition> 
      <component-name>PivotViewComponent</component-name>
      <action-inputs> 
        <mode type="string"/>  
        <regionSelects type="string"/>  
        <departmentSelects type="string"/>  
        <positionSelects type="string"/> 
      </action-inputs>
      <action-outputs> 
        <connection type="string"/>  
        <mdx type="string"/>  
        <options type="list"/>  
        <title type="string"/>  
        <url type="string"/> 
      </action-outputs>
      <component-definition> 
        <title>Drill Down to Pivot Table</title>  
        <viewer>Pivot</viewer>  
        <model>samples/analysis/SampleData.mondrian.xml</model>  
        <!--  connection>jdbc/SampleData</connection -->  
        <jndi>SampleData</jndi>  
        <!--  query>default</query -->  
        <options> 
          <personal/>  
          <cube-nav/>  
          <mdx-edit/>  
          <sort-conf/>  
          <spacer/>  
          <level-style/>  
          <hide-spans/>  
          <properties/>  
          <non-empty/>  
          <swap-axes/>  
          <spacer/>  
          <drill-member/>  
          <drill-position/>  
          <drill-replace/>  
          <drill-thru/>  
          <spacer/>  
          <chart/>  
          <chart-conf/>  
          <spacer/>  
          <print-conf/>  
          <print-pdf/>  
          <spacer/>  
          <excel/> 
        </options>  
        <query><![CDATA[with member [Measures].[Variance Percent] as '([Measures].[Variance] / [Measures].[Budget])', 
     format_string = IIf(((([Measures].[Variance] / [Measures].[Budget]) * 100.0) > 2.0), "|#.00%|style='green'", 
                               IIf(((([Measures].[Variance] / [Measures].[Budget]) * 100.0) < 0.0), "|#.00%|style='red'", "#.00%"))

select NON EMPTY {[Measures].[Actual], [Measures].[Budget], [Measures].[Variance], [Measures].[Variance Percent]} ON COLUMNS,
           NON EMPTY Crossjoin({ {regionSelects} }, 
                               Crossjoin({ {departmentSelects} }, { {positionSelects} } ) ) ON ROWS

from [Quadrant Analysis]]]></query> 
      </component-definition>  
      <action-name>Pivot View</action-name>  
      <logging-level>DEBUG</logging-level> 
    </action-definition>
 
  </actions> 
</action-sequence>