示例#1
1
 /** {@inheritdoc} */
 public function renderFieldset(\Zend\View\Renderer\PhpRenderer $view, \Zend\Form\Fieldset $fieldset)
 {
     if ($fieldset->getName()) {
         return parent::renderFieldset($view, $fieldset);
     }
     // Reimplement form renderer to align submit button with elements from Preferences fieldset.
     $output = "<div class='table'>\n";
     foreach ($this->get('Preferences') as $element) {
         if ($element instanceof \Zend\Form\Fieldset) {
             $output .= $view->htmlElement('span', $view->translate($element->getLabel()), array('class' => 'label'), true) . "\n";
             $output .= $view->htmlElement('fieldset', "<legend></legend>\n" . $this->renderFieldset($view, $element));
         } else {
             $output .= $view->formRow($element, 'prepend', false);
             if ($element->getMessages()) {
                 $output .= "\n<div class='row'>\n<span class='cell'></span>\n";
                 $output .= $view->formElementErrors($element, array('class' => 'errors'));
                 $output .= "\n</div>";
             }
         }
         $output .= "\n";
     }
     $output .= "<div class='row'>\n";
     $output .= "<span class='cell'></span>\n";
     $output .= $view->formRow($this->get('Submit'));
     $output .= "\n</div>\n</div>\n";
     return $output;
 }
示例#2
0
 /** {@inheritdoc} */
 public function setData($data)
 {
     if (isset($data['Packages'])) {
         $packages = array_keys($data['Packages']);
     } else {
         $packages = array();
     }
     $this->setPackages($packages);
     return parent::setData($data);
 }
 public function testValidateType()
 {
     $this->assertTrue($this->_form->validateType('', null, 'text'));
     $this->assertTrue($this->_form->validateType(0, null, 'text'));
     $this->assertTrue($this->_form->validateType(null, null, 'text'));
     $this->assertFalse($this->_form->validateType('', null, 'integer'));
     $this->assertTrue($this->_form->validateType(0, null, 'integer'));
     $this->assertFalse($this->_form->validateType(null, null, 'integer'));
     $this->assertFalse($this->_form->validateType('', null, 'float'));
     $this->assertTrue($this->_form->validateType(0.0, null, 'float'));
     $this->assertFalse($this->_form->validateType(null, null, 'float'));
     $this->assertFalse($this->_form->validateType('', null, 'date'));
     $this->assertTrue($this->_form->validateType(new \DateTime(), null, 'date'));
     $this->assertFalse($this->_form->validateType(null, null, 'date'));
 }
示例#4
0
 /** {@inheritdoc} */
 public function isValid()
 {
     // Invoke parent implementation in any case to apply filters and
     // initialize messages.
     $isValid = parent::isValid();
     if ($this->getData()['MailAddress'] === null) {
         // A bug in the InputFilter causes NULL values to be passed to the
         // EmailAddress validator which will fail despite being optional.
         // Remove incorrect message.
         $mailAddress = $this->get('MailAddress');
         $messages = $mailAddress->getMessages();
         unset($messages[\Zend\Validator\EmailAddress::INVALID]);
         $mailAddress->setMessages($messages);
         // Evaluate remaining messages.
         $isValid = !$this->getMessages();
     }
     return $isValid;
 }
示例#5
0
 /** {@inheritdoc} */
 public function getMessages($elementName = null)
 {
     if ($elementName === null) {
         $messages = parent::getMessages();
         $filterMessages = $this->getInputFilter()->getMessages();
         if (isset($filterMessages['clients'])) {
             $messages['clients'] = $filterMessages['clients'];
         }
         return $messages;
     } elseif ($elementName == 'clients') {
         $messages = array();
         $filterMessages = $this->getInputFilter()->getMessages();
         if (isset($filterMessages['clients'])) {
             $messages += $filterMessages['clients'];
         }
         return $messages;
     } else {
         return parent::getMessages($elementName);
     }
 }
示例#6
0
    /** {@inheritdoc} */
    public function render(\Zend\View\Renderer\PhpRenderer $view)
    {
        $commandLine = $view->translate('Command line');
        $labels = array('launch' => $commandLine, 'execute' => $commandLine, 'store' => $view->translate('Target Path'));
        $labels = '    var actionParamLabels = ' . json_encode($labels) . ";\n";
        $view->headScript()->captureStart();
        print $labels;
        ?>

        /**
         * Hide or display a block element.
         */
        function display(name, display)
        {
            document.getElementsByName(name)[0].parentNode.style.display = display ? 'table-row' : 'none';
        }

        /*
         * Event handler for Platform combobox. Also called for form
         * initialization. Hides/displays notification elements which have no
         * effect on non-Windows platforms.
         */
        function changePlatform()
        {
            if (document.getElementById('form_package_build_platform').value == 'windows') {
                display('Warn', true);
                display('PostInstMessage', true);
                toggleWarn();
            } else {
                display('Warn', false);
                display('WarnMessage', false);
                display('WarnCountdown', false);
                display('WarnAllowAbort', false);
                display('WarnAllowDelay', false);
                display('PostInstMessage', false);
            }
        }

        /*
         * Event handler for Action combobox. Also called for form initialization.
         * Changes label of parameter input field according to selected action.
         */
        function changeParam()
        {
            var label = actionParamLabels[document.getElementsByName('DeployAction')[0].value];
            document.getElementsByName('ActionParam')[0].parentNode.getElementsByTagName('span')[0].innerHTML = label;
        }

        /*
         * Event handler for Warn checkbox. Also called for form initialization.
         * Hides or displays Warn* fields according to checked state.
         */
        function toggleWarn()
        {
            var checked = document.getElementById('form_package_build_warn').checked &&
                          document.getElementById('form_package_build_platform').value == 'windows';
            display('WarnMessage', checked);
            display('WarnCountdown', checked);
            display('WarnAllowAbort', checked);
            display('WarnAllowDelay', checked);
        }

        <?php 
        $view->headScript()->captureEnd();
        $view->placeholder('BodyOnLoad')->append('changePlatform()');
        $view->placeholder('BodyOnLoad')->append('changeParam()');
        $view->placeholder('BodyOnLoad')->append('toggleWarn()');
        $view->placeholder('BodyOnLoad')->append('document.getElementsByName("Name")[0].focus()');
        return parent::render($view);
    }
