



<div class="row">
    <div class="container">

        <ol class="breadcrumb">
            <li><a href="#">المنتجات</a></li>
            <li><a href="sizecolorController.php?do=show">مقاسات والوان</a></li>
            <li class="active">تعديل </li>
        </ol>


        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">تعديل </h3>
            </div>
            <div class="panel-body">
                <form class="nameToBeChecked form-horizontal" role="form" action="sizecolorController.php?do=update" method="post" id="spform">



                    <div class="form-group">
                        <label class="col-lg-2 control-label">الاسم</label>
                        <div class="col-lg-4">
                            <input type="text" name="name" id="name" class="form-control" value="{$loadData->name}"/>
                            <div id="nameError" style="display:none;"></div>
                        </div>
                    </div>



                    <div class="form-group">
                        <label class="col-lg-2 control-label">النوع</label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input value="0"  class="noradioR" name="type" type="radio" {if $loadData->type == 0}checked{/if}/>
                                    مقاس</label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input value="1"  class="radioR" name="type"   type="radio" {if $loadData->type == 1}checked{/if}/>
                                    لون </label>
                            </div>
                        </div>
                    </div>



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

                    <input type="hidden" name="oldname" id="oldname" value="{$loadData->name}"/>
                    <input type="hidden" name="id" id="id" value="{$loadData->id}"/>


                    <!-- =================================================   -->
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="button"  class="btn btn-primary pull-left"  id="spbutton">تعديل</button>
                        </div>
                    </div>


                </form>
            </div>
        </div>




    </div>
</div>

{literal}
<script type="text/javascript">
    $('#spbutton').live('click', function (e) {
        if ($('#spform').validate().form()) {
            //ckeck name
            var tableName = 'sizecolor';
            var inputName = 'name';
            var name = $("#" + inputName).val();
            var id = $("#id").val();
            $.ajax({
                url: 'checkRedundantNames.php?do=checkNameWithId&name=' + name + '&tablename=' + tableName + '&id=' + id,
                success: function (data) {
                    //alert(data);
                    if (data == '0')
                    {
                        $("#nameError").css("display", "none");
                        var myForm = document.getElementById("spform");
                        var SS = Spry.Widget.Form.validate(myForm);
                        if (SS == true) {
                            if (!$('#spbutton').hasClass("processing"))
                            {
                                $('#spbutton').addClass("processing");
                                myForm.submit();
                                //$('#spbutton').unbind('click');
                            }
                        }
                        //return true;
                    } else if (data == '1')
                    {
                        $("#" + inputName).val("");
                        $("#" + inputName).focus();
                        $("#nameError").css("display", "block");
                        return false;
                    }
                }});
        } else {
            e.preventDefault();
        }
    });



</script>
{/literal}
