diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index 6c29b73a401..2ef13959c3a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -1,21 +1,23 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ +var deviceMgtAPIsBasePath = "/api/device-mgt/v1.0"; + /** * Checks if provided input is valid against RegEx input. * @@ -35,10 +37,10 @@ function inputIsValid(regExp, inputString) { $(function () { var sortableElem = '.wr-sortable'; $(sortableElem).sortable({ - beforeStop: function () { - var sortedIDs = $(this).sortable('toArray'); - } - }); + beforeStop: function () { + $(this).sortable('toArray'); + } + }); $(sortableElem).disableSelection(); }); @@ -46,11 +48,9 @@ var modalPopup = ".wr-modalpopup"; var modalPopupContainer = modalPopup + " .modalpopup-container"; var modalPopupContent = modalPopup + " .modalpopup-content"; var body = "body"; -var isInit = true; +//var isInit = true; $(".icon .text").res_text(0.2); -var resetPasswordServiceURL = "/devicemgt_admin/users/reset-password"; - /* * set popup maximum height function. */ @@ -80,11 +80,9 @@ function hidePopup() { */ function getSelectedUsernames() { var usernameList = []; - var userList = $("#user-grid").find('> tbody > tr'); + var userList = $("#user-grid").find('tr.DTTT_selected'); userList.each(function () { - if ($(this).hasClass('DTTT_selected')) { - usernameList.push($(this).attr('data-username')); - } + usernameList.push($(this).data('username')); }); return usernameList; } @@ -96,7 +94,7 @@ function getSelectedUsernames() { */ $("a.invite-user-link").click(function () { var usernameList = getSelectedUsernames(); - var inviteUserAPI = "/devicemgt_admin/users/email-invitation"; + var inviteUserAPI = deviceMgtAPIsBasePath + "/users/send-invitation"; if (usernameList.length == 0) { $(modalPopupContent).html($("#errorUsers").html()); @@ -108,20 +106,25 @@ $("a.invite-user-link").click(function () { $("a#invite-user-yes-link").click(function () { invokerUtil.post( - inviteUserAPI, - usernameList, - function () { + inviteUserAPI, + usernameList, + // The success callback + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { $(modalPopupContent).html($('#invite-user-success-content').html()); $("a#invite-user-success-link").click(function () { hidePopup(); }); - }, - function () { - $(modalPopupContent).html($('#invite-user-error-content').html()); - $("a#invite-user-error-link").click(function () { - hidePopup(); - }); } + }, + // The error callback + function (jqXHR) { + console.log("error in invite-user API, status code: " + jqXHR.status); + $(modalPopupContent).html($('#invite-user-error-content').html()); + $("a#invite-user-error-link").click(function () { + hidePopup(); + }); + } ); }); @@ -137,16 +140,17 @@ $("a.invite-user-link").click(function () { */ function removeUser(uname, uid) { var username = uname; - var userid = uid; - var removeUserAPI = "/devicemgt_admin/users?username=" + username; + var userId = uid; + var removeUserAPI = deviceMgtAPIsBasePath + "/users/" + username; $(modalPopupContent).html($('#remove-user-modal-content').html()); showPopup(); $("a#remove-user-yes-link").click(function () { invokerUtil.delete( - removeUserAPI, - function () { - $("#" + userid).remove(); + removeUserAPI, + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $("#" + userId).remove(); // get new user-list-count var newUserListCount = $(".user-list > span").length; // update user-listing-status-msg with new user-count @@ -156,13 +160,16 @@ function removeUser(uname, uid) { $("a#remove-user-success-link").click(function () { hidePopup(); }); - }, - function () { - $(modalPopupContent).html($('#remove-user-error-content').html()); - $("a#remove-user-error-link").click(function () { - hidePopup(); - }); } + }, + // The error callback + function (jqXHR) { + console.log("error in remove-user API, status code: " + jqXHR.status); + $(modalPopupContent).html($('#remove-user-error-content').html()); + $("a#remove-user-error-link").click(function () { + hidePopup(); + }); + } ); }); @@ -202,29 +209,30 @@ function resetPassword(uname) { $(errorMsgWrapper).removeClass("hidden"); } else { var resetPasswordFormData = {}; - resetPasswordFormData.username = user; - resetPasswordFormData.newPassword = window.btoa(unescape(encodeURIComponent(confirmedPassword))); + //resetPasswordFormData.username = user; + resetPasswordFormData.newPassword = unescape(confirmedPassword); + + var resetPasswordServiceURL = deviceMgtAPIsBasePath + "/admin/users/"+ user +"/credentials"; invokerUtil.post( - resetPasswordServiceURL, - resetPasswordFormData, - function (data) { // The success callback - data = JSON.parse(data); - if (data.statusCode == 201) { - $(modalPopupContent).html($('#reset-password-success-content').html()); - $("a#reset-password-success-link").click(function () { - hidePopup(); - }); - } - }, function (data) { // The error callback - if (data.statusCode == 400) { - $(errorMsg).text("Old password does not match with the provided value."); - $(errorMsgWrapper).removeClass("hidden"); - } else { - $(errorMsg).text("An unexpected error occurred. Please try again later."); - $(errorMsgWrapper).removeClass("hidden"); - } + resetPasswordServiceURL, + resetPasswordFormData, + // The success callback + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $(modalPopupContent).html($('#reset-password-success-content').html()); + $("a#reset-password-success-link").click(function () { + hidePopup(); + }); } + }, + // The error callback + function (jqXHR) { + console.log("error in reset-password API, status code: " + jqXHR.status); + var payload = JSON.parse(jqXHR.responseText); + $(errorMsg).text(payload.message); + $(errorMsgWrapper).removeClass("hidden"); + } ); } }); @@ -250,7 +258,7 @@ $("#search-btn").click(function () { * when a user clicks on the list item * initial mode and with out select mode. */ -function InitiateViewOption() { +function initiateViewOption() { if ($("#can-view").val()) { $(location).attr('href', $(this).data("url")); } else { @@ -259,74 +267,112 @@ function InitiateViewOption() { } } -function loadUsers(searchParam) { - $("#loading-content").show(); - var userListing = $("#user-listing"); - var userListingSrc = userListing.attr("src"); - $.template("user-listing", userListingSrc, function (template) { - var serviceURL = "/devicemgt_admin/users"; - if (searchParam) { - serviceURL = serviceURL + "/view-users?username=" + searchParam; - } - var successCallback = function (data) { - if (!data) { - $('#ast-container').addClass('hidden'); - $('#user-listing-status-msg').text('No users are available to be displayed.'); - return; +function loadUsers() { + var loadingContentIcon = "#loading-content"; + $(loadingContentIcon).show(); + + var dataFilter = function (data) { + data = JSON.parse(data); + + var objects = []; + + $(data.users).each(function (index) { + objects.push({ + username: data.users[index].username, + firstname: data.users[index].firstname ? data.users[index].firstname: '' , + lastname: data.users[index].lastname ? data.users[index].lastname : '', + emailAddress : data.users[index].emailAddress ? data.users[index].emailAddress: '', + DT_RowId : "role-" + data.users[index].username}) + }); + + var json = { + "recordsTotal": data.count, + "recordsFiltered": data.count, + "data": objects + }; + + return JSON.stringify(json); + }; + + var fnCreatedRow = function(nRow, aData, iDataIndex) { + console.log(JSON.stringify(aData)); + $(nRow).attr('data-type', 'selectable'); + $(nRow).attr('data-username', aData["username"]); + }; + + var columns = [ + { + class: "remove-padding icon-only content-fill", + data: null, + defaultContent: + '