function getStudentNotice(user_id){ var markup = '
'+ '
'+ '
'+ '
'; $("#modal").html(markup); var markup2 = ''; //var markup2=''; $.get('/api/student/'+user_id, function(data) { console.log(data); markup = '
' + '
' + '

${inputLastName}, ${inputFirstName}

' + '
' + '
' + markup2 + '
' + '
' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); }); // Inline Admin-Form example $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true }); } function getUserComments(user_id) { var markup = '
'+ '
'+ '
'+ '
'; $("#modal").html(markup); var markup2 = '{{for(j=0,j_cnt=comments.length;j' + '' + '
' + '
${comments[j].comment}
' + '' + '
' + '' + '{{/for}}'; $.get('/api/user/'+user_id+'/comment', function(data) { console.log(data); markup = '
' + '
' + '

${email}

' + '

(${firstname} ${lastname})

' + '
' + '
' + markup2 + '
' + '' + '
' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); $("#btn_comment_write").off('click'); $("#btn_comment_write").on('click', function() { if($('#comment').val() == '') return; var input_obj = { comment: $('#comment').val() } $('#comment').val(''); $.ajax({ method: "post", url: "/api/user/"+user_id+"/comment", data: input_obj }) .done(function( msg ) { $.get('/api/user/'+user_id+'/comment', function(data) { $.template( "template", markup2 ); $("#modal .panel-body").html($.tmpl( "template", data )); setCommentEvent(user_id); $(".user-comment-label[data-user-id="+user_id+"]").eq(0).text(data.comments.length); }); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); setCommentEvent(user_id); }); // Inline Admin-Form example $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true }); } function setCommentEvent(user_id) { $(".btn_comment_delete").off('click'); $(".btn_comment_delete").on('click', function() { var comment_id = $(this).parent().parent().attr('comment_id'); swal({ title: "Delete comment?", text: '', type: "info", html: true, allowOutsideClick: true, showCancelButton: true, cancelButtonText: "No", confirmButtonText: "Yes", closeOnConfirm: true }, function(isConfirm){ if(!isConfirm) return; $.ajax({ method: "delete", url: "/api/user/"+user_id+"/comment/"+comment_id, }) .done(function( msg ) { $("#modal [comment_id='"+comment_id+"']").remove(); if(parseInt($(".user-comment-label[data-user-id="+user_id+"]").eq(0).text())-1 > 0) { $(".user-comment-label[data-user-id="+user_id+"]").eq(0).text(parseInt($(".user-comment-label[data-user-id="+user_id+"]").eq(0).text())-1); } else { $(".user-comment-label[data-user-id="+user_id+"]").eq(0).text(''); } }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); }); } function getAccountInfo(user_id) { var markup = '
'+ '
'+ '
'+ '
'; $("#modal").html(markup); var d1 = $.get('/api/config/state'); var d2 = $.get('/api/user/'+user_id); $.when( d1, d2 ).done(function ( v1, v2 ) { var data = { states: v1[0], user: v2[0], }; markup = '
' + '
' + '

${user.email}

' + '

(${user.firstname} ${user.lastname})

' + '
' + '
' + '
' + '' + '
' + '
' + '{{if user.is_block == "Y" }}' + '' + '{{else}}' + '' + '{{/if}}' + '' + '
' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '
' + '' + '
' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); $("#btn_user_modify").off('click'); $("#btn_user_modify").on('click', function() { var is_block = $("#modify_is_block:checked").val() != undefined ? $("#modify_is_block:checked").val() : 'N'; var input_obj = { is_block: is_block, grade_id: $('#modify_grade_id').val(), phone: $('#modify_phone').val(), state: $('#modify_state').val(), birth: $('#modify_birth').val(), addr_city: $('#modify_addr_city').val(), addr_street: $('#modify_addr_street').val(), firstname: $('#modify_firstname').val(), lastname: $('#modify_lastname').val(), student_id: $('#modify_student_id').val(), sex: $('#modify_sex').val() } $.ajax({ method: "put", url: "/api/user/"+user_id, data: input_obj }) .done(function( msg ) { //alert('complete modify'); //location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); /*2018.06.25 dorothy 삭제 버튼 relation 확인 기능 추가 */ $("#btn_user_delete").off('click'); $("#btn_user_delete").on('click', function() { var grade=$.get('/api/user/'+user_id, function(data, status){ var grade_id=data.grade_id; if(grade_id==2){ var data =$.get('/api/relation/student/'+user_id, function(data, status){ var delete_account=false; if(data[0].host_id!=null||data[0].local_id!=null||data[0].agency_id!=null||data[0].school_id!=null||data[0].sa_id!=null){ swal({ title: "Relation exists.", text: 'Please delete the relation and try again.', type: "warning", html: true, allowOutsideClick: true, showCancelButton: false, confirmButtonColor: "#DD6B55", cancelButtonText: "cancel", confirmButtonText: "Confirm", closeOnConfirm: true }); } else{ swal({ title: "Are you sure you want to delete the account?", text: 'If you delete your account, you will not be able to restore your data', type: "warning", html: true, allowOutsideClick: true, showCancelButton: true, confirmButtonColor: "#DD6B55", cancelButtonText: "cancel", confirmButtonText: "Yes, delete it!", closeOnConfirm: true }, function(isConfirm){ if(!isConfirm) return; if(confirm("Are you sure you want to delete it?")==true){ alert("Delete the account."); if(!isConfirm) return; $.ajax({ method: "delete", url: "/api/user/"+user_id }) .done(function( msg ) { location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); } }); } }); } else if (grade_id==4){ $.get('/api/relation/agency/'+user_id, function(data, status){ if(data[0]){ swal({ title: "Relation exists.", text: 'Please delete the relation and try again.', type: "warning", html: true, allowOutsideClick: true, showCancelButton: false, confirmButtonColor: "#DD6B55", cancelButtonText: "cancel", confirmButtonText: "Confirm", closeOnConfirm: true }); } else{ swal({ title: "Are you sure you want to delete the account?", text: 'If you delete your account, you will not be able to restore your data', type: "warning", html: true, allowOutsideClick: true, showCancelButton: true, confirmButtonColor: "#DD6B55", cancelButtonText: "cancel", confirmButtonText: "Yes, delete it!", closeOnConfirm: true }, function(isConfirm){ if(!isConfirm) return; if(confirm("Are you sure you want to delete it?")==true){ alert("Delete the account."); if(!isConfirm) return; $.ajax({ method: "delete", url: "/api/user/"+user_id }) .done(function( msg ) { location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); } }); } }); } else if (grade_id==5){ $.get('/api/host/'+user_id, function(data, status){ if(data.school_id ||data.school1_id||data.school2_id||data.local_id){ swal({ title: "Relation exists.", text: 'Please delete the relation and try again.', type: "warning", html: true, allowOutsideClick: true, showCancelButton: false, confirmButtonColor: "#DD6B55", cancelButtonText: "cancel", confirmButtonText: "Confirm", closeOnConfirm: true }); } else{ $.get('/api/relation/student/'+user_id, function(data, status){ if(data[0]){ swal({ title: "Relation exists.", text: 'Please delete the relation and try again.', type: "warning", html: true, allowOutsideClick: true, showCancelButton: false, confirmButtonColor: "#DD6B55", cancelButtonText: "cancel", confirmButtonText: "Confirm", closeOnConfirm: true }); } else{ swal({ title: "Are you sure you want to delete the account?", text: 'If you delete your account, you will not be able to restore your data', type: "warning", html: true, allowOutsideClick: true, showCancelButton: true, confirmButtonColor: "#DD6B55", cancelButtonText: "cancel", confirmButtonText: "Yes, delete it!", closeOnConfirm: true }, function(isConfirm){ if(!isConfirm) return; if(confirm("Are you sure you want to delete it?")==true){ alert("Delete the account."); if(!isConfirm) return; $.ajax({ method: "delete", url: "/api/user/"+user_id }) .done(function( msg ) { location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); } }); } }); } }); } }); }); $("#btn_password_change").off('click'); $("#btn_password_change").on('click', function() { var input_obj = { password: $('#password').val() } $.ajax({ method: "post", url: "/api/user/"+user_id+"/password", data: input_obj }) .done(function( msg ) { location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); // 공통 기능 $('.date-picker').datetimepicker({ pickTime: false, format: 'MM-DD-YYYY' }); }); $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true }); } function getAccountInfoRole(user_id){ var markup = '
'+ '
'+ '
'+ '
'; $("#modal").html(markup); var d1 = $.get('/api/config/state'); var d2 = $.get('/api/user/'+user_id); $.when( d1, d2 ).done(function ( v1, v2 ) { var data = { states: v1[0], user: v2[0], }; markup = '
' + '
' + '

${user.email}

' + '

(${user.firstname} ${user.lastname})

' + '
' + '
' + '
' + '' + '
' + '
' + '{{if user.is_block == "Y" }}' + '' + '{{else}}' + '' + '{{/if}}' + '' + '
' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '
' + '' + '
' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); $("#btn_user_modify").off('click'); $("#btn_user_modify").on('click', function() { var is_block = $("#modify_is_block:checked").val() != undefined ? $("#modify_is_block:checked").val() : 'N'; var input_obj = { is_block: is_block, grade_id: $('#modify_grade_id').val(), phone: $('#modify_phone').val(), state: $('#modify_state').val(), birth: $('#modify_birth').val(), addr_city: $('#modify_addr_city').val(), addr_street: $('#modify_addr_street').val(), firstname: $('#modify_firstname').val(), lastname: $('#modify_lastname').val(), student_id: $('#modify_student_id').val(), sex: $('#modify_sex').val() } $.ajax({ method: "put", url: "/api/user/"+user_id, data: input_obj }) .done(function( msg ) { //alert('complete modify'); //location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); $("#btn_user_delete").off('click'); $("#btn_user_delete").on('click', function() { $.get('/api/student/delete/'+user_id, function(data, status){ alert(data); }); swal({ title: "Are you sure?", text: '', type: "warning", html: true, allowOutsideClick: true, showCancelButton: true, confirmButtonColor: "#DD6B55", cancelButtonText: "cancel", confirmButtonText: "Yes, delete it!", closeOnConfirm: true }, function(isConfirm){ if(!isConfirm) return; $.ajax({ method: "delete", url: "/api/user/"+user_id }) .done(function( msg ) { location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); }); $("#btn_password_change").off('click'); $("#btn_password_change").on('click', function() { var input_obj = { password: $('#password').val() } $.ajax({ method: "post", url: "/api/user/"+user_id+"/password", data: input_obj }) .done(function( msg ) { location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); // 공통 기능 $('.date-picker').datetimepicker({ pickTime: false, format: 'MM-DD-YYYY' }); }); $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true }); } function getHostRelation(user_id) { var markup = '
'+ '
'+ '
'+ '
'; $("#modal").html(markup); var d1 = $.get('/api/local'); var d2 = $.get('/api/school'); var d3 = $.get('/api/host/' + user_id + '?relation_students=1'); $.when( d1, d2, d3 ).done(function ( v1, v2, v3 ) { var data = { locals: v1[0], schools: v2[0], host: v3[0], }; console.log(data); markup = '
' + '
' + 'Host relation' + '
' + '
' + '
' + '
' + '' + '
' + '

${host.user.lastname}, ${host.user.firstname}
( ${host.user.email} )

' + '
' + '
' + '
' + '' + '
' + '
' + '' + '
' + '
' + '
' + '' + '
' + '{{for(var j=0,cnt_j=locals.length;j' + '${locals[j].inputFirstName} ${locals[j].inputLastName} | ${locals[j].inputAddrState}
( ${locals[j].inputEmail} )' +'

' +'{{/if}}' + '{{/for}}' + '
' + '
' + '
' + '' + '
' + '{{for(var j=0,cnt_j=schools.length;j${schools[j].school_name}

' + '{{/if}}' + '{{if host.school1_id == schools[j].id }}' + '

${schools[j].school_name}

' + '{{/if}}' + '{{if host.school2_id == schools[j].id }}' + '

${schools[j].school_name}

' + '{{/if}}' + '{{/for}}' + '
' + '
' + '
' + '' + '
' + '
' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); $("#search_student").off('keyup'); $("#search_student").on('keyup', function() { if($(this).val() == '') { $("#search_student_list").html(''); return; } $.get('/api/student?sl_search=email&sl_keyword='+$(this).val(), function(data) { var student_markup = '
  • ' + '${email}' + '
  • '; $.template( "template", student_markup ); $("#search_student_list").html($.tmpl( "template", data.data )); $("#search_student_list").show(); $(".btn_student_add").off('click'); $(".btn_student_add").on('click', function() { $(".tm-input").tagsManager('pushTag', $(this).text()); }); }); }); var prefilled = []; var host_student_user_email=''; for(var i=0;i( '+data.host.students[i].user.email+' )'+'\r\n\r\n'; } $("#search_student_list_string").html(host_student_user_email); $(".tm-input").tagsManager({ tagsContainer: '.tags', prefilled: prefilled, tagClass: 'tm-tag-info', }); $("#search_student").off('focusout'); $("#search_student").on('focusout', function() { setTimeout(function() { $("#search_student_list").hide(); }, 300); }); $("#search_student").off('focus'); $("#search_student").on('focus', function() { if($(this).val() != '') { $("#search_student_list").show(); } }); $("#btn_relation_modify").off('click'); $("#btn_relation_modify").on('click', function() { var input_obj = { school_id: $('#school_id').val(), local_id: $('#relation_lc_id').val(), student_email: $(".tm-input").tagsManager('tags'), } $.ajax({ method: "post", url: "/api/host/"+user_id+"/student", data: input_obj }) .done(function( msg ) { location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); }); // Inline Admin-Form example $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true }); } function changeHostStatus(this_obj, user_id) { var markup = '
    '+ '
    '+ '
    '+ '
    '; $("#modal").html(markup); $.get('/api/host/' + user_id, function(data) { console.log(data); markup = '
    ' + '
    ' + '

    ${user.email}

    ' + '

    (${user.firstname} ${user.lastname})

    ' + '
    ' + '
    ' + '
    ' + '{{if host_status == "Application"}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if host_status == "CBC"}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if host_status == "Agreement"}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if host_status == "Present HF"}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if host_status == "Selection By Student"}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if host_status == "Home visit"}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if host_status == "PC"}}' + '' + '{{else}}' + '' + '{{/if}}' + '
    ' + '
    ' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); $(".btn_status_select").off('click'); $(".btn_status_select").on('click', function() { var obj = $(this); $(".btn_status_select").removeClass('btn-dark').addClass('btn-default'); obj.removeClass('btn-default').addClass('btn-dark'); $.ajax({ method: "put", url: "/api/host/"+user_id, data: {'host_status':obj.attr('data-value')} }) .success(function( msg ) { this_obj.removeClass('btn-system').removeClass('btn-cbc').removeClass('btn-agree').removeClass('btn-phf').removeClass('btn-sbs').removeClass('btn-hv').removeClass('btn-pc'); if(obj.attr('data-value') == 'Application') { this_obj.attr('data-value', 'Application').addClass('btn-system').text('Application'); } else if(obj.attr('data-value') == 'CBC') { this_obj.attr('data-value', 'CBC').addClass('btn-cbc').text('CBC'); } else if(obj.attr('data-value') == 'Agreement') { this_obj.attr('data-value', 'Agreement').addClass('btn-agree').text('Agreement'); } else if(obj.attr('data-value') == 'Present HF') { this_obj.attr('data-value', 'Present HF').addClass('btn-phf').text('Present HF'); } else if(obj.attr('data-value') == 'Selection By Student') { this_obj.attr('data-value', 'Selection By Student').addClass('btn-sbs').text('Selection By Student'); } else if(obj.attr('data-value') == 'Home visit') { this_obj.attr('data-value', 'Home visit').addClass('btn-hv').text('Home visit'); } else if(obj.attr('data-value') == 'PC') { this_obj.attr('data-value', 'PC').addClass('btn-pc').text('PC'); } $.magnificPopup.close(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); }); // Inline Admin-Form example $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true }); } function changeStudentStatus(this_obj, user_id) { var markup = '
    '+ '
    '+ '
    '+ '
    '; $("#modal").html(markup); $.get('/api/student/' + user_id, function(data) { console.log(data); markup = '
    ' + '
    ' + '

    ${user.email}

    ' + '

    (${user.firstname} ${user.lastname})

    ' + '
    ' + '
    ' + '
    ' + '
    ' + '{{if status_new > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if status_reentry > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if status_application > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if status_invoice > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '
    ' + '
    ' + '{{if status_pc > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if status_flight > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if status_changehf > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if status_finished > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '
    ' + '
    ' + '{{if status_springsemester > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if status_fallsemester > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if status_warning > 0}}' + '' + '{{else}}' + '' + '{{/if}}' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); $(".btn_status_select").off('click'); $(".btn_status_select").on('click', function() { var obj = $(this); //$(".btn_status_select").removeClass('btn-dark').addClass('btn-default'); if(obj.hasClass('btn-default')) { obj.removeClass('btn-default'); obj.addClass('btn-dark'); } else if(obj.hasClass('btn-dark')) { obj.removeClass('btn-dark'); obj.addClass('btn-default'); } }); $(".btn_status_save").off('click'); $(".btn_status_save").on('click', function() { var input = { status_new: 0, status_reentry: 0, status_application: 0, status_invoice: 0, status_pc: 0, status_flight: 0, status_changehf: 0, status_finished: 0, status_springsemester: 0, status_fallsemester: 0, status_warning: 0 } $(".btn_status_select.btn-dark").each(function( index ) { if($(this).attr('data-value') == 'new') { input.status_new = 1; } if($(this).attr('data-value') == 'reentry') { input.status_reentry = 1; } if($(this).attr('data-value') == 'application') { input.status_application = 1; } if($(this).attr('data-value') == 'invoice') { input.status_invoice = 1; } if($(this).attr('data-value') == 'pc') { input.status_pc = 1; } if($(this).attr('data-value') == 'flight') { input.status_flight = 1; } if($(this).attr('data-value') == 'changehf') { input.status_changehf = 1; } if($(this).attr('data-value') == 'finished') { input.status_finished = 1; } if($(this).attr('data-value') == 'springsemester') { input.status_springsemester = 1; } if($(this).attr('data-value') == 'fallsemester') { input.status_fallsemester = 1; } if($(this).attr('data-value') == 'warning') { input.status_warning = 1; } }); $.ajax({ method: "put", url: "/api/student/"+user_id+"/status", data: input }) .success(function( msg ) { location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); }); // Inline Admin-Form example $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true }); } function changeStudentDocumentStatus(this_obj, user_id) { var markup = '
    '+ '
    '+ '
    '+ '
    '; $("#modal").html(markup); $.get('/api/student/' + user_id, function(data) { console.log(data); markup = '
    ' + '
    ' + '

    ${user.email}

    ' + '

    (${user.firstname} ${user.lastname})

    ' + '
    ' + '
    ' + '
    ' + '{{if document_status == "process"}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if document_status == "completed"}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if document_status == "cancelled"}}' + '' + '{{else}}' + '' + '{{/if}}' + '{{if document_status == "edited"}}' + '' + '{{else}}' + '' + '{{/if}}' + '
    ' + '
    ' + '
    ' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); $(".btn_status_select").off('click'); $(".btn_status_select").on('click', function() { var obj = $(this); $(".btn_status_select").removeClass('btn-dark').addClass('btn-default'); obj.removeClass('btn-default').addClass('btn-dark'); console.log(obj.attr('data-value')); $.ajax({ method: "put", url: "/api/student/"+user_id+"/document_status", data: {'document_status':obj.attr('data-value')} }) .success(function( msg ) { this_obj.attr('data-value', obj.attr('data-value')).text(ucfirst(obj.attr('data-value'))); $.magnificPopup.close(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); }); // Inline Admin-Form example $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true }); } function getStudentRelation(user_id) { var markup = '
    '+ '
    '+ '
    '+ '
    '; $("#modal").html(markup); var d1 = $.get('/api/local'); var d2 = $.get('/api/host'); var d3 = $.get('/api/agency'); var d4 = $.get('/api/school'); var d5 = $.get('/api/student/'+user_id); var d6 = $.get('/api/parent'); var d7 = $.get('/api/sa'); $.when( d1, d2, d3, d4, d5, d6 ,d7).done(function ( v1, v2, v3, v4, v5, v6 ,v7) { var data = { locals: v1[0], hosts: v2[0], agencies: v3[0], schools: v4[0], student: v5[0], parents: v6[0], sas: v7[0], }; console.log(data); markup = '
    ' + '
    ' + 'Student relation' + '
    ' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '

    ${student.user.lastname}, ${student.user.firstname}
    ( ${student.user.email} )

    ' + '
    ' + '
    ' /* + '
    ' + '' + '
    ' + '' + '
    ' + '
    ' */ + '
    ' + '' + '
    ' + '{{for(j=0,j_cnt=hosts.length;j${hosts[j].user.firstname} ${hosts[j].user.lastname} | ${hosts[j].selectAddrState}
    ( ${hosts[j].user.email} )

    ' + '{{/if}}' + '{{/for}}' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '{{for(j=0,j_cnt=locals.length;j${locals[j].inputFirstName} ${locals[j].inputLastName} | ${locals[j].inputAddrState}
    ( ${locals[j].inputEmail} )

    ' + '{{/if}}' + '{{/for}}' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); //$(".select2-single").select2(); $("#btn_student_relation_modify").off('click'); $("#btn_student_relation_modify").on('click', function() { var input_obj = { school_id: $('#relation_school_id').val(), agency_id: $('#relation_agency_id').val(), parent_id: $('#relation_parent_id').val(), sa_id: $('#relation_sa_id').val(), } $.ajax({ method: "post", url: "/api/student/"+user_id+"/relation", data: input_obj }) .done(function( msg ) { location.reload(); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); }); $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source. }); } function getLocalRelation(user_id) { var markup = '
    '+ '
    '+ '
    '+ '
    '; $("#modal").html(markup); var d1 = $.get('/api/local/' + user_id); $.when( d1 ).done(function ( v1 ) { var data = { local: v1, }; console.log(data); markup = '
    ' + '
    ' + 'Local relation' + '
    ' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '

    ${local.user.email}

    ' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '
    ' + '' + '
    ' + '' + '' + '' + '
    ' + '
    ' + '
    ' + '' + '' + '
    ' + '
    ' + '
    ' + '
    ' + ''; $.template( "template", markup ); $("#modal").html($.tmpl( "template", data )); $("#search_student").off('keyup'); $("#search_student").on('keyup', function() { if($(this).val() == '') { $("#search_student_list").html(''); return; } $.get('/api/student?sl_search=email&sl_keyword='+$(this).val(), function(data) { var student_markup = '
  • ' + '${email}' + '
  • '; $.template( "template", student_markup ); $("#search_student_list").html($.tmpl( "template", data.data )); $("#search_student_list").show(); $(".btn_student_add").off('click'); $(".btn_student_add").on('click', function() { //btn_student_add 일경우 기존 LC 와 연결관계가 있는지 파악 $(".tm-input").tagsManager('pushTag', $(this).text()); var input_obj={ student_email : $(this).text() } $.ajax({ method: "post", url: '/api/student/relation/check/lc', data: input_obj }) .done(function( msg ) { //location.reload(); if(msg['msg']=='EMPTY'){ } if(msg['msg']=='HAVE'){ var swal_text="This student is related with LC "+'('+msg['relation_email']+'). If you want to add this student, you have to disconnect it first.'; $(".tm-input").tagsManager('popTag'); swal({ title: "WARNING", text: swal_text, type: "warning", html: true, allowOutsideClick: true, showCancelButton: false, confirmButtonText: "OK", closeOnConfirm: true }, function(isConfirm){ return; }); } }) .fail(function( a ) { //alert(a.responseJSON.msg); console.log(a); }); }); }); }); var prefilled = []; for(var i=0;i${email}' + ''; $.template( "template", student_markup ); $("#search_host_list").html($.tmpl( "template", data.data )); $("#search_host_list").show(); $(".btn_host_add").off('click'); $(".btn_host_add").on('click', function() { //btn_host_add 일경우 기존 LC 와 연결관계가 있는지 파악 $(".tm-input2").tagsManager('pushTag', $(this).text()); var input_obj={ host_email : $(this).text() } $.ajax({ method: "post", url: '/api/host/relation/check/lc', data: input_obj }) .done(function( msg ) { //location.reload(); if(msg['msg']=='EMPTY'){ } else if(msg['msg']=='HAVE'){ $(".tm-input2").tagsManager('popTag'); var swal_text="This host is related with LC "+'('+msg['relation_email']+'). If you want to add this host, you have to disconnect it first.'; swal({ title: "WARNING", text: swal_text, type: "warning", html: true, allowOutsideClick: true, showCancelButton: false, confirmButtonText: "OK", closeOnConfirm: true }, function(isConfirm){ return; }); } }) .fail(function( a ) { //alert(a.responseJSON.msg); console.log(a); }); }); }); }); var prefilled2 = []; for(var i=0;i'; if(data.local.hosts.length!=0){ add_code+=''; } add_code+=''; //btn-primary } //code add $("#relation_tbody").empty(); $("#relation_tbody").append(add_code); $('select').on('change', function () { $(this).parent().parent().children("td:eq(2)").children("button").addClass("btn-primary"); $(this).parent().parent().children("td:eq(2)").children("button").removeClass("btn-default"); $(this).parent().parent().children("td:eq(2)").children("button").css("cursor","pointer"); $(this).parent().parent().children("td:eq(2)").children("button").removeAttr('disabled'); }); $('.btn-default').on('click',function(){ var student_email_relation=$(this).parent().parent().children("td:eq(0)").text(); var host_id_relation=$(this).parent().parent().children("td:eq(1)").children('select').val(); if(host_id_relation=="") { host_id_relation=0; console.log("empty host"); } console.log($(this).parent().parent().children("td:eq(0)").text()); console.log($(this).parent().parent().children("td:eq(1)").children('select').val()); console.log($(this)); var $button_modify=$(this); var input_obj = { student_email: student_email_relation } $.ajax({ method: "post", url: "/api/host/"+host_id_relation+"/student", data: input_obj }) .done(function( msg ) { //location.reload(); $button_modify.addClass('btn-default'); $button_modify.removeClass('btn-primary'); $button_modify.attr('disabled','disabled'); //저장완료되면 다시 button disabled하기 }) .fail(function( a ) { //alert(a.responseJSON.msg); console.log(a); }); }); }); $("#btn_tab_lc_relation_hf_student").siblings("li").removeClass('active'); $("#btn_tab_lc_relation_hf_student").addClass('active'); $("#lc_relation_student_section").hide(); $("#lc_relation_hf_section").hide(); $("#lc_relation_hf_student_section").show(); $("#btn_relation_modify").hide(); }); $("#btn_relation_modify").off('click'); $("#btn_relation_modify").on('click', function() { if($('#btn_tab_lc_relation_student').hasClass("active")){ var input_obj = { index : 1, student_email: $(".tm-input").tagsManager('tags'), } console.log("this is student tab"); } else if($('#btn_tab_lc_relation_hf').hasClass("active")){ var input_obj = { index : 2, host_email: $(".tm-input2").tagsManager('tags'), } console.log("this is host tab"); } else{ var input_obj = { index :3, student_email: $(".tm-input").tagsManager('tags'), host_email: $(".tm-input2").tagsManager('tags'), } } $.ajax({ method: "post", url: "/api/local/"+user_id, data: input_obj }) .done(function( msg ) { //location.reload(); alert("saved."); }) .fail(function( a ) { alert(a.responseJSON.msg); }); }); }); // Inline Admin-Form example $.magnificPopup.open({ items: { src: '#modal' }, callbacks: { beforeOpen: function(e) { this.st.mainClass = 'mfp-zoomIn'; } }, midClick: true }); } // Place custom scripts here function ucfirst(str) { var str = str.substring(0, 1).toUpperCase() + str.substring(1, str.length); return str; }