Example #1
0
 public static function getObjId($obj)
 {
     Assert::assert($obj);
     $obj_class_name = get_class($obj);
     $obj_id_field_name = CRUDFieldsAccess::getIdFieldName($obj_class_name);
     return CRUDFieldsAccess::getObjectFieldValue($obj, $obj_id_field_name);
 }
 public function html($obj)
 {
     $field_name = $this->getFieldName();
     $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
     $is_required_str = '';
     if ($this->is_required) {
         $is_required_str = ' required ';
     }
     $disabled = '';
     if ($this->getDisabled()) {
         $disabled = 'disabled';
     }
     return '<textarea name="' . Sanitize::sanitizeAttrValue($field_name) . '"  ' . $is_required_str . ' class="form-control" rows="5"  ' . $disabled . '>' . Sanitize::sanitizeTagContent($field_value) . '</textarea>';
 }
 public function html($obj)
 {
     Assert::assert($obj);
     $title_field_name = $this->getTitleFieldName();
     $obj_title = CRUDFieldsAccess::getObjectFieldValue($obj, $title_field_name);
     $id_field_name = $this->getIdFieldName();
     if ($id_field_name == '') {
         $id = CRUDFieldsAccess::getObjId($obj);
     } else {
         $id = CRUDFieldsAccess::getObjectFieldValue($obj, $id_field_name);
     }
     $o = '';
     $o .= '<button class="btn btn-xs btn-default js-ajax-form-select" type="submit" data-id="' . Sanitize::sanitizeAttrValue($id) . '" data-title="' . Sanitize::sanitizeAttrValue($obj_title) . '">Выбор</button>';
     return $o;
 }
Example #4
0
 public function html($obj)
 {
     Assert::assert($obj);
     $o = '';
     $o .= '<form style="display: inline;" method="post" action="' . \OLOG\Url::getCurrentUrl() . '">';
     $o .= Operations::operationCodeHiddenField(CRUDTable::OPERATION_DELETE_MODEL);
     $o .= '<input type="hidden" name="' . self::FIELD_CLASS_NAME . '" value="' . Sanitize::sanitizeAttrValue(get_class($obj)) . '">';
     $o .= '<input type="hidden" name="' . self::FIELD_OBJECT_ID . '" value="' . Sanitize::sanitizeAttrValue(CRUDFieldsAccess::getObjId($obj)) . '">';
     if ($this->redirect_after_delete_url != '') {
         $o .= '<input type="hidden" name="' . self::FIELD_REDIRECT_AFTER_DELETE_URL . '" value="' . Sanitize::sanitizeAttrValue($this->redirect_after_delete_url) . '">';
     }
     $o .= '<button class="' . $this->button_class_str . '" type="submit" onclick="return window.confirm(\'Delete?\');">' . $this->button_text . '</button>';
     $o .= '</form>';
     return $o;
 }
Example #5
0
 public static function getReplacement($obj, $obj_field_name)
 {
     \OLOG\Assert::assert($obj);
     $matches = [];
     if (preg_match('@^(\\w+)\\(\\)$@', $obj_field_name, $matches)) {
         // имя поля заканчивается скобками - значит это имя метода
         $method_name = $matches[1];
         Assert::assert(method_exists($obj, $method_name));
         $replacement = call_user_func([$obj, $method_name]);
     } else {
         $replacement = CRUDFieldsAccess::getObjectFieldValue($obj, $obj_field_name);
     }
     if (is_null($replacement)) {
         $replacement = self::NULL_STRING;
     }
     return $replacement;
 }
    public function html($obj)
    {
        static $CRUDFormWidgetMediumEditor_include_script;
        $field_name = $this->getFieldName();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        /* Нужно изменить на нах CDN */
        $script = '';
        $uniqid = $this->getUniqid();
        if (!isset($CRUDFormWidgetMediumEditor_include_script)) {
            $script = '
				<script src="//cdnjs.cloudflare.com/ajax/libs/medium-editor/5.22.0/js/medium-editor.min.js"></script>
				<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/medium-editor/5.22.0/css/medium-editor.min.css" type="text/css" media="screen" charset="utf-8">
				<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/medium-editor/5.22.0/css/themes/default.min.css" type="text/css" media="screen" charset="utf-8">			';
            $CRUDFormWidgetMediumEditor_include_script = false;
        }
        $html = '';
        $html .= '<textarea id="' . $uniqid . '_textarea" name="' . Sanitize::sanitizeAttrValue($field_name) . '" style="display: none;">' . $field_value . '</textarea>';
        $html .= '<div id="' . $uniqid . '" class="form-control" style="height: auto;">' . $field_value . '</div>';
        ob_start();
        ?>
			<script>
				var <?php 
        echo $uniqid;
        ?>
 = new MediumEditor("#<?php 
        echo $uniqid;
        ?>
", {
					placeholder: false
				});

                <?php 
        echo $uniqid;
        ?>
