CLIENT GUI Framework
[vnfsdk/refrepo.git] / openo-portal / portal-extsys / src / main / webapp / extsys / vim / js / vimController.js
1 /*\r
2  * Copyright 2016-2017 ZTE Corporation.\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 var vm = avalon\r
17     .define({\r
18         $id: "vimController",\r
19         vimInfo: [],\r
20         //vimStatusTime:$.i18n.prop('com_zte_ums_eco_roc_vim_getting_info'),\r
21         // ifSearch : 0,\r
22         // server_rtn:{\r
23         //      info_block:false,\r
24         //      warning_block:false,\r
25         //      rtn_info:"",\r
26         //      $RTN_SUCCESS:"RTN_SUCCESS",\r
27         //      $RTN_FAILED:"RTN_FAILED",\r
28         //              wait : $.i18n.prop('com_zte_ums_eco_roc_vim_checking_status')\r
29         // },\r
30         executeWait: {clazz: 'alert-info', visible: true, text: $.i18n.prop('com_zte_ums_eco_roc_vim_checking_status')},\r
31         executeError: {clazz: 'alert-danger', visible: true, text: 'error'},\r
32         $Status: {\r
33             success: "active",\r
34             failed: "inactive",\r
35             displayActive: $.i18n.prop('com_zte_ums_eco_roc_vim_normal'),\r
36             displayInactive: $.i18n.prop('com_zte_ums_eco_roc_vim_abnormal')\r
37         },\r
38         isSave: true,\r
39         action: {ADD: 'add', UPDATE: 'update'},\r
40         $queryVimInfoUrl: '/openoapi/extsys/v1/vims',\r
41         $addVimInfoUrl: '/openoapi/extsys/v1/vims/',\r
42         $updateVimInfoUrl: '/openoapi/extsys/v1/vims/',\r
43         $delVimInfoUrl: '/openoapi/extsys/v1/vims/{vim_id}',\r
44         $initTable: function () {\r
45             $.ajax({\r
46                 "type": 'get',\r
47                 "url": vm.$queryVimInfoUrl,\r
48                 //"dataType": "json",\r
49                 "success": function (resp, statusText, jqXHR) {\r
50                     if (jqXHR.status == "200") {\r
51                         vm.vimInfo = resp;\r
52                     }\r
53                     else {\r
54                         vm.vimInfo = [];\r
55                         bootbox.alert($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_query_failed"));\r
56                         return;\r
57                     }\r
58                 },\r
59                 error: function (XMLHttpRequest, textStatus, errorThrown) {\r
60                     bootbox.alert($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_query_failed") + textStatus + ":" + errorThrown);\r
61                     return;\r
62                 },\r
63                 complete: function () {\r
64                     resUtil.tooltipVimStatus();\r
65                 }\r
66             });\r
67 \r
68         },\r
69         $vimType: {\r
70             condName: $.i18n.prop("com_zte_ums_eco_roc_vim_type"),\r
71             component_type: 'select',\r
72             selectItems: [\r
73                 {\r
74                     cond_value: 'vmware',\r
75                     name: "vmware",\r
76                     value: true\r
77                 },\r
78                 {\r
79                     cond_value: 'openstack',\r
80                     name: "openstack",\r
81                     value: true\r
82                 }\r
83             ]\r
84         },\r
85         addVim: {\r
86             titleName: $.i18n.prop("com_zte_ums_eco_roc_vim_register_info"),\r
87             vimId: "",\r
88             vimName: "",\r
89             domain: '',\r
90             domainVisable:true,\r
91             vimNameModify:false,\r
92             userName: "",\r
93             tenant: "",\r
94             password: "",\r
95             url: "",\r
96             saveType: "add",\r
97             description: "",\r
98             vimType: "openstack",\r
99             vendor: "",\r
100             version: ""\r
101         },\r
102         $showVimTable: function (el, action) {\r
103             vm.isSave = false;\r
104             if (vm.action.ADD == action) {\r
105                 vm.addVim.vimId = "";\r
106                 vm.addVim.vimName = "";\r
107                 vm.addVim.vimNameModify=false;\r
108                 vm.addVim.userName = "";\r
109                 vm.addVim.password = "";\r
110                 vm.addVim.url = "";\r
111                 vm.addVim.domain = "";\r
112                 vm.addVim.domainVisable = true;\r
113                 vm.addVim.description = "";\r
114                 vm.addVim.tenant = "";\r
115                 vm.addVim.vendor = "";\r
116                 vm.addVim.saveType = "add";\r
117                 vm.addVim.vimType = "openstack";\r
118                 vm.addVim.titleName = $.i18n.prop("com_zte_ums_eco_roc_vim_register_info");\r
119 \r
120             } else {\r
121                 vm.addVim.vimId = el.vimId;\r
122                 vm.addVim.vimName = el.name;\r
123                 vm.addVim.vimNameModify=true;\r
124                 vm.addVim.url = el.url;\r
125                 vm.addVim.description = el.description;\r
126                 vm.addVim.userName = el.userName;\r
127                 vm.addVim.password = el.password;\r
128                 vm.addVim.tenant = el.tenant;\r
129                 vm.addVim.domain = el.domain;\r
130                 vm.addVim.domainVisable=vm.$getdomainVisable(el.type);\r
131                 vm.addVim.saveType = "update";\r
132                 vm.addVim.titleName = $.i18n.prop('com_zte_ums_eco_roc_vim_modify_info');\r
133                 vm.addVim.vimType = el.type;\r
134                 vm.addVim.vendor = el.vendor;\r
135                 vm.addVim.version = el.version;\r
136             }\r
137             vm.executeError.visible = false;\r
138             vm.executeWait.visible = false;\r
139             $(".form-group").each(function () {\r
140                 $(this).removeClass('has-success');\r
141                 $(this).removeClass('has-error');\r
142                 $(this).find(".help-block[id]").remove();\r
143             });\r
144             $("#addVimDlg").modal("show");\r
145         },\r
146 \r
147         $saveVimTable: function () {\r
148             vm.isSave = true;\r
149             success.hide();\r
150             error.hide();\r
151             if (form.valid() == false) {\r
152                 vm.isSave = false;\r
153                 return false;\r
154             }\r
155             vm.executeWait.visible = true;\r
156             vm.executeError.visible = false;\r
157             if (vm.addVim.saveType == "add") { \r
158                 for( var i = 0; i < vm.vimInfo.length; i ++ ){\r
159                     if(vm.addVim.name == vm.vimInfo[i].name){\r
160                        resUtil.growl($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_title") +  ' already exists',"info");\r
161                        $('#addVimDlg').modal('hide');\r
162                         return;\r
163                     }\r
164                 }                 \r
165                 vm.persistVim();\r
166             } else if (vm.addVim.saveType == "update") {\r
167                 vm.updateVim();\r
168             }\r
169         },\r
170         //add vim\r
171         persistVim: function () {\r
172             $.ajax({\r
173                 type: "Post",\r
174                 url: vm.$addVimInfoUrl,\r
175                 data: JSON.stringify({\r
176                     name: vm.addVim.vimName,\r
177                     url: vm.addVim.url,\r
178                     userName: vm.addVim.userName,\r
179                     password: vm.addVim.password,\r
180                     tenant: vm.addVim.tenant,\r
181                     domain: vm.addVim.domain,\r
182                     vendor: vm.addVim.vendor,\r
183                     version: vm.addVim.version,\r
184                     description: vm.addVim.description,\r
185                     type: vm.addVim.vimType,\r
186                 }),\r
187                 async: false,\r
188                 dataType: "json",\r
189                 contentType: 'application/json',\r
190                 success: function (data, statusText, jqXHR) {\r
191                     vm.executeWait.visible = false;\r
192                     vm.executeError.visible = false;\r
193                     if (jqXHR.status == "201") {\r
194                         vm.addVim.vimId = data.vimId;\r
195                         vm.addVim.name = data.name;\r
196                         vm.addVim.tenant = data.tenant;\r
197                         vm.addVim.type = data.type;\r
198                         var newVim = jQuery.extend({}, vm.addVim);\r
199                         vm.vimInfo.push(newVim);\r
200 \r
201                         $('#addVimDlg').modal('hide');\r
202                         resUtil.growl($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_title") + $.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_save_success"), "success");\r
203                     } else {\r
204                         vm.executeError.visible = true;\r
205                         vm.executeError.text = $.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_save_failed");\r
206                     }\r
207                 },\r
208                 error: function (XMLHttpRequest, textStatus, errorThrown) {\r
209                     vm.executeError.visible = true;\r
210                     vm.executeError.text = textStatus + ":" + errorThrown;\r
211                     vm.executeWait.visible = false;\r
212                     vm.isSave = false;\r
213                 }\r
214             });\r
215         },\r
216         //update vim\r
217         updateVim: function () {\r
218             $.ajax({\r
219                 type: "Put",\r
220                 url: vm.$updateVimInfoUrl + vm.addVim.vimId,\r
221                 contentType: 'application/json',\r
222                 data: JSON.stringify({\r
223                     name: vm.addVim.vimName,\r
224                     userName: vm.addVim.userName,\r
225                     password: vm.addVim.password,\r
226                     domain: vm.addVim.domain,\r
227                     version: vm.addVim.version,\r
228                     description: vm.addVim.description,\r
229                     url: vm.addVim.url,\r
230                     tenant: vm.addVim.tenant,\r
231                     type: vm.addVim.vimType,\r
232                     vendor: vm.addVim.vendor,\r
233                 }),\r
234                 dataType: "json",\r
235                 async: false,\r
236                 success: function (data, statusText, jqXHR) {\r
237                     vm.executeWait.visible = false;\r
238                     vm.executeError.visible = false;\r
239                     if (jqXHR.status == "200") {\r
240                         for (var i = 0; i < vm.vimInfo.length; i++) {\r
241                             if (vm.vimInfo[i].vimId == vm.addVim.vimId) {\r
242                                 vm.vimInfo[i].name = vm.addVim.vimName;\r
243                                 vm.vimInfo[i].userName = vm.addVim.userName;\r
244                                 vm.vimInfo[i].password = vm.addVim.password;\r
245                                 vm.vimInfo[i].url = vm.addVim.url;\r
246                                 vm.vimInfo[i].tenant = vm.addVim.tenant;\r
247                                 vm.vimInfo[i].domain = vm.addVim.domain;\r
248                                 vm.vimInfo[i].description = vm.addVim.description;\r
249                                 vm.vimInfo[i].type = vm.addVim.vimType;\r
250                                 vm.vimInfo[i].version=vm.addVim.version;\r
251                                 vm.vimInfo[i].vendor=vm.addVim.vendor;\r
252                             }\r
253                         }\r
254                         $('#addVimDlg').modal('hide');\r
255                         resUtil.growl($.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_title') + $.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_save_success'), "success");\r
256                     }\r
257                     else {\r
258                         vm.executeError.visible = true;\r
259                         vm.executeError.text = $.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_save_failed');\r
260                     }\r
261                 },\r
262                 error: function (XMLHttpRequest, textStatus, errorThrown) {\r
263                     vm.isSave = false;\r
264                     vm.executeError.visible = true;\r
265                     vm.executeError.text = textStatus + ":" + errorThrown;\r
266                     vm.executeWait.visible = false;\r
267                 }\r
268             });\r
269         },\r
270         delVim: function (el) {\r
271             bootbox.confirm($.i18n.prop('com_zte_ums_eco_roc_vim_confirm_delete_vim_record'), function (result) {\r
272                 if (result) {\r
273                     $.ajax({\r
274                         type: "DELETE",\r
275                         url: vm.$delVimInfoUrl.replace('{vim_id}', el.vimId),\r
276                         success: function (data, statusText, jqXHR) {\r
277                             if (jqXHR.status == "204") {\r
278                                 for (var i = 0; i < vm.vimInfo.length; i++) {\r
279                                     if (el.vimId == vm.vimInfo[i].vimId) {\r
280                                         vm.vimInfo.splice(i, 1);\r
281                                         break;\r
282                                     }\r
283                                 }\r
284                                 resUtil.growl($.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_title') + $.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_remove_success'), "success");\r
285                             }\r
286                             else {\r
287                                 resUtil.growl($.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_title') + $.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_remove_failed'), "warning");\r
288                             }\r
289                         },\r
290                         error: function (XMLHttpRequest, textStatus, errorThrown) {\r
291                             resUtil.growl($.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_title') + errorThrown, "danger");\r
292                         }\r
293                     });\r
294                 }\r
295             });\r
296         },\r
297         gotoChartPage: function (oid, name, tenant) {\r
298             window.location.href = "vimChart.html?" + oid + "&" + name + "&" + tenant;\r
299         },\r
300         $getdomainVisable:function(vimType){\r
301             if ("openstack"==vimType){\r
302                 return true;           \r
303              }else{\r
304                 return false;\r
305              }\r
306 \r
307         },\r
308         vimTypeRendered:function(){\r
309             vm.addVim.domainVisable=vm.$getdomainVisable(vm.addVim.vimType);\r
310         }\r
311 \r
312 \r
313     });\r
314 avalon.scan();\r
315 vm.$initTable();\r
316 \r
317 \r
318 \r
319 \r