Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(".btn-proses").click(function() {
- prosesOpen(true);
- });
- function prosesOpen(event) {
- $.ajax({
- type: 'POST',
- url: get.urlOpen,
- data: {start: event},
- beforeSend: function(){
- disableButton(true);
- $(".pesan").hide();
- },
- success: function(event){
- getJson = $.parseJSON(event);
- if (getJson.persen >= 0) {
- bar(getJson.hasOpen, getJson.total, getJson.proses, getJson.persen);
- statusProses(getJson.countSuccess, getJson.countError, getJson.totalCount);
- if (getJson.persen < 100) {
- prosesOpen();
- } else {
- tampilPesan('Finish .. !!', getJson.message, false);
- disableButton(false);
- }
- }
- },
- error: function (status, exception) {
- getErrorMessage(status, exception);
- disableButton(false);
- bars(0);
- }
- });
- }
- function disableButton(event) {
- if (event === true) {
- $('.btn-proses').attr('disabled', 'disabled');
- $('.btn-kembali').attr('disabled', 'disabled');
- } else {
- $('.btn-proses').removeAttr('disabled');
- $('.btn-kembali').removeAttr('disabled');
- }
- }
- function statusProses(success, error, total) {
- $("#success").html(success);
- $("#error").html(error);
- $("#total").html(total);
- }
- function bar(open, total, proses, persen) {
- $(".progress-bar").css("width",persen+"%");
- $(".progress-number").html("Proses "+open+" dari <strong>"+total+"</strong> ("+persen+"%)");
- }
- function tampilPesan(title, msg, error){
- if (error == true) {
- $(".pesan").attr('class','alert alert-danger pesan');
- } else {
- $(".pesan").attr('class','alert alert-success pesan');
- }
- $(".pesan").show();
- $("#title").html(title);
- $("#isi_pesan").html(msg);
- }
- function getErrorMessage(stat, exception) {
- var msg = '';
- var title = '';
- if (stat.status === 0) {
- msg = stat.responseText;
- title = 'Error '+stat.status;
- } else if (stat.status == 404) {
- msg = stat.responseText;
- title = 'Error '+stat.status;
- } else if (stat.status == 500) {
- msg = stat.responseText;
- title = 'Error '+stat.status;
- } else if (exception === 'parsererror') {
- msg = stat.responseText;
- title = 'Error '+stat.status;
- } else if (exception === 'timeout') {
- msg = stat.responseText;
- title = 'Error '+stat.status;
- } else if (exception === 'abort') {
- msg = stat.responseText;
- title = 'Error '+stat.status;
- } else {
- msg = 'Uncaught Error.\n' + stat.responseText;
- title = 'Error '+stat.status;
- }
- tampilPesan(title, msg, true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement