From aa7d3385ce3dc0685c6c30674dd9b4c737221349 Mon Sep 17 00:00:00 2001 From: Ace Date: Tue, 9 Aug 2016 08:10:51 +0530 Subject: [PATCH] Adding missed role-listing changes --- .../units/cdmf.unit.role.listing/listing.hbs | 13 -- .../public/js/role-listing.js | 152 +++++++++++------- 2 files changed, 90 insertions(+), 75 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.hbs index fc648ff450..acf56f7963 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.hbs @@ -47,19 +47,6 @@ By Role Name - - - - - - - - - diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/public/js/role-listing.js index bee418fd1c..1b0991cb0a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/public/js/role-listing.js @@ -16,10 +16,12 @@ * under the License. */ var loadRoleBasedActionURL = function (action, rolename) { - var href = $("#ast-container").data("app-context") + "role/" + action + "/" + rolename; + var href = $("#ast-container").data("app-context") + "roles/" + action + "?rolename=" + rolename; $(location).attr('href', href); }; +var apiBasePath = "/api/device-mgt/v1.0"; + /** * Following function would execute * when a user clicks on the list item @@ -38,34 +40,34 @@ var loadPaginatedObjects = function (objectGridId, objectGridContainer, objectGr var templateSrc = $(objectGridTemplateSrc).attr("src"); $.template(objectGridId, templateSrc, function (template) { invokerUtil.get(serviceURL, - function (data) { - data = callback(data); - if (data.length > 0 && data != null) { - $('#ast-container').removeClass('hidden'); - $('#role-listing-status').hide(); - for (var i = 0; i < data.viewModel.roles.length; i++) { - data.viewModel.roles[i].adminRole = $("#role-table").data("role"); - } - var content = template(data.viewModel); - $(objectGridContainer).html(content); - if (isInit) { - $('#role-grid').datatables_extended(); - isInit = false; - } - $("#dt-select-all").addClass("hidden"); - $(".icon .text").res_text(0.2); - } else { - $('#ast-container').addClass('hidden'); - $('#role-listing-status-msg').text('No roles are available to be displayed.'); - $('#role-listing-status').show(); - } - - //$(objectGridId).datatables_extended(); - }, function (message) { - $('#ast-container').addClass('hidden'); - $('#role-listing-status-msg').text('Invalid search query. Try again with a valid search ' + - 'query'); - $('#role-listing-status').show(); + function (data) { + data = callback(data); + if (data.length > 0 && data != null) { + $('#ast-container').removeClass('hidden'); + $('#role-listing-status').hide(); + for (var i = 0; i < data.viewModel.roles.length; i++) { + data.viewModel.roles[i].adminRole = $("#role-table").data("role"); + } + var content = template(data.viewModel); + $(objectGridContainer).html(content); + if (isInit) { + $('#role-grid').datatables_extended_serverside_paging(); + isInit = false; + } + $("#dt-select-all").addClass("hidden"); + $(".icon .text").res_text(0.2); + } else { + $('#ast-container').addClass('hidden'); + $('#role-listing-status-msg').text('No roles are available to be displayed.'); + $('#role-listing-status').show(); + } + + //$(objectGridId).datatables_extended(); + }, function (message) { + $('#ast-container').addClass('hidden'); + $('#role-listing-status-msg').text('Invalid search query. Try again with a valid search ' + + 'query'); + $('#role-listing-status').show(); }); }); }; @@ -73,46 +75,72 @@ var loadPaginatedObjects = function (objectGridId, objectGridContainer, objectGr function loadRoles(searchQuery) { var loadingContent = $("#loading-content"); loadingContent.show(); - var serviceURL = "/devicemgt_admin/roles"; - if (searchQuery) { - serviceURL = serviceURL + "/search?filter=" + searchQuery; + + var dataFilter = function(data){ + data = JSON.parse(data); + + var objects = []; + + $(data.roles).each(function( index ) { + objects.push({name: data.roles[index], DT_RowId : "role-" + data.roles[index]}) + }); + + json = { + "recordsTotal": data.count, + "recordsFiltered": data.count, + "data": objects + }; + + return JSON.stringify( json ); } - var callback = function (data) { - if (data != null || data == "null") { - data = JSON.parse(data); - var canRemove = $("#can-remove").val(); - var canEdit = $("#can-edit").val(); - var roles = []; - for(var i=0; i ' + }, + { + class: "fade-edge remove-padding-top", + data: "name", + defaultContent: '' + }, + { + class: "text-right content-fill text-left-on-grid-view no-wrap", + data: null, + render: function ( data, type, row, meta ) { + return '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' } } - return data; + ]; + + var options = { + "placeholder": "Search By Role Name", + "searchKey" : "filter" }; - loadPaginatedObjects("#role-grid", "#ast-container", "#role-listing", serviceURL, callback); + $('#role-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/roles', dataFilter, columns, fnCreatedRow, null, options); + loadingContent.hide(); - var sortableElem = '.wr-sortable'; - $(sortableElem).sortable({ - beforeStop: function () { - var sortedIDs = $(this).sortable('toArray'); - } - }); - $(sortableElem).disableSelection(); + } var modalPopup = ".wr-modalpopup"; @@ -153,7 +181,7 @@ function hidePopup() { */ $("#role-grid").on("click", ".remove-role-link", function () { var role = $(this).data("role"); - var removeRoleAPI = "/devicemgt_admin/roles?rolename=" + role; + var removeRoleAPI = apiBasePath + "/roles/" + role; $(modalPopupContent).html($('#remove-role-modal-content').html()); showPopup();