Ejemplo n.º 1
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $what = new \Zend\Form\Element\Radio('What');
     $what->setValueOptions(array(\Model\Client\Client::MEMBERSHIP_AUTOMATIC => $this->_('Store search parameters. Group memberships will be updated automatically.'), \Model\Client\Client::MEMBERSHIP_ALWAYS => $this->_('Add current search results. Group memberships will be set only this time.'), \Model\Client\Client::MEMBERSHIP_NEVER => $this->_('Exclude search results from a group.')));
     $what->setValue(\Model\Client\Client::MEMBERSHIP_AUTOMATIC);
     $this->add($what);
     $where = new \Zend\Form\Element\Radio('Where');
     $where->setValueOptions(array('new' => $this->_('Store in new group'), 'existing' => $this->_('Store in existing group')));
     $where->setValue('new')->setAttribute('onchange', 'selectElements()');
     $this->add($where);
     $newGroup = new \Zend\Form\Element\Text('NewGroup');
     $newGroup->setLabel('Name');
     $this->add($newGroup);
     $description = new \Zend\Form\Element\Text('Description');
     $description->setLabel('Description');
     $this->add($description);
     $existingGroup = new \Library\Form\Element\SelectSimple('ExistingGroup');
     $existingGroup->setLabel('Group');
     $groups = array();
     foreach ($this->getOption('GroupManager')->getGroups(null, null, 'Name') as $group) {
         $groups[] = $group['Name'];
     }
     $existingGroup->setValueOptions($groups);
     $this->add($existingGroup);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'NewGroup', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(1, 255), 'message' => "Value is required and can't be empty"), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateGroupExists'), 'message' => $this->_('The name already exists'))))));
     $inputFilter->add(array('name' => 'Description', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null', 'options' => array('type' => 'string'))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long'))))));
     $this->setInputFilter($inputFilter);
 }
Ejemplo n.º 2
0
 public function testInArrayValidator()
 {
     $element = new \Library\Form\Element\SelectSimple();
     $element->setValueOptions(array('option1', 'option2'));
     $factory = new \Zend\InputFilter\Factory();
     $input = $factory->createInput($element->getInputSpecification());
     $input->setValue('option1');
     $this->assertTrue($input->isValid());
     $input->setValue('option2');
     $this->assertTrue($input->isValid());
     $input->setValue('option3');
     $this->assertFalse($input->isValid());
 }
Ejemplo n.º 3
0
    public function testFormElementHelperIntegration()
    {
        $element = new \Library\Form\Element\SelectSimple('test');
        $element->setValueOptions(array('option<b>1', 'option2'))->setValue('option<b>1');
        $expected = <<<EOT
<select name="test">
<option selected="selected">option&lt;b&gt;1</option>
<option>option2</option>
</select>
EOT;
        $view = new \Zend\View\Renderer\PhpRenderer();
        $view->setHelperPluginManager(static::$_helperManager);
        $helper = static::$_helperManager->get('formElement');
        $helper->setView($view);
        $this->assertEquals($expected, $helper($element));
    }
