rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / auth / src / main / webapp / user / js / modifyUser.js
1 /*
2  * Copyright 2016-2017 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 $(document).ready(function() {
17     var USER_SERVICE = "/openoapi/auth/v1/users";
18     var userId;
19     function initialPage() {
20         userId = getId();
21         getUserDetails(userId).done(function(data) {
22             listUserDetails(data);
23         });
24
25         /*initial the event*/
26         $("#confirm").click(function(e) {
27             var data = getModifyUser();
28             modifyUser(data).done(function() {
29                 window.document.location = "/openoui/user/user.html";
30             })
31         })
32         $("#cancel").click(function(e) {
33             window.document.location = "/openoui/user/user.html";
34         })
35     }
36
37     function getModifyUser() {
38         var data = {};
39         data.description = $("#description").val();
40         data.email = "xxxx@xxxx.com";
41         return data;
42     }
43     function getUserDetails(id) {
44         return Rest.http({
45             url: USER_SERVICE + "/" + id + "?=" + new Date().getTime(),
46             type: "GET",
47             async: false,
48             contentType: 'application/json',
49             dataType: "json"
50         })
51     }
52
53     function listUserDetails(data) {
54         $("#userName").val(data.name);
55         $("#description").val(data.description);
56     }
57
58     function modifyUser(data) {
59         return Rest.http({
60             url: USER_SERVICE + "/" + userId + "?=" + new Date().getTime(),
61             type: "PATCH",
62             async: false,
63             contentType: 'application/json',
64             dataType: "json",
65             data: JSON.stringify(data)
66         })
67     }
68
69     function getId() {
70         var qs = location.search;
71         qs = qs.indexOf("?") === 0 ? qs : ("?" + qs);
72         var start = qs.indexOf("id=") + 3;
73         var end = qs.indexOf("&") === -1 ? qs.length : qs.indexOf("&") - start;
74         return qs.substr(start, end);
75     }
76
77     initialPage();
78 })