示例#7
0
 /**
  * Test basic form properties (form class, "class" attribute, CSRF element)
  */
 public function testForm()
 {
     $this->assertInstanceOf('Console\\Form\\Form', $this->_form);
     $this->assertEquals('form ' . substr(strtr(strtolower($this->_getFormClass()), '\\', '_'), 8), $this->_form->getAttribute('class'));
     $this->assertInstanceOf('\\Zend\\Form\\Element\\Csrf', $this->_form->get('_csrf'));
 }
示例#8
0
    /** {@inheritdoc} */
    public function render(\Zend\View\Renderer\PhpRenderer $view)
    {
        $view->headScript()->captureStart();
        ?>

        // Hide or show all label elements following the checkbox within the same fieldset
        function toggle(element)
        {
            var node = element.parentNode.parentNode;
            while (node = node.nextSibling) {
                switch (node.nodeName) {
                    case 'LABEL':
                        node.style.display = element.checked ? 'table-row' : 'none';
                        break;
                    case 'UL':
                        node.style.display = element.checked ? 'block' : 'none';
                        break;
                    default:
                        // Invisible text node, nothing to be changed
                }
            }
        }

        // Initialize display of fieldset content
        function toggleByName(name)
        {
            var elements = document.getElementsByName(name);
            for (var i = elements.length - 1; i >= 0; i--) {
                if (elements[i].type == 'checkbox') {
                    toggle(elements[i]);
                    break;
                }
            }
        }

        <?php 
        $view->headScript()->captureEnd();
        $view->placeholder('BodyOnLoad')->append('toggleByName("Download[packageDeployment]")');
        $view->placeholder('BodyOnLoad')->append('toggleByName("Scan[allowScan]")');
        return parent::render($view);
    }
 /** {@inheritdoc} */
 public function renderFieldset(\Zend\View\Renderer\PhpRenderer $view, \Zend\Form\Fieldset $fieldset = null)
 {
     $output = '';
     $name = $fieldset->getName();
     switch ($name) {
         case 'inspect':
             $output .= "<div class='textcenter'>\n";
             $output .= $view->formRow($fieldset->get('inspect'), 'append') . "\n";
             $output .= "</div>\n";
             break;
         case 'existing':
             $table = '';
             foreach ($this->_definedValues as $value) {
                 $id = $value['Id'];
                 $element = $fieldset->get("value_{$id}_name");
                 $row = $view->htmlElement('td', $view->formElement($element) . $view->formElementErrors($element, array('class' => 'errors')));
                 $row .= $view->htmlElement('td', $view->escapeHtml($element->getLabel()));
                 $row .= $view->htmlElement('td', $view->htmlElement('a', $view->translate('Delete'), array('href' => $view->consoleUrl('preferences', 'deleteregistryvalue', array('name' => $value['Name'])))));
                 $table .= $view->htmlElement('tr', $row);
             }
             $output .= $view->htmlElement('table', $table);
             break;
         case 'new_value':
             $output .= parent::renderFieldset($view, $fieldset);
             break;
         default:
             if ($fieldset == $this) {
                 $output .= $this->renderFieldset($view, $fieldset->get('inspect'));
                 if (count($this->_definedValues)) {
                     $output .= $view->htmlElement('h2', $view->translate('Values'));
                     $output .= $this->renderFieldset($view, $fieldset->get('existing'));
                 }
                 $output .= $view->htmlElement('h2', $view->translate('Add'));
                 $output .= $this->renderFieldset($view, $fieldset->get('new_value'));
             }
             break;
     }
     return $output;
 }
示例#10
0
    /**
     * Render form
     *
     * @param \Zend\View\Renderer\PhpRenderer $view
     * @return string
     */
    public function render(\Zend\View\Renderer\PhpRenderer $view)
    {
        $view->headScript()->captureStart();
        ?>

        // Filter types
        var types = <?php 
        print json_encode($this->_types);
        ?>
;

        /**
         * Event handler for Filter combobox
         *
         * Sets options for "operators" element according to selected filter.
         */
        function filterChanged()
        {
            var elements = document.getElementById('form_search').elements;
            var operators;
            switch (types[elements['filter'].value]) {
                case 'integer':
                case 'float':
                case 'date':
                    operators = <?php 
        print json_encode($this->_operatorsOrdinal);
        ?>
;
                    break;
                default:
                    operators = <?php 
        print json_encode($this->_operatorsText);
        ?>
;
            }
            var options = elements['operator'].options;
            options.length = 0;
            for (var value in operators) {
                options.add(new Option(operators[value], value));
            }
        }

        <?php 
        $view->headScript()->captureEnd();
        $onload = $view->placeholder('BodyOnLoad');
        $onload->append('filterChanged()');
        // Set operator value manually because the element creation code does
        // not know it's valid and ignores it.
        $initialOperator = $this->get('operator')->getValue();
        if ($initialOperator) {
            $onload->append(sprintf('document.getElementById("form_search").elements["operator"].value = %s', json_encode($initialOperator)));
        }
        return parent::render($view);
    }