

@{section header}

<title>ثبت اطلاعات کاربر</title>

@{end}


@{view('~../modules/https_modules/users/views/partial/userADDRESS',model)}


@{section footer}

  <script type="text/javascript">


function show_res(result){
    switch(result.status){
     case 200:
            var city=$("#city option:selected").text();
            var province=$("#province option:selected").text();
            
            var obj='<div class="Hrow Hpadd-5 useraddress-list" ><input type="hidden" name="addressid" value="'+result.address._id+'"/><div class="Hcol-xlg-6 Hcol-lg-6 Hcol-xmd-6 Hcol-md-12 Hcol-xsm-6 Hcol-sm-12 Hcol-xs-12 Hcol-xss-12 Hpadd-5 Htxt-center"  idc="'+result.address._idc+'" idp="'+result.address._idp+'">'+ province +' - '+ city +'</div><div class="Hcol-xlg-6 Hcol-lg-6 Hcol-xmd-6 Hcol-md-12 Hcol-xsm-6 Hcol-sm-12 Hcol-xs-12 Hcol-xss-12 Hpadd-5 Htxt-center">'+result.address.postcode+'</div><div class="Hrow Hpadd-5">'+result.address.address+'</div><b class="Hbtn-mini Hbg-digired fas fa-trash-alt Hfloat-L remove-address" style="color:#fff;"></b><b class="Hbtn-mini Hbg-sharpyellow fas fa-pencil-alt Hfloat-L update-address" style="color:#fff;" data-selector="#modal_address" data-target="Hmodal"></b></div>';
            $("#addslist").append(obj);
            $("#modal_address .close").trigger("click");
            document.getElementById("frm").reset();
            Hnotification({status:"success",Cstyle:[{color:"#000000"}],Ctext:result.data});
      break;
        default:
            Hnotification({status:"warning",Cstyle:[{color:"#000000"}],Ctext:result.data});
      break;
    }
}




var opensubmit=[0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1];






$(document).ready(function(){

    $("#addaddress").click(async function(){
        
            var id=window.location.href.split("/");
            id=id[id.length-1];
            // $("#frm input").each(function(index,element){

            //     $("#"+$(element).attr("id")).trigger("blur");
            // });
            if($("#Hnotification").children().length==0){
                var formdata=new FormData(frm);
                var result=await jqajax(("/useraddress/insert/"+id),formdata,"post","loader");
                show_res(result);
            }
        

    });
    
    
        
    $("#updaddress").click(async function(){
            var id=window.location.href.split("/");
            id=id[id.length-1];

            // $("#frm input").each(function(index,element){

            //     $("#"+$(element).attr("id")).trigger("blur");
            // });
            if($("#Hnotification").children().length==0){
                var formdata=new FormData(frm);
                var result=await jqajax(("/useraddress/update/"+id),formdata,"post","loader");
                show_res2(result);
            }
        

    });
    
    $(document).on("click",".remove-address",async function(){
        
            var id=$(this).siblings("input").eq(0).val();
            var uid=window.location.href.split("/");
            uid=uid[uid.length-1];
            // $("#frm input").each(function(index,element){

            //     $("#"+$(element).attr("id")).trigger("blur");
            // });
            if($("#Hnotification").children().length==0){
      
                var result=await jqajax(("/useraddress/delete/"+uid),"id="+id,"get","loader");
                show_res3(result);
            }
        

    });
    
    
    
    
});

</script>







@{end}







