



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

        <ol class="breadcrumb">
            <li><a href="#">اداره الموظفين</a></li>
            <li><a href="employeesubgroups.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="employeesubgroups.php?do=update" method="post" id="spform">



                    <div class="form-group">
                        <label class="col-lg-2 control-label">اسم المجموعة الفرعية</label>
                        <div class="col-lg-4">
                            <span id="namesp">
                                <input required="required" type="text" name="name" id="name" class="form-control" value="{$loadData->name}"/>
                                <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">×</button>
                                <h4>رسالة خطا</h4>
                                <p>هذا الاسم مستخدم من قبل</p>

                                <div class="clearfix"></div>
                            </div>
                        </div>
                    </div>

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



                    <div class="form-group">
                        <label class="col-lg-2 control-label">مجموعة الموظفين </label>
                        <div class="col-lg-4">
                            <span id="employeegroupidsp">
                                <select class="select2" name="employeegroupid" id="employeegroupid" onchange="getAttendanceSystem(this.value);">
                                    <option value="-1"></option>
                                    {foreach $employeeGroup as $data}
                                    <option value="{$data->id}" {if $data->id == $loadData->employeegroupid}selected{/if}>{$data->name}</option>
                                    {/foreach}
                                </select>
                                <span class="selectInvalidMsg">*</span><span class="selectRequiredMsg">*</span></span>
                        </div>
                    </div>

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


                    <div class="form-group">
                        <label class="col-lg-2 control-label">نظام الحضور</label>
                        <div class="col-lg-4">
                            <span id="employeeattendancesystemidsp">
                                <select class="select2" name="employeeattendancesystemid" id="employeeattendancesystemid">
                                    <option value="-1"></option>
                                    {foreach $employeeAttendanceSystem as $data}
                                    <option value="{$data->id}" {if $data->id == $loadData->employeeattendancesystemid}selected{/if}>{$data->name}</option>
                                    {/foreach}
                                </select>
                                <span class="selectInvalidMsg">*</span><span class="selectRequiredMsg">*</span></span>
                        </div>
                    </div>

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

                    <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>
    var namesp = new Spry.Widget.ValidationTextField("namesp");
    var employeegroupidsp = new Spry.Widget.ValidationSelect("employeegroupidsp", {invalidValue: "-1"});
    var employeeattendancesystemidsp = new Spry.Widget.ValidationSelect("employeeattendancesystemidsp", {invalidValue: "-1"});
    $('#spbutton').live('click', function (e) {
        if ($('#spform').validate().form()) {
            //ckeck name
            var tableName = 'employeesubgroup';
            var inputName = 'name';
            var name = $("#" + inputName).val();
            var id = $("#id").val();

            $.ajax({
                url: 'checkRedundantNames.php?do=checkNameWithId&name=' + name + '&id=' + id + '&tablename=' + tableName,
                success: function (data) {
                    //alert(data);
                    if (data == '0')
                    {
                        $("#nameError").css("display", "none");
                        //return true;
                        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');
                            }
                        }

                    } else if (data == '1')
                    {
                        $("#" + inputName).val("");
                        $("#" + inputName).focus();
                        $("#nameError").css("display", "block");
                        return false;
                    }
                }});
        }
        else
        {
            e.preventDefault();
        }
    });
    function getAttendanceSystem(id) {
        if (Number(id) > 0) {
            $.post('employeegroups.php?do=getattendancesystemajax', {id: id}, function (data) {
                if (Number(data) > 0) {
                    $('#employeeattendancesystemid').val(data).change();
                }
            });
        }
    }
</script>
{/literal}

