13. Spring - Adding bootsrap alert and using It call to backend.

Adding bootsrap alert and using It call to backend.

Go to bootboxjs.com and download any alert message JS code and import it to project.


<table id="productsTable" class="table table-condensed table-bordered">


// list of all products for admin
var $productsTable = $('#productsTable');

if($productsTable.length) {
var jsonUrl = window.contextRoot + '/json/data/admin/all/products';
$productsTable.DataTable({
lengthMenu : [ [ 10, 30, 50, -1 ], [ '10 Records', '30 Records', '50 Records', 'ALL' ] ],
pageLength :30,
ajax : {
url : jsonUrl,
dataSrc :''
},
columns : [
{data:'id'},
{data:'code',
bSortable:false,
mRender:function(data,type,row) {
return'<img src="' + window.contextRoot
+ '/resources/images/' + data
+ '.jpg" class="dataTableImg"/>';
}
},
{data :'quantity',
mRender :function(data, type, row) {
if (data <1) {
return'<span style="color:red">Out of Stock!</span>';
}
return data;
}
},
{data :'unitPrice',
mRender :function(data, type, row) {
return'&#8377; ' + data
}
},
{data :'active',
bSortable :false,
mRender :function(data, type, row) {
var str = '';
if(data) {
str += '<label class="switch"><input type="checkbox" value="'+row.id+'" checked="checked"><div class="slider round"></div></label>';

}else {
str += '<label class="switch"><input type="checkbox" value="'+row.id+'"><div class="slider round"></div></label>';
}

return str;
}
},
{data :'id',
bSortable :false,
mRender :function(data, type, row) {
varstr = '';
str += '<a href="'
+ window.contextRoot
+ '/manage/'
+ data
+ '/product" class="btn btn-primary"><span class="glyphicon glyphicon-pencil"></span></a>&#160;';

return str;
}
}
],


initComplete:function () {
var api = this.api();
api.$('.switch input[type="checkbox"]').on('change' , function() {
var dText = (this.checked)?'You want to activate the Product?':'You want to de-activate the Product?';
var checked = this.checked;
var checkbox = $(this);
debugger;
bootbox.confirm({
size:'medium',
title:'Product Activation/Deactivation',
message: dText,
callback:function (confirmed) {
if (confirmed) {
$.ajax({
type:'GET',
url:window.contextRoot + '/manage/product/'+checkbox.prop('value')+'/activation',
timeout :100000,
success :function(data) {
bootbox.alert(data);
},
error :function(e) {
bootbox.alert('ERROR: '+ e);
//display(e);
}
});
}
else {
checkbox.prop('checked', !checked);
}
}
});
});

}
});
}





Comments

Popular posts from this blog

09.Data Binding.

Database - Topics

02. Spring – Creating spring project clone it with GIT step by step.