private static function addPlanJsFunction(array $parameters)
 {
     // Adds script to add plan to scene
     $jsOutput = DataCenterJs::callFunction('scene.setModule', array(DataCenterJs::buildInstance('DataCenterScenePlan', array(DataCenterJs::toScalar($parameters['plan']->getId()), self::buildPhysicalJsObject($parameters), self::buildStateJsObject($parameters)))));
     // Adds script to render scene
     $jsOutput .= DataCenterJs::callFunction('scene.render');
     // Returns JavaScript
     return DataCenterJs::buildFunction(array('scene'), $jsOutput);
 }
Exemple #2
0
 private static function addMarkersJsFunction(array $parameters)
 {
     // Begins building javascript for adding markers
     $jsMarkers = '';
     // Loops over each location
     foreach ($parameters['locations'] as $location) {
         // Builds script to add marker
         $jsMarkers .= sprintf("map.addMarker( %F, %F, %s );", DataCenterJs::toScalar($location->get('latitude')), DataCenterJs::toScalar($location->get('longitude')), self::markerOptions($parameters, $location));
     }
     return sprintf("function( map ) { %s }", $jsMarkers);
 }
 public function view($path)
 {
     // Checks if the user did not provide enough information
     if (!$path['id']) {
         // Returns error message
         return DataCenterUI::message('error', 'insufficient-data');
     }
     // Gets plan from database
     $plan = DataCenterDB::getPlan($path['id']);
     // Gets space of plan
     $space = $plan->getSpace();
     // Gets location of space
     $location = $space->getLocation();
     // Sets location information to space
     $space->set('location_name', implode(' / ', $location->get(array('name', 'region'))));
     // Gets structure of plan from database
     $structure = $plan->getStructure(DataCenterDB::buildSort('link', 'asset', array('x', 'y')));
     // Builds tables from structure
     $tables = DataCenterDB::buildLookupTable('asset_type', $structure);
     // Builds list of rack/object assets used in plan
     if (isset($tables['rack']) && is_array($tables['rack'])) {
         foreach ($tables['rack'] as $key => $link) {
             $asset = $link->getAsset();
             $model = $asset->getModel();
             $tables['rack'][$key]->set(array('model' => implode(' / ', $model->get(array('manufacturer', 'name')))));
         }
     } else {
         $tables['rack'] = null;
     }
     // Builds javascript that references the renderable plan
     $target = array('dataCenter.renderer.getTarget' => array(DataCenterJs::toScalar('plan')), 'getModule');
     // Detects if this user came from a zoomed in page
     $refererPath = DataCenterPage::getRefererPath();
     $zoomOptions = array();
     if ($refererPath['page'] == $path['page'] && $refererPath['type'] == 'rack' && $refererPath['id'] !== null) {
         $rackLink = DataCenterDB::getAssetLink($refererPath['id']);
         $rack = $rackLink->getAsset();
         $zoomOptions['zoom-from-rack'] = $rack->getId();
     }
     if (!isset($tables['rack'])) {
         $tables['rack'] = array();
     }
     // Builds table of racks
     $racks = DataCenterUI::renderWidget('table', array('rows' => $tables['rack'], 'fields' => array('name', 'model', 'position' => array('fields' => array('x', 'y'), 'glue' => ' x ')), 'link' => array('page' => 'plans', 'type' => 'rack', 'action' => 'view', 'id' => '#id'), 'effects' => array(array('event' => 'onmouseover', 'script' => DataCenterJs::chain(array_merge($target, array('setRackHighlight' => array('{asset_id}', DataCenterJs::toScalar(true)))), false)), array('event' => 'onmouseout', 'script' => DataCenterJs::chain(array_merge($target, array('clearRackHighlight' => array(DataCenterJs::toScalar(true)))), false)))));
     // Returns single columm layout with a table
     return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'racks')), $racks, DataCenterUI::renderWidget('actions', array('links' => array(array('page' => 'plans', 'type' => 'rack', 'action' => 'select', 'parameter' => array('plan', $path['id']))), 'rights' => array('change'))), DataCenterUI::renderWidget('heading', array('message' => 'configuration')), DataCenterUI::renderWidget('details', array('row' => $plan, 'fields' => array('tense' => array('format' => 'option'), 'name', 'note'))), DataCenterUI::renderWidget('heading', array('message' => 'facility')), DataCenterUI::renderWidget('details', array('row' => $space, 'fields' => array('tense' => array('format' => 'option'), 'location' => array('field' => 'location_name'), 'name', 'size' => array('fields' => array('width', 'depth', 'height'), 'glue' => ' x '), 'power'))))), DataCenterUI::renderWidget('plan', array_merge(array('plan' => $plan), $zoomOptions))));
 }
 public function edit($path)
 {
     // Checks if...
     if (!$path['id'] && is_array($path['parameter']) && count($path['parameter'] >= 2) && $path['parameter'][0] == 'location') {
         // Creates new facility with default parameters
         $space = DataCenterDBSpace::newFromValues(array('location' => $path['parameter'][1], 'tense' => 'present', 'name' => DataCenterUI::message('default', 'new-type', DataCenterUI::message('type', 'space'))));
         // Sets 'do' specific parameters
         $formParameters = array('label' => 'add', 'hidden' => array($path['parameter'][0]), 'success' => array('page' => 'facilities', 'type' => $path['parameter'][0], 'action' => 'view', 'id' => $path['parameter'][1]), 'type' => 'add');
         $headingParameters = array('message' => 'adding-type', 'subject' => DataCenterUI::message('type', $path['type']));
     } else {
         // Gets facility from database
         $space = DataCenterDB::getSpace($path['id']);
         // Sets 'do' specific parameters
         $formParameters = array('label' => 'save', 'hidden' => array('location', 'id'), 'success' => array('page' => 'facilities', 'type' => 'space', 'action' => 'view', 'id' => $path['id']), 'type' => 'edit');
         $headingParameters = array('message' => 'editing-type', 'subject' => DataCenterUI::message('type', $path['type']));
     }
     // Builds JavaScript to access renderable facility
     $jsTarget = DataCenterJs::chain(array("dataCenter.renderer.getTarget" => DataCenterJs::toScalar('space'), 'getModule'), false);
     // Complete form parameters
     $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'facilities', 'type' => 'space'), 'row' => $space, 'fields' => array('tense' => array('type' => 'tense', 'disable' => array('past')), 'name' => array('type' => 'string'), 'width' => array('type' => 'number', 'effect' => $jsTarget . '.setWidth( {this}.value, true );'), 'height' => array('type' => 'number', 'effect' => $jsTarget . '.setHeight( {this}.value, true );'), 'depth' => array('type' => 'number', 'effect' => $jsTarget . '.setDepth( {this}.value, true );'), 'power' => array('type' => 'number', 'min' => 0, 'max' => 100000, 'step' => 100))));
     // Returns 2 columm layout with a form and a scene
     return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderWidget('space', array('space' => $space))));
 }
 public function edit($path)
 {
     // Detects mode
     if (!$path['id']) {
         // Creates a new facility location
         $location = DataCenterDBLocation::newFromValues(array('tense' => 'present', 'name' => DataCenterUI::message('default', 'new-type', DataCenterUI::message('type', 'location'))));
         // Sets 'do' specific parameters
         $formParameters = array('label' => 'add', 'success' => array('page' => 'facilities', 'type' => 'location'), 'type' => 'add');
         $headingParameters = array('message' => 'adding-type', 'subject' => DataCenterUI::message('type', $path['type']));
     } else {
         // Gets facility location from database
         $location = DataCenterDB::getLocation($path['id']);
         // Sets 'do' specific parameters
         $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'facilities', 'type' => 'location', 'action' => 'view', 'id' => $path['id']), 'type' => 'edit');
         $headingParameters = array('message' => 'editing-type', 'subject' => DataCenterUI::message('type', $path['type']));
     }
     // Builds JavaScript that hooks the button into the geocoder
     $jsForm = 'document.form_save';
     $jsOut = DataCenterJs::callFunction('addHandler', array("{$jsForm}.field_button_0", DataCenterJs::toScalar('click'), DataCenterJs::buildFunction(null, DataCenterJs::chain(array('dataCenter.renderer.getTarget' => DataCenterJs::toScalar('map'), 'showAddress' => array('document.form_save.field_region.value', DataCenterJs::toObject(array('latField' => "'{$jsForm}.field_latitude'", 'lngField' => "'{$jsForm}.field_longitude'"))))))));
     // Complete form parameters
     $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'facilities', 'type' => 'location'), 'row' => $location, 'fields' => array('tense' => array('type' => 'tense', 'disable' => !$path['id'] ? array('past') : array()), 'name' => array('type' => 'string'), 'region' => array('type' => 'string'), array('type' => 'button', 'label' => 'lookup'), 'latitude' => array('type' => 'string'), 'longitude' => array('type' => 'string'))));
     // Returns 2 columm layout with a form and a map widget
     return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderWidget('map', !$path['id'] ? array() : array('location' => $location)))) . DataCenterXml::script($jsOut);
 }
