<style>
    .new_prices {
        border-right: 0;
        border-bottom-right-radius: 0;
        border-top-right-radius: 0;
        font-weight: bold;
        padding: 4px 12px;
        font-size: 14px;
        font-weight: bold;
        line-height: 1;
        text-align: center;
        background-color: #eee;
        border: 1px solid #ccc;
        border-radius: 4px;
        width: 66px;
        white-space: nowrap;
        vertical-align: middle;
        display: table-cell;
        border-radius: 0px;
        border-bottom-left-radius: 4px;
        border-top-left-radius: 4px;
    }
</style>
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">{$smarty.const.PRODUCTS}</a></li>
            <li><a href="searchFiltersController.php?do=show">{$smarty.const.SEARCH_FILTERS}</a></li>
            <li class="active">{$smarty.const.EDIT_SEARCH_FILTER}</li>
        </ol>
        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">{$smarty.const.EDIT_SEARCH_FILTER}</h3>
            </div>
            <div class="panel-body"> {literal}
                <form class="nameToBeChecked form-horizontal" role="form" action="searchFiltersController.php?do=update"
                    method="post" enctype="multipart/form-data" id="spform">
                    {/literal}
                    <div class="form-group">
                        <label for="parent" class="col-lg-2 control-label">{$smarty.const.MAIN_FILTER}</label>
                        <div class="col-lg-4">
                            <input type="hidden" name="parent" id="parent">
                            <input type="hidden" id="oldid" value="{$searchFiltersparent->id}">
                            <input type="hidden" id="oldname" value="{$searchFiltersparent->name}">
                        </div>
                    </div>

                    <!-- =================================================   -->

                    <div class="form-group">
                        <label for="name" class="col-lg-2 control-label">{$smarty.const.FILTER_NAME}</label>
                        <div class="col-lg-4"> <span id="sprytextfield1">
                                <input type="text" name="name" id="name" placeholder="{$smarty.const.FILTER_NAME}"
                                    class="form-control" value="{$searchFiltersData->name}"
                                    onblur="checkNameWithId(event, 'searchfilters', 'name', 'id')" />
                                <span class="textfieldRequiredMsg">*</span></span>
                            <div id="nameError" class="alert alert-block alert-danger fade in" style="display:none">
                                <button type="button" class="close pull-left" data-dismiss="alert"
                                    aria-hidden="true">&times;</button>
                                <h4>{$smarty.const.WRONG_MESSAGE}</h4>
                                <p>{$smarty.const.NAME_ALREADY_TAKEN}</p>
                                <div class="clearfix"></div>
                            </div>
                        </div>
                    </div>
                    <!-- =================================================   -->

                    <div class="form-group">
                        <label for="nameE" class="col-lg-2 control-label">{$smarty.const.FILTER_NAME}E</label>
                        <div class="col-lg-4"> <span id="sprytextfield1">
                                <input type="text" name="name_en" id="nameE"
                                    placeholder="{$smarty.const.FILTER_NAME}E" class="form-control"
                                    value="{$searchFiltersData->name_en}"
                                    onblur="checkNameWithId(event, 'searchfilters', 'name_en', 'id')" />
                                <span class="textfieldRequiredMsg">*</span></span>
                            <div id="nameError" class="alert alert-block alert-danger fade in" style="display:none">
                                <button type="button" class="close pull-left" data-dismiss="alert"
                                    aria-hidden="true">&times;</button>
                                <h4>{$smarty.const.WRONG_MESSAGE}</h4>
                                <p>{$smarty.const.NAME_ALREADY_TAKEN}</p>
                                <div class="clearfix"></div>
                            </div>
                        </div>
                    </div>
                    <!-- =================================================   -->

                    <input name="id" id="id" type="hidden" value="{$searchFiltersData->id}" />
                    <input name="conditions" id="conditions" type="hidden" value="{$searchFiltersData->conditions}" />

                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="button" class="btn btn-primary pull-left"
                                id="spbutton">{$smarty.const.SAVE_IT}</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div id="productUnitsDiv" style="display:none;">
    <option value="-1">{$smarty.const.CHOOSE_UNIT_NAME}</option>
    {foreach $unitsData as $unit}
    <option value="{$unit->unitId}">{$unit->unitName}</option>
    {/foreach}
</div>
{literal}
<script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    $('#spbutton').live('click', function (e) {
        if (!$('#spbutton').hasClass("processing")) {
            $('#spbutton').addClass("processing");
            $('#name').trigger('blur');
            setTimeout(function () {
                var myForm = document.getElementById("spform");
                var SS = Spry.Widget.Form.validate(myForm);
                if (SS == true) {
                    myForm.submit();
                }
                else {
                    $('#spbutton').removeClass("processing");
                }
            }, 500);
        }
    });

    $(function () {
        $('#parent').select2({
            placeholder: "اختر تصنيف ",
            minimumInputLength: 0,
            //  minimumInputLength: 3,
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "searchFiltersController.php?do=getallsearchfilters",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        term: term, //search term
                        page_limit: 30, // page size
                        withoutId: $('#id').val(),
                    };
                },
                results: function (data) {
                    return { results: data };
                }
            },
            formatResult: function (data) {
                return data.text;
            },
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = { id: item[0], text: item[1] };
                callback(data);
            }
        });
        $('#parent').select2('data', { id: $('#oldid').val(), text: $('#oldname').val() })
    });
</script>
{/literal}