.subscribe('editableInput', function (event, editable) {
					var content = $(editable).html();
					$('#<?php 
        echo $uniqid;
        ?>
_textarea').val(content).trigger('MediumEditor.change');
				});
			</script>
		<?php 
        $html .= ob_get_clean();
        return $script . $html;
    }
Example #7
0
 /**
  * @param $obj InterfaceWeight
  * @return string
  */
 public function html($obj)
 {
     Assert::assert($obj);
     $o = '';
     $o .= '<form style="display: inline;" method="post" action="' . \OLOG\Url::getCurrentUrl() . '">';
     $o .= Operations::operationCodeHiddenField(CRUDTable::OPERATION_SWAP_MODEL_WEIGHT);
     $o .= '<input type="hidden" name="' . self::FORMFIELD_CONTEXT_FIELDS_NAME . '" value="' . Sanitize::sanitizeAttrValue(implode(',', array_keys($this->context_fields_arr))) . '">';
     foreach ($this->context_fields_arr as $context_field_name => $context_field_value) {
         $context_field_value = CRUDCompiler::compile($context_field_value, ['this' => $obj]);
         $o .= NullablePostFields::hiddenFieldHtml($context_field_name, $context_field_value);
     }
     $o .= '<input type="hidden" name="_class_name" value="' . Sanitize::sanitizeAttrValue(get_class($obj)) . '">';
     $o .= '<input type="hidden" name="_id" value="' . Sanitize::sanitizeAttrValue(CRUDFieldsAccess::getObjId($obj)) . '">';
     $o .= '<button class="' . $this->button_class_str . '" type="submit">' . $this->button_text . '</button>';
     $o .= '</form>';
     return $o;
 }
    public function html($obj)
    {
        $field_name = $this->getFieldName();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        $editor_element_id = 'editor_' . time() . '_' . rand(1, 999999);
        $html = '';
        $html .= '
            <style>
             #' . $editor_element_id . ' {
                position: relative;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        height: 500px;
            }
            </style>
            ';
        // TODO: is form-control needed?
        $html .= '<div id="' . $editor_element_id . '" class="form-control">' . Sanitize::sanitizeTagContent($field_value) . '</div>';
        $html .= '<textarea id="' . $editor_element_id . '_target" name="' . Sanitize::sanitizeAttrValue($field_name) . '" style="display: none;">' . Sanitize::sanitizeTagContent($field_value) . '</textarea>';
        // TODO: multiple insertion!!!!
        $html .= '<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js" type="text/javascript" charset="utf-8"></script>
            <script>
            //var editor_element = document.getElementById("' . $editor_element_id . '");
            //editor_element.parentElement.style.height = "500px";
            var editor = ace.edit("' . $editor_element_id . '");

            // TODO: enable another modes
            editor.getSession().setMode("ace/mode/html");

            editor.getSession().on("change", function() {
                var target = document.getElementById("' . $editor_element_id . '_target");
                //var editor_element = document.getElementById("' . $editor_element_id . '");
                target.innerHTML = editor.getSession().getValue();
            });
            </script>
            ';
        return $html;
    }
    public function html($obj)
    {
        static $CRUDFormWidgetDateTime_include_script;
        $field_name = $this->getFieldName();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        /* Нужно изменить на нах CDN */
        $script = '';
        if (!isset($CRUDFormWidgetDateTime_include_script)) {
            $script = '
								<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script>
								<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/locale/ru.js"></script>
				<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker.min.css">
								<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/js/bootstrap-datetimepicker.min.js"></script>
			';
            $CRUDFormWidgetDateTime_include_script = false;
        }
        $is_required_str = '';
        if ($this->is_required) {
            $is_required_str = ' required ';
        }
        $field_value_attr = '';
        if ($field_value) {
            $field_value_attr = date('d-m-Y H:i:s', strtotime($field_value));
        }
        $uniqid = uniqid('CRUDFormWidgetDateTime_');
        $input_cols = $this->getShowNullCheckbox() ? '10' : '12';
        $html = '';
        $html .= '<div class="row">';
        $html .= '<div class="col-sm-' . $input_cols . '">';
        ob_start();
        ?>
		<input type="hidden" id="<?php 
        echo $uniqid;
        ?>
_input" name="<?php 
        echo Sanitize::sanitizeAttrValue($field_name);
        ?>
" value="<?php 
        echo Sanitize::sanitizeTagContent($field_value);
        ?>
" data-field="<?php 
        echo $uniqid;
        ?>
_date" <?php 
        echo $is_required_str;
        ?>
>
		<div class="input-group date" id="<?php 
        echo $uniqid;
        ?>
">
			<input id="<?php 
        echo $uniqid;
        ?>
_date" type="text" class="form-control" value="<?php 
        echo $field_value_attr;
        ?>
">
			<span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
		</div>
		<script>
			$("#<?php 
        echo $uniqid;
        ?>
").datetimepicker({
				format: "DD-MM-YYYY HH:mm:ss",
				sideBySide: true,
				showTodayButton: true
			}).on("dp.change", function (obj) {
				if (obj.date) {
					$("#<?php 
        echo $uniqid;
        ?>
_input").val(obj.date.format("YYYY-MM-DD HH:mm:ss")).trigger('change');
				} else {
					$("#<?php 
        echo $uniqid;
        ?>
_input").val('').trigger('change');
				}
			});
		</script>
		<?php 
        $html .= ob_get_clean();
        $html .= '</div>';
        if ($this->getShowNullCheckbox()) {
            $is_null_checked = '';
            if (is_null($field_value)) {
                $is_null_checked = ' checked ';
            }
            ob_start();
            ?>
			<div class="col-sm-2">
				<label class="form-control-static">
					<input id="<?php 
            echo $uniqid;
            ?>
___is_null" type="checkbox" value="1" name="<?php 
            echo Sanitize::sanitizeAttrValue($field_name);
            ?>
___is_null" <?php 
            echo $is_null_checked;
            ?>
> NULL
				</label>
			</div>
			<script>
				(function () {
					var $input_is_null = $('#<?php 
            echo $uniqid;
            ?>
___is_null');

					$("#<?php 
            echo $uniqid;
            ?>
_input").on('change', function () {
						$input_is_null.prop('checked',false);
					});

					$input_is_null.on('change', function () {
						if ($(this).is(':checked')) {
							$('#<?php 
            echo $uniqid;
            ?>
').data("DateTimePicker").clear();
							$('#<?php 
            echo $uniqid;
            ?>
_input').val('');
						}
					});
				})();
			</script>
			<?php 
            $html .= ob_get_clean();
        }
        $html .= '</div>';
        return $script . $html;
    }
Example #10
0
    public function html($obj)
    {
        $field_name = $this->getFieldName();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        $is_required_str = '';
        if ($this->is_required) {
            $is_required_str = ' required ';
        }
        $uniqid = uniqid('CRUDFormWidgetInput_');
        $input_cols = $this->getShowNullCheckbox() ? '10' : '12';
        $html = '';
        $html .= '<div class="row">';
        $html .= '<div class="col-sm-' . $input_cols . '">';
        $html .= '<input id="' . $uniqid . '_input" name="' . Sanitize::sanitizeAttrValue($field_name) . '" ' . $is_required_str . ' class="form-control" value="' . Sanitize::sanitizeAttrValue($field_value) . '"/>';
        $html .= '</div>';
        if ($this->getShowNullCheckbox()) {
            $is_null_checked = '';
            if (is_null($field_value)) {
                $is_null_checked = ' checked ';
            }
            ob_start();
            ?>
            <div class="col-sm-2">
                <label class="form-control-static">
                    <input id="<?php 
            echo $uniqid;
            ?>
___is_null" type="checkbox" value="1" name="<?php 
            echo Sanitize::sanitizeAttrValue($field_name);
            ?>
___is_null" <?php 
            echo $is_null_checked;
            ?>
> NULL
                </label>
            </div>
            <script>
                (function () {
                    var $input_is_null = $('#<?php 
            echo $uniqid;
            ?>
___is_null');
                    var $input = $('#<?php 
            echo $uniqid;
            ?>
_input');

                    $input.on('change keydown', function () {
                        $input_is_null.prop('checked', false);
                    });

                    $input_is_null.on('change', function () {
                        if ($(this).is(':checked')) {
                            $input.val('');
                        }
                    });
                })();
            </script>
            <?php 
            $html .= ob_get_clean();
        }
        $html .= '</div>';
        return $html;
    }
 /**
  * Возвращает одну страницу списка объектов указанного класса.
  * Сортировка: TODO.
  * Фильтры: массив $context_arr.
  * Как определяется страница: см. Pager.
  * @param $model_class_name Имя класса модели
  * @param $context_arr array Массив пар "имя поля" - "значение поля"
  * @return array Массив идентикаторов объектов.
  */
 public static function getObjIdsArrForClassName($table_index_on_page, $model_class_name, $filters_arr, $order_by = '')
 {
     \OLOG\CheckClassInterfaces::exceptionIfClassNotImplementsInterface($model_class_name, \OLOG\Model\InterfaceLoad::class);
     $page_size = Pager::getPageSize($table_index_on_page);
     $start = Pager::getPageOffset($table_index_on_page);
     $db_table_name = $model_class_name::DB_TABLE_NAME;
     $db_id = $model_class_name::DB_ID;
     $db_id_field_name = CRUDFieldsAccess::getIdFieldName($model_class_name);
     $query_param_values_arr = array();
     $where = ' 1 = 1 ';
     foreach ($filters_arr as $filter_obj) {
         /*
         if ($filter_obj instanceof InterfaceCRUDTableFilter) {
         
             $column_name = $filter_obj->getFieldName();
             $operation_code = $filter_obj->getOperationCode();
             $value = $filter_obj->getValue();
         
             $column_name = preg_replace("/[^a-zA-Z0-9_]+/", "", $column_name);
         
             switch ($operation_code) {
                 case CRUDTableFilter::FILTER_EQUAL:
                     $where .= ' and ' . $column_name . ' = ? ';
                     $query_param_values_arr[] = $value;
                     break;
         
                 case CRUDTableFilter::FILTER_IS_NULL:
                     $where .= ' and ' . $column_name . ' is null ';
                     break;
         
                 case CRUDTableFilter::FILTER_LIKE:
                     $where .= ' and ' . $column_name . ' like ? ';
                     $query_param_values_arr[] = '%' . $value . '%';
                     break;
         
                 case CRUDTableFilter::FILTER_IN:
                     if (count($value)) {
                         $in_placeholders_arr = [];
         
                         foreach ($value as $in_single_value) {
                             $in_placeholders_arr[] = '?';
                             $query_param_values_arr[] = $in_single_value;
                         }
         
                         $where .= ' and ' . $column_name . ' in (' . implode(', ', $in_placeholders_arr) . ') ';
                     }
                     break;
         
                 default:
                     throw new \Exception('unknown filter code');
             }
         } else
         */
         if ($filter_obj instanceof InterfaceCRUDTableFilter2) {
             list($filter_sql_condition, $filter_placeholder_values_arr) = $filter_obj->sqlConditionAndPlaceholderValue();
             if ($filter_sql_condition != '') {
                 $where .= ' and ' . $filter_sql_condition;
             }
             $query_param_values_arr = array_merge($query_param_values_arr, $filter_placeholder_values_arr);
         } elseif ($filter_obj instanceof InterfaceCRUDTableFilterInvisible) {
             list($filter_sql_condition, $filter_placeholder_values_arr) = $filter_obj->sqlConditionAndPlaceholderValue();
             if ($filter_sql_condition != '') {
                 $where .= ' and ' . $filter_sql_condition;
             }
             $query_param_values_arr = array_merge($query_param_values_arr, $filter_placeholder_values_arr);
         } else {
             throw new \Exception('filter doesnt implement InterfaceCRUDTableFilter nor InterfaceCRUDTableFilter2');
         }
     }
     if ($order_by == '') {
         $order_by = $db_id_field_name;
     }
     $obj_ids_arr = \OLOG\DB\DBWrapper::readColumn($db_id, "select " . $db_id_field_name . " from " . $db_table_name . ' where ' . $where . ' order by ' . $order_by . ' limit ' . intval($page_size) . ' offset ' . intval($start), $query_param_values_arr);
     return $obj_ids_arr;
 }
Example #12
0
 public function html($obj)
 {
     $field_name = $this->getFieldName();
     $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
     return $this->htmlForValue($field_value);
 }
    public function html($obj)
    {
        $field_name = $this->getFieldName();
        $referenced_class_name = $this->getReferencedClassName();
        $referenced_class_title_field = $this->getReferencedClassTitleField();
        $field_value = CRUDFieldsAccess::getObjectFieldValue($obj, $field_name);
        $options_html_arr = ['<option value=""></option>'];
        // TODO: check referenced class interfaces
        $referenced_obj_ids_arr = \OLOG\DB\DBWrapper::readColumn($referenced_class_name::DB_ID, 'select ID from ' . $referenced_class_name::DB_TABLE_NAME . ' order by ID');
        $options_arr = [];
        foreach ($referenced_obj_ids_arr as $id) {
            $obj = CRUDObjectLoader::createAndLoadObject($referenced_class_name, $id);
            $options_arr[$id] = CRUDFieldsAccess::getObjectFieldValue($obj, $referenced_class_title_field);
        }
        foreach ($options_arr as $value => $title) {
            $selected_html_attr = '';
            if ($field_value == $value) {
                $selected_html_attr = ' selected';
            }
            $options_html_arr[] = '<option value="' . $value . '"' . $selected_html_attr . '>' . $title . '</option>';
            // TODO: sanitize
        }
        $html = '';
        $select_element_id = 'js_select_' . rand(1, 999999);
        $html .= '<select id="' . Sanitize::sanitizeAttrValue($select_element_id) . '" name="' . Sanitize::sanitizeAttrValue($field_name) . '" class="form-control">' . implode('', $options_html_arr) . '</select>';
        $html .= '<input type="hidden" id="' . Sanitize::sanitizeAttrValue($select_element_id) . '_is_null" name="' . Sanitize::sanitizeAttrValue($field_name) . '___is_null"/>';
        ob_start();
        ?>
        <script>
            var select_element = document.getElementById('<?php 
        echo $select_element_id;
        ?>
');
            select_element.addEventListener(
                'change',
                function(){
                    var select_element_id = document.getElementById('<?php 
        echo $select_element_id;
        ?>
');
                    var is_null_element = document.getElementById('<?php 
        echo $select_element_id;
        ?>
_is_null');
                    var value = select_element_id.options[select_element_id.selectedIndex].value;

                    if (value == ''){
                        is_null_element.value = '1';
                    } else {
                        is_null_element.value = '';
                    }
                }
            );

            select_element.dispatchEvent(new Event('change')); // fire to initialize is_null input on display
        </script>

        <?php 
        $html .= ob_get_clean();
        return $html;
    }
    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;
    }
Example #15
0
 /**
  * ид объекта может быть пустым - тогда при сохранении формы создаст новый объект
  * @param $obj
  * @param $element_obj_arr
  * @param string $url_to_redirect_after_save
  * @param array $redirect_get_params_arr
  * @return string html-код формы редактирования
  * @throws \Exception
  */
 public static function html($obj, $element_obj_arr, $url_to_redirect_after_save = '', $redirect_get_params_arr = [], $form_id = '', $operation_code = self::OPERATION_SAVE_EDITOR_FORM, $hide_submit_button = false)
 {
     self::executeOperations($url_to_redirect_after_save, $redirect_get_params_arr);
     $form_element_id = 'formElem_' . uniqid();
     if ($form_id) {
         $form_element_id = $form_id;
     }
     $html = '';
     $html .= '<form id="' . $form_element_id . '" class="form-horizontal" role="form" method="post" action="' . Sanitize::sanitizeUrl(\OLOG\Url::getCurrentUrl()) . '">';
     $html .= Operations::operationCodeHiddenField($operation_code);
     $html .= '<input type="hidden" name="' . self::FIELD_CLASS_NAME . '" value="' . Sanitize::sanitizeAttrValue(get_class($obj)) . '">';
     $html .= '<input type="hidden" name="' . self::FIELD_OBJECT_ID . '" value="' . Sanitize::sanitizeAttrValue(CRUDFieldsAccess::getObjId($obj)) . '">';
     /** @var InterfaceCRUDFormRow $element_obj */
     foreach ($element_obj_arr as $element_obj) {
         Assert::assert($element_obj instanceof InterfaceCRUDFormRow);
         $html .= $element_obj->html($obj);
     }
     $html .= '<div class="row">';
     $html .= '<div class="col-sm-8 col-sm-offset-4">';
     if (!$hide_submit_button) {
         $html .= '<button style="width: 100%" type="submit" class="btn btn-primary">Сохранить</button>';
     }
     $html .= '</div>';
     $html .= '</div>';
     $html .= '</form>';
     // Загрузка скриптов
     $html .= CRUDFormScript::getHtml($form_element_id);
     return $html;
 }