Updating User Listing UI

merge-requests/7/head
dilanua 8 years ago
parent 32fc58c917
commit 6f28bf1d94

@ -32,7 +32,7 @@ $(function () {
var sortableElem = '.wr-sortable'; var sortableElem = '.wr-sortable';
$(sortableElem).sortable({ $(sortableElem).sortable({
beforeStop: function () { beforeStop: function () {
var sortedIDs = $(this).sortable('toArray'); $(this).sortable('toArray');
} }
}); });
$(sortableElem).disableSelection(); $(sortableElem).disableSelection();
@ -43,7 +43,6 @@ var modalPopup = ".wr-modalpopup";
var modalPopupContainer = modalPopup + " .modalpopup-container"; var modalPopupContainer = modalPopup + " .modalpopup-container";
var modalPopupContent = modalPopup + " .modalpopup-content"; var modalPopupContent = modalPopup + " .modalpopup-content";
var body = "body"; var body = "body";
var isInit = true;
$(".icon .text").res_text(0.2); $(".icon .text").res_text(0.2);
/* /*
@ -137,17 +136,15 @@ function removeUser(uname) {
$("a#remove-user-yes-link").click(function () { $("a#remove-user-yes-link").click(function () {
invokerUtil.delete( invokerUtil.delete(
removeUserAPI, removeUserAPI,
function () { function (data, textStatus, jqXHR) {
$("#role-" + username).remove(); if (jqXHR.status == 200) {
// get new user-list-count $("#user-" + username).remove();
var newUserListCount = $(".user-list > span").length; // update modal-content with success message
// update user-listing-status-msg with new user-count $(modalPopupContent).html($('#remove-user-success-content').html());
$("#user-listing-status-msg").text("Total number of Users found : " + newUserListCount); $("a#remove-user-success-link").click(function () {
// update modal-content with success message hidePopup();
$(modalPopupContent).html($('#remove-user-success-content').html()); });
$("a#remove-user-success-link").click(function () { }
hidePopup();
});
}, },
function () { function () {
$(modalPopupContent).html($('#remove-user-error-content').html()); $(modalPopupContent).html($('#remove-user-error-content').html());
@ -202,14 +199,17 @@ function resetPassword(uname) {
invokerUtil.post( invokerUtil.post(
resetPasswordServiceURL, resetPasswordServiceURL,
resetPasswordFormData, resetPasswordFormData,
function (data, textStatus, jqXHR) { // The success callback // The success callback
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200) { if (jqXHR.status == 200) {
$(modalPopupContent).html($('#reset-password-success-content').html()); $(modalPopupContent).html($('#reset-password-success-content').html());
$("a#reset-password-success-link").click(function () { $("a#reset-password-success-link").click(function () {
hidePopup(); hidePopup();
}); });
} }
}, function (jqXHR) { // The error callback },
// The error callback
function (jqXHR) {
var payload = JSON.parse(jqXHR.responseText); var payload = JSON.parse(jqXHR.responseText);
$(errorMsg).text(payload.message); $(errorMsg).text(payload.message);
$(errorMsgWrapper).removeClass("hidden"); $(errorMsgWrapper).removeClass("hidden");
@ -223,17 +223,6 @@ function resetPassword(uname) {
}); });
} }
/**
* Following on click function would execute
* when a user type on the search field on User Listing page in
* WSO2 MDM Console then click on the search button.
*/
//$("#search-btn").click(function () {
// var searchQuery = $("#search-by-username").val();
// $("#ast-container").empty();
// loadUsers(searchQuery);
//});
/** /**
* Following function would execute * Following function would execute
* when a user clicks on the list item * when a user clicks on the list item
@ -260,9 +249,9 @@ function loadUsers() {
$(data.users).each( function (index) { $(data.users).each( function (index) {
objects.push({ objects.push({
filter: data.users[index].username, filter: data.users[index].username,
firstname: data.users[index].firstname ? data.users[index].firstname : '' , firstname: data.users[index].firstname ? data.users[index].firstname : "" ,
lastname: data.users[index].lastname ? data.users[index].lastname : '', lastname: data.users[index].lastname ? data.users[index].lastname : "",
emailAddress : data.users[index].emailAddress ? data.users[index].emailAddress : '', emailAddress : data.users[index].emailAddress ? data.users[index].emailAddress : "",
DT_RowId : "user-" + data.users[index].username}) DT_RowId : "user-" + data.users[index].username})
}); });
@ -294,28 +283,36 @@ function loadUsers() {
class: "fade-edge", class: "fade-edge",
data: null, data: null,
render: function (data, type, row, meta) { render: function (data, type, row, meta) {
return '<h4>' + data.firstname + ' ' + data.lastname + '</h4>'; if (!data.firstname && !data.lastname) {
return "";
} else if (data.firstname && data.lastname) {
return "<h4>&nbsp;&nbsp;" + data.firstname + " " + data.lastname + "</h4>";
}
} }
}, },
{ {
class: "fade-edge remove-padding-top", class: "fade-edge remove-padding-top",
data: 'filter', data: 'filter',
render: function (filter, type, row, meta) { render: function (filter, type, row, meta) {
return '<i class="fw-user"></i> ' + filter; return '&nbsp;&nbsp;<i class="fw-user"></i>&nbsp;&nbsp;' + filter;
} }
}, },
{ {
class: "fade-edge remove-padding-top", class: "fade-edge remove-padding-top",
data: null, data: null,
render: function (data, type, row, meta) { render: function (data, type, row, meta) {
return '<a href="mailto:' + data.emailAddress + ' " class="wr-list-email"> <i class="fw-mail"></i> ' + data.emailAddress + ' </a>'; if (!data.emailAddress) {
return "";
} else {
return "&nbsp;&nbsp;<a href='mailto:" + data.emailAddress + "' ><i class='fw-mail'></i>&nbsp;&nbsp;" + data.emailAddress + "</a>";
}
} }
}, },
{ {
class: "text-right content-fill text-left-on-grid-view no-wrap", class: "text-right content-fill text-left-on-grid-view no-wrap",
data: null, data: null,
render: function (data, type, row, meta) { render: function (data, type, row, meta) {
return '<a href="/emm/user/edit?username=' + data.filter + '" data-username="' + data.filter + '" ' + return '&nbsp;<a href="/emm/user/edit?username=' + data.filter + '" data-username="' + data.filter + '" ' +
'data-click-event="edit-form" ' + 'data-click-event="edit-form" ' +
'class="btn padding-reduce-on-grid-view edit-user-link"> ' + 'class="btn padding-reduce-on-grid-view edit-user-link"> ' +
'<span class="fw-stack"> ' + '<span class="fw-stack"> ' +
@ -360,70 +357,8 @@ function loadUsers() {
"searchKey" : "filter" "searchKey" : "filter"
}; };
$('#user-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null, options); $('#user-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null, options);
$(loadingContentView).hide();
$("#loading-content").hide();
// $("#loading-content").show();
// var userListing = $("#user-listing");
// var userListingSrc = userListing.attr("src");
// $.template("user-listing", userListingSrc, function (template) {
// var serviceURL = apiBasePath + "/users";
// if (searchParam) {
// serviceURL = serviceURL + "?filter=" + searchParam;
// }
// var successCallback = function (data) {
// if (!data) {
// $('#ast-container').addClass('hidden');
// $('#user-listing-status-msg').text('No users are available to be displayed.');
// return;
// }
// var canRemove = $("#can-remove").val();
// var canEdit = $("#can-edit").val();
// var canResetPassword = $("#can-reset-password").val();
// data = JSON.parse(data);
// var viewModel = {};
// viewModel.users = data.users;
// for (var i = 0; i < viewModel.users.length; i++) {
// viewModel.users[i].userid = viewModel.users[i].username.replace(/[^\w\s]/gi, '');
// if (canRemove) {
// viewModel.users[i].canRemove = true;
// }
// if (canEdit) {
// viewModel.users[i].canEdit = true;
// }
// if (canResetPassword) {
// viewModel.users[i].canResetPassword = true;
// }
// viewModel.users[i].adminUser = $("#user-table").data("user");
// }
// if (data.count > 0) {
// $('#ast-container').removeClass('hidden');
// $('#user-listing-status-msg').text("");
// var content = template(viewModel);
// $("#ast-container").html(content);
// } else {
// $('#ast-container').addClass('hidden');
// $('#user-listing-status-msg').text('No users are available to be displayed.');
// }
// $("#loading-content").hide();
// if (isInit) {
// $('#user-grid').datatables_extended();
// isInit = false;
// }
// $(".icon .text").res_text(0.2);
// };
// invokerUtil.get(serviceURL,
// successCallback,
// function (message) {
// $('#ast-container').addClass('hidden');
// $('#user-listing-status-msg').
// text('Invalid search query. Try again with a valid search query');
// }
// );
// });
} }
$(document).ready(function () { $(document).ready(function () {

Loading…
Cancel
Save