7da69471248617301c56aa04111b26b1f9167c54
[vnfsdk/refrepo.git] / openo-portal / portal-lifecyclemgr / src / main / webapp / lifecyclemgr / js / tmNodesController.js
1 /*
2  * Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
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='../component/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],
57                         [resp.vlInfo.vldId],
58                         [resp.vnffgInfo.vnffgInstanceId]
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         //$('#'+ tableId).append(' <thead><tr role="row" class="heading" ></tr></thead><tbody></tbody>');
120         var trEle = $('#'+ tableId  + ' > thead >tr');
121         //var dataTableColumn = [];
122         for ( var one in column){
123             var th = '<th>' + column[one].name + '</th>';
124             trEle.append(th);
125         }
126         var table = $("#" + tableId).dataTable({
127             //"sDom" : "tr<'row'<'col-md-6 col-sm-12'><'col-md-6 col-sm-12'pli>>", // datatable layout
128             //"sDom" : "<'row'<'col-md-12 col-sm-12'lip>r><'table-scrollable't>>",
129             "sDom": '<"top"rt><"bottom"lip>',
130             "oLanguage": setting.language,//language
131             //"bJQueryUI": true,
132             "bPaginate": setting.paginate,// page button
133             "bFilter": false,// search bar
134             "bAutoWidth":true,//automatically set colum width
135             "bLengthChange": true,// record number in each row
136             "iDisplayLength": 10,// row number in each page
137             "bSort": setting.sort ? true : false,// sort
138             "bInfo": setting.info,// Showing 1 to 10 of 23 entries 
139             "bWidth": true,
140             "bScrollCollapse": true,
141             "sPaginationType": "bootstrap_extended", // page, a total of two kinds of style, another one is two_button
142             "bProcessing": true,
143             "bServerSide": false,
144             "bDestroy": true,
145             "bSortCellsTop": true,
146             "aoColumns": setting.columns,
147             "aoColumnDefs": [
148                         {
149                             sDefaultContent: '',
150                             aTargets: [ '_all' ]
151                         }
152             ],
153             "aaData": tableData
154         });
155     };
156
157     //nodes list table
158     nodesList :{
159         nodesData: [],
160         $nodesTabDataId : "ict_nodes_table",
161         $nodesTabFields : {// table columns
162             table: [
163                 {"mData": "id", name: "ID", "bVisible": false},
164                 {"mData": "instanceId", name: "Instance Id"}
165             ]
166         },
167         $initNodesTable: function () {
168             var setting = {};
169             setting.language = vm.$language;
170             setting.paginate = true;
171             setting.info = true;
172             setting.columns = vm.nodesList.$nodesTabFields.table;
173             setting.tableId = vm.nodesList.$nodesTabDataId;
174             vm.$initDataTable(setting,vm.nodesList.$nodesTabDataId + '_div', vm.nodesList.nodesData);
175         }
176     }
177 });
178
179 var initParam = function() { //initialize template detail params
180     var paramStr = window.location.search.substring(1);
181     if(paramStr.length > 0) {
182         avalon.scan();
183         var params = paramStr.split("&");
184         var instanceId = params[0].substring(params[0].indexOf('=') + 1);
185         
186         vm.instanceId = instanceId;
187         vm.$restUrl.queryNodeInstanceUrl = commonUtil.format(vm.$restUrl.queryNodeInstanceUrl, instanceId);
188         vm.$init();
189     }
190 };
191 initParam();