protected function _get_input_html(array $params = array()) { $title = $this->_get_title(); if ((!array_key_exists('placeholder', $params) || !$params['placeholder']) && $this->get_use_title_label() && $title) { $params['placeholder'] = $title; } $attrs_html = self::_get_attr_html($params); $input_html = "<{$this->_tagname}{$attrs_html} />"; if ($this->_mask) { $input_html .= new HTMLScriptTag("\$(" . JSHelper::cast_str('#' . $this->get_id()) . ").mask(" . JSHelper::cast_str($this->_mask) . ", {placeholder: " . JSHelper::cast_str($this->_mask_placeholder) . "});"); } return $input_html; }
public function to_string() { $attrs_html = self::_get_attr_html($this->_params); $html = "<{$this->_tagname}{$attrs_html}>"; if ($this->_header) { $html .= "<div class='modal-header'>{$this->_header}</div>"; } $html .= "<div class='modal-body'>"; $html .= $this->_prepare_body(); $html .= "</div>"; if ($this->_footer || !empty($this->_buttons)) { $html .= "<div class='modal-footer'>"; $html .= $this->_footer; $html .= $this->_prepare_buttons(); $html .= "</div>"; } $html .= "</{$this->_tagname}>"; $html .= "<script type='text/javascript'>\n"; $html .= "\$(" . \ZPHP\JSHelper::cast_str('#' . $this->get_id()) . ").bindSubmitDialog(function(data) { {$this->_callback} });"; $html .= "</script>"; return "<div class='modal-dialog'>{$html}</div>"; }
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; }
/** * * @return HTMLTag * */ public function add_route_link_icon($title, $icon_class, $id_url, $row_field = null, $request_varname = null, $method = "get", $confirm = null) { if (!$row_field) { $row_field = self::ROW_ID_FIELD; } if (!$request_varname) { $request_varname = self::DEFAULT_REQUEST_VARNAME; } $route_args = array("{{row:{$row_field}}}"); $url = route($id_url, $route_args); $navigation_options = array(); $navigation_options['method'] = strtolower($method); $navigation_options['data'] = array('_token' => csrf_token(), $request_varname => "{{{row:{$row_field}}}}"); $call_js = \ZPHP\JSHelper::call_quote('Navigation.go', $url, $navigation_options); if ($confirm) { $call_js = \ZPHP\JSHelper::call('$.zmodal.confirm', \ZPHP\JSHelper::cast_str($confirm), "function() { {$call_js} }"); } return $this->add_action_link_icon($title, $icon_class, $call_js); }
protected function _get_input_html(array $params = array()) { if (isset($params['value'])) { unset($params['value']); } $title = $this->_get_title(); if ((!array_key_exists('placeholder', $params) || !$params['placeholder']) && $this->get_use_title_label() && $title) { $params['placeholder'] = $title; } if ($this->_date_value) { $params['value'] = $this->_date_value->format($this->_date_format); } $style = ''; if (isset($params['style'])) { $params['style'] = String::put_sufix($params['style'], ';') . $style; } else { $params['style'] = $style; } $params['style'] = "letter-spacing: 3px; {$params['style']}"; $attrs_html = self::_get_attr_html($params); $datepicker_options = array_merge(array(), self::$_DEFAULT_DATEPICKER_OPTIONS); $datepicker_options['format'] = self::_datepicker_format($this->_date_format); $datepicker_options['clearBtn'] = $this->_clear_button; if ($this->_before_show_day) { $datepicker_options[JSHelper::get_avoid_cast_key('beforeShowDay')] = $this->_before_show_day; } if ($this->_before_show_month) { $datepicker_options[JSHelper::get_avoid_cast_key('beforeShowMonth')] = $this->_before_show_month; } if ($this->_start_date) { $datepicker_options['startDate'] = $this->_start_date->format(self::$_START_DATE_FORMAT); } if ($this->_end_date) { $datepicker_options['endDate'] = $this->_end_date->format(self::$_END_DATE_FORMAT); } $datepicker_options['language'] = 'es'; $html = "<{$this->_tagname}{$attrs_html} />"; $html .= new HTMLScriptTag("\$(" . JSHelper::cast_str('#' . $this->_get_id()) . ").datepicker(" . JSHelper::cast_obj($datepicker_options) . ");"); $html .= new HTMLScriptTag("\$(" . JSHelper::cast_str('#' . $this->_get_id()) . ").mask(" . JSHelper::cast_str($this->_date_mask) . ");"); return $html; }
protected function _get_input_html(array $params = array()) { $html = parent::_get_input_html($params); $html .= new HTMLScriptTag("\$(" . JSHelper::cast_str('#' . $this->_get_id()) . ").bind('change', function() { \$(this).val(String(\$(this).val()).replace(/[^\\d\\.\\-\\,]/g, '')); });"); return $html; }
protected function _get_input_html(array $params = array()) { $title = $this->_get_title(); if ((!array_key_exists('placeholder', $params) || !$params['placeholder']) && $this->get_use_title_label() && $title) { $params['placeholder'] = $title; } $value = null; if (array_key_exists('value', $params)) { $value = self::parse_autocomplete_option($params['value']); if (!$value) { $value = array('id' => $params['value'], 'text' => ''); } $params['value'] = $value['id']; } $attrs_html = self::_get_attr_html($params); $input_html = "<{$this->_tagname}{$attrs_html} />"; $js_id = \ZPHP\JSHelper::cast_str('#' . $this->_get_id()); $js_searching = \ZPHP\String::get_js('searching'); $js_no_matches = \ZPHP\String::get_js('no_matches_found'); $js_url = \ZPHP\JSHelper::cast_str($this->_request_url); $js_search_varname = \ZPHP\JSHelper::cast_str($this->_search_varname); $js_min_length = \ZPHP\JSHelper::cast_number($this->_min_length); $js_data = \ZPHP\JSHelper::cast_obj($this->_request_data); $js_method = \ZPHP\JSHelper::cast_str($this->_request_method); $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); $js_window_id = \ZPHP\JSHelper::cast_str('#s2id_' . $this->_get_id()); $html = "{$input_html}\n"; $html .= "<script type='text/javascript'>\n"; $html .= "if(!window[{$js_window_id}]) {\n\n\t\t\$({$js_id}).select2({formatSearching: function() {\n\t\t\treturn {$js_searching};\n\t\t\t},\n\t\t\tallowClear: " . JSHelper::cast_bool($this->_allow_clear) . ",\n\t\t\tformatNoMatches: function() {\n\t\t\treturn {$js_no_matches};\n\t\t\t},formatInputTooShort: function() {\n\t\t\t\treturn '';\n\t\t\t},\n\t\t\tescapeMarkup: function(s) { return s; },\n\t\t\tminimumInputLength: {$js_min_length},"; if ($this->get_width()) { $html .= "width: " . \ZPHP\JSHelper::cast_str($this->get_width()) . ","; } $html .= "multiple: false,"; if ($this->get_value()) { $html .= "placeholder: {$js_placeholder},"; } $html .= "ajax: {\n\t\t\turl: {$js_url},\n\t\t\tdataType: 'json',\n\t\t\tdata: function(term, page)\n\t\t\t{\n\t\t\t\treturn \$.extend({}, { {$js_search_varname}: term}, {$js_data});\n\t\t\t},\n\t\t\tresults: function(data, page)\n\t\t\t{\n\t\t\t\treturn {results: data['rows']};\n\t\t\t}\n\t\t\t}\n\t\t"; if ($value && is_array($value) && isset($value['id'])) { if (isset($value['text']) && $value['text']) { $html .= ", initSelection : function (element, callback) {\n\t\t\t\t\telement.val(" . \ZPHP\JSHelper::cast_str($value['id']) . ");\n\t\t\t\t\tcallback(" . \ZPHP\JSHelper::cast_obj($value) . ");\n\t\t\t\t}"; } else { $html .= ", initSelection : function (element, callback) {\n\n\t\t\t\t\tvar ajaxData = {};\n\t\t\t\t\tajaxData[" . JSHelper::cast_str($this->_id_varname) . "] = " . JSHelper::cast_str($value['id']) . ";\n\n\t\t\t\t\t\$.ajax({\n\t\t\t\t\t\turl: {$js_url},\n\t\t\t\t\t\tdataType: 'json',\n\t\t\t\t\t\ttype: " . JSHelper::cast_str($this->_request_method) . ",\n\t\t\t\t\t\tdata: ajaxData,\n\t\t\t\t\t\tsuccess: function(data)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tvar row = null;\n\n\t\t\t\t\t\t\tif(data)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif(data['row'])\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\trow = data['row'];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if(data['rows'])\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\trow = data['rows'][0];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif(row)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\telement.val(row['id']);\n\t\t\t\t\t\t\t\tcallback(row);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}"; } } $html .= "});"; $html .= "window[{$js_window_id}] = true; }"; $html .= "\n</script>"; return $html; }
public function call_js_checked_rows_function($field = null) { return $this->get_js_checked_rows_function() . '(' . JSHelper::cast($field) . ')'; }
public static function page_entities() { $block = new HTML\HTMLLongTag('div'); $form = new HTML\HTMLForm(); $block->add_content($form); $form->set_id('tables-form'); $form->action = ''; $form->method = 'post'; $form->add_content('<style type="text/css">#tables-form legend {font-weight: bold; border-bottom: solid 1px #333; } #tables-form div.table { border-bottom: solid 1px #CCC; padding: 0 0 20px 0; } #tables-form div.table input.text{ border: solid 1px #999; padding: 4px 3px; }</style>'); $form->add_content('<style type="text/css">#tables-form .action .row { padding: 10px 20px; } </style>'); $form->add_content('<style type="text/css">#tables-form .form-buttons { padding: 30px 0px; margin: 30px 0 0 0; border-top: solid 1px #444; text-align: right; background: #DDD; } #tables-form .form-buttons button { margin: 0 40px 0 0; padding: 5px 30px; border: solid 1px #999;} </style>'); $tables = \DB::select(\DB::raw('SHOW TABLES')); $form->open_fieldset('tables'); $legend_buttons = new HTML\HTMLLongTag('div'); $legend_buttons->add_style('float', 'right'); $legend_buttons->add_style('font-size', '10pt'); $check_all_button = new HTML\HTMLLongTag('a'); $check_all_button->set_content('Check All'); $check_all_button->href = 'javascript:void(0)'; $check_all_button->onclick = "\$('.tables .checkbox').not(':checked').click()"; $legend_buttons->add_content($check_all_button); $legend_buttons->add_content(' / '); $check_all_button = new HTML\HTMLLongTag('a'); $check_all_button->set_content('Uncheck All'); $check_all_button->href = 'javascript:void(0)'; $check_all_button->onclick = "\$('.tables .checkbox').filter(':checked').click()"; $legend_buttons->add_content($check_all_button); $form->add_legend('Tables' . $legend_buttons); foreach ($tables as $table) { $table_name = ''; foreach ($table as $str) { $table_name = $str; break; } if (!in_array($table_name, self::$_PROTECTED_TABLES)) { $table_paths = self::_get_table_paths($table_name); $table_entity_name = $table_paths['entity']['name']; $table_repository_name = $table_paths['repository']['name']; $table_repository_database_name = $table_paths['repository_database']['name']; $entities_dir = self::_get_entities_dir(); $dir = opendir($entities_dir); while ($phppath = readdir($dir)) { if ($phppath != '.' && $phppath != '..') { $phppath = $entities_dir . DIRECTORY_SEPARATOR . $phppath; $phpcontents = file_get_contents($phppath); if (preg_match('#(?i)protected\\s+\\$table\\s+\\=\\s+(\'|")(?P<table>.+?)(\'|\\")#', $phpcontents, $match)) { if ($match['table'] == $table_name) { if (preg_match('#(?i)class\\s+(?P<classname>.+?)\\s+#', $phpcontents, $match)) { $table_entity_name = $match['classname']; break; } } } } } closedir($dir); $repositories_dir = self::_get_repositories_dir(); $dir = opendir($repositories_dir); while ($phppath = readdir($dir)) { if ($phppath != '.' && $phppath != '..') { $phppath = $repositories_dir . DIRECTORY_SEPARATOR . $phppath; $phpcontents = file_get_contents($phppath); if (preg_match('#(?i)const\\s+TABLE_NAME\\s+\\=\\s+(\'|")(?P<table>.+?)(\'|\\")#', $phpcontents, $match)) { if ($match['table'] == $table_name) { if (preg_match('#(?i)interface\\s+(?P<classname>.+?)\\s+#', $phpcontents, $match)) { $table_repository_name = $match['classname']; break; } } } } } closedir($dir); $repositories_database_dir = self::_get_repositories_database_dir(); $dir = opendir($repositories_database_dir); while ($phppath = readdir($dir)) { if ($phppath != '.' && $phppath != '..') { $phppath = $repositories_database_dir . DIRECTORY_SEPARATOR . $phppath; $phpcontents = file_get_contents($phppath); if (preg_match('#(?i)class\\s+(?P<classname>.+?)\\s+extends\\s+.*?\\s+implements\\s+.*?\\\\' . preg_quote($table_repository_name) . '#', $phpcontents, $match)) { $table_repository_database_name = $match['classname']; break; } } } closedir($dir); $form->open_row('table'); $checkbox = new HTML\HTMLInputCheckboxControl('tables[' . $table_name . ']', $table_name); $checkbox->get_label()->add_style('display', 'inline')->add_style('margin', '-3px 0 5px 10px')->add_style('vertical-align', 'top')->add_style('cursor', 'pointer'); $checkbox->add_style('display', 'inline'); $checkbox->onclick = "\$(" . JSHelper::cast_str('.table-' . $table_name) . ").attr({'disabled':!\$(this).is(':checked')});"; $form->open_col_md(3); $form->add_content($checkbox); $text = new HTML\HTMLInputTextControl('tables[' . $table_name . '][entity]', $table_name, $table_entity_name); $text->set_show_label(false); $text->add_style('width', '100%'); $text->add_class('table-' . $table_name); $text->disabled = true; $form->open_col_md(3); $form->add_content($text); $text = new HTML\HTMLInputTextControl('tables[' . $table_name . '][repository]', $table_name, $table_repository_name); $text->set_show_label(false); $text->add_style('width', '100%'); $text->add_class('table-' . $table_name); $text->disabled = true; $form->open_col_md(3); $form->add_content($text); $text = new HTML\HTMLInputTextControl('tables[' . $table_name . '][repository_database]', $table_name, $table_repository_database_name); $text->set_show_label(false); $text->add_style('width', '100%'); $text->add_class('table-' . $table_name); $text->disabled = true; $form->open_col_md(3); $form->add_content($text); $form->close_row(); } } $form->open_fieldset('action'); $form->add_legend('Action'); $form->open_row(); $checkbox = new HTML\HTMLInputRadioControl('action', 'Create Entities & Servicies', 'create'); $checkbox->get_label()->add_style('display', 'inline')->add_style('margin', '-3px 0 5px 10px')->add_style('vertical-align', 'top')->add_style('cursor', 'pointer'); $checkbox->add_style('display', 'inline'); $checkbox->set_checked(true); $form->add_content($checkbox); $form->open_row(); $checkbox = new HTML\HTMLInputRadioControl('action', 'Delete Tables', 'delete'); $checkbox->get_label()->add_style('display', 'inline')->add_style('margin', '-3px 0 5px 10px')->add_style('vertical-align', 'top')->add_style('cursor', 'pointer'); $checkbox->add_style('display', 'inline'); $form->add_content($checkbox); $form->add_submit_cancel_buttons(); $form->set_cancel_action('location.href = "' . \URL::route(self::URL_INDEX) . '";'); return self::_prepare_page_html($block, 'Database Tables', \URL::route(self::URL_INDEX)); }