function testAddExtraClass() {
		/* DropdownField has an extra class name and is in the HTML the field returns */
		$dropdownField = new DropdownField('FeelingOk', 'Are you feeling ok?', array(0 => 'No', 1 => 'Yes'), '', null, '(Select one)');
		$dropdownField->addExtraClass('thisIsMyExtraClassForDropdownField');
		preg_match('/thisIsMyExtraClassForDropdownField/', $dropdownField->Field(), $matches);
		$this->assertTrue($matches[0] == 'thisIsMyExtraClassForDropdownField');
	}
 public function Field($properties = array())
 {
     if (empty($this->source) || count($this->source) === 1) {
         $this->setEmptyString('');
     }
     return parent::Field($properties);
 }
예제 #3
0
	function testReadonlyField() {
		$dropdownField = new DropdownField('FeelingOk', 'Are you feeling ok?', array(0 => 'No', 1 => 'Yes'), '', null, '(Select one)');
		$dropdownField->setValue(1);
		$readonlyDropdownField = $dropdownField->performReadonlyTransformation();
		preg_match('/Yes/', $dropdownField->Field(), $matches);
		$this->assertEquals($matches[0], 'Yes');
	}
 function Field()
 {
     $source = $this->getSource();
     if ($this->defaultToVisitorCountry && !$this->value || !isset($source[$this->value])) {
         $this->value = ($vc = Geoip::visitor_country()) ? $vc : Geoip::$default_country_code;
     }
     return parent::Field();
 }
 public function testStringOneValueSelectedOptionBehaviour()
 {
     $field = new DropdownField('Field', null, array('-1' => 'some negative', '0' => 'none', '1' => 'one', '2+' => 'two or more'), '1');
     $selectedOptions = $this->findSelectedOptionElements($field->Field());
     $this->assertEquals((string) $selectedOptions[0], 'one', 'The selected option is "one"');
     $field = new DropdownField('Field', null, array('-1' => 'some negative', '0' => 'none', '1' => 'one', '2+' => 'two or more'), 1);
     $selectedOptions = $this->findSelectedOptionElements($field->Field());
     $this->assertEquals((string) $selectedOptions[0], 'one', 'The selected option is "one"');
 }
 /**
  * {@inheritdoc}
  */
 public function getColumnContent($gridField, $record, $columnName)
 {
     if ($columnName === 'MergeAction' && $record->{$this->childMethod}()->Count() > 0) {
         $dropdown = new DropdownField('Target', 'Target', $this->records->exclude('ID', $record->ID)->map());
         $prefix = strtolower($this->parentMethod . '-' . $this->childMethod);
         $action = GridFieldFormAction::create($gridField, 'MergeAction' . $record->ID, 'Move', 'merge', array('record' => $record->ID, 'target' => $prefix . '-target-record-' . $record->ID));
         $action->setExtraAttributes(array('data-target' => $prefix . '-target-record-' . $record->ID));
         return $dropdown->Field() . $action->Field() . '<a title="Move posts to" class="MergeActionReveal">move posts to</a>';
     }
     return null;
 }
 /**
  * @param array $properties
  * @return HTMLText
  */
 public function Field($properties = array())
 {
     $this->addExtraClass('selectboxfield')->setAttribute('data-selectboxconfig', Convert::array2json($this->selectbox_config));
     //allow for not including default styles
     if ($this->config()->get('require_css') == true) {
         Requirements::css(SELECTBOX_DROPDOWN_FIELD_DIR_THIRD_PARTY_DIR . 'jquery.selectbox-0.2/css/jquery.selectbox.css');
     }
     Requirements::javascript(SELECTBOX_DROPDOWN_FIELD_DIR_THIRD_PARTY_DIR . 'jquery.selectbox-0.2/js/jquery.selectbox-0.2.min.js');
     Requirements::javascript(SELECTBOX_DROPDOWN_FIELD_JAVASCRIPT . '/selectbox.dropdown.field.js');
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript(DEPENDENTDROPDOWNFIELD . '/javascript/dependentdropdownfield.js');
     $this->setAttribute('data-link', $this->Link('load'));
     $this->setAttribute('data-depends', $this->getDepends()->getName());
     $this->setAttribute('data-empty', $this->getEmptyString());
     $this->setAttribute('data-unselected', $this->getUnselectedString());
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript(SELECT2_MODULE . "/select2/select2.js");
     Requirements::javascript(SELECT2_MODULE . "/javascript/select2.init.js");
     Requirements::css(SELECT2_MODULE . "/select2/select2.min.css");
     $this->addExtraClass('select2')->addExtraClass('no-chzn');
     if (!$this->getAttribute('data-search-threshold')) {
         $this->setSearchThreshold(self::$default_search_threshold);
     }
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     $this->addExtraClass('ColorpaletteInput');
     ColorpaletteHelper::requirements();
     Requirements::javascript("calendar/javascript/admin/ColorpaletteField.js");
     $source = $this->getSource();
     //adding the current value to the mix if isn't in the array
     $val = $this->getColorWithHash();
     $this->value = $val;
     $source[$val] = $val;
     $this->setSource($source);
     return parent::Field();
 }
예제 #11
0
 public function Field($properties = array())
 {
     $source = $this->getSource();
     if (!$this->value || !isset($source[$this->value])) {
         if ($this->config()->get('default_to_locale') && $this->locale()) {
             $locale = new Zend_Locale();
             $locale->setLocale($this->locale());
             $this->value = $locale->getRegion();
         }
     }
     if (!$this->value || !isset($source[$this->value])) {
         $this->value = $this->config()->get('default_country');
     }
     return parent::Field();
 }
 public function Field($properties = array())
 {
     $source = $this->getSource();
     // Default value to best availabel locale
     $value = $this->Value();
     if ($this->config()->default_to_locale && (!$value || !isset($source[$value])) && $this->locale()) {
         $locale = new Zend_Locale();
         $locale->setLocale($this->locale());
         $value = $locale->getRegion();
         $this->setValue($value);
     }
     // Default to default country otherwise
     if (!$value || !isset($source[$value])) {
         $this->setValue($this->config()->default_country);
     }
     return parent::Field($properties);
 }
 /**
  * Returns a readonly span containing the correct value.
  *
  * @param array $properties
  *
  * @return string
  */
 public function Field($properties = array())
 {
     $source = $this->getSource();
     // Normalize value to array to simplify further processing
     if (is_array($this->value) || is_object($this->value)) {
         $values = $this->value;
     } else {
         $values = array(trim($this->value));
     }
     $mapped = array();
     if ($source instanceof SQLMap) {
         foreach ($values as $value) {
             $mapped[] = $source->getItem($value);
         }
     } else {
         if ($source instanceof ArrayAccess || is_array($source)) {
             $source = ArrayLib::flatten($source);
             foreach ($values as $value) {
                 if (isset($source[$value])) {
                     $mapped[] = $source[$value];
                 }
             }
         } else {
             $mapped = array();
         }
     }
     // Don't check if string arguments are matching against the source,
     // as they might be generated HTML diff views instead of the actual values
     if ($this->value && !is_array($this->value) && !$mapped) {
         $mapped = array(trim($this->value));
         $values = array();
     }
     if ($mapped) {
         $attrValue = implode(', ', array_values($mapped));
         if (!$this->dontEscape) {
             $attrValue = Convert::raw2xml($attrValue);
         }
         $inputValue = implode(', ', array_values($values));
     } else {
         $attrValue = "<i>(none)</i>";
         $inputValue = '';
     }
     $properties = array_merge($properties, array('AttrValue' => $attrValue, 'InputValue' => $inputValue));
     return parent::Field($properties);
 }
    /**
     * @param array $parameters
     * @return string
     */
    public function Field($parameters = array())
    {
        $field = parent::Field($parameters);
        if ($this->autocomplete) {
            $this->addExtraClass("chosenAutocompleteField");
            $field = parent::Field($parameters);
            Requirements::css("dropdown2autocomplete/javascript/chosen/chosen.min.css");
            Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
            Requirements::javascript("dropdown2autocomplete/javascript/chosen/chosen.jquery.min.js");
            Requirements::customScript('
					jQuery("#' . $this->ID() . '").chosen(' . $this->Config()->get("js_settings") . ');
					jQuery("body").on(
						"focus",
						".chosenAutocompleteField:visible",
						function(){
							jQuery(this).chosen(' . $this->Config()->get("js_settings") . ');
						}
					);
				', $this->ID() . "_chosen_setup");
        }
        return $field;
    }
 /**
  * @todo This should be generated by JavaScript, but we don't have the date libraries'
  */
 function Field($properties = array())
 {
     $this->addExtraClass('timedropdownfield');
     $html = parent::Field($properties);
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript('framework/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript('timedropdownfield/javascript/TimeDropdownField.js');
     Requirements::css('timedropdownfield/css/TimeDropdownField.css');
     $iteratedTime = new Zend_Date('00:00:00', 'h:mm:ss');
     $options = array();
     $count = 24 * (60 / $this->config['interval']);
     for ($i = 0; $i < $count; $i++) {
         $key = $iteratedTime->toString($this->getConfig('datavalueformat'));
         $options[$key] = $iteratedTime->toString($this->getConfig('timeformat'));
         $iteratedTime->add($this->config['interval'], Zend_Date::MINUTE);
     }
     $dropdownField = new DropdownField('dropdown_' . $this->getName(), false, $options, $this->Value());
     $dropdownField->addExtraClass('presets');
     $dropdownField->setHasEmptyDefault(true);
     $dropdownField->setForm($this->getForm());
     $html .= $dropdownField->Field();
     $html .= '<a href="#" class="presets-trigger"></a>';
     return $html;
 }
	function Field() {
		ShowHideField::include_files();
		return parent::Field();
	}
 public function SiteTreeFilterPageTypeField()
 {
     $types = SiteTree::page_type_classes();
     array_unshift($types, 'All');
     $source = array_combine($types, $types);
     asort($source);
     $optionsetField = new DropdownField('ClassName', 'ClassName', $source, 'Any');
     return $optionsetField->Field();
 }
 /**
  * Adds the form fields for the batch actions
  * 
  * @param GridField $gridField GridField to get HTML fragments for
  * 
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     Requirements::css('silvercart/admin/css/SilvercartGridFieldBatchController.css');
     Requirements::javascript('silvercart/admin/javascript/SilvercartGridFieldBatchController.js');
     $source = array('' => 'Bitte wählen');
     $targetBatchActionObjects = $this->getTargetBatchActionObjects();
     foreach ($targetBatchActionObjects as $targetBatchAction => $targetBatchActionObject) {
         $source[$targetBatchAction] = $targetBatchActionObject->getTitle();
         $targetBatchActionObject->RequireJavascript();
     }
     $dropdown = new DropdownField($this->getDropdownName(), $this->getDropdownName(), $source);
     $dropdown->addExtraClass('grid-batch-action-selector');
     $button = new GridField_FormAction($gridField, 'execute_batch_action', _t('Silvercart.EXECUTE', 'Execute'), 'handleBatchAction', null);
     $button->setAttribute('data-icon', 'navigation');
     $button->addExtraClass('gridfield-button-batch');
     return array($this->targetFragment => '<div class="grid-batch-action-button"><div class="field dropdown plain">' . $dropdown->Field() . '</div><div class="grid-batch-action-callback-target"></div>' . $button->Field() . '</div>');
 }
예제 #19
0
    /**
     * Returns a <select> tag containing all the appropriate <option> tags and with add/useExisting link
     */
    function Field()
    {
        //Add these js file so that the DropdownField_WithAdd can work alone (in a webpage, rather than CMS).
        Requirements::javascript('jsparty/prototype.js');
        Requirements::javascript('jsparty/behaviour.js');
        Requirements::javascript('jsparty/prototype_improvements.js');
        Requirements::Javascript("sapphire/javascript/DropdownField_WithAdd.js");
        $dropdown = parent::Field();
        if ($this->addLink) {
            $addLink = <<<HTML
<a class="addlink link" id="{$this->name}_addLink" href="{$this->addLink}" style="display: inline; padding-left: 1em; text-decoration: underline;">{$this->addText}</a>
HTML;
        }
        if ($this->useExistingLink) {
            $useExistingLink = <<<HTML
<a class="useExistinglink link" id="{$this->name}_useExistingLink" href="{$this->useExistingLink}" style="display: none; padding-left: 1em; text-decoration: underline;">{$this->useExistingText}</a>
HTML;
        }
        if ($this->editLink) {
            $editLink = <<<HTML
<a class="editlink" id="{$this->name}_editLink" href="{$this->editLink}" style="display: inline; padding-left: 1em; text-decoration: underline;">edit</a>
HTML;
        }
        return $dropdown . $addLink . $useExistingLink . $editLink;
    }
 /**
  * Returns the HTML for the field
  * 
  * @param array $properties Properties
  *
  * @return string
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 25.06.2014
  */
 public function Field($properties = array())
 {
     Requirements::css('silvercart/admin/css/SilvercartMultiDropdownField.css');
     Requirements::javascript('silvercart/admin/javascript/SilvercartMultiDropdownField.js');
     return parent::Field($properties);
 }