public static function ui( MEOW_Field $field ) { // $field here is a MEOW_Field, which is a class that encapsulates the value of a field AND the info associated with it $options = $field->info->type_options; $select_none_label = __("Select None", MASTERPRESS_DOMAIN); $select_all_label = __("Select All", MASTERPRESS_DOMAIN); $disabled = WOOF_HTML::disabled_attr(!$field->is_editable()); $field_value = $field->value(); if (!is_array($field_value)) { $field_value = array(); } $selected_values = $field_value; $values = WOOF_HTML::option_values($options["values"]); self::$values_keys = array(); if (!$field->blank()) { // populate the values $selected_values = array(); foreach ($values as $key => $value) { if (in_array($value, $field_value)) { self::$values_keys[] = $key; // cache the keys for the summary, so we don't have to look them up again! $selected_values[] = $value; } } } $hidden = ""; $buttons = ""; $checkbox_name = "{{name}}[]"; $checkbox_id = "{{id}}"; if (!$field->is_editable()) { $hidden_name = $checkbox_name; $hidden_id = $checkbox_id; $checkbox_name = "display_".$checkbox_name; $checkbox_id = "display_".$checkbox_id; foreach ($selected_values as $value) { $hidden .= '<input id="'.$hidden_id.'" name="'.$hidden_name.'" value="'.$value.'" type="hidden" />'; } } else { $buttons = <<<HTML <div class="buttons"> <button type="button" class="button button-small check-all">{$select_all_label}</button> <button type="button" class="button button-small uncheck-all">{$select_none_label}</button> </div> HTML; } $checkboxes = WOOF_HTML::input_checkbox_group( "{{name}}[]", "{{id}}", $values, $selected_values, WOOF_HTML::open("div", "class=fwi"), WOOF_HTML::close("div"), !$field->is_editable()); $html = <<<HTML <div class="f"> <div class="fw"> {$checkboxes} {$hidden} </div> {$buttons} </div> HTML; return $html; }
function text() { if (!isset($this->_tv)) { $options = $this->field()->info->type_options; if (isset($options, $options["values"])) { $this->_tv = WOOF_HTML::option_values($options["values"]); if (is_array($this->_tv)) { $this->_vt = array_flip($this->_tv); } else { $this->_tv = array(); $this->_vt = array(); } } else { $this->_tv = array(); $this->_vt = array(); } } $val = $this->value(); if (isset($this->_vt[$val])) { return $this->_vt[$val]; } return ""; }
public static function ui( MEOW_Field $field ) { $options = $field->info->type_options; $maxwidth = ""; $height = ""; $maxwidth = self::option_value($options, "maxwidth"); if (isset($options["height"])) { $height = $options["height"]; } if (is_numeric($maxwidth)) { $maxwidth = "{$maxwidth}px"; } else { $maxwidth = "580px"; } if (is_numeric($height)) { $height = "{$height}px"; } else { $height = "160px"; } $size = ""; $select_attr = array( "id" => "{{id}}", "name" => "{{name}}", "size" => "2", "style" => "max-width: {$maxwidth}; height: {$height};" ); $allow_multiple = $options["allow_multiple"] == "yes"; if ($allow_multiple) { $select_attr["multiple"] = "multiple"; $select_attr["name"] = "{{name}}[]"; $select_attr["data-placeholder"] = self::option_value($options, "placeholder", "-- Select an item --"); } $select_none_label = __("Select None", MASTERPRESS_DOMAIN); $select_all_label = __("Select All", MASTERPRESS_DOMAIN); $values = WOOF_HTML::option_values($field->info->options("values"), "", true); $field_values = $field->values(); $selected_values = $field_values; if (!is_array($field_values)) { $field_values = explode(",", $field_values); } self::$values_keys = array(); if (!$field->blank()) { // populate the values $selected_values = array(); foreach ($values as $key => $value) { if ($allow_multiple) { if (is_array($value)) { foreach ($value as $sub_key => $sub_value) { if (in_array($sub_value, $field_values)) { self::$values_keys[] = $sub_key; // cache the keys for the summary, so we don't have to look them up again! $selected_values[] = $sub_value; } } } else { if (in_array($value, $field_values)) { self::$values_keys[] = $key; // cache the keys for the summary, so we don't have to look them up again! $selected_values[] = $value; } } } else { if (is_array($value)) { foreach ($value as $sub_key => $sub_value) { if ($sub_value == $field_values) { self::$values_keys[] = $sub_key; // cache the keys for the summary, so we don't have to look them up again! $selected_values[] = $sub_value; } } } else { if ($value == $field_values) { self::$values_keys[] = $key; // cache the keys for the summary, so we don't have to look them up again! $selected_values = $value; } } } } } if (!$field->is_editable()) { $select_attr["disabled"] = "disabled"; $select_attr["data-placeholder"] = __("-- None Selected --", MASTERPRESS_DOMAIN); } $basic = self::option_value($options, "basic") == "yes"; $val = implode(",", $field_values); $select_attr["data-value-input"] = "{{id}}-value-input"; $input = '<input type="hidden" id="{{id}}-value-input" name="{{name}}" type="hidden" value="'.$val.'" class="select2-hidden" />'; if (!$basic) { // ensure the select control does not affect the values posted, the hidden input is responsible for this $select_attr["name"] = "src_".$select_attr["name"]; } $select = WOOF_HTML::select( $select_attr, $values, $selected_values ); $buttons = ""; if ($allow_multiple) { if (isset($options["buttons"])) { if (in_array("select_all", $options["buttons"])) { $buttons .= '<button type="button" class="button button-small select-all">'.$select_all_label.'</button>'; } if (in_array("select_none", $options["buttons"])) { $buttons .= '<button type="button" class="button button-small select-none">'.$select_none_label.'</button>'; } } } $html = "$input $select"; return $html; }