
<form id="frm_user" class="Hpadd-15 Hbg-white Hround-10 Hform-med" style="" name="frm_user" action="" method="post" enctype="text/plain" >
    <h3 clas="Hrow" style="padding-right:2%">ثبت | ویرایش  &nbsp; &nbsp;کاربر</h3>     
    <div class="Hrow Hpadd-1per">
             <label class="HpaddR-10" data-color="#424750">نام کاربری</label>
             <input type="text" class="Hrow Htxt-center" style="letter-spacing:5px;border:1px solid #bbb;" name="username" id="Fusername" @{if model} value="@{!model.username}" @{fi}/>
     </div>
     <div class="Hrow Hpadd-1per">
             <label class="HpaddR-10" data-color="#424750">رمز کاربر</label>
             <input type="text" class="Hrow Htxt-center" style="letter-spacing:5px;border:1px solid #bbb;" name="password" id="Fpassword" @{if model} value="@{!model.password}" @{fi}/>
     </div>

     @{if model}
        @{if model._id+"" != repository.user._id+""}
                <div class="Hrow Hpadd-1per">
                        <label>&nbsp;</label>
                        <select name="role" id="role" class="Hrow Htxt-center Hbg-white" style="border:1px solid #bbb;">
                        @{if repository.user.role=="administrator"}<option value="administrator" @{if model} @{if model.role=="administrator"} selected @{fi} @{fi} >مدیر</option>@{fi}
                        <option value="admin" @{if model} @{if model.role=="admin"} selected @{fi} @{fi} >ادمین</option>
                        <option value="user" @{if model} @{if model.role=="user"} selected @{fi} @{fi} >کارمند</option>
                        </select>
                        
                </div>  
        @{else}
             <input name="role" value="@{model.role}" type="hidden" />
        @{fi}
     @{else}
        <div class="Hrow Hpadd-1per">
                <label>&nbsp;</label>
                <select name="role" id="role" class="Hrow Htxt-center Hbg-white" style="border:1px solid #bbb;">
                    @{if repository.user.role=="administrator"}<option value="administrator" >مدیر</option>@{fi}
                        <option value="admin" >ادمین</option>
                        <option value="user"  selected>کارمند</option>
                </select>
        </div>
     @{fi}
     
     <div class="Hrow Hpadd-1per">
        <h4 clas="Hrow" style="padding:0% 2%;">مسئولیت <b class="Hfloat-L Hbtn-mini Hbg-skyblue fa fa-plus" data-color="#fff" data-selector="#modal_unit" data-target="Hmodal" data-action=""></b></h4>
        <div class="Hrow listShow-N2 HpaddT-10 HpaddB-10" id="unitlist">
                 @{if model}
                    @{foreach y in model.unit}
                        <div class="Hrow Hpadd-5" unit="@{y}">@{resource("unit_"+y)}<b class="Hbtn-mini Hbg-digired fas fa-times Hfloat-L removeunit" style="color:#fff;"></b></div>
                    @{end}
                 @{fi}
        </div>
        <input type="hidden" id="ulist" name="ulist" @{if model} value="@{model.unit}" @{else} value="" @{fi}/>
     </div>
     @{if model._id != repository.user._id}
     <div class="Hrow Hpadd-1per">
             <div class="check-items HpaddT-20 HpaddB-10 HpaddR-15 HpaddL-15" style="">
                     <b style="position:relative;top:10px;">فعال | غیر فعال</b>
                     <label class="switch Hfloat-L">
                             <input type="checkbox" @{if model}  value="@{!model.active}"  @{if model.active}checked="checked"@{fi} @{else} value=true checked="checked"@{fi} name="active" id="active"  />
                             <span class="slider round"></span>
                     </label>
             </div>
     </div>
     @{fi}

     
     @{if model}
     <div class="Hrow">
       <input type="hidden" id="userID" name="userID" placeholder=""  value="@{!model._id}" />
     </div>  
     @{fi}
   
     <div class="Hrow SubmitionBox Hpadd-2per">
       <input  class="trans0_25 Hbtn-fullfix @{if model} Hbtn-yellow2 @{else} Hbtn-lightGreen @{fi} Hpadd-15"  type="button" id="userINSup" data-action="" @{if model} value="ویرایش کاربر" @{else} value="ثبت کاربر" @{fi}/>
     </div>
</form>



<div class="Hmodal" id="modal_unit"> 
  <div class="Hmodal-sm Hcards" style="background:#fff;border-radius:5px;">
    <div class="Hcards-header">
      <div class="close" data-color="#ffffff" style="background:#ff3333;border-radius:4px;"></div>
      <h3 class="HpaddR-10 Hfloat-R">واحد ها : </h3>

    </div>
    <div class="Hcards-content Hpadd-10 listShow-N2">
            <div class="Hrow"><label class="checkBox" style="font-size:22px;"><input type="checkbox" value="1" style="display:none;"/><span class="checkmark" style=""></span>پشتیبانی</label></div>
            <div class="Hrow"><label class="checkBox" style="font-size:22px;"><input type="checkbox" value="2" style="display:none;"/><span class="checkmark" style=""></span>فروش</label></div>
            <div class="Hrow"><label class="checkBox" style="font-size:22px;"><input type="checkbox" value="3" style="display:none;"/><span class="checkmark" style=""></span>خدمات</label></div>
            <div class="Hrow"><label class="checkBox" style="font-size:22px;"><input type="checkbox" value="4" style="display:none;"/><span class="checkmark" style=""></span>روابط عمومی</label></div>
            <div class="Hrow"><label class="checkBox" style="font-size:22px;"><input type="checkbox" value="5" style="display:none;"/><span class="checkmark" style=""></span>مدیریت</label></div>
   
    </div>
    
  </div>
</div>



@{section footer2}
<script type="text/javascript">
$(document).ready(function(){
     var ulist=[];
     ulist=($("#ulist").val()!="")? $("#ulist").val().split(","):[];
     
     for(var i=0;i<ulist.length;i++){
         $(".checkBox input[type=checkbox][value="+ulist[i]+"]").attr("checked","checked");
     }
     
     $(document).on("click",".removeunit",function(){
        var u=$(this).parent().attr("unit");
        for( var i = 0; i < ulist.length; i++){ 
            (ulist[i] == u)? ulist.splice(i, 1):""; 
        }
        
        $("#ulist").val(ulist);
        $(this).parent().remove();
         $(".checkBox input[type=checkbox][value="+u+"]").removeAttr("checked");
     });
     

     
     $(document).on("change",".checkBox",function(){

        var u=$(this).children().eq(0).val();
        if($(this).children().eq(0).is(":checked")){
            ulist.push(u);
            $("#ulist").val(ulist);
            var obj='<div class="Hrow Hpadd-5" unit="'+u+'">'+$(this).text()+'<b class="Hbtn-mini Hbg-digired fas fa-times Hfloat-L removeunit" style="color:#fff;"></b></div>';
            $("#unitlist").append(obj);
            
        }else{
            for( var i = 0; i < ulist.length; i++){ 
                (ulist[i] == u)? ulist.splice(i, 1):""; 
            }
            $("#ulist").val(ulist);
            $("#unitlist").children().filter("div[unit="+u+"]").remove();

        }
        
     });
     
});
</script>
@{end}

