Created
September 16, 2016 19:32
-
-
Save bunlongheng/b1d42cd281f6cae0e16fb4d6016aaa58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
//Edit Mode | |
$('body').on('click', '.account-edit', function () { | |
var id = $(this).data("id"); | |
console.log(id); | |
//Declare Variables | |
fm_switch = $("[name='follow_me_switch_edit']"); | |
fm_input = $("[name='follow_me_input_edit']"); | |
ap_switch = $("[name='auto_provisioning_switch_edit']"); | |
ap_input = $("[name='auto_provisioning_input_edit']"); | |
//Initialize Switches | |
ap_switch.bootstrapSwitch('size', 'mini'); | |
fm_switch.bootstrapSwitch('size', 'mini'); | |
//Dynamically create the modal | |
$('.modal-edit').addClass('account-edit-'+id); | |
$('.modal-edit').find('form').attr("action", '{{ env('APP_URL') }}'+'account/'+id+'/update'); | |
$('.modal-edit').find('form').attr("data-id", id); | |
$("[name='_token']").val($('meta[name="csrf-token"]').attr('value')); | |
$("[name='service_plan_edit']").attr("id", 'service_plan-'+id); | |
$(".service_plan_div").attr("id", 'service_plan_div-'+id); | |
$('.modal-edit').find('form').trigger("reset"); | |
var ajax = $.ajax({url: '/api/account/'+id}); | |
ajax.done(function (account) { | |
console.log(account); | |
var old_customer_type = account.customer_type; | |
//Dynamic Modal | |
$("[name='account_type']").val(account.account_type); | |
$("[name='customer_type']").val(account.customer_type); | |
/*================================= | |
= Follow_me = | |
=================================*/ | |
var ajax = $.ajax({url: '/api/account/'+id+'/follow_me'}); | |
ajax.done(function (data) { | |
//Set the switch | |
if(data.follow_me == null || data.follow_me == false ){ | |
fm_input.val(0); | |
fm_switch.bootstrapSwitch('state', false); | |
}else{ | |
fm_input.val(1); | |
fm_switch.bootstrapSwitch('state', true); | |
} | |
}); | |
//Change | |
fm_switch.on('switchChange.bootstrapSwitch', function (event) { | |
if ($(this).is(':checked')) { | |
fm_input.val(1); | |
}else { | |
fm_input.val(0); | |
} | |
}); | |
$("[name='first_name']").val(account.first_name).addClass('fadeIn'); | |
$("[name='last_name']").val(account.last_name).addClass('fadeIn'); | |
$("[name='email_address']").val(account.email_address).addClass('fadeIn'); | |
$("[name='password']").val(account.password).addClass('fadeIn'); | |
$("[name='address1']").val(account.address1).addClass('fadeIn'); | |
$("[name='address2']").val(account.address2).addClass('fadeIn'); | |
$("[name='city']").val(account.city).addClass('fadeIn'); | |
$("[name='state']").val(account.state).addClass('fadeIn'); | |
$("[name='postal_code']").val(account.postal_code).addClass('fadeIn'); | |
$("[name='nation_code']").val(account.nation_code).addClass('fadeIn'); | |
$("[name='phone1']").val(account.phone1).addClass('fadeIn'); | |
//hidden | |
$("[name='id']").val(id); | |
$("[name='old_customer_type']").val(old_customer_type); | |
}); | |
/*========================================= | |
= Auto Provisioning = | |
=========================================*/ | |
var ajax = $.ajax({url: '/api/account/'+id+'/auto_provisioning'}); | |
ajax.done(function (auto_provisioning) { | |
console.log('auto_provisioning = '+auto_provisioning); | |
if(auto_provisioning == null || auto_provisioning == false ){ | |
ap_input.val(0); | |
ap_switch.bootstrapSwitch('state', false); | |
$('#service_plan_div-'+id).hide(); | |
}else{ | |
ap_input.val(1); | |
ap_switch.bootstrapSwitch('state', true); | |
$('#service_plan_div-'+id).show(); | |
// Set the service plan dd menu | |
var ajax = $.ajax({url: '/api/account/'+id+'/service_plan'}); | |
ajax.done(function (service_plan) { | |
console.log('service_plan = '+ service_plan); | |
$("[name='service_plan_edit']").val(service_plan); | |
}); | |
} | |
}); | |
//On change | |
ap_switch.on('switchChange.bootstrapSwitch', function (event) { | |
if ($(this).is(':checked')) { | |
ap_input.val(1); | |
ap_switch.bootstrapSwitch('state', true); | |
$('#service_plan_div-'+id).show(); | |
// Set the service plan dd menu | |
var ajax = $.ajax({url: '/api/account/'+id+'/service_plan'}); | |
ajax.done(function (service_plan) { | |
console.log('service_plan = '+service_plan); | |
if(service_plan != ''){ | |
$('#service_plan-'+id).val(service_plan); | |
} | |
}); | |
if({{ $count_service_plan }} == 0 ){ | |
$('.account-edit-'+id).modal('hide'); | |
$('body').notificationJs({'position': 2, 'type': 'Error', 'background': '#384049', 'color' : '#FFF', 'message': 'No Service Plan Available', 'timeout': 5000 }); | |
} | |
}else { | |
ap_input.val(0); | |
ap_switch.bootstrapSwitch('state', false); | |
$('#service_plan_div-'+id).hide(); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment