Missing Licenses
[aaf/authz.git] / auth / auth-gui / theme / onap / common.js
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21 Object.defineProperty(Element.prototype, 'outerHeight', {
22     'get': function(){
23         var height = this.clientHeight;
24         height += getStyle(this,'marginTop');
25         height += getStyle(this,'marginBottom');
26         height += getStyle(this,'borderTopWidth');
27         height += getStyle(this,'borderBottomWidth');
28         return height;
29     }
30 });
31
32 if (document.addEventListener) {
33         document.addEventListener('DOMContentLoaded', function () {
34                 var height = document.querySelector("#footer").outerHeight;
35                 document.querySelector("#inner").setAttribute("style",
36                                 "margin-bottom:" + height.toString()+ "px");
37         });
38 } else {
39         window.attachEvent("onload", function () {
40                 var height = document.querySelector("#footer").outerHeight;
41                 document.querySelector("#inner").setAttribute("style",
42                                 "margin-bottom:" + height.toString()+ "px");
43         });
44 }
45
46
47
48 function getStyle(el, prop) {
49         var result = el.currentStyle ? el.currentStyle[prop] :
50                 document.defaultView.getComputedStyle(el,"")[prop];
51         if (parseInt(result,10))
52                 return parseInt(result,10);
53         else
54                 return 0;
55 }
56
57 function divVisibility(divID) {
58         var element = document.querySelector("#"+divID);
59         if (element.style.display=="block")
60                 element.style.display="none";
61         else
62                 element.style.display="block";
63 }
64
65 function datesURL(histPage) {
66         var validated=true;
67         var yearStart = document.querySelector('#yearStart').value;
68         var yearEnd = document.querySelector('#yearEnd').value;
69         var monthStart = document.querySelector('#monthStart').value;
70         var monthEnd = document.querySelector('#monthEnd').value;
71         if (monthStart.length == 1) monthStart = 0 + monthStart;
72         if (monthEnd.length == 1) monthEnd = 0 + monthEnd;
73
74         validated &= validateYear(yearStart);
75         validated &= validateYear(yearEnd);
76         validated &= validateMonth(monthStart);
77         validated &= validateMonth(monthEnd);
78         
79         if (validated) window.location=histPage+"&dates="+yearStart+monthStart+"-"+yearEnd+monthEnd;
80         else alert("Please correct your date selections");
81 }
82
83 function userFilter(approvalPage) {
84         var user = document.querySelector('#userTextBox').value;
85         if (user != "")
86                 window.location=approvalPage+"?user="+user;
87         else
88                 window.location=approvalPage;
89 }
90
91 function validateYear(year) {
92         var today = new Date();
93         if (year >= 1900 && year <= today.getFullYear()) return true;
94         else return false;
95 }
96
97 function validateMonth(month) {
98         if (month) return true;
99         else return false;
100 }
101
102 function alterLink(breadcrumbToFind, newTarget) {
103         var breadcrumbs = document.querySelector("#breadcrumbs").getElementsByTagName("A");
104         for (var i=0; i< breadcrumbs.length;i++) {
105                 var breadcrumbHref = breadcrumbs[i].getAttribute('href');
106                 if (breadcrumbHref.indexOf(breadcrumbToFind)>-1) 
107                         breadcrumbs[i].setAttribute('href', newTarget);
108         }
109 }
110
111 // clipBoardData object not cross-browser supported. Only IE it seems
112 function copyToClipboard(controlId) { 
113     var control = document.getElementById(controlId); 
114     if (control == null) { 
115         alert("ERROR - control not found - " + controlId); 
116     } else { 
117         var controlValue = control.href; 
118         window.clipboardData.setData("text/plain", controlValue); 
119         alert("Copied text to clipboard : " + controlValue); 
120     } 
121 }