Ejemplo n.º 4
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $integerFilter = array('name' => 'Callback', 'options' => array('callback' => array($this, 'normalize'), 'callback_params' => 'integer'));
     $integerValidator = array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateType'), 'callbackOptions' => 'integer'));
     // Package name
     $name = new Element\Text('Name');
     $name->setLabel('Name');
     $this->add($name);
     $inputFilter->add(array('name' => 'Name', 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)), array('name' => 'Library\\Validator\\NotInArray', 'options' => array('haystack' => $this->getOption('packageManager')->getAllNames(), 'caseSensitivity' => \Library\Validator\NotInArray::CASE_INSENSITIVE)))));
     // Comment
     $comment = new Element\Textarea('Comment');
     $comment->setLabel('Comment');
     $this->add($comment);
     $inputFilter->add(array('name' => 'Comment', 'required' => false, 'filters' => array(array('name' => 'StringTrim'))));
     // Platform combobox
     $platform = new Element\Select('Platform');
     $platform->setLabel('Platform')->setAttribute('type', 'select_untranslated')->setAttribute('id', 'form_package_build_platform')->setAttribute('onchange', 'changePlatform()')->setValueOptions(array('windows' => 'Windows', 'linux' => 'Linux', 'mac' => 'MacOS'));
     $this->add($platform);
     // Action combobox
     // Translate labels manually to let xgettext recognize them
     $action = new Element\Select('DeployAction');
     $action->setLabel('Action')->setAttribute('onchange', 'changeParam()')->setValueOptions(array('launch' => $this->_('Download package, execute command, retrieve result'), 'execute' => $this->_('Optionally download package, execute command'), 'store' => $this->_('Just download package to target path')));
     $this->add($action);
     // Command line or target path for action
     // Label is set by JavaScript code.
     $actionParam = new Element\Text('ActionParam');
     $this->add($actionParam);
     $inputFilter->add(array('name' => 'ActionParam', 'required' => true));
     // Upload file
     $file = new Element\File('File');
     $file->setLabel('File');
     $this->add($file);
     $inputFilter->add(array('name' => 'File'));
     // Requirement is set in isValid()
     // Priority combobox
     $priority = new \Library\Form\Element\SelectSimple('Priority');
     $priority->setValueOptions(range(0, 10))->setLabel('Priority (0: exclusive, 10: lowest)');
     $this->add($priority);
     // Maximum fragment size.
     $maxFragmentSize = new Element\Text('MaxFragmentSize');
     $maxFragmentSize->setAttribute('size', '8')->setLabel('Maximum fragment size (kB)');
     $this->add($maxFragmentSize);
     $inputFilter->add(array('name' => 'MaxFragmentSize', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     // Warn user before installation
     $warn = new Element\Checkbox('Warn');
     $warn->setLabel('Warn user')->setAttribute('id', 'form_package_build_warn')->setAttribute('onchange', 'toggleWarn()');
     $this->add($warn);
     // Message to display to user before installation
     $warnMessage = new Element\Textarea('WarnMessage');
     $warnMessage->setLabel('Message');
     $this->add($warnMessage);
     $inputFilter->add(array('name' => 'WarnMessage', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateNotificationMessage'), 'message' => $this->_('Message must not contain double quotes.'))))));
     // Countdown before installation starts automatically
     $warnCountdown = new Element\Text('WarnCountdown');
     $warnCountdown->setAttribute('size', '5')->setLabel('Countdown (seconds)');
     $this->add($warnCountdown);
     $inputFilter->add(array('name' => 'WarnCountdown', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     // Allow user abort
     $warnAllowAbort = new Element\Checkbox('WarnAllowAbort');
     $warnAllowAbort->setLabel('Allow abort by user');
     $this->add($warnAllowAbort);
     // Allow user delay
     $warnAllowDelay = new Element\Checkbox('WarnAllowDelay');
     $warnAllowDelay->setLabel('Allow delay by user');
     $this->add($warnAllowDelay);
     // Message to display to user after deployment
     $postInstMessage = new Element\Textarea('PostInstMessage');
     $postInstMessage->setLabel('Post-installation message');
     $this->add($postInstMessage);
     $inputFilter->add(array('name' => 'PostInstMessage', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateNotificationMessage'), 'message' => $this->_('Message must not contain double quotes.'))))));
     // Submit button
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('Build');
     $this->add($submit);
     $this->setInputFilter($inputFilter);
 }
Ejemplo n.º 5
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $integerFilter = array('name' => 'Callback', 'options' => array('callback' => array($this, 'normalize'), 'callback_params' => 'integer'));
     $integerValidator = array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateType'), 'callbackOptions' => 'integer'));
     $deploy = new \Zend\Form\Fieldset('Deploy');
     $deploy->setLabel('Defaults for deploying updated packages');
     $deployNonnotified = new \Zend\Form\Element\Checkbox('defaultDeployNonnotified');
     $deployNonnotified->setLabel('Not notified');
     $deploy->add($deployNonnotified);
     $deploySuccess = new \Zend\Form\Element\Checkbox('defaultDeploySuccess');
     $deploySuccess->setLabel('Success');
     $deploy->add($deploySuccess);
     $deployNotified = new \Zend\Form\Element\Checkbox('defaultDeployNotified');
     $deployNotified->setLabel('Running');
     $deploy->add($deployNotified);
     $deployError = new \Zend\Form\Element\Checkbox('defaultDeployError');
     $deployError->setLabel('Error');
     $deploy->add($deployError);
     $deployGroups = new \Zend\Form\Element\Checkbox('defaultDeployGroups');
     $deployGroups->setLabel('Groups');
     $deploy->add($deployGroups);
     $preferences->add($deploy);
     $defaultPlatform = new \Zend\Form\Element\Select('defaultPlatform');
     $defaultPlatform->setLabel('Default platform')->setAttribute('type', 'select_untranslated')->setValueOptions(array('windows' => 'Windows', 'linux' => 'Linux', 'mac' => 'MacOS'));
     $preferences->add($defaultPlatform);
     $defaultAction = new \Zend\Form\Element\Select('defaultAction');
     $defaultAction->setLabel('Default action')->setValueOptions(array('launch' => $this->_('Download package, execute command, retrieve result'), 'execute' => $this->_('Optionally download package, execute command'), 'store' => $this->_('Just download package to target path')));
     $preferences->add($defaultAction);
     $defaultActionParam = new \Zend\Form\Element\Text('defaultActionParam');
     $defaultActionParam->setLabel('Default action parameter');
     $preferences->add($defaultActionParam);
     $defaultPackagePriority = new \Library\Form\Element\SelectSimple('defaultPackagePriority');
     $defaultPackagePriority->setValueOptions(range(0, 10))->setLabel('Default priority (0: exclusive, 10: lowest)');
     $preferences->add($defaultPackagePriority);
     $defaultMaxFragmentSize = new \Zend\Form\Element\Text('defaultMaxFragmentSize');
     $defaultMaxFragmentSize->setAttribute('size', '8')->setLabel('Default maximum fragment size (kB)');
     $preferences->add($defaultMaxFragmentSize);
     $inputFilter->add(array('name' => 'defaultMaxFragmentSize', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     $defaultWarn = new \Zend\Form\Element\Checkbox('defaultWarn');
     $defaultWarn->setLabel('Warn user by default');
     $preferences->add($defaultWarn);
     $defaultWarnMessage = new \Zend\Form\Element\Textarea('defaultWarnMessage');
     $defaultWarnMessage->setLabel('Default warn message');
     $preferences->add($defaultWarnMessage);
     $defaultWarnCountdown = new \Zend\Form\Element\Text('defaultWarnCountdown');
     $defaultWarnCountdown->setAttribute('size', '5')->setLabel('Default warn countdown (seconds)');
     $preferences->add($defaultWarnCountdown);
     $inputFilter->add(array('name' => 'defaultWarnCountdown', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     $defaultWarnAllowAbort = new \Zend\Form\Element\Checkbox('defaultWarnAllowAbort');
     $defaultWarnAllowAbort->setLabel('Allow user abort by default');
     $preferences->add($defaultWarnAllowAbort);
     $defaultWarnAllowDelay = new \Zend\Form\Element\Checkbox('defaultWarnAllowDelay');
     $defaultWarnAllowDelay->setLabel('Allow user delay by default');
     $preferences->add($defaultWarnAllowDelay);
     $defaultPostInstMessage = new \Zend\Form\Element\Textarea('defaultPostInstMessage');
     $defaultPostInstMessage->setLabel('Default post-installation message');
     $preferences->add($defaultPostInstMessage);
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }