public static function render(array $parameters)
 {
     // Sets defaults
     $parameters = array_merge(self::$defaultParameters, $parameters);
     // Begins input
     $xmlOutput = parent::begin($parameters['class']);
     // Adds buttons
     foreach (array('past', 'present', 'future') as $tense) {
         $radioAttributes = array('type' => 'radio', 'id' => $parameters['id'] . '_' . $tense, 'name' => $parameters['name'], 'value' => $tense, 'class' => 'button');
         $labelAttributes = array('for' => $parameters['id'] . '_' . $tense, 'class' => 'label');
         if ($parameters['value'] == $tense) {
             $radioAttributes['checked'] = 'checked';
         }
         if (in_array($tense, $parameters['disable'])) {
             $radioAttributes['disabled'] = 'true';
             $labelAttributes['class'] .= ' disabled';
         }
         $xmlOutput .= DataCenterXml::tag('input', $radioAttributes);
         $xmlOutput .= DataCenterXml::tag('label', $labelAttributes, DataCenterUI::message('option', $tense));
     }
     // Ends input
     $xmlOutput .= parent::end();
     // Returns XML
     return $xmlOutput;
 }
 public static function render(array $parameters)
 {
     // Sets defaults
     $parameters = array_merge(self::$defaultParameters, $parameters);
     // Begins input
     $xmlOutput = parent::begin($parameters['class']);
     // Adds button
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'button', 'id' => $parameters['id'], 'name' => $parameters['name'], 'class' => 'button', 'value' => DataCenterUI::message('label', $parameters['label'])));
     // Ends input
     $xmlOutput .= parent::end();
     // Returns XML
     return $xmlOutput;
 }
 public static function render(array $parameters)
 {
     // Sets defaults
     $parameters = array_merge(self::$defaultParameters, $parameters);
     // Begins input
     $xmlOutput = parent::begin($parameters['class']);
     // Adds button
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'text', 'id' => $parameters['id'], 'name' => $parameters['name'], 'class' => 'string', 'value' => $parameters['value'], 'autocomplete' => 'off'));
     // Ends input
     $xmlOutput .= parent::end();
     // Returns XML
     return $xmlOutput;
 }
 public static function render(array $parameters)
 {
     // Sets defaults
     $parameters = array_merge(self::$defaultParameters, $parameters);
     // Begins input
     $xmlOutput = parent::begin($parameters['class']);
     // Creates list of buttons
     $buttons = array('true' => true, 'false' => false);
     // Adds buttons
     foreach ($buttons as $button => $value) {
         $radioAttributes = array('type' => 'radio', 'id' => $parameters['id'] . '_' . $button, 'name' => $parameters['name'], 'value' => $value ? 1 : 0, 'class' => 'button');
         $labelAttributes = array('for' => $parameters['id'] . '_' . $button, 'class' => 'label');
         if ($parameters['value'] == ($value ? 1 : 0) && $parameters['value'] !== null && $parameters['value'] !== '') {
             $radioAttributes['checked'] = 'checked';
         }
         $xmlOutput .= DataCenterXml::tag('input', $radioAttributes);
         $xmlOutput .= DataCenterXml::tag('label', $labelAttributes, DataCenterUI::message('option', $button));
     }
     // Ends input
     $xmlOutput .= parent::end();
     // Returns XML
     return $xmlOutput;
 }
Exemple #5
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;
        }
    }
Exemple #6
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)
 {
     // Sets defaults
     $parameters = array_merge(self::$defaultParameters, $parameters);
     // Begins input
     $xmlOutput = parent::begin($parameters['class']);
     // Begins select
     $xmlOutput .= DataCenterXml::open('select', array('name' => $parameters['name'], 'id' => $parameters['id'], 'class' => 'list'));
     // Checks if rows were given
     if ($parameters['rows']) {
         // Loops over each row
         foreach ($parameters['rows'] as $row) {
             // Builds attributes for option
             $optionAttributes = array('value' => $row->getId());
             // Checks if option value matches input value
             if ($optionAttributes['value'] == $parameters['value']) {
                 // Adds selected attribute to option
                 $optionAttributes['selected'] = 'selected';
             }
             // Adds option
             $xmlOutput .= DataCenterXml::tag('option', $optionAttributes, implode($row->get($parameters['labels']), $parameters['glue']));
         }
         // Alternatively check if options were given
     } elseif ($parameters['options']) {
         // Loops over each option
         foreach ($parameters['options'] as $key => $value) {
             // Checks if option key was not given
             if (is_int($key)) {
                 // Uses key as value
                 $optionAttributes = array('value' => $key);
                 // Uses value as label
                 $optionLabel = $value;
             } else {
                 // Uses value as value
                 $optionAttributes = array('value' => $value);
                 // Uses key as label
                 $optionLabel = $key;
             }
             // Checks if option value matches input value
             if ($optionAttributes['value'] == $parameters['value']) {
                 // Adds selected attribute to option
                 $optionAttributes['selected'] = 'selected';
             }
             // Adds option
             $xmlOutput .= DataCenterXml::tag('option', $optionAttributes, DataCenterUI::message('option', $optionLabel));
         }
         // Alternatively check if an enum was given
     } elseif (isset($parameters['enum']['category'], $parameters['enum']['type'], $parameters['enum']['field'])) {
         // Gets enum values from database
         $enum = DataCenterDB::getEnum($parameters['enum']['category'], $parameters['enum']['type'], $parameters['enum']['field']);
         // Loops over each name
         foreach ($enum as $name) {
             // Uses name as value
             $optionAttributes = array('value' => $name);
             // Uses name as label
             $optionLabel = $name;
             // Checks if option value matches input value
             if ($optionAttributes['value'] == $parameters['value']) {
                 // Adds selected attribute to option
                 $optionAttributes['selected'] = 'selected';
             }
             // Adds option
             $xmlOutput .= Xml::element('option', $optionAttributes, DataCenterUI::message('option', $optionLabel));
         }
     }
     // Ends select
     $xmlOutput .= DataCenterXml::close('select');
     // Ends input
     $xmlOutput .= parent::end();
     // Returns XML
     return $xmlOutput;
 }