Exemple #6
0
    public static function render(array $parameters)
    {
        global $wgScriptPath;
        // Checks that...
        if (isset($parameters['fields']['x'], $parameters['fields']['y']) && is_array($parameters['fields']['x']) && is_array($parameters['fields']['y']) && count($parameters['fields']) == 2) {
            // Sets defaults
            $parameters = array_merge(self::$defaultParameters, $parameters);
            // Begins input
            $xmlOutput = parent::begin($parameters['class']);
            // Builds resource path
            $resourcePath = $wgScriptPath . '/extensions/DataCenter/Resources/Inputs/Position/';
            // Converts mode to upper case to avoid case-sensitivity errors
            $mode = strtoupper($parameters['mode']);
            // Builds list of resource paths
            $resources = array('normal' => $resourcePath . $mode . '-Normal.png', 'n' => $resourcePath . $mode . '-N.png', 'e' => $resourcePath . $mode . '-E.png', 's' => $resourcePath . $mode . '-S.png', 'w' => $resourcePath . $mode . '-W.png');
            // Builds lists of image map polygons
            $polygons = array('2D' => array('n' => '24,2,42,2,42,16,24,16', 'e' => '42,2,58,2,58,32,42,32', 's' => '24,16,42,16,42,32,24,32', 'w' => '8,2,24,2,24,32,8,32'), 'ISO' => array('n' => '30,0,60,17,30,17', 'e' => '60,17,30,34,30,17', 's' => '30,34,0,17,30,17', 'w' => '0,17,30,0,30,17'));
            // Creates structure of elements to be created
            $structure = array('x' => array('e' => array('op' => '+', 'func' => 'min', 'limit' => 'max'), 'w' => array('op' => '-', 'func' => 'max', 'limit' => 'min')), 'y' => array('n' => array('op' => '-', 'func' => 'max', 'limit' => 'min'), 's' => array('op' => '+', 'func' => 'min', 'limit' => 'max')));
            // Creates shortcut to fields
            $fields = $parameters['fields'];
            // Builds effect
            $effect = DataCenterJs::buildEffect($parameters['effect'], array('this.x' => sprintf("document.getElementById( %s )", DataCenterJs::toScalar($fields['x']['id'])), 'this.y' => sprintf("document.getElementById( %s )", DataCenterJs::toScalar($fields['y']['id']))));
            // Loops over each field
            $jsOutput = '';
            foreach ($structure as $field => $directions) {
                // Adds label
                $xmlOutput .= DataCenterXml::tag('label', array('for' => $fields[$field]['id'], 'class' => 'label'), DataCenterUI::message('field', 'position-' . $field));
                // Adds input
                $xmlOutput .= DataCenterXml::tag('input', array('type' => 'text', 'name' => $fields[$field]['name'], 'id' => $fields[$field]['id'], 'class' => 'number', 'value' => $fields[$field]['value']));
                // Calculates minimum and maximum values
                $range = array('min' => min($fields[$field]['min'], $fields[$field]['max']), 'max' => max($fields[$field]['min'], $fields[$field]['max']));
                foreach ($directions as $direction => $options) {
                    // Builds javascript to connect button to input
                    $jsOutput .= <<<END

\t\t\t\t\t\t\$('#{$fields[$field]['id']}_{$direction}).on({
\t\t\t\t\t\t\t'mouseover':
\t\t\t\t\t\t\tfunction() {
\t\t\t\t\t\t\t\tdocument.getElementById(
\t\t\t\t\t\t\t\t\t'{$parameters['id']}'
\t\t\t\t\t\t\t\t).src = '{$resources[$direction]}';
\t\t\t\t\t\t\t},

\t\t\t\t\t\t\t'mouseout':
\t\t\t\t\t\t\tfunction() {
\t\t\t\t\t\t\t\tdocument.getElementById(
\t\t\t\t\t\t\t\t\t'{$parameters['id']}'
\t\t\t\t\t\t\t\t).src = '{$resources['normal']}';
\t\t\t\t\t\t\t},

\t\t\t\t\t\t\t'click':
\t\t\t\t\t\t\tfunction() {
\t\t\t\t\t\t\t\tvar input = document.getElementById(
\t\t\t\t\t\t\t\t\t'{$fields[$field]['id']}'
\t\t\t\t\t\t\t\t);
\t\t\t\t\t\t\t\tvar value = parseInt( input.value );
\t\t\t\t\t\t\t\tif ( !isNaN( value ) ) {
\t\t\t\t\t\t\t\t\tinput.value = Math.{$options['func']}(
\t\t\t\t\t\t\t\t\t\tvalue {$options['op']} 1,
\t\t\t\t\t\t\t\t\t\t{$range[$options['limit']]}
\t\t\t\t\t\t\t\t\t)
\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t\t{$effect}
\t\t\t\t\t\t\t}
\t\t\t\t\t\t});
END;
                }
            }
            // Begins map
            $xmlOutput .= DataCenterXml::open('map', array('name' => "{$parameters['id']}_map"));
            // Loops over each field
            foreach ($structure as $field => $directions) {
                // Loops over each direction
                foreach ($directions as $direction => $options) {
                    $xmlOutput .= DataCenterXml::tag('area', array('href' => '#', 'shape' => 'poly', 'coords' => $polygons[$mode][$direction], 'id' => $fields[$field]['id'] . '_' . $direction));
                }
            }
            // Ends map
            $xmlOutput .= DataCenterXml::close('map');
            // Adds image
            $xmlOutput .= DataCenterXml::tag('img', array('src' => $resources['normal'], 'usemap' => "#{$parameters['id']}_map", 'id' => $parameters['id'], 'class' => 'navigator'));
            // Adds JavaScript
            $xmlOutput .= DataCenterXml::script($jsOutput);
            // Begins preloading
            $xmlOutput .= DataCenterXml::open('div', array('style' => 'display:none'));
            // Loops over each resource
            foreach ($resources as $resource) {
                // Adds resource
                $xmlOutput .= DataCenterXml::tag('img', array('src' => $resource));
            }
            // Ends preloading
            $xmlOutput .= DataCenterXml::close('div');
            // Ends input
            $xmlOutput .= parent::end();
            // Returns XML
            return $xmlOutput;
        }
    }
 public function configure($path)
 {
     // Checks if...
     if (!$path['id'] && is_array($path['parameter']) && count($path['parameter']) >= 3 && $path['parameter'][0] == 'rack') {
         $object = DataCenterDB::getAsset('object', $path['parameter'][2]);
         $model = $object->getModel();
         $rackLink = DataCenterDB::getAssetLink($path['parameter'][1]);
         $rack = $rackLink->getAsset();
         $plan = DataCenterDB::getPlan($rackLink->get('plan'));
         $objectLink = DataCenterDBAssetLink::newFromValues(array('name' => $model->get('kind'), 'plan' => $plan->getId(), 'parent_link' => $rackLink->getId(), 'asset_type' => 'object', 'asset_id' => $object->getId(), 'z' => 1, 'orientation' => 0));
         // Sets action specific parameters
         $formParameters = array('label' => 'attach', 'hidden' => array('plan', 'parent_link', 'asset_type', 'asset_id'), 'success' => array('page' => 'plans', 'type' => $path['parameter'][0], 'action' => 'view', 'id' => $path['parameter'][1]));
         $headingParameters = array('message' => 'attaching-type', 'type' => 'object');
     } else {
         // Gets asset from database
         $objectLink = DataCenterDB::getAssetLink($path['id']);
         // Gets object that object link links to
         $object = $objectLink->getAsset();
         // Gets plan from database
         $plan = DataCenterDB::getPlan($objectLink->get('plan'));
         // Gets rack link object is linked to
         $rackLink = DataCenterDB::getAssetLink($objectLink->get('parent_link'));
         // Extracts rack from rack link
         $rack = $rackLink->getAsset();
         // Sets action specific parameters
         $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'plans', 'type' => 'object', 'action' => 'view', 'id' => $path['id']));
         $headingParameters = array('message' => 'configuring-type', 'type' => 'object');
     }
     // Builds javascript that references the renderable asset
     $target = array('dataCenter.renderer.getTarget' => array(DataCenterJs::toScalar('plan')), 'getModule');
     $rackId = $rack->getId();
     $rackModel = $rack->getModel();
     $objectModel = $object->getModel();
     $objectId = $object->getId();
     $maxZ = $rackModel->get('units') - $objectModel->get('units') + 1;
     // Builds form parameters
     $formFields = array('name' => array('type' => 'string'), 'position' => array('type' => 'number', 'field' => 'z', 'min' => 1, 'max' => $maxZ, 'effect' => DataCenterJs::chain(array_merge($target, array('setObjectPosition' => array(DataCenterJs::toScalar($rackId), DataCenterJs::toScalar($objectId), '{this}.value', DataCenterJs::toScalar(true)))), false)), 'orientation' => array('type' => 'number', 'min' => 0, 'max' => 1, 'effect' => DataCenterJs::chain(array_merge($target, array('setObjectOrientation' => array(DataCenterJs::toScalar($rackId), DataCenterJs::toScalar($objectId), '{this}.value', DataCenterJs::toScalar(true)))), false)));
     // Returns 2 columm layout with a form and a scene
     return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'plans', 'type' => 'object'), 'row' => $objectLink, 'fields' => $formFields))))), DataCenterUI::renderWidget('plan', array('plan' => $plan, 'current-rack' => $rack->getId(), 'look-at-rack' => $rack->getId(), 'current-object' => $object->getId(), 'include' => !$path['id'] ? $objectLink : null))));
 }
