예제 #1
0
 public static function render(array $parameters)
 {
     // Adds script to UI
     DataCenterUI::addScript('/extensions/DataCenter/Resources/Widgets/Plan/Plan.js');
     // Sets defaults
     $parameters = array_merge(self::$defaultParameters, $parameters);
     // Checks if width was given as an integer
     if (is_int($parameters['width'])) {
         // Converts width to CSS pixel definition
         $parameters['width'] .= 'px';
     }
     // Checks if height was given as an integer
     if (is_int($parameters['height'])) {
         // Converts height to CSS pixel definition
         $parameters['height'] .= 'px';
     }
     // Begins widget
     $xmlOutput = parent::begin($parameters['class']);
     // Adds XML element
     $xmlOutput .= DataCenterXML::div(array('id' => $parameters['id'], 'style' => DataCenterCss::toAttributes(array('width' => $parameters['width'], 'height' => $parameters['height']))), ' ');
     // Builds script for adding setup job to renderer
     $jsOutput = DataCenterJs::callFunction('dataCenter.renderer.addJob', array(DataCenterJs::toScalar('scene'), DataCenterJs::toScalar($parameters['id']), self::addPlanJsFunction($parameters)));
     // Adds script
     $xmlOutput .= DataCenterXml::script($jsOutput);
     // Begins widget
     $xmlOutput .= parent::end();
     // Returns XML
     return $xmlOutput;
 }
예제 #2
0
 public static function render(array $parameters)
 {
     global $egDataCenterGoogleMapsAPIKey;
     DataCenterUI::addScript('http://maps.google.com/maps?file=api&v=2&key=' . $egDataCenterGoogleMapsAPIKey);
     // Sets defaults
     $parameters = array_merge(self::$defaultParameters, $parameters);
     // Begins widget
     $xmlOutput = parent::begin($parameters['class']);
     // Checks if width was given as an integer
     if (is_int($parameters['width'])) {
         // Converts width to CSS pixel definition
         $parameters['width'] .= 'px';
     }
     // Checks if height was given as an integer
     if (is_int($parameters['height'])) {
         // Converts height to CSS pixel definition
         $parameters['height'] .= 'px';
     }
     // Build CSS style for XML element
     $style = "width:{$parameters['width']};height:{$parameters['height']};";
     // Adds XML element
     $xmlOutput .= DataCenterXML::div(array('id' => $parameters['id'], 'style' => $style), ' ');
     // Checks if multiple locations were given
     if ($parameters['locations']) {
         // Builds script to add setup job to renderer
         $jsOutput = sprintf("dataCenter.renderer.addJob( 'map', %s, %s );", DataCenterJs::toScalar($parameters['id']), self::addMarkersJsFunction($parameters));
         // Alternatively checks if a single location was given
     } elseif ($parameters['location']) {
         // Builds script to add setup job to renderer
         $jsOutput = sprintf("dataCenter.renderer.addJob( 'map', %s, %s );", DataCenterJS::toScalar($parameters['id']), self::showPositionJsFunction($parameters));
     } else {
         // Adds an empty job to the render queue so the map gets rendered
         $jsOutput = sprintf("dataCenter.renderer.addJob( 'map', %s, %s );", DataCenterJS::toScalar($parameters['id']), 'function( map ) { return true; }');
     }
     $xmlOutput .= DataCenterXml::script($jsOutput);
     // Ends widget
     $xmlOutput .= parent::end();
     // Returns XML
     return $xmlOutput;
 }
예제 #3
0
 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);
 }
예제 #4
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;
        }
    }
예제 #5
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;
    }
 /**
  * Renders a final composition from cached output
  */
 public static function render()
 {
     global $wgOut, $wgScriptPath;
     // Adds XML head content
     foreach (self::$output['scripts'] as $url) {
         if (strpos($url, 'http://') !== false) {
             $wgOut->addScript(DataCenterXml::script(array('src' => $url)));
         } elseif (strpos($url, '<') !== false) {
             $wgOut->addScript(sprintf($url, $wgScriptPath));
         } else {
             $wgOut->addScriptFile($wgScriptPath . $url);
         }
     }
     $wgOut->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $wgScriptPath . '/extensions/DataCenter/DataCenter.css'));
     // Adds XML body content
     $wgOut->addHTML(DataCenterXml::div(array('class' => 'datacenter-ui'), self::$output['menu'] . self::$output['content']));
     if (self::$output['script'] !== null) {
         $wgOut->addHTML(DataCenterXml::script(self::$output['script']));
     }
 }
예제 #7
0
    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;
    }