rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / lifecyclemgr / src / main / webapp / lifecyclemgr / js / tmNodesController.js
1 /*
2  * Copyright 2016-2017 ZTE Corporation.
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
17 var vm = avalon.define({
18     $id: "tmNodesController",
19     instanceId: "",
20     $language: {
21         "sProcessing": "<img src='../common/thirdparty/data-tables/images/loading-spinner-grey.gif'/><span>&nbsp;&nbsp;"
22         + $.i18n.prop("nfv-nso-iui-table-sProcess") + "</span>",
23         "sLengthMenu": $.i18n.prop("nfv-nso-iui-table-sLengthMenu"),
24         "sZeroRecords": $.i18n.prop("nfv-nso-iui-table-sZeroRecords"),
25         "sInfo": "<span class='seperator'>  </span>" + $.i18n.prop("nfv-nso-iui-table-sInfo"),
26         "sInfoEmpty": $.i18n.prop("nfv-nso-iui-table-sInfoEmpty"),
27         "sGroupActions": $.i18n.prop("nfv-nso-iui-table-sGroupActions"),
28         "sAjaxRequestGeneralError": $.i18n.prop("nfv-nso-iui-table-sAjaxRequestGeneralError"),
29         "sEmptyTable": $.i18n.prop("nfv-nso-iui-table-sEmptyTable"),
30         "oPaginate": {
31             "sPrevious": $.i18n.prop("nfv-nso-iui-table-sPrevious"),
32             "sNext": $.i18n.prop("nfv-nso-iui-table-sNext"),
33             "sPage": $.i18n.prop("nfv-nso-iui-table-sPage"),
34             "sPageOf": $.i18n.prop("nfv-nso-iui-table-sPageOf")
35         }
36     },
37     $restUrl: {
38         queryNodeInstanceUrl: "/openoapi/nslcm/v1.0/ns/"
39     },
40     $init: function () {
41         vm.$initInstanceData();
42     },
43     $initInstanceData: function () {
44         $.ajax({
45             type: "GET",
46             url: vm.$restUrl.queryNodeInstanceUrl,
47             success: function (resp) {
48                 if (resp) {
49                     vm.servicesInstanceData = [
50                         resp.nsName,
51                         resp.description,
52                         resp.nsdId,
53                         resp.nsState
54                     ];
55                     var tableData = [
56                         [resp.vnfInfoId, 'vnf'],
57                         [resp.vlInfo.vldId, 'vl'],
58                         [resp.vnffgInfo.vnffgInstanceId, 'vnffg']
59                     ];
60                     vm.$initNfvNodesTab();
61                     vm.nodesList.nodesData = tableData;
62                     vm.nodesList.$initNodesTable();
63                 }
64             },
65             error: function () {
66                 commonUtil.showMessage($.i18n.prop("nfv-topology-iui-message-error"), "danger");
67             }
68         });
69     },
70     servicesInstanceData: [],
71     $nodesTabId: "ict_nodes_template_table",
72     $nodesInstanceTabFields: {// table columns
73         table: [
74             {"mData": "serviceInstanceId", name: "ID", "bVisible": false},
75             {"mData": "", name: "", "sClass": 'details-control'},
76             {"mData": "serviceName", name: "Service Name"},
77             {"mData": "serviceDescription", name: "Service Description"},
78             {"mData": "nsdId", name: "NSD ID"},
79             {"mData": "status", name: "Status"}
80         ]
81     },
82     $initNfvNodesTab: function () {
83         var setting = {};
84         setting.language = vm.$language;
85         setting.paginate = true;
86         setting.info = true;
87         setting.columns = vm.$nodesInstanceTabFields.table;
88         setting.tableId = vm.$nodesTabId;
89         vm.$initDataTable(setting, vm.$nodesTabId + '_div', vm.servicesInstanceData);
90         $('#' + vm.$nodesTabId + '>tbody').on("click", 'td.details-control', function () {
91             var tr = $(this).closest('tr');
92             var table = $('#' + vm.$nodesTabId).dataTable();
93             if (table.fnIsOpen(tr[0])) {
94                 table.fnClose(tr[0]);
95                 tr.removeClass('shown');
96             }
97             else {
98                 table.fnOpen(tr[0], vm.nodesList.$format_Detail(), 'details');
99                 tr.addClass('shown');
100             }
101         });
102     },
103
104     $initDataTable: function (setting, divId, tableData) {
105         //transform colomn
106         var column = setting.columns;
107         //empty table
108         $('#' + divId).children().remove();
109         var tableId = setting.tableId;
110         var tableEleStr = '<table class="table table-striped table-bordered table-hover" id= ' + tableId + '>'
111             + '<thead>'
112             + '<tr role="row" class="heading" >'
113             + '</tr>'
114             + '</thead>'
115             + '<tbody>'
116             + '</tbody>'
117             + '</table>';
118         $('#' + divId).append(tableEleStr);
119         var trEle = $('#' + tableId + ' > thead >tr');
120         for (var one in column) {
121             var th = '<th>' + column[one].name + '</th>';
122             trEle.append(th);
123         }
124         var table = $("#" + tableId).dataTable({
125             "sDom": '<"top"rt><"bottom"lip>',
126             "oLanguage": setting.language,//language
127             "bPaginate": setting.paginate,// page button
128             "bFilter": false,// search bar
129             "bAutoWidth": true,//automatically set colum width
130             "bLengthChange": true,// record number in each row
131             "iDisplayLength": 10,// row number in each page
132             "bSort": setting.sort ? true : false,// sort
133             "bInfo": setting.info,// Showing 1 to 10 of 23 entries 
134             "bWidth": true,
135             "bScrollCollapse": true,
136             "sPaginationType": "bootstrap_extended", // page, a total of two kinds of style, another one is two_button
137             "bProcessing": true,
138             "bServerSide": false,
139             "bDestroy": true,
140             "bSortCellsTop": true,
141             "aoColumns": setting.columns,
142             "aoColumnDefs": [
143                 {
144                     sDefaultContent: '',
145                     aTargets: ['_all']
146                 }
147             ],
148             "aaData": tableData
149         });
150     };
151
152 //nodes list table
153 nodesList :{
154     nodesData: [],
155         $nodesTabDataId
156 :
157     "ict_nodes_table",
158         $nodesTabFields
159 :
160     {// table columns
161         table: [
162             {"mData": "id", name: "ID", "bVisible": false},
163             {"mData": "instanceId", name: "Instance Id"},
164             {"mData": "nodeType", name: "Node Type"}
165         ]
166     }
167 ,
168     $initNodesTable: function () {
169         var setting = {};
170         setting.language = vm.$language;
171         setting.paginate = true;
172         setting.info = true;
173         setting.columns = vm.nodesList.$nodesTabFields.table;
174         setting.tableId = vm.nodesList.$nodesTabDataId;
175         vm.$initDataTable(setting, vm.nodesList.$nodesTabDataId + '_div', vm.nodesList.nodesData);
176     }
177 }
178 })
179 ;
180
181 var initParam = function () {
182     var paramStr = window.location.search.substring(1);
183     if (paramStr.length > 0) {
184         avalon.scan();
185         var params = paramStr.split("&");
186         var instanceId = params[0].substring(params[0].indexOf('=') + 1);
187
188         vm.instanceId = instanceId;
189         vm.$restUrl.queryNodeInstanceUrl = commonUtil.format(vm.$restUrl.queryNodeInstanceUrl, instanceId);
190         vm.$init();
191     }
192 };
193
194 initParam();