2 * Copyright 2016-2017 Huawei Technologies Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 $(document).ready(function() {
\r
17 var USER_SERVICE = "/openoapi/auth/v1/users";
\r
18 var deleteEditOpt = "<img class='edit' title='edit' src='/openoui/user/images/edit.png'><img class='changePsd' title='Change Password' src='/openoui/user/images/reset.png'><img class='delete' title='delete' src='/openoui/user/images/delete.png'>";
\r
19 var editOpt = "<img class='edit' title='edit' src='/openoui/user/images/edit.png'><img class='changePsd' title='Change Password' src='/openoui/user/images/reset.png'>";
\r
21 var userListHeader = [
\r
22 { title: "User", data: "User",width: "20%"},
\r
23 { title: "Description", data: "Description",width: "60%"},
\r
24 { title: "Operations", data: "Operations",width: "20%"}
\r
26 function initialPage() {
\r
27 /*get the user list data;*/
\r
28 getUserList().done(function(data) {
\r
29 var data = formatUsers(data);
\r
30 Table.create(data, "table_id", userListHeader);
\r
31 $(".hw_body").css("visibility", "visible");
\r
32 }).error(function(data) {
\r
33 if (data.status == 403) {
\r
34 $(".hw_body").html("<span style='font-size:20px;'>" + JSON.parse(data.responseText).error.message + "</span>");
\r
38 /*add the listener*/
\r
39 $("#table_id tbody").on("click", "td", function(e) {
\r
40 var classname = e.target.className;
\r
41 var id = $("#table_id").DataTable().row(this).data().rowid;
\r
42 if (classname == "delete") {
\r
43 top.bootbox.confirm("Are you sure to delete this user?", function(result) {
\r
45 deleteUser(id).done(function() {
\r
46 getUserList().done(function(data) {
\r
47 var data = formatUsers(data);
\r
48 var datatable = $("#table_id").dataTable().api();
\r
50 datatable.rows.add(data);
\r
56 } else if (classname == "edit") {
\r
57 window.document.location = "/openoui/user/modifyUser.html" + "?id=" + id;
\r
58 } else if (classname == "changePsd") {
\r
59 window.document.location = "/openoui/user/changePassword.html" + "?id=" + id;
\r
63 $("#create").click(function(e) {
\r
64 window.document.location = "/openoui/user/createUser.html";
\r
68 function getUserList() {
\r
70 url: USER_SERVICE + "?=" + new Date().getTime(),
\r
73 contentType: 'application/json',
\r
78 function deleteUser(id) {
\r
80 url: USER_SERVICE + "/" + id + "?=" + new Date().getTime(),
\r
83 contentType: 'application/json',
\r
88 function formatUsers(data) {
\r
90 for (var i = 0; i < data.length; i++) {
\r
92 temp.rowid = data[i].id;
\r
93 temp.User = data[i].name;
\r
94 temp.Description = data[i].description;
\r
95 if (data[i].name == "admin") {
\r
96 temp.Operations = editOpt;
\r
98 temp.Operations = deleteEditOpt;
\r
100 tableData.push(temp);
\r
106 setTimeout(function() {
\r
107 Table.enableToolTips("table_id");
\r