public function __construct($title = null) { parent::__construct(uniqid('image_'), ' ', 1); $this->add_style('text-align', 'center'); $this->_title = $title ? $title : \ZPHP\String::get('image'); $this->_render_function = array($this, '_row_render_function'); }
protected function _get_input_html(array $params = array()) { $attrs_html = self::_get_attr_html($params); $input_html = "<{$this->_tagname}{$attrs_html}>"; if ($this->get_default_option_enabled()) { $option_text = $this->get_default_option_text() ? $this->get_default_option_text() : \ZPHP\String::get($this->get_optional() ? 'not_specified' : 'select'); $input_html .= "<option value='" . \ZPHP\HTMLHelper::escape($this->get_default_option_value()) . "'>" . \ZPHP\HTMLHelper::escape($option_text) . "</option>"; $input_html .= "<option value='" . \ZPHP\HTMLHelper::escape($this->get_default_option_value()) . "'></option>"; } foreach ($this->_options as $option) { $option_tag = new HTMLLongTag('option', \ZPHP\HTMLHelper::escape($option['label'])); $option_tag->set_param('value', \ZPHP\HTMLHelper::escape($option['value'])); if (!is_null($this->get_value()) && $option['value'] == $this->get_value()) { $option_tag->set_param('selected', true); } $input_html .= $option_tag; } $input_html .= "</{$this->_tagname}>"; return $input_html; }
public function __construct($name = null, $title = null, $value = null) { parent::__construct(self::$_TAGNAME, $name, $title, $value); $this->_params['type'] = self::$_TYPE; $this->add_class(self::$_CLASS); $this->get_container()->add_class(self::$_CONTAINER_CLASS); $this->set_clear_button(self::$_DEFAULT_CLEAR_BUTTON); $this->_date_mask = String::get('date_mask'); if (!$this->_date_mask) { $this->_date_mask = self::$_DEFAULT_DATE_MASK; } $this->_date_mask = self::_prepare_format($this->_date_mask); $this->_date_format = String::get('date_format'); if (!$this->_date_format) { $this->_date_format = self::$_DEFAULT_DATE_FORMAT; } $this->_date_format = self::_prepare_format($this->_date_format); if (self::$_DEFAULT_VALUE_NOW && !$value) { $this->set_value(Date::now()); } }
protected function _get_input_html(array $params = array()) { $title = $this->_get_title(); $attrs_html = self::_get_attr_html($params); $input_html = "<{$this->_tagname}{$attrs_html}>"; if ($this->get_default_option_enabled()) { $option_text = $this->get_default_option_text() ? $this->get_default_option_text() : \ZPHP\String::get($this->get_optional() ? 'not_specified' : 'select'); $input_html .= "<option value='" . \ZPHP\HTMLHelper::escape($this->get_default_option_value()) . "'>" . \ZPHP\HTMLHelper::escape($option_text) . "</option>"; $input_html .= "<option value='" . \ZPHP\HTMLHelper::escape($this->get_default_option_value()) . "'></option>"; } foreach ($this->_options as $option) { $option_tag = new HTMLLongTag('option', \ZPHP\HTMLHelper::escape($option['label'])); $option_tag->set_param('value', \ZPHP\HTMLHelper::escape($option['value'])); if (!is_null($this->get_value()) && $option['value'] == $this->get_value()) { $option_tag->set_param('selected', true); } $input_html .= $option_tag; } $input_html .= "</{$this->_tagname}>"; $js_id = \ZPHP\JSHelper::cast_str('#' . $this->_get_id()); $js_container_class = \ZPHP\JSHelper::cast_str(self::$_SELECT2_CONTAINER_CLASS); $js_searching = \ZPHP\String::get_js('searching'); $js_no_matches = \ZPHP\String::get_js('no_matches_found'); $js_placeholder = $this->_get_title(); if ((!array_key_exists('placeholder', $params) || !$params['placeholder']) && $this->get_use_title_label() && $title) { $js_placeholder = $title; } $js_placeholder = \ZPHP\JSHelper::cast_str($js_placeholder); $input_html .= "<script type='text/javascript'>\n\n\t\t\t\t//\$(document).ready(function () {\n\t\t\t\t\t\t\$({$js_id}).select2({\n\t\t\tcontainerCssClass: {$js_container_class},\n\t\t\tformatSearching: function() {\n\t\t\treturn {$js_searching};\n\t\t\t},\n\t\t\tformatNoMatches: function() {\n\t\t\treturn {$js_no_matches};\n\t\t\t},"; if ($this->get_width()) { $input_html .= "width: " . \ZPHP\JSHelper::cast_str($this->get_width()) . ","; } $input_html .= "dropdownAutoWidth: true,\n\t\t\tminimumResultsForSearch: -1,\n\t\t\tescapeMarkup: function(s) { return s; },\n\t\t\tplaceholder: {$js_placeholder}\n\t\t\t});"; /*$(<?=JSHelper::cast_str("#{$id}")?><!--).on('change', function() { --><?//=$tag_attrs['onchange']?><!-- });-->*/ // $input_html.= " }); "; $input_html .= "\n</script>"; return $input_html; }
protected function _get_input_html(array $params = array()) { $title = $this->_get_title(); $attrs_html = self::_get_attr_html($params); $html = "<{$this->_tagname}{$attrs_html} />"; if ($this->get_value()) { $delete_checkbox = new HTMLInputCheckboxControl($this->get_name() . '_delete', \ZPHP\String::get('delete')); $delete_checkbox->onclick = '$(' . JSHelper::cast_str('#' . $this->get_name() . '_image') . ').toggleClass("todelete", $(this).attr("checked"))'; $delete_checkbox->onclick = '$(this).parents(".input-image-container").find("img").toggleClass("todelete", $(this).attr("checked"))'; $html .= '<br />'; $html .= '<div class="input-image-container"> '; $html .= '<img src="' . HTMLHelper::escape($this->get_value()) . '" alt="Image" id="' . HTMLHelper::escape($this->get_name() . '_image') . '" class="' . HTMLHelper::escape(self::$_IMAGE_CLASS) . '" />'; $html .= $delete_checkbox->to_string(); $html .= '</div>'; $html .= '<br />'; } else { $delete_checkbox = new HTMLInputHiddenControl($this->get_name() . '_delete', ''); $html .= '<div class="input-image-container"> '; $html .= $delete_checkbox->to_string(); $html .= '</div>'; } return $html; }
protected function _format_replace_callback($match) { switch ($match['letter']) { case 'Y': return $this->get_year(); break; case 'y': return substr((string) $this->get_year(), 2); break; case 'm': return str_pad($this->get_month(), 2, '0', STR_PAD_LEFT); break; case 'd': return str_pad($this->get_day(), 2, '0', STR_PAD_LEFT); break; case 'H': return str_pad($this->get_hour(), 2, '0', STR_PAD_LEFT); break; case 'M': return str_pad($this->get_minutes(), 2, '0', STR_PAD_LEFT); break; case 'S': return str_pad($this->get_seconds(), 2, '0', STR_PAD_LEFT); break; case 'A': return $this->get_hour() >= 12 ? 'pm' : 'am'; break; case 'K': $hour = $this->get_hour(); if ($hour == 0) { $hour = 12; } else { if ($hour > 12) { $hour = $hour - 12; } } return str_pad($hour, 2, '0', STR_PAD_LEFT); break; case 'r': return mktime($this->get_hour(), $this->get_minutes(), $this->get_seconds(), $this->get_month(), $this->get_day(), $this->get_year()); break; case 'O': return self::get_month_name_long($this->get_month()); break; case 'o': return self::get_month_name_short($this->get_month()); break; case 'W': return $this->get_day_of_week(); break; case 'p': return self::get_day_name_short($this->get_day_of_week()); break; case 'P': return self::get_day_name_long($this->get_day_of_week()); break; case 'T': $days_diff = self::now()->diff_days($this); if (isset(self::$_days_diff_labels[$days_diff])) { $key = self::$_language_text_prefix . self::$_days_diff_labels[$days_diff]; return String::get($key); } else { return $this->format(self::get_default_format_date()); } break; default: return ''; break; } }
public function to_string() { $prepared_rows = array(); $prepared_columns = array(); $array_rows = array(); $has_checkbox_column = false; foreach ($this->_rows as $row) { $prepared_row = array(); foreach ($this->_columns as $column) { $prepared_row[] = $column->call_row_render_function($row, $this); } $prepared_rows[] = $prepared_row; $array_rows[$this->get_row_id($row)] = $row; } foreach ($this->_columns as $column) { $prepared_column = array(); $prepared_column['title'] = $column->call_header_render_function($this); $prepared_column['orderable'] = $column->get_orderable(); $prepared_column['class'] = trim($column->get_class()); $prepared_columns[] = $prepared_column; if (ClassHelper::is_instance_of($column, 'ZPHP\\HTML\\HTMLTableColumnCheckbox')) { $has_checkbox_column = true; } } $html = ''; if (empty($this->_rows)) { $html = '<div class="panel panel-default datatable-empty"> <div class="panel-body"> ' . $this->_empty_html . ' </div> </div>'; } else { $attrs_html = self::_get_attr_html($this->_params); $html = ' <div id="' . HTMLHelper::escape('div_container_' . $this->id) . '" class="datatable-container"> <table' . $attrs_html . '> <thead><tr>'; foreach ($this->_columns as $column) { $html .= $column; } $data_table_params = array(); $data_table_params['data'] = $prepared_rows; $data_table_params['columns'] = $prepared_columns; $data_table_params['paging'] = $this->_paging; $data_table_params['info'] = $this->_show_info; $data_table_params['ordering'] = $this->_ordering; $data_table_params['language'] = array(); $data_table_params['language']['search'] = \ZPHP\String::get('datatables_search'); $data_table_params['language']['lengthMenu'] = \ZPHP\String::get('datatables_length_menu'); $data_table_params['language']['zeroRecords'] = \ZPHP\String::get('datatables_zero_records'); $data_table_params['language']['info'] = \ZPHP\String::get('datatables_info'); $data_table_params['language']['infoEmpty'] = \ZPHP\String::get('datatables_info_empty'); $data_table_params['language']['infoFiltered'] = \ZPHP\String::get('datatables_info_filtered'); $data_table_params['language']['loadingRecords'] = \ZPHP\String::get('datatables_loading_records'); $data_table_params['language']['paginate'] = array(); $data_table_params['language']['paginate']['first'] = \ZPHP\String::get('datatables_first'); $data_table_params['language']['paginate']['last'] = \ZPHP\String::get('datatables_last'); $data_table_params['language']['paginate']['last'] = \ZPHP\String::get('datatables_last'); $data_table_params['language']['paginate']['next'] = \ZPHP\String::get('datatables_next'); $data_table_params['language']['paginate']['previous'] = \ZPHP\String::get('datatables_previous'); $html .= ' </tr></thead> <tbody></tbody> </table> </div> <script type="text/javascript"> (function() { var table = $(' . JSHelper::cast_str('#' . $this->id) . '); var dataTable = table.dataTable(' . JSHelper::cast_obj($data_table_params) . '); table.data("rowsData", ' . JSHelper::cast_obj($array_rows) . '); table.data("dataTable", dataTable); table.data("getRowData", function(id) { return table.data("rowsData")[id]; }); '; foreach ($this->_columns as $column) { $html .= $column->call_load_render_function($this); } if ($has_checkbox_column) { $html .= 'table.data("getCheckedRows", function(field) { var checkedInputs = table.find("tbody tr input.checkbox:checked"); var rowsData = []; checkedInputs.each(function(index, item) { var id = $(this).val(); var rowData = table.data("getRowData")(id); if(field) { rowData = rowData[field]; } rowsData.push(rowData); }); return rowsData; });'; } $html .= ' })();'; $html .= "\n\t\t\t\$(document).ready(function() {\n\t\t\t\tvar table = \$(" . JSHelper::cast_str('#' . $this->id) . ");\n\t\t\t\ttable.parent().css({'min-height': table.height()});\n\n\t\t\t\tvar selects = \$('.dataTables_length select');\n\n\t\t\t\tselects.each(function() {\n\n\t\t\t\t\tif(\$(this).children().length == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t\$(this).parents('.dataTables_length').css({'visibility': 'hidden'});\n\t\t\t\t\t}\n\n\t\t\t\t});\n\t\t\t});\n\n\t\t\t"; $html .= "</script>"; } return $html; }