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