Merge pull request #1171 from Kamidu/master

Fix git issue https://github.com/wso2/product-iots/issues/1629
revert-70aa11f8
Rasika Perera 7 years ago committed by GitHub
commit 20a7072f90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,45 +19,45 @@
/* ======================================================================== /* ========================================================================
* datatables_extended function * datatables_extended function
* ======================================================================== */ * ======================================================================== */
$.fn.datatables_extended = function(settings){ $.fn.datatables_extended = function (settings) {
var elem = $(this); var elem = $(this);
// EMM related function // EMM related function
if (InitiateViewOption) { if (InitiateViewOption) {
$(document).on('click','.viewEnabledIcon',InitiateViewOption); $(document).on('click', '.viewEnabledIcon', InitiateViewOption);
} }
//--- End of EMM related codes //--- End of EMM related codes
/* /*
* Work around for accessing settings params inside datatable functions * Work around for accessing settings params inside datatable functions
*/ */
if(settings != null && settings.sorting != null && settings.sorting != undefined && settings.sorting){ if (settings != null && settings.sorting != null && settings.sorting != undefined && settings.sorting) {
elem.addClass('sorting-enabled'); elem.addClass('sorting-enabled');
}else{ } else {
elem.addClass('sorting-disabled'); elem.addClass('sorting-disabled');
} }
$(elem).DataTable( $(elem).DataTable(
$.extend({},{ $.extend({}, {
bSortCellsTop: true, bSortCellsTop: true,
responsive: false, responsive: false,
autoWidth: false, autoWidth: false,
dom:'<"dataTablesTop"' + dom: '<"dataTablesTop"' +
'f' + 'f' +
'<"dataTables_toolbar">' + '<"dataTables_toolbar">' +
'>' + '>' +
'rt' + 'rt' +
'<"dataTablesBottom"' + '<"dataTablesBottom"' +
'lip' + 'lip' +
'>', '>',
language: { language: {
searchPlaceholder: 'Search ...', searchPlaceholder: 'Search ...',
search: '' search: ''
}, },
initComplete: function(){ initComplete: function () {
this.api().columns().every(function(){ this.api().columns().every(function () {
var column = this; var column = this;
var filterColumn = $('.filter-row th', elem); var filterColumn = $('.filter-row th', elem);
@ -74,18 +74,18 @@ $.fn.datatables_extended = function(settings){
); );
column column
//.search(val ? '^' + val + '$' : '', true, false) //.search(val ? '^' + val + '$' : '', true, false)
.search(val ? val : '', true, false) .search(val ? val : '', true, false)
.draw(); .draw();
if (filterColumn.eq(column.index()).hasClass('data-platform')){ if (filterColumn.eq(column.index()).hasClass('data-platform')) {
if(val == null || val == undefined || val == ""){ if (val == null || val == undefined || val == "") {
$("#operation-bar").hide(); $("#operation-bar").hide();
$( "#operation-guide" ).show(); $("#operation-guide").show();
$( "#operation-bar" ).addClass("hidden"); $("#operation-bar").addClass("hidden");
}else{ } else {
$( "#operation-guide" ).hide(); $("#operation-guide").hide();
$( "#operation-bar" ).removeClass("hidden"); $("#operation-bar").removeClass("hidden");
$("#operation-bar").show(); $("#operation-bar").show();
//TODO: Enable after adding iot operations bar //TODO: Enable after adding iot operations bar
//loadOperationBar(val); //loadOperationBar(val);
@ -117,11 +117,12 @@ $.fn.datatables_extended = function(settings){
} }
else if (filterColumn.eq(column.index()).hasClass('text-filter')) { else if (filterColumn.eq(column.index()).hasClass('text-filter')) {
var title = filterColumn.eq(column.index()).attr('data-for'); var title = filterColumn.eq(column.index()).attr('data-for');
$(filterColumn.eq(column.index()).empty()).html('<input type="text" class="form-control" placeholder="Search ' + title + '" />'); $(filterColumn.eq(column.index()).empty()).html('<input type="text" class="form-control" ' +
'placeholder="Search ' + title + '" />');
filterColumn.eq(column.index()).find('input').on('keyup change', function () { filterColumn.eq(column.index()).find('input').on('keyup change', function () {
column.search($(this).val()).draw(); column.search($(this).val()).draw();
if($('.dataTables_empty').length > 0) { if ($('.dataTables_empty').length > 0) {
$('.bulk-action-row').addClass("hidden"); $('.bulk-action-row').addClass("hidden");
} else { } else {
$('.bulk-action-row').removeClass("hidden"); $('.bulk-action-row').removeClass("hidden");
@ -141,34 +142,36 @@ $.fn.datatables_extended = function(settings){
* create sorting dropdown menu for list table advance operations * create sorting dropdown menu for list table advance operations
*/ */
var table = this; var table = this;
if(table.hasClass('sorting-enabled')){ if (table.hasClass('sorting-enabled')) {
var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>'); var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list ' +
'add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>');
$('.sort-row th', elem).each(function () { $('.sort-row th', elem).each(function () {
if (!$(this).hasClass('no-sort')) { if (!$(this).hasClass('no-sort')) {
dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() + '">' + $(this).html() + '</a></li>'); dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() +
'">' + $(this).html() + '</a></li>');
} }
}); });
} }
function getAdvanceToolBar(){ function getAdvanceToolBar() {
if (!table.hasClass('no-toolbar')) { if (!table.hasClass('no-toolbar')) {
if (table.hasClass('sorting-enabled')) { if (table.hasClass('sorting-enabled')) {
return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' + return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' + '<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' + '<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' + '<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' + '<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'<li><button class="btn btn-default" data-toggle="dropdown"><i class="fw fw-sort"></i></button>' + dropdownmenu[0].outerHTML + '</li>' + '<li><button class="btn btn-default" data-toggle="dropdown"><i class="fw fw-sort"></i></button>' + dropdownmenu[0].outerHTML + '</li>' +
'</ul>' '</ul>'
} else { } else {
return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' + return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' + '<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' + '<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' + '<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' + '<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'</ul>' '</ul>'
} }
}else{ } else {
return ''; return '';
} }
} }
@ -184,22 +187,22 @@ $.fn.datatables_extended = function(settings){
/** /**
* sorting dropdown menu select function * sorting dropdown menu select function
*/ */
$('.dataTables_wrapper .sort-list li a').click(function() { $('.dataTables_wrapper .sort-list li a').click(function () {
$(this).closest('li').siblings('li').find('a').removeClass('sorting_asc').removeClass('sorting_desc'); $(this).closest('li').siblings('li').find('a').removeClass('sorting_asc').removeClass('sorting_desc');
var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable();
if (!($(this).hasClass('sorting_asc')) && !($(this).hasClass('sorting_desc'))) { if (!($(this).hasClass('sorting_asc')) && !($(this).hasClass('sorting_desc'))) {
$(this).addClass('sorting_asc'); $(this).addClass('sorting_asc');
thisTable.fnSort( [ [$(this).attr('data-column'),'asc'] ] ); thisTable.fnSort([[$(this).attr('data-column'), 'asc']]);
} }
else if($(this).hasClass('sorting_asc')) { else if ($(this).hasClass('sorting_asc')) {
$(this).switchClass('sorting_asc', 'sorting_desc'); $(this).switchClass('sorting_asc', 'sorting_desc');
thisTable.fnSort( [ [$(this).attr('data-column'),'desc'] ] ); thisTable.fnSort([[$(this).attr('data-column'), 'desc']]);
} }
else if($(this).hasClass('sorting_desc')) { else if ($(this).hasClass('sorting_desc')) {
$(this).switchClass('sorting_desc', 'sorting_asc'); $(this).switchClass('sorting_desc', 'sorting_asc');
thisTable.fnSort( [ [$(this).attr('data-column'),'asc'] ] ); thisTable.fnSort([[$(this).attr('data-column'), 'asc']]);
} }
}); });
@ -216,44 +219,44 @@ $.fn.datatables_extended = function(settings){
$(button).addClass("active").html('Cancel'); $(button).addClass("active").html('Cancel');
$(button).parent().next().children("button").removeClass("disabled"); $(button).parent().next().children("button").removeClass("disabled");
// EMM related code // EMM related code
$(document).off('click','.viewEnabledIcon'); $(document).off('click', '.viewEnabledIcon');
//--- End of EMM related codes //--- End of EMM related codes
} else if ($(button).html() == 'Cancel'){ } else if ($(button).html() == 'Cancel') {
$('.bulk-action-row').addClass('hidden'); $('.bulk-action-row').addClass('hidden');
thisTable.removeClass("table-selectable"); thisTable.removeClass("table-selectable");
$(button).addClass("active").html('Select'); $(button).addClass("active").html('Select');
$(button).parent().next().children().addClass("disabled"); $(button).parent().next().children().addClass("disabled");
// EMM related function // EMM related function
$(document).on('click','.viewEnabledIcon',InitiateViewOption); $(document).on('click', '.viewEnabledIcon', InitiateViewOption);
//--- End of EMM related codes //--- End of EMM related codes
} }
}); });
/** /**
* select/deselect all rows function * select/deselect all rows function
*/ */
$('.dataTables_wrapper [data-click-event=toggle-selected]').click(function() { $('.dataTables_wrapper [data-click-event=toggle-selected]').click(function () {
var button = this, var button = this,
thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable();
if(!$(button).hasClass('disabled')){ if ($(button).html() == 'Select All') {
if($(button).html() == 'Select All') { $(button).html('Deselect All');
thisTable.api().rows().every(function () { $('.bulk-action-row').removeClass('hidden');
$(this.node()).addClass(rowSelectedClass); thisTable.api().rows().every(function () {
$(button).html('Deselect All'); $(this.node()).addClass(rowSelectedClass);
}); });
} }
else if($(button).html() == 'Deselect All') { else if ($(button).html() == 'Deselect All') {
thisTable.api().rows().every(function () { $('.bulk-action-row').addClass('hidden');
$(this.node()).removeClass(rowSelectedClass); $(button).html('Select All');
$(button).html('Select All'); thisTable.api().rows().every(function () {
}); $(this.node()).removeClass(rowSelectedClass);
} });
} }
}); });
/** /**
* on row click select/deselect row function * on row click select/deselect row function
*/ */
$('body').on('click', '[data-type=selectable]', function(){ $('body').on('click', '[data-type=selectable]', function () {
var rowSelectedClass = 'DTTT_selected selected'; var rowSelectedClass = 'DTTT_selected selected';
$(this).toggleClass(rowSelectedClass); $(this).toggleClass(rowSelectedClass);
if ($('.table-selectable .DTTT_selected').length > 0) { if ($('.table-selectable .DTTT_selected').length > 0) {
@ -265,8 +268,9 @@ $.fn.datatables_extended = function(settings){
thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable();
thisTable.api().rows().every(function () { thisTable.api().rows().every(function () {
if(!$(this.node()).hasClass(rowSelectedClass)){ if (!$(this.node()).hasClass(rowSelectedClass)) {
$(button).closest('.dataTables_wrapper').find('[data-click-event=toggle-selected]').html('Select All'); $(button).closest('.dataTables_wrapper').find('[data-click-event=toggle-selected]').
html('Select All');
} }
}); });
}); });
@ -275,8 +279,8 @@ $.fn.datatables_extended = function(settings){
* list table list/grid view toggle function * list table list/grid view toggle function
*/ */
var toggleButton = $('[data-click-event=toggle-list-view]'); var toggleButton = $('[data-click-event=toggle-list-view]');
toggleButton.click(function(){ toggleButton.click(function () {
if($(this).attr('data-view') == 'grid') { if ($(this).attr('data-view') == 'grid') {
$(this).closest('.dataTables_wrapper').find('.dataTable').addClass('grid-view'); $(this).closest('.dataTables_wrapper').find('.dataTable').addClass('grid-view');
//$(this).closest('li').hide(); //$(this).closest('li').hide();
//$(this).closest('li').siblings().show(); //$(this).closest('li').siblings().show();
@ -288,7 +292,7 @@ $.fn.datatables_extended = function(settings){
} }
}); });
} }
},settings) }, settings)
); );
}; };

@ -50,12 +50,12 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter
var deviceType; var deviceType;
var ownership; var ownership;
var searching = true; var searching = true;
if (options) { if (options) {
if (typeof options.searching !== 'undefined') { if (typeof options.searching !== 'undefined') {
searching = options.searching; searching = options.searching;
} }
} }
//--- End of EMM related codes //--- End of EMM related codes
@ -190,7 +190,8 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter
}); });
} else if (filterColumn.eq(column.index()).hasClass('text-filter')) { } else if (filterColumn.eq(column.index()).hasClass('text-filter')) {
var title = filterColumn.eq(column.index()).attr('data-for'); var title = filterColumn.eq(column.index()).attr('data-for');
$(filterColumn.eq(column.index()).empty()).html('<input type="text" class="form-control" placeholder="Search ' + title + '" />'); $(filterColumn.eq(column.index()).empty()).html('<input type="text" class="form-control" ' +
'placeholder="Search ' + title + '" />');
//noinspection SpellCheckingInspection //noinspection SpellCheckingInspection
filterColumn.eq(column.index()).find('input').on('keyup', function () { filterColumn.eq(column.index()).find('input').on('keyup', function () {
@ -211,10 +212,12 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter
*/ */
var table = this; var table = this;
if (table.hasClass('sorting-enabled')) { if (table.hasClass('sorting-enabled')) {
var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>'); var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list ' +
'add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>');
$('.sort-row th', elem).each(function () { $('.sort-row th', elem).each(function () {
if (!$(this).hasClass('no-sort')) { if (!$(this).hasClass('no-sort')) {
dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() + '">' + $(this).html() + '</a></li>'); dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() +
'">' + $(this).html() + '</a></li>');
} }
}); });
} }
@ -303,15 +306,17 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter
thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable();
if (!$(button).hasClass('disabled')) { if (!$(button).hasClass('disabled')) {
if ($(button).html() == 'Select All') { if ($(button).html() == 'Select All') {
$(button).html('Deselect All');
$('.bulk-action-row').removeClass('hidden');
thisTable.api().rows().every(function () { thisTable.api().rows().every(function () {
$(this.node()).addClass(rowSelectedClass); $(this.node()).addClass(rowSelectedClass);
$(button).html('Deselect All');
}); });
} }
else if ($(button).html() == 'Deselect All') { else if ($(button).html() == 'Deselect All') {
$('.bulk-action-row').addClass('hidden');
$(button).html('Select All');
thisTable.api().rows().every(function () { thisTable.api().rows().every(function () {
$(this.node()).removeClass(rowSelectedClass); $(this.node()).removeClass(rowSelectedClass);
$(button).html('Select All');
}); });
} }
} }
@ -333,7 +338,8 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter
thisTable.api().rows().every(function () { thisTable.api().rows().every(function () {
if (!$(this.node()).hasClass(rowSelectedClass)) { if (!$(this.node()).hasClass(rowSelectedClass)) {
$(button).closest('.dataTables_wrapper').find('[data-click-event=toggle-selected]').html('Select All'); $(button).closest('.dataTables_wrapper').find('[data-click-event=toggle-selected]').
html('Select All');
} }
}); });
}); });

Loading…
Cancel
Save