public static function render($form_id, $table_class) { static $include_script; if (!isset($include_script)) { $include_script = false; echo \OLOG\Preloader::preloaderJsHtml(); ?> <script> var CRUD = CRUD || {}; CRUD.CreateForm = CRUD.CreateForm || { init: function (form_elem, table_elem) { var $form = $(form_elem); $form.on('submit', function (e) { e.preventDefault(); var url = $form.attr('action'); var data = $form.serializeArray(); CRUD.CreateForm.requestAjax(table_elem, url, data); }); }, requestAjax: function (table_elem, query, data) { OLOG.preloader.show(); $.ajax({ type: "POST", url: query, data: data }).success(function (received_html) { OLOG.preloader.hide(); var $box = $('<div>', {html: received_html}); $(table_elem).html($box.find(table_elem).html()); }).fail(function () { OLOG.preloader.hide(); }); } }; </script> <?php } ?> <script> CRUD.CreateForm.init('#<?php echo $form_id; ?> ', '.<?php echo $table_class; ?> '); </script> <?php }
public static function render($table_class, $query_url) { static $include_script; if (!isset($include_script)) { $include_script = false; echo \OLOG\Preloader::preloaderJsHtml(); ?> <script> var CRUD = CRUD || {}; CRUD.Table = CRUD.Table || { init: function (table_class, query_url) { CRUD.Table.clickTableRow(table_class); CRUD.Table.filterAjaxLoad(table_class, query_url); CRUD.Table.paginationAjaxLoad(table_class, query_url); }, clickTableRow: function (table_class) { var table_elem_selector = '.' + table_class + ' .table'; $(table_elem_selector).each(function () { $(this).find("tbody tr").each(function () { var $tr = $(this); // Проверка на наличие ссылки if ($tr.find("a").length == 0) { return false; } // Проверка на наличие только одной ссылки if ($tr.find("a").length > 1) { return false; } var $link = $tr.find("a:first"); var url = $link.attr("href"); var link_style = "z-index: 1;position: absolute;top: 0;bottom: 0;left: 0;right: 0;display: block;"; $tr.find("td").each(function () { var $td = $(this).css({"position":"relative"}); var $childrenTag = $td.find(">*"); if ($childrenTag[0] && $childrenTag[0].tagName == "FORM") { return false; } $td.prepend('<a href="' + url + '" style="' + link_style + '"></a>'); }); }); }); }, filterAjaxLoad: function (table_class, query_url) { var filter_elem_selector = '.' + table_class + ' .filters-form'; var pagination_elem_selector = '.' + table_class + ' .pagination'; $(filter_elem_selector).on('submit', function (e) { e.preventDefault(); e.stopPropagation(); // for a case when filters form is within another form (model creation form for example) var params = $(this).serialize(); $(this).data('params', params); var filters = $(this).data('params') || ''; var pagination = $(pagination_elem_selector).data('params') || ''; var query = query_url + '?' + filters + '&' + pagination; CRUD.Table.requestAjax(table_class, query); }); }, paginationAjaxLoad: function (table_class, query_url) { var filter_elem_selector = '.' + table_class + ' .filters-form'; var pagination_elem_selector = '.' + table_class + ' .pagination'; $(pagination_elem_selector).on('click', 'a', function (e) { e.preventDefault(); if ($(this).attr('href') == "#") { return false; } var params = $(this).attr('href').split('?')[1]; $(this).data('params', params); var filters = $(filter_elem_selector).data('params') || ''; var pagination = $(this).data('params') || ''; var query = query_url + '?' + filters + '&' + pagination; CRUD.Table.requestAjax(table_class, query); }); }, requestAjax: function (table_class, query) { var table_elem_selector = '.' + table_class + ' .table'; var pagination_elem_selector = '.' + table_class + ' .pagination'; OLOG.preloader.show(); $.ajax({ url: query }).success(function (received_html) { OLOG.preloader.hide(); var $box = $('<div>', {html: received_html}); $(table_elem_selector).html($box.find(table_elem_selector).html()); $(pagination_elem_selector).html($box.find(pagination_elem_selector).html()); CRUD.Table.clickTableRow(table_class); }).fail(function () { OLOG.preloader.hide(); }); } }; </script> <?php } ?> <script> CRUD.Table.init('<?php echo $table_class; ?> ', '<?php echo $query_url; ?> '); </script> <?php }
public static function render($form_id) { static $include_script; if (!isset($include_script)) { $include_script = false; echo \OLOG\Preloader::preloaderJsHtml(); ?> <style> .required-class {border: 1px solid red;} .required-class[type="radio"]:before {font-size: 1em;content: '*';color: red;} </style> <script> var CRUD = CRUD || {}; CRUD.Form = CRUD.Form || { init: function (form_id) { var $form = $('#' + form_id); CRUD.Form.required(form_id); $form.find('[type="submit"]').on('click', function (e) { if (CRUD.Form.validator(form_id) == true) { } else { e.preventDefault(); CRUD.Form.errors(CRUD.Form.validator(form_id)); } }); }, required: function (form_id) { var $form = $('#' + form_id); var required_class = 'required-class'; $form.find('[required]').each(function () { var $this = $(this); var $field = ($this.data('field')) ? $('#' + $this.data('field')) : $this; $this.on('change keyup blur', function () { if (CRUD.Form.validator(form_id, $this) == true) { if ($this.attr('type') != 'radio') { $field.removeClass(required_class); } else { var radio_name = $this.attr('name'); $form.find('[name="' + radio_name + '"]').removeClass(required_class); } } else { if ($this.attr('type') != 'radio') { $field.addClass(required_class); } else { var radio_name = $this.attr('name'); $form.find('[name="' + radio_name + '"]').addClass(required_class); } } }).trigger('change'); }); }, validator: function (form_id, $required_elem) { var $form = $('#' + form_id); var $required = $required_elem || '[required]'; var errors = []; $form.find($required).each(function () { var $this = $(this); if ($this.attr('type') != 'radio') { if ($this.val() == '') { errors.push($this.attr('name')); } } else { var radio_name = $this.attr('name'); if ($form.find('[name="' + radio_name + '"]:checked').length == 0) { if ($.inArray($this.attr('name'), errors) < 0) { errors.push($this.attr('name')); } } } }); if (errors.length == 0) { return true; } else { return errors; } }, errors: function (errors) { alert('Нужно заполнить поля:\n - ' + errors.join('\n - ')); } }; </script> <?php } ?> <script> CRUD.Form.init('<?php echo $form_id; ?> '); </script> <?php }
public function htmlForValue($field_value, $input_name = null) { $field_name = $this->getFieldName(); if (is_null($input_name)) { $input_name = $field_name; } $referenced_class_name = $this->getReferencedClassName(); $referenced_class_title_field = $this->getReferencedClassTitleField(); $referenced_obj_title = ''; $disabled_btn_link = 'disabled'; $is_null_value = ''; if (is_null($field_value)) { $is_null_value = "1"; } if (!is_null($field_value)) { $referenced_obj = CRUDObjectLoader::createAndLoadObject($referenced_class_name, $field_value); $referenced_obj_title = CRUDFieldsAccess::getObjectFieldValue($referenced_obj, $referenced_class_title_field); $disabled_btn_link = ''; } $is_required_str = ''; if ($this->is_required) { $is_required_str = ' required '; } $html = ''; $html .= Preloader::preloaderJsHtml(); $select_element_id = 'js_select_' . rand(1, 999999); $choose_form_element_id = 'collapse_' . rand(1, 999999); $html .= '<input type="hidden" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '" name="' . Sanitize::sanitizeAttrValue($input_name) . '" value="' . $field_value . '" data-field="' . Sanitize::sanitizeAttrValue($select_element_id) . '_text" ' . $is_required_str . '/>'; $html .= '<input type="hidden" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_is_null" name="' . Sanitize::sanitizeAttrValue($input_name) . '___is_null" value="' . $is_null_value . '"/>'; $html .= '<div class="input-group">'; if ($this->getAjaxActionUrl()) { $html .= '<span class="input-group-btn">'; $html .= '<button type="button" class="btn btn-default" data-toggle="modal" data-target="#' . $choose_form_element_id . '"><span class="glyphicon glyphicon-folder-open"></span></button>'; $html .= '<button type="button" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_btn_is_null" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></button>'; $html .= '</span>'; } $html .= '<div class="form-control" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_text">' . $referenced_obj_title . '</div>'; if ($this->getEditorUrl()) { $html .= '<span class="input-group-btn">'; $html .= '<button ' . $disabled_btn_link . ' type="button" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_btn_link" class="btn btn-default">Перейти</button>'; $html .= '</span>'; } $html .= '</div>'; $html .= BT::modal($choose_form_element_id, 'Выбрать'); ob_start(); ?> <script> $('#<?php echo $choose_form_element_id; ?> ').on('hidden.bs.modal', function () { $('#<?php echo $choose_form_element_id; ?> .modal-body').html(''); }); $('#<?php echo $choose_form_element_id; ?> ').on('shown.bs.modal', function (e) { OLOG.preloader.show(); $.ajax({ url: "<?php echo $this->getAjaxActionUrl(); ?> " }).success(function(received_html) { $('#<?php echo $choose_form_element_id; ?> .modal-body').html(received_html); OLOG.preloader.hide(); }); }); $('#<?php echo $choose_form_element_id; ?> ').on('click', '.js-ajax-form-select', function (e) { e.preventDefault(); var select_id = $(this).data('id'); var select_title = $(this).data('title'); $('#<?php echo $choose_form_element_id; ?> ').modal('hide'); $('#<?php echo $select_element_id; ?> _text').text(select_title); $('#<?php echo $select_element_id; ?> _btn_link').attr('disabled', false); $('#<?php echo $select_element_id; ?> ').val(select_id).trigger('change'); $('#<?php echo $select_element_id; ?> _is_null').val(''); }); $('#<?php echo $select_element_id; ?> _btn_is_null').on('click', function (e) { e.preventDefault(); $('#<?php echo $select_element_id; ?> _text').text(''); $('#<?php echo $select_element_id; ?> _btn_link').attr('disabled', true); $('#<?php echo $select_element_id; ?> ').val('').trigger('change'); $('#<?php echo $select_element_id; ?> _is_null').val(1); }); $('#<?php echo $select_element_id; ?> _btn_link').on('click', function (e) { var url = '<?php echo $this->getEditorUrl(); ?> '; var id = $('#<?php echo $select_element_id; ?> ').val(); url = url.replace('REFERENCED_ID', id); window.location = url; }); </script> <?php $html .= ob_get_clean(); return $html; }