From b6c33a0aec41d1df7af5685642b44a7d8ead7311 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Tue, 3 May 2016 19:49:09 +0530 Subject: [PATCH] Fixing group roles listing --- .../cdmf.page.groups/public/js/listing.js | 137 +++++++++--------- 1 file changed, 66 insertions(+), 71 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index 9d4b89a8f0..62944a0636 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -141,24 +141,24 @@ function loadGroups() { render: function ( id, type, row, meta ) { var html; html = '' + - '' + - ''; + '' + + ''; html += '' + - '' + - ''; + '' + + ''; html += '' + - ''; + 'data-group-owner="' + row.owner + '">' + + ''; html += '' + - ''; + 'data-group-owner="' + row.owner + '" data-group-description="' + row.description + '">' + + ''; html += '' + - ''; + 'data-group-owner="' + row.owner + '">' + + ''; return html; }} @@ -221,12 +221,12 @@ $(document).ready(function () { /* for device list sorting drop down */ $(".ctrl-filter-type-switcher").popover( - { - html: true, - content: function () { - return $("#content-filter-types").html(); - } + { + html: true, + content: function () { + return $("#content-filter-types").html(); } + } ); /* for data tables*/ @@ -235,20 +235,20 @@ $(document).ready(function () { $("[data-toggle=popover]").popover(); $(".ctrl-filter-type-switcher").popover( - { - html: true, - content: function () { - return $('#content-filter-types').html(); - } + { + html: true, + content: function () { + return $('#content-filter-types').html(); } + } ); $('#nav').affix( - { - offset: { - top: $('header').height() - } + { + offset: { + top: $('header').height() } + } ); }); @@ -301,12 +301,12 @@ function attachEvents() { showPopup(); $("a#share-group-next-link").hide(); var userRequest = $.ajax( - { - url: "api/user/all", - method: "GET", - contentType: "application/json", - accept: "application/json" - } + { + url: "api/user/all", + method: "GET", + contentType: "application/json", + accept: "application/json" + } ); userRequest.done(function (data, txtStatus, jqxhr) { var users = JSON.parse(data); @@ -360,23 +360,23 @@ function attachEvents() { showPopup(); $("a#remove-group-yes-link").click(function () { - var successCallback = function (data) { + var successCallback = function (data, textStatus, xhr) { data = JSON.parse(data); - if (data.status == 200) { + if (xhr.status == 200) { $(modalPopupContent).html($('#remove-group-200-content').html()); setTimeout(function () { hidePopup(); location.reload(false); }, 2000); } else { - displayErrors(status); + displayErrors(xhr); } }; invokerUtil.delete("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName, - successCallback, function (message) { - displayErrors(message.content); - }); + successCallback, function (message) { + displayErrors(message.content); + }); }); $("a#remove-group-cancel-link").click(function () { @@ -405,22 +405,22 @@ function attachEvents() { var newGroupDescription = $('#edit-group-description').val(); var group = {"name": newGroupName, "description": newGroupDescription, "owner": groupOwner}; - var successCallback = function (data) { + var successCallback = function (data, textStatus, xhr) { data = JSON.parse(data); - if (data.status == 200) { + if (xhr.status == 200) { setTimeout(function () { hidePopup(); location.reload(false); }, 2000); } else { - displayErrors(status); + displayErrors(xhr); } }; invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName, group, - successCallback, function (message) { - displayErrors(message.content); - }); + successCallback, function (message) { + displayErrors(message.content); + }); }); $("a#edit-group-cancel-link").click(function () { @@ -433,23 +433,23 @@ function getAllRoles(groupName, groupOwner, selectedUser) { $(modalPopupContent).html($('#share-group-w2-modal-content').html()); $('#user-roles').html('
'); $("a#share-group-yes-link").hide(); - var successCallback = function (data) { + var successCallback = function (data, textStatus, xhr) { data = JSON.parse(data); - if (data.status == 200) { - if (data.data.length > 0) { - generateRoleMap(groupName, groupOwner, selectedUser, data.data); + if (xhr.status == 200) { + if (data.length > 0) { + generateRoleMap(groupName, groupOwner, selectedUser, data); } else { $('#user-roles').html("There is no any roles for this group."); } } else { - displayErrors(status); + displayErrors(xhr); } }; invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles", - successCallback, function (message) { - displayErrors(message.content); - }); + successCallback, function (message) { + displayErrors(message.content); + }); $("a#share-group-w2-cancel-link").click(function () { hidePopup(); @@ -457,10 +457,10 @@ function getAllRoles(groupName, groupOwner, selectedUser) { } function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) { - var successCallback = function (data) { + var successCallback = function (data, textStatus, xhr) { data = JSON.parse(data); - if (data.status == 200) { - var userRoles = data.data; + if (xhr.status == 200) { + var userRoles = data; var roleMap = []; var str = ''; var isChecked = ''; @@ -474,20 +474,15 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) { break; } } + roleMap.push(objRole); str += '    '; - roleMap.push(objRole); } $('#user-roles').html(str); $("a#share-group-yes-link").show(); - var isOngoing; + $("a#share-group-yes-link").show(); $("a#share-group-yes-link").click(function () { - if (isOngoing) { - return false; - } - $("a#share-group-yes-link").html("Wait..."); - isOngoing = true; for (var role in roleMap) { if ($('#user-role-' + roleMap[role].role).is(':checked') != roleMap[role].assigned) { roleMap[role].assigned = $('#user-role-' + roleMap[role].role).is(':checked'); @@ -496,14 +491,14 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) { } }); } else { - displayErrors(status); + displayErrors(xhr); } }; invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles?userName=" + selectedUser, - successCallback, function (message) { - displayErrors(message.content); - }); + successCallback, function (message) { + displayErrors(message.content); + }); $("a#share-group-w2-cancel-link").click(function () { hidePopup(); @@ -511,9 +506,9 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) { } function updateGroupShare(groupName, groupOwner, selectedUser, role) { - var successCallback = function (data) { + var successCallback = function (data, textStatus, xhr) { data = JSON.parse(data); - var status = data.status; + var status = xhr.status; if (status == 200) { $(modalPopupContent).html($('#share-group-200-content').html()); setTimeout(function () { @@ -521,14 +516,14 @@ function updateGroupShare(groupName, groupOwner, selectedUser, role) { location.reload(false); }, 2000); } else { - displayErrors(status); + displayErrors(xhr); } }; invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles?userName=" + selectedUser, - role, successCallback, function (message) { - displayErrors(message.content); - }); + role, successCallback, function (message) { + displayErrors(message.content); + }); } function displayErrors(jqXHR) { @@ -555,4 +550,4 @@ function displayErrors(jqXHR) { }); console.log("Error code: " + jqXHR.status); } -} +} \ No newline at end of file