fbe8d083c663cdef90767889e422efa43b6ecaed
[aaf/authz.git] / auth / auth-gui / theme / onap / common.js
1 Object.defineProperty(Element.prototype, 'outerHeight', {
2     'get': function(){
3         var height = this.clientHeight;
4         height += getStyle(this,'marginTop');
5         height += getStyle(this,'marginBottom');
6         height += getStyle(this,'borderTopWidth');
7         height += getStyle(this,'borderBottomWidth');
8         return height;
9     }
10 });
11
12 if (document.addEventListener) {
13         document.addEventListener('DOMContentLoaded', function () {
14                 var height = document.querySelector("#footer").outerHeight;
15                 document.querySelector("#inner").setAttribute("style",
16                                 "margin-bottom:" + height.toString()+ "px");
17         });
18 } else {
19         window.attachEvent("onload", function () {
20                 var height = document.querySelector("#footer").outerHeight;
21                 document.querySelector("#inner").setAttribute("style",
22                                 "margin-bottom:" + height.toString()+ "px");
23         });
24 }
25
26
27
28 function getStyle(el, prop) {
29         var result = el.currentStyle ? el.currentStyle[prop] :
30                 document.defaultView.getComputedStyle(el,"")[prop];
31         if (parseInt(result,10))
32                 return parseInt(result,10);
33         else
34                 return 0;
35 }
36
37 function divVisibility(divID) {
38         var element = document.querySelector("#"+divID);
39         if (element.style.display=="block")
40                 element.style.display="none";
41         else
42                 element.style.display="block";
43 }
44
45 function datesURL(histPage) {
46         var validated=true;
47         var yearStart = document.querySelector('#yearStart').value;
48         var yearEnd = document.querySelector('#yearEnd').value;
49         var monthStart = document.querySelector('#monthStart').value;
50         var monthEnd = document.querySelector('#monthEnd').value;
51         if (monthStart.length == 1) monthStart = 0 + monthStart;
52         if (monthEnd.length == 1) monthEnd = 0 + monthEnd;
53
54         validated &= validateYear(yearStart);
55         validated &= validateYear(yearEnd);
56         validated &= validateMonth(monthStart);
57         validated &= validateMonth(monthEnd);
58         
59         if (validated) window.location=histPage+"&dates="+yearStart+monthStart+"-"+yearEnd+monthEnd;
60         else alert("Please correct your date selections");
61 }
62
63 function userFilter(approvalPage) {
64         var user = document.querySelector('#userTextBox').value;
65         if (user != "")
66                 window.location=approvalPage+"?user="+user;
67         else
68                 window.location=approvalPage;
69 }
70
71 function validateYear(year) {
72         var today = new Date();
73         if (year >= 1900 && year <= today.getFullYear()) return true;
74         else return false;
75 }
76
77 function validateMonth(month) {
78         if (month) return true;
79         else return false;
80 }
81
82 function alterLink(breadcrumbToFind, newTarget) {
83         var breadcrumbs = document.querySelector("#breadcrumbs").getElementsByTagName("A");
84         for (var i=0; i< breadcrumbs.length;i++) {
85                 var breadcrumbHref = breadcrumbs[i].getAttribute('href');
86                 if (breadcrumbHref.indexOf(breadcrumbToFind)>-1) 
87                         breadcrumbs[i].setAttribute('href', newTarget);
88         }
89 }
90
91 // clipBoardData object not cross-browser supported. Only IE it seems
92 function copyToClipboard(controlId) { 
93     var control = document.getElementById(controlId); 
94     if (control == null) { 
95         alert("ERROR - control not found - " + controlId); 
96     } else { 
97         var controlValue = control.href; 
98         window.clipboardData.setData("text/plain", controlValue); 
99         alert("Copied text to clipboard : " + controlValue); 
100     } 
101 }