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