aboutsummaryrefslogtreecommitdiffstats
path: root/openo-portal/portal-extsys/src/main/webapp/extsys/vim/js/vimController.js
blob: dfeb5dd89c4c7e7c72307bffd16943b5411a8221 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
 * Copyright 2016 [ZTE] and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var vm = avalon
    .define({
        $id: "vimController",
        vimInfo: [],
        //vimStatusTime:$.i18n.prop('com_zte_ums_eco_roc_vim_getting_info'),
        // ifSearch : 0,
        // server_rtn:{
        // 	info_block:false,
        // 	warning_block:false,
        // 	rtn_info:"",
        // 	$RTN_SUCCESS:"RTN_SUCCESS",
        // 	$RTN_FAILED:"RTN_FAILED",
        //              wait : $.i18n.prop('com_zte_ums_eco_roc_vim_checking_status')
        // },
        executeWait: {clazz: 'alert-info', visible: true, text: $.i18n.prop('com_zte_ums_eco_roc_vim_checking_status')},
        executeError: {clazz: 'alert-danger', visible: true, text: 'error'},
        $Status: {
            success: "active",
            failed: "inactive",
            displayActive: $.i18n.prop('com_zte_ums_eco_roc_vim_normal'),
            displayInactive: $.i18n.prop('com_zte_ums_eco_roc_vim_abnormal')
        },
        isSave: true,
        action: {ADD: 'add', UPDATE: 'update'},
        $queryVimInfoUrl: '/openoapi/extsys/v1/vims',
        $addVimInfoUrl: '/openoapi/extsys/v1/vims/',
        $updateVimInfoUrl: '/openoapi/extsys/v1/vims/',
        $delVimInfoUrl: '/openoapi/extsys/v1/vims/{vim_id}',
        $initTable: function () {
            $.ajax({
                "type": 'get',
                "url": vm.$queryVimInfoUrl,
                //"dataType": "json",
                "success": function (resp, statusText, jqXHR) {
                    if (jqXHR.status == "200") {
                        vm.vimInfo = resp;
                    }
                    else {
                        vm.vimInfo = [];
                        bootbox.alert($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_query_failed"));
                        return;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    bootbox.alert($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_query_failed") + textStatus + ":" + errorThrown);
                    return;
                },
                complete: function () {
                    resUtil.tooltipVimStatus();
                }
            });

        },
        $vimType: {
            condName: $.i18n.prop("com_zte_ums_eco_roc_vim_type"),
            component_type: 'select',
            selectItems: [
                {
                    cond_value: 'vmware',
                    name: "vmware",
                    value: true
                },
                {
                    cond_value: 'openstack',
                    name: "openstack",
                    value: true
                }
            ]
        },
        addVim: {
            titleName: $.i18n.prop("com_zte_ums_eco_roc_vim_register_info"),
            vimId: "",
            vimName: "",
            domain: '',
            userName: "",
            tenant: "",
            password: "",
            url: "",
            saveType: "add",
            description: "",
            vimType: "openstack",
            vendor: "",
            version: ""
        },
        $showVimTable: function (el, action) {
            vm.isSave = false;
            if (vm.action.ADD == action) {
                vm.addVim.vimId = "";
                vm.addVim.vimName = "";
                vm.addVim.userName = "";
                vm.addVim.password = "";
                vm.addVim.url = "";
                vm.addVim.domain = "";
                vm.addVim.description = "";
                vm.addVim.tenant = "";
                vm.addVim.vendor = "";
                vm.addVim.saveType = "add";
                vm.addVim.vimType = "openstack";
                vm.addVim.titleName = $.i18n.prop("com_zte_ums_eco_roc_vim_register_info");

            } else {
                vm.addVim.vimId = el.vimId;
                vm.addVim.vimName = el.name;
                vm.addVim.url = el.url;
                vm.addVim.description = el.description;
                vm.addVim.userName = el.userName;
                vm.addVim.password = el.password;
                vm.addVim.tenant = el.tenant;
                vm.addVim.domain = el.domain;
                vm.addVim.saveType = "update";
                vm.addVim.titleName = $.i18n.prop('com_zte_ums_eco_roc_vim_modify_info');
                vm.addVim.vimType = el.type;
                vm.addVim.vendor = el.vendor;
                vm.addVim.version = el.version;
            }
            vm.executeError.visible = false;
            vm.executeWait.visible = false;
            $(".form-group").each(function () {
                $(this).removeClass('has-success');
                $(this).removeClass('has-error');
                $(this).find(".help-block[id]").remove();
            });
            $("#addVimDlg").modal("show");
        },

        $saveVimTable: function () {
            vm.isSave = true;
            success.hide();
            error.hide();
            if (form.valid() == false) {
                vm.isSave = false;
                return false;
            }
            vm.executeWait.visible = true;
            vm.executeError.visible = false;
            if (vm.addVim.saveType == "add") {               
                /*
                 for( var i = 0; i < vm.vimInfo.length; i ++ ){
                 if(vm.addVim.url == vm.vimInfo[i].url){
                 resUtil.growl($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_title") +  'already exists',"info");
                 $('#addVimDlg').modal('hide');
                 return;
                 }
                 }
                 */
                vm.persistVim();
            } else if (vm.addVim.saveType == "update") {
                vm.updateVim();
            }
        },
        //add vim
        persistVim: function () {
            $.ajax({
                type: "Post",
                url: vm.$addVimInfoUrl,
                data: JSON.stringify({
                    name: vm.addVim.vimName,
                    url: vm.addVim.url,
                    userName: vm.addVim.userName,
                    password: vm.addVim.password,
                    tenant: vm.addVim.tenant,
                    domain: vm.addVim.domain,
                    vendor: vm.addVim.vendor,
                    version: vm.addVim.version,
                    description: vm.addVim.description,
                    type: vm.addVim.vimType,
                }),
                async: false,
                dataType: "json",
                contentType: 'application/json',
                success: function (data, statusText, jqXHR) {
                    vm.executeWait.visible = false;
                    vm.executeError.visible = false;
                    if (jqXHR.status == "201") {
                        vm.addVim.vimId = data.vimId;
                        vm.addVim.name = data.name;
                        vm.addVim.tenant = data.tenant;
                        vm.addVim.type = data.type;
                        var newVim = jQuery.extend({}, vm.addVim);
                        vm.vimInfo.push(newVim);

                        $('#addVimDlg').modal('hide');
                        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");
                    } else {
                        vm.executeError.visible = true;
                        vm.executeError.text = $.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_save_failed");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    vm.executeError.visible = true;
                    vm.executeError.text = textStatus + ":" + errorThrown;
                    vm.executeWait.visible = false;
                    vm.isSave = false;
                }
            });
        },
        //update vim
        updateVim: function () {
            $.ajax({
                type: "Put",
                url: vm.$updateVimInfoUrl + vm.addVim.vimId,
                contentType: 'application/json',
                data: JSON.stringify({
                    name: vm.addVim.vimName,
                    userName: vm.addVim.userName,
                    password: vm.addVim.password,
                    domain: vm.addVim.domain,
                    version: vm.addVim.version,
                    description: vm.addVim.description,
                    url: vm.addVim.url,
                    tenant: vm.addVim.tenant,
                    type: vm.addVim.vimType,
                    vendor: vm.addVim.vendor,
                }),
                dataType: "json",
                async: false,
                success: function (data, statusText, jqXHR) {
                    vm.executeWait.visible = false;
                    vm.executeError.visible = false;
                    if (jqXHR.status == "200") {
                        for (var i = 0; i < vm.vimInfo.length; i++) {
                            if (vm.vimInfo[i].vimId == vm.addVim.vimId) {
                                vm.vimInfo[i].name = vm.addVim.vimName;
                                vm.vimInfo[i].userName = vm.addVim.userName;
                                vm.vimInfo[i].password = vm.addVim.password;
                                vm.vimInfo[i].url = vm.addVim.url;
                                vm.vimInfo[i].tenant = vm.addVim.tenant;
                                vm.vimInfo[i].domain = vm.addVim.domain;
                                vm.vimInfo[i].description = vm.addVim.description;
                                vm.vimInfo[i].type = vm.addVim.vimType;
                                vm.vimInfo[i].version=vm.addVim.version;
                                vm.vimInfo[i].vendor=vm.addVim.vendor;
                            }
                        }
                        $('#addVimDlg').modal('hide');
                        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");
                    }
                    else {
                        vm.executeError.visible = true;
                        vm.executeError.text = $.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_save_failed');
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    vm.isSave = false;
                    vm.executeError.visible = true;
                    vm.executeError.text = textStatus + ":" + errorThrown;
                    vm.executeWait.visible = false;
                }
            });
        },
        delVim: function (el) {
            bootbox.confirm($.i18n.prop('com_zte_ums_eco_roc_vim_confirm_delete_vim_record'), function (result) {
                if (result) {
                    $.ajax({
                        type: "DELETE",
                        url: vm.$delVimInfoUrl.replace('{vim_id}', el.vimId),
                        success: function (data, statusText, jqXHR) {
                            if (jqXHR.status == "204") {
                                for (var i = 0; i < vm.vimInfo.length; i++) {
                                    if (el.vimId == vm.vimInfo[i].vimId) {
                                        vm.vimInfo.splice(i, 1);
                                        break;
                                    }
                                }
                                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");
                            }
                            else {
                                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");
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            resUtil.growl($.i18n.prop('com_zte_ums_eco_roc_vim_growl_msg_title') + errorThrown, "danger");
                        }
                    });
                }
            });
        },
        gotoChartPage: function (oid, name, tenant) {
            window.location.href = "vimChart.html?" + oid + "&" + name + "&" + tenant;
        }
    });
avalon.scan();
vm.$initTable();