From b56c92620344ad7b775272a07f6788d4eb88459f Mon Sep 17 00:00:00 2001 From: kamidu Date: Thu, 25 Jan 2018 17:12:25 +0530 Subject: [PATCH 1/4] Fix git issue https://github.com/wso2/product-iots/issues/1629 Fixes wso2/product-iots#1629 --- .../public/js/dataTables.extended.js | 2 ++ .../public/js/dataTables.extended.serversidepaging.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js index 31400687bc..9b533b3e0d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js @@ -239,12 +239,14 @@ $.fn.datatables_extended = function(settings){ thisTable.api().rows().every(function () { $(this.node()).addClass(rowSelectedClass); $(button).html('Deselect All'); + $('.bulk-action-row').addClass('hidden'); }); } else if($(button).html() == 'Deselect All') { thisTable.api().rows().every(function () { $(this.node()).removeClass(rowSelectedClass); $(button).html('Select All'); + $('.bulk-action-row').removeClass('hidden'); }); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js index c79bd99516..02505d97ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -306,12 +306,14 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter thisTable.api().rows().every(function () { $(this.node()).addClass(rowSelectedClass); $(button).html('Deselect All'); + $('.bulk-action-row').addClass('hidden'); }); } else if ($(button).html() == 'Deselect All') { thisTable.api().rows().every(function () { $(this.node()).removeClass(rowSelectedClass); $(button).html('Select All'); + $('.bulk-action-row').removeClass('hidden'); }); } } From 479c76d8977d862253a90ca9489c836d026ade4f Mon Sep 17 00:00:00 2001 From: kamidu Date: Thu, 25 Jan 2018 17:12:25 +0530 Subject: [PATCH 2/4] Fix git issue https://github.com/wso2/product-iots/issues/1629 Fixes wso2/product-iots#1629 --- .../public/js/dataTables.extended.js | 2 ++ .../public/js/dataTables.extended.serversidepaging.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js index 31400687bc..9b533b3e0d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js @@ -239,12 +239,14 @@ $.fn.datatables_extended = function(settings){ thisTable.api().rows().every(function () { $(this.node()).addClass(rowSelectedClass); $(button).html('Deselect All'); + $('.bulk-action-row').addClass('hidden'); }); } else if($(button).html() == 'Deselect All') { thisTable.api().rows().every(function () { $(this.node()).removeClass(rowSelectedClass); $(button).html('Select All'); + $('.bulk-action-row').removeClass('hidden'); }); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js index c79bd99516..02505d97ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -306,12 +306,14 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter thisTable.api().rows().every(function () { $(this.node()).addClass(rowSelectedClass); $(button).html('Deselect All'); + $('.bulk-action-row').addClass('hidden'); }); } else if ($(button).html() == 'Deselect All') { thisTable.api().rows().every(function () { $(this.node()).removeClass(rowSelectedClass); $(button).html('Select All'); + $('.bulk-action-row').removeClass('hidden'); }); } } From 0ad6448c12ea77b17855a471e78e6cab3fe1903c Mon Sep 17 00:00:00 2001 From: kamidu Date: Fri, 26 Jan 2018 10:37:17 +0530 Subject: [PATCH 3/4] improve the java script code of changing the text and visibility Improved the logic in order to remove the unesssary text changes and visibility changes. and fix the code formatting issues found in the code. --- .../public/js/dataTables.extended.js | 134 +++++++++--------- .../dataTables.extended.serversidepaging.js | 20 +-- 2 files changed, 76 insertions(+), 78 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js index 9b533b3e0d..a10ee0a5b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js @@ -19,45 +19,45 @@ /* ======================================================================== * datatables_extended function * ======================================================================== */ -$.fn.datatables_extended = function(settings){ +$.fn.datatables_extended = function (settings) { var elem = $(this); // EMM related function if (InitiateViewOption) { - $(document).on('click','.viewEnabledIcon',InitiateViewOption); + $(document).on('click', '.viewEnabledIcon', InitiateViewOption); } //--- End of EMM related codes /* * 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'); - }else{ + } else { elem.addClass('sorting-disabled'); } $(elem).DataTable( - $.extend({},{ + $.extend({}, { bSortCellsTop: true, responsive: false, autoWidth: false, - dom:'<"dataTablesTop"' + - 'f' + - '<"dataTables_toolbar">' + - '>' + - 'rt' + - '<"dataTablesBottom"' + - 'lip' + - '>', + dom: '<"dataTablesTop"' + + 'f' + + '<"dataTables_toolbar">' + + '>' + + 'rt' + + '<"dataTablesBottom"' + + 'lip' + + '>', language: { searchPlaceholder: 'Search ...', search: '' }, - initComplete: function(){ + initComplete: function () { - this.api().columns().every(function(){ + this.api().columns().every(function () { var column = this; var filterColumn = $('.filter-row th', elem); @@ -74,18 +74,18 @@ $.fn.datatables_extended = function(settings){ ); column - //.search(val ? '^' + val + '$' : '', true, false) + //.search(val ? '^' + val + '$' : '', true, false) .search(val ? val : '', true, false) .draw(); - if (filterColumn.eq(column.index()).hasClass('data-platform')){ - if(val == null || val == undefined || val == ""){ + if (filterColumn.eq(column.index()).hasClass('data-platform')) { + if (val == null || val == undefined || val == "") { $("#operation-bar").hide(); - $( "#operation-guide" ).show(); - $( "#operation-bar" ).addClass("hidden"); - }else{ - $( "#operation-guide" ).hide(); - $( "#operation-bar" ).removeClass("hidden"); + $("#operation-guide").show(); + $("#operation-bar").addClass("hidden"); + } else { + $("#operation-guide").hide(); + $("#operation-bar").removeClass("hidden"); $("#operation-bar").show(); //TODO: Enable after adding iot operations bar //loadOperationBar(val); @@ -121,7 +121,7 @@ $.fn.datatables_extended = function(settings){ filterColumn.eq(column.index()).find('input').on('keyup change', function () { column.search($(this).val()).draw(); - if($('.dataTables_empty').length > 0) { + if ($('.dataTables_empty').length > 0) { $('.bulk-action-row').addClass("hidden"); } else { $('.bulk-action-row').removeClass("hidden"); @@ -141,7 +141,7 @@ $.fn.datatables_extended = function(settings){ * create sorting dropdown menu for list table advance operations */ var table = this; - if(table.hasClass('sorting-enabled')){ + if (table.hasClass('sorting-enabled')) { var dropdownmenu = $(''); $('.sort-row th', elem).each(function () { if (!$(this).hasClass('no-sort')) { @@ -150,25 +150,25 @@ $.fn.datatables_extended = function(settings){ }); } - function getAdvanceToolBar(){ + function getAdvanceToolBar() { if (!table.hasClass('no-toolbar')) { if (table.hasClass('sorting-enabled')) { return '' + '
  • ' + + '
  • ' + + '
  • ' + + '
  • ' + + '
  • ' + dropdownmenu[0].outerHTML + '
  • ' + + '' } else { return '' + '
  • ' + + '
  • ' + + '
  • ' + + '
  • ' + + '' } - }else{ + } else { return ''; } } @@ -184,22 +184,22 @@ $.fn.datatables_extended = function(settings){ /** * 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'); var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); if (!($(this).hasClass('sorting_asc')) && !($(this).hasClass('sorting_desc'))) { $(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'); - 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'); - thisTable.fnSort( [ [$(this).attr('data-column'),'asc'] ] ); + thisTable.fnSort([[$(this).attr('data-column'), 'asc']]); } }); @@ -216,46 +216,44 @@ $.fn.datatables_extended = function(settings){ $(button).addClass("active").html('Cancel'); $(button).parent().next().children("button").removeClass("disabled"); // EMM related code - $(document).off('click','.viewEnabledIcon'); + $(document).off('click', '.viewEnabledIcon'); //--- End of EMM related codes - } else if ($(button).html() == 'Cancel'){ + } else if ($(button).html() == 'Cancel') { $('.bulk-action-row').addClass('hidden'); thisTable.removeClass("table-selectable"); $(button).addClass("active").html('Select'); $(button).parent().next().children().addClass("disabled"); // EMM related function - $(document).on('click','.viewEnabledIcon',InitiateViewOption); + $(document).on('click', '.viewEnabledIcon', InitiateViewOption); //--- End of EMM related codes } }); /** * 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, thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); - if(!$(button).hasClass('disabled')){ - if($(button).html() == 'Select All') { - thisTable.api().rows().every(function () { - $(this.node()).addClass(rowSelectedClass); - $(button).html('Deselect All'); - $('.bulk-action-row').addClass('hidden'); - }); - } - else if($(button).html() == 'Deselect All') { - thisTable.api().rows().every(function () { - $(this.node()).removeClass(rowSelectedClass); - $(button).html('Select All'); - $('.bulk-action-row').removeClass('hidden'); - }); - } + if ($(button).html() == 'Select All') { + $(button).html('Deselect All'); + $('.bulk-action-row').removeClass('hidden'); + thisTable.api().rows().every(function () { + $(this.node()).addClass(rowSelectedClass); + }); + } + else if ($(button).html() == 'Deselect All') { + $('.bulk-action-row').addClass('hidden'); + $(button).html('Select All'); + thisTable.api().rows().every(function () { + $(this.node()).removeClass(rowSelectedClass); + }); } }); /** * 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'; $(this).toggleClass(rowSelectedClass); if ($('.table-selectable .DTTT_selected').length > 0) { @@ -267,7 +265,7 @@ $.fn.datatables_extended = function(settings){ thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); 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'); } }); @@ -277,8 +275,8 @@ $.fn.datatables_extended = function(settings){ * list table list/grid view toggle function */ var toggleButton = $('[data-click-event=toggle-list-view]'); - toggleButton.click(function(){ - if($(this).attr('data-view') == 'grid') { + toggleButton.click(function () { + if ($(this).attr('data-view') == 'grid') { $(this).closest('.dataTables_wrapper').find('.dataTable').addClass('grid-view'); //$(this).closest('li').hide(); //$(this).closest('li').siblings().show(); @@ -290,7 +288,7 @@ $.fn.datatables_extended = function(settings){ } }); } - },settings) + }, settings) ); }; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js index 02505d97ca..991e082153 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -50,12 +50,12 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter var deviceType; var ownership; - var searching = true; - if (options) { - if (typeof options.searching !== 'undefined') { - searching = options.searching; - } - } + var searching = true; + if (options) { + if (typeof options.searching !== 'undefined') { + searching = options.searching; + } + } //--- End of EMM related codes @@ -303,17 +303,17 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); if (!$(button).hasClass('disabled')) { if ($(button).html() == 'Select All') { + $(button).html('Deselect All'); + $('.bulk-action-row').removeClass('hidden'); thisTable.api().rows().every(function () { $(this.node()).addClass(rowSelectedClass); - $(button).html('Deselect All'); - $('.bulk-action-row').addClass('hidden'); }); } else if ($(button).html() == 'Deselect All') { + $('.bulk-action-row').addClass('hidden'); + $(button).html('Select All'); thisTable.api().rows().every(function () { $(this.node()).removeClass(rowSelectedClass); - $(button).html('Select All'); - $('.bulk-action-row').removeClass('hidden'); }); } } From b086e227eff529607fa4831e753f0e81cdad8380 Mon Sep 17 00:00:00 2001 From: kamidu Date: Fri, 26 Jan 2018 10:42:19 +0530 Subject: [PATCH 4/4] code reformatted to resolve the exsisted code formatting issues --- .../public/js/dataTables.extended.js | 12 ++++++++---- .../js/dataTables.extended.serversidepaging.js | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js index a10ee0a5b5..ed736c01c6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js @@ -117,7 +117,8 @@ $.fn.datatables_extended = function (settings) { } else if (filterColumn.eq(column.index()).hasClass('text-filter')) { var title = filterColumn.eq(column.index()).attr('data-for'); - $(filterColumn.eq(column.index()).empty()).html(''); + $(filterColumn.eq(column.index()).empty()).html(''); filterColumn.eq(column.index()).find('input').on('keyup change', function () { column.search($(this).val()).draw(); @@ -142,10 +143,12 @@ $.fn.datatables_extended = function (settings) { */ var table = this; if (table.hasClass('sorting-enabled')) { - var dropdownmenu = $(''); + var dropdownmenu = $(''); $('.sort-row th', elem).each(function () { if (!$(this).hasClass('no-sort')) { - dropdownmenu.append('
  • ' + $(this).html() + '
  • '); + dropdownmenu.append('
  • ' + $(this).html() + '
  • '); } }); } @@ -266,7 +269,8 @@ $.fn.datatables_extended = function (settings) { thisTable.api().rows().every(function () { 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'); } }); }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js index 991e082153..836bef71cb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -190,7 +190,8 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter }); } else if (filterColumn.eq(column.index()).hasClass('text-filter')) { var title = filterColumn.eq(column.index()).attr('data-for'); - $(filterColumn.eq(column.index()).empty()).html(''); + $(filterColumn.eq(column.index()).empty()).html(''); //noinspection SpellCheckingInspection 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; if (table.hasClass('sorting-enabled')) { - var dropdownmenu = $(''); + var dropdownmenu = $(''); $('.sort-row th', elem).each(function () { if (!$(this).hasClass('no-sort')) { - dropdownmenu.append('
  • ' + $(this).html() + '
  • '); + dropdownmenu.append('
  • ' + $(this).html() + '
  • '); } }); } @@ -335,7 +338,8 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter thisTable.api().rows().every(function () { 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'); } }); });