Exemple #8
0
    public static function render(array $parameters)
    {
        // Sets defaults
        $parameters = array_merge(self::$defaultParameters, $parameters);
        // Begins input
        $xmlOutput = parent::begin($parameters['class']);
        // Adds number
        $xmlOutput .= DataCenterXml::tag('input', array('type' => 'text', 'id' => $parameters['id'], 'name' => $parameters['name'], 'class' => 'number', 'value' => $parameters['value'], 'autocomplete' => 'off'));
        // Adds decriment button
        $xmlOutput .= DataCenterXml::tag('input', array('type' => 'button', 'id' => $parameters['id'] . '_dec', 'name' => $parameters['name'], 'class' => 'button-dec', 'value' => '-'));
        // Adds incriment button
        $xmlOutput .= DataCenterXml::tag('input', array('type' => 'button', 'id' => $parameters['id'] . '_inc', 'name' => $parameters['name'], 'class' => 'button-inc', 'value' => '+'));
        // Calculates the minimum value
        $min = min($parameters['min'], $parameters['max']);
        // Calculates the maximum value
        $max = max($parameters['min'], $parameters['max']);
        // Clamps the step value
        $step = max(min($parameters['step'], 1000), 1);
        // Builds effect
        $effect = DataCenterJs::buildEffect($parameters['effect'], array('this' => sprintf("document.getElementById( %s )", DataCenterJs::toScalar($parameters['id']))));
        // Builds javascript to connect buttons to number
        $jsOutput = <<<END
\t\t\t\$('#{$parameters['id']}')
\t\t\t.on(
\t\t\t\t'change',
\t\t\t\tfunction() {
\t\t\t\t\tvar input = document.getElementById( '{$parameters['id']}' );
\t\t\t\t\tvar value = parseInt( input.value );
\t\t\t\t\tif ( !isNaN( value ) ) {
\t\t\t\t\t\tinput.value = Math.min(
\t\t\t\t\t\t\tMath.max( value, {$min} ), {$max}
\t\t\t\t\t\t);
\t\t\t\t\t\t{$effect}
\t\t\t\t\t}
\t\t\t\t}
\t\t\t)
\t\t\t.on(
\t\t\t\t'keyup',
\t\t\t\tfunction() {
\t\t\t\t\tvar input = document.getElementById( '{$parameters['id']}' );
\t\t\t\t\tvar value = parseInt( input.value );
\t\t\t\t\tif ( !isNaN( value ) ) {
\t\t\t\t\t\tinput.value = Math.min(
\t\t\t\t\t\t\tMath.max( value, {$min} ), {$max}
\t\t\t\t\t\t);
\t\t\t\t\t\t{$effect}
\t\t\t\t\t}
\t\t\t\t}
\t\t\t)
\t\t\t\$('#{$parameters['id']}_dec').on(
\t\t\t\t'click',
\t\t\t\tfunction() {
\t\t\t\t\tvar input = document.getElementById( '{$parameters['id']}' );
\t\t\t\t\tvar value = parseInt( input.value );
\t\t\t\t\tif ( !isNaN( value ) ) {
\t\t\t\t\t\tinput.value = Math.max( value - {$step}, {$min} );
\t\t\t\t\t}
\t\t\t\t\t{$effect}
\t\t\t\t}
\t\t\t);
\t\t\t\$('#{$parameters['id']}_inc').on(
\t\t\t\t'click',
\t\t\t\tfunction() {
\t\t\t\t\tvar input = document.getElementById( '{$parameters['id']}' );
\t\t\t\t\tvar value = parseInt( input.value );
\t\t\t\t\tif ( !isNaN( value ) ) {
\t\t\t\t\t\tinput.value = Math.min( value + {$step}, {$max} );
\t\t\t\t\t}
\t\t\t\t\t{$effect}
\t\t\t\t}
\t\t\t);
END;
        // Adds JavaScript
        $xmlOutput .= DataCenterXml::script($jsOutput);
        // Ends input
        $xmlOutput .= parent::end();
        // Returns XML
        return $xmlOutput;
    }
    public static function render(array $parameters)
    {
        // Increment the number of tabbed layouts in existence
        self::$sets++;
        // Gets id for this set
        $set = self::$sets;
        // Begins layout
        $xmlOutput = parent::begin(self::$parameters['class']);
        $xmlOutput .= DataCenterXml::open('div', array('class' => 'tabs'));
        // Loops over each content block
        $state = 'current';
        $tab = 0;
        foreach ($parameters as $name => $content) {
            if ($content !== null) {
                // Adds row
                $xmlOutput .= DataCenterXml::div(array('class' => 'item-' . $state, 'id' => 'tabs_' . $set . '_tab_' . $tab, 'onclick' => DataCenterJs::callFunction('dataCenter.ui.layouts.tabs.select', array(DataCenterJs::toScalar($set), DataCenterJs::toScalar($tab)))), DataCenterUI::message('tab', $name));
                $state = 'normal';
                $tab++;
            } else {
                $xmlOutput .= DataCenterXml::div(array('class' => 'item-disabled'), DataCenterUI::message('tab', $name));
            }
        }
        $xmlOutput .= DataCenterXml::close('div');
        $xmlOutput .= DataCenterXml::clearFloating();
        // Loops over each content block
        $display = 'block';
        $tab = 0;
        foreach ($parameters as $content) {
            if ($content !== null) {
                // Adds row
                $xmlOutput .= DataCenterXml::div(DataCenterXml::div(array('class' => 'page', 'id' => 'tabs_' . $set . '_page_' . $tab, 'style' => 'display:' . $display), $content));
                $display = 'none';
                $tab++;
            }
        }
        // Ends layout
        $xmlOutput .= parent::end();
        // Builds javascript for layout
        $jsOutput = <<<END
\t\t\tif ( !dataCenter.ui.layouts.tabs ) {
\t\t\t\tdataCenter.ui.layouts.tabs = {
\t\t\t\t\tsets: {},
\t\t\t\t\tselect: function(
\t\t\t\t\t\tsetID, tabID
\t\t\t\t\t) {
\t\t\t\t\t\tif ( this.sets[setID] ) {
\t\t\t\t\t\t\tfor ( var i = 0; i < this.sets[setID].count; i++ ) {
\t\t\t\t\t\t\t\tvar page = document.getElementById(
\t\t\t\t\t\t\t\t\t'tabs_' + setID + '_page_' + i
\t\t\t\t\t\t\t\t);
\t\t\t\t\t\t\t\tvar tab = document.getElementById(
\t\t\t\t\t\t\t\t\t'tabs_' + setID + '_tab_' + i
\t\t\t\t\t\t\t\t);
\t\t\t\t\t\t\t\tif ( tab && page ) {
\t\t\t\t\t\t\t\t\tif ( i == tabID ) {
\t\t\t\t\t\t\t\t\t\tpage.style.display = 'block';
\t\t\t\t\t\t\t\t\t\ttab.className = 'item-current';
\t\t\t\t\t\t\t\t\t} else {
\t\t\t\t\t\t\t\t\t\tpage.style.display = 'none';
\t\t\t\t\t\t\t\t\t\ttab.className = 'item-normal';
\t\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t}
\t\t\t\t\t\t}
\t\t\t\t\t},
\t\t\t\t\taddSet: function( name, count ) {
\t\t\t\t\t\tthis.sets[name] = {};
\t\t\t\t\t\tthis.sets[name].count = count;
\t\t\t\t\t}
\t\t\t\t}
\t\t\t}
\t\t\t// Add information for this set
\t\t\tdataCenter.ui.layouts.tabs.addSet( {$set}, {$tab} );
END;
        // Adds script
        $xmlOutput .= DataCenterXml::script($jsOutput);
        // Returns results
        return $xmlOutput;
    }
Exemple #10
0
 public function configure($path)
 {
     // Checks if...
     if (!$path['id'] && is_array($path['parameter']) && count($path['parameter']) >= 3 && $path['parameter'][0] == 'plan') {
         // Gets plan from database
         $plan = DataCenterDB::getPlan($path['parameter'][1]);
         // Creates new asset with default parameters
         $rack = DataCenterDB::getAsset('rack', $path['parameter'][2]);
         // Creates new asset link
         $rackLink = DataCenterDBAssetLink::newFromValues(array('name' => DataCenterUI::message('type', 'rack'), 'plan' => $plan->getId(), 'asset_type' => 'rack', 'asset_id' => $rack->getId(), 'x' => 1, 'y' => 1, 'orientation' => 0));
         // Sets action specific parameters
         $formParameters = array('label' => 'attach', 'hidden' => array('plan', 'asset_type', 'asset_id'), 'success' => array('page' => 'plans', 'type' => 'plan', 'action' => 'view', 'id' => $path['parameter'][1]));
         $headingParameters = array('message' => 'attaching-type', 'type' => 'rack');
     } else {
         // Gets asset from database
         $rackLink = DataCenterDB::getAssetLink($path['id']);
         // Gets rack that rack link links to
         $rack = $rackLink->getAsset();
         // Gets plan from database
         $plan = DataCenterDB::getPlan($rackLink->get('plan'));
         // Sets action specific parameters
         $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'plans', 'type' => 'rack', 'action' => 'view', 'id' => $path['id']));
         $headingParameters = array('message' => 'configuring-type', 'type' => 'rack');
     }
     // Gets parent asset from database
     $space = $plan->getSpace();
     // Builds javascript that references the renderable asset
     $target = array('dataCenter.renderer.getTarget' => array(DataCenterJs::toScalar('plan')), 'getModule');
     $objectId = $rack->getId();
     // Builds form parameters
     $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'plans', 'type' => 'rack'), 'row' => $rackLink, 'fields' => array('name' => array('type' => 'string'), 'position' => array('fields' => array('x' => array('field' => 'x', 'min' => 1, 'max' => $space->get('width')), 'y' => array('field' => 'y', 'min' => 1, 'max' => $space->get('depth'))), 'type' => 'position', 'effect' => DataCenterJs::chain(array_merge($target, array('setRackPosition' => array(DataCenterJs::toScalar($objectId), '{this.x}.value', '{this.y}.value', DataCenterJs::toScalar(true)))), false), 'mode' => 'iso'), 'orientation' => array('type' => 'number', 'min' => 0, 'max' => 3, 'effect' => DataCenterJs::chain(array_merge($target, array('setRackOrientation' => array(DataCenterJs::toScalar($objectId), '{this}.value', DataCenterJs::toScalar(true)))), false)))));
     // Returns 2 columm layout with a form and a scene
     return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderWidget('plan', array('plan' => $plan, 'zoom-from-rack' => $rack->getIdOrZero(), 'current-rack' => $rack->getId(), 'include' => $rackLink))));
 }