2 * Copyright 2016-2017 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 Table.create = function(data, id, columns) {
18 $('#' + id).DataTable({
21 "sDom": "<t<'left'li><'right'p>>",
26 * update the table data, the cloumns must be same with the create one.
27 * data: the update data. as the create structure
30 Table.updata = function(data, id) {
31 var datatable = $('#' + id).dataTable().api();
33 datatable.rows.add(data);
37 Table.enableToolTips = function(id) {
38 $("#" + id + " tr th").each(function(index, sdom){
39 sdom.title = sdom.textContent;
41 $("#" + id + " tbody tr td").each(function(index, sdom){
42 sdom.title = sdom.textContent;
48 Rest.http = function(setting) {
49 var ret = $.ajax(setting);
50 ret.fail(function(data) {
52 if (data.responseText.indexOf("login") != -1) {
53 top.window.document.location.reload()
55 var result = JSON.parse(data.responseText);
56 if (result.error && result.error.message) {
57 top.bootbox.alert(result.error.message, function() {});
66 Rest.turn2URI = function(url) {
67 var cookies = document.cookie.split(";");
69 for (var i = 0; i < cookies.length; i++) {
70 if (cookies[i].split("=")[0] == "X-Auth-Token") {
71 cookie = cookies[i].split("=")[1];
76 url: "/openoapi/auth/v1/tokens",
79 "X-Auth-Token": cookie
81 success: function(data) {
82 window.document.location = url;
84 error: function(data) {
85 top.window.document.location.reload();