

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

         <ol class="breadcrumb">
            <li><a href="#">نظام  المهام</a></li>
            <li><a href="tasksController.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">


                {literal}
                <form class="form-horizontal"  action="tasksController.php?do=update"   method="post"  enctype="multipart/form-data" >
                    {/literal}

                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">العملاء</label>
                        <div class="col-lg-4">
                            <input type="text" name="taskclientid" required="required" class="wdt100" id="select2client" data-placeholder="اختر " />
                              <input type="hidden" id="clientid" value="{$client.clientid}">
                            <input type="hidden" id="clienttext" value="{$client.clientname}">
                         </div>
                    </div>


                     <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">المواظفين</label>
                        <div class="col-lg-4">
                            <input type="text" name="taskuserid" required="required" class="wdt100" id="select2user" data-placeholder="اختر " />
                            <input type="hidden" id="taskuserid" value="{$user.userid}">
                            <input type="hidden" id="usertext" value="{$user.employeename}">
                         </div>
                    </div>


                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">انواع المهام</label>
                        <div class="col-lg-4">
                            <input type="text" name="tasktypeid" required="required" class="wdt100" id="select2types" data-placeholder="اختر " />
                            <input type="hidden" id="tasktypeid" value="{$tasktype->id}">
                            <input type="hidden" id="tasktypetext" value="{$tasktype->typename}">
                         </div>
                    </div>

                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">تاريخ التنفيذ</label>
                        <div class="col-lg-4">
                             <input type="text"  required="required" class="form-control awdatepicker" name="taskdate" data-date-format="yyyy-mm-dd"  placeholder="تاريخ التنفيذ"  value="{$task->taskdate}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">عنوان المهمه</label>
                        <div class="col-lg-4">
                            <input    required="required"    type="text" name="taskaddress"  class="form-control" placeholder="عنوان المهمه "/  value="{$task->taskaddress}">
                            
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">تفاصيل المهمه</label>
                        <div class="col-lg-10">
                             <textarea  class="form-control" required="required" name="taskdetail" rows="3"  placeholder="تفاصيل المهمه">{$task->taskdetail}</textarea>
                        </div>
                    </div>

                     <div class="form-group"  >
                        <label  class="col-lg-2 control-label">حالات المهمه </label>
                        <div class="col-lg-4">
                            <select name="taskcaseid" required id="taskscases" data-placeholder="اختر " class="select2 taskscases">
                                <option value="" ></option>
                                {foreach $taskscases as $taskcase}
                                <option value="{$taskcase->id}" {if $task->taskcaseid eq $taskcase->id} selected {/if}>{$taskcase->taskcase}</option>
                                {/foreach}
                            </select>
                        </div>
                        <label class="col-lg-2 control-label">تعليق الحاله</label>
                        <div class="col-lg-4">
                             <textarea  class="form-control" required="required" name="taskcasecomment" rows="1"  placeholder="تعليق الحاله">{$task->taskcasecomment}</textarea>
                        </div>
                    </div>


                    <div class="form-group">
                        <div class="col-md-12">
                              <div>
                                 <button type="button" class="btn green-meadow btn-sm pull-right addappend"  style="font-size: 10px;background: #ccc">اضافه  تعليق </button>
                                  <input type="hidden" id="taskscommentsitr" name="taskscommentsitr" value="{$taskscomments|@count + 1}" />
                              </div>
                              <div class="clearfix"></div>
                              <ul class="taskscommentscontainer" >
                                {assign var=itr value=1}
                                {foreach $taskscomments as $single}
                                <li  id="litaskscomments1{$single->id}" style="list-style-type: none;">
                                   <input type="hidden" name="taskcommentid_{$itr}" value="{$single->id}">
                                   <div class="col-lg-11">
                                       <input   type="text" name="taskcomment_{$itr}" class="form-control " placeholder=" التعليق "  value="{$single->taskcomment}">
                                   </div>
                                   <div class="col-md-1">                                                   
                                        <button type="button" data-edit="1" data-id='{$single->id}' class="btn red btn-sm pull-right removeappend" >X</button>
                                    </div>
                                </li>
                                {capture assign=itr}{$itr+1}{/capture}
                                {/foreach}
                            </ul>  
                        </div>
                    </div>
                  

                    <div class="form-group">
                        <input type="hidden" name="id" value="{$task->id}">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="submit" class="btn btn-primary pull-left" >تعديل </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{literal}
<script type="text/javascript">


    $(document).ready(function () {
        var formatResult;
        formatResult = function (data) {
            return  data.text;
        }


        $("#select2client").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.php?do=select2client",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        searchTerm: term,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });
       $('#select2client').select2('data', {id: $('#clientid').val(), text: $('#clienttext').val()});
        $("#select2user").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.php?do=select2user",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        searchTerm: term,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });

        $('#select2user').select2('data', {id: $('#taskuserid').val(), text: $('#usertext').val()});
        $("#select2types").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.php?do=select2types",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        searchTerm: term,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });
        $('#select2types').select2('data', {id: $('#tasktypeid').val(), text: $('#tasktypetext').val()});
        $('body').on('click', '.addappend', function () {
            var itr = Number($('#taskscommentsitr').val());
            $.post('tasksController.php?do=appendcomment', {itr: itr}, function (result) {
                $('.taskscommentscontainer').append(result);
                $('#taskscommentsitr').val(itr + 1);
            });
        });


        $('body').on('click', '.removeappend', function () {
            var editcheck = $(this).attr('data-edit');
            var id = $(this).attr('data-id');
            var thisis = $(this);
            if (confirm('هل انت متاكد من الحذف ؟')) {
                if (editcheck == 1) {
                    $.post('tasksController.php?do=removecomment', {id: id, editcheck: editcheck}, function (data) {
                        if (data == 1) {
                            $('#litaskscomments'+editcheck+id).remove();
                        }else{
                             alert('حدث خطأ أثناء التنفيذ');
                        }
                    });
                } else {
                    $('#litaskscomments'+editcheck+id).remove();
                }
            } else {
            alert('لماذا ضغطت إلغاء؟ يجب أن تكون قد أكدت');
            }
        });


    });
</script>
{/literal}


