init'
This commit is contained in:
23
assets/admin.js
Normal file
23
assets/admin.js
Normal file
@@ -0,0 +1,23 @@
|
||||
jQuery(function($){
|
||||
// Tabs
|
||||
$('#wzhf .tabs a').on('click', function(e){ e.preventDefault(); var tab=$(this).data('tab'); $('#wzhf .tabs a').removeClass('active'); $(this).addClass('active'); $('#wzhf .tab').hide(); $('#wzhf .tab[data-tab="'+tab+'"]').show(); history.replaceState(null,'','#'+tab); });
|
||||
var hash=location.hash.replace('#',''); if(hash && $('#wzhf .tabs a[data-tab="'+hash+'"]').length){ $('#wzhf .tabs a[data-tab="'+hash+'"]').trigger('click'); } else { $('#wzhf .tabs a').first().trigger('click'); }
|
||||
|
||||
function postTool(op, payload, outEl){
|
||||
$(outEl).removeClass('error').text('Running...');
|
||||
fetch(WZHF.rest, {method:'POST', headers:{'Content-Type':'application/json','X-WP-Nonce':WZHF.nonce}, body: JSON.stringify(Object.assign({op:op}, payload||{}))})
|
||||
.then(r=>r.json().then(data=>({ok:r.ok,status:r.status,data})))
|
||||
.then(res=>{ if(res.ok){ $(outEl).text('✔ ' + (res.data.message || 'OK')); } else { $(outEl).addClass('error').text('✖ ' + (res.data && (res.data.error||res.data.message) || ('HTTP '+res.status))); } })
|
||||
.catch(err=>{ $(outEl).addClass('error').text('✖ ' + err); });
|
||||
}
|
||||
|
||||
$(document).on('click','#btn-reset-map', function(e){ e.preventDefault(); var id=parseInt($('#tool-order-id').val(),10)||0; if(!id) return alert('Укажи Order ID'); postTool('reset_map', {order_id:id}, '#res-reset-map'); });
|
||||
$(document).on('click','#btn-resend-so', function(e){ e.preventDefault(); var id=parseInt($('#tool-order-id').val(),10)||0; if(!id) return alert('Укажи Order ID'); postTool('resend_so', {order_id:id}, '#res-resend-so'); });
|
||||
});
|
||||
|
||||
$(document).on('click','#btn-patch-so-address', function(e){
|
||||
e.preventDefault();
|
||||
var id=parseInt($('#tool-order-id').val(),10)||0;
|
||||
if(!id) return alert('Укажи Order ID');
|
||||
postTool('patch_so_address', {order_id:id}, '#res-patch-so');
|
||||
});
|
||||
Reference in New Issue
Block a user