2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 function getCommand() {
22 if(typeof String.prototype.trim !== 'function') {
23 String.prototype.trim = function() {
24 return this.replace(/^\s+|\s+$/g, '');
29 cmds = document.querySelector("#command_field").value.split(" ");
31 if (document.querySelector("#details_img").getAttribute("class") == "selected")
32 cleanCmd += "details ";
33 for (var i = 0; i < cmds.length;i++) {
34 var trimmed = cmds[i].trim();
36 cleanCmd += trimmed + " ";
39 return cleanCmd.trim();
42 function moveCommandToDiv() {
44 var textInput = document.querySelector("#command_field");
45 var content = document.createTextNode(textInput.value);
46 var parContent = document.createElement("p");
47 var consoleDiv = document.querySelector("#console_area");
48 var commandCount = consoleDiv.querySelectorAll(".command").length;
49 parContent.setAttribute("class", "command");
50 parContent.appendChild(content);
51 consoleDiv.appendChild(parContent);
56 function printResponse(response) {
57 var parContent = document.createElement("p");
58 parContent.setAttribute("class", "response");
59 var preTag = document.createElement("pre");
60 parContent.appendChild(preTag);
61 var content = document.createTextNode(response);
62 preTag.appendChild(content);
63 var consoleDiv = document.querySelector("#console_area");
64 consoleDiv.appendChild(parContent);
66 consoleDiv.scrollTop = consoleDiv.scrollHeight;
69 function clearHistory() {
70 var consoleDiv = document.querySelector("#console_area");
72 while (curr=consoleDiv.firstChild) {
73 consoleDiv.removeChild(curr);
75 document.querySelector("#command_field").value = "";
79 function buttonChangeFontSize(direction) {
80 var slider = document.querySelector("#text_size_slider");
81 var currentSize = parseInt(slider.value);
83 if (direction == "inc") {
84 newSize = currentSize + 10;
86 newSize = currentSize - 10;
88 if (newSize > slider.max) newSize = parseInt(slider.max);
89 if (newSize < slider.min) newSize = parseInt(slider.min);
90 slider.value = newSize;
91 changeFontSize(newSize);
94 function changeFontSize(size) {
95 var consoleDiv = document.querySelector("#console_area");
96 consoleDiv.style.fontSize = size + "%";
99 function handleDivHiding(id, img) {
100 var options_link = document.querySelector("#options_link");
101 var divHeight = toggleVisibility(document.querySelector("#"+id));
103 if (id == 'options') {
104 if (options_link.getAttribute("class") == "open") {
105 changeImg(document.querySelector("#options_img"), "../../theme/onap/options_down.png");
106 options_link.setAttribute("class", "closed");
108 changeImg(document.querySelector("#options_img"), "../../theme/onap/options_up.png");
109 options_link.setAttribute("class", "open");
111 moveToggleImg(options_link, divHeight);
112 } else { //id=text_slider
113 selectOption(img,divHeight);
118 function selectOption(img, divHeight) {
119 var options_link = document.querySelector("#options_link");
121 if (img.getAttribute("class") != "selected") {
122 anySelected = document.querySelectorAll(".selected").length>0;
123 if (anySelected == false)
125 img.setAttribute("class", "selected");
127 img.setAttribute("class", "");
128 anySelected = document.querySelectorAll(".selected").length>0;
129 if (anySelected == false)
134 moveToggleImg(options_link, divHeight);
137 function toggleVisibility(element) {
139 if(element.style.display == 'block') {
140 divHeight = 0 - element.clientHeight;
141 element.style.display = 'none';
143 element.style.display = 'block';
144 divHeight = element.clientHeight;
149 function moveToggleImg(element, height) {
150 var curTop = (element.style.top == "" ? 0 : parseInt(element.style.top));
151 element.style.top = curTop + height;
154 function changeImg(img, loc) {
159 function keyPressed() {
160 document.querySelector("#command_field").onkeyup=function(e) {
161 if (!e) e = window.event;
162 var keyCode = e.which || e.keyCode;
163 if (keyCode == 38 || keyCode == 40 || keyCode == 13 || keyCode == 27) {
164 var cmdHistoryList = document.querySelectorAll(".command");
169 if (getCommand().toLowerCase()=="clear") {
172 currentCmd = cmdHistoryList.length + 1;
173 document.querySelector("#submit").click();
179 currentCmd = cmdHistoryList.length;
180 document.querySelector("#command_field").value = "";
187 if (cmdHistoryList.length != 0)
188 document.querySelector("#command_field").value = cmdHistoryList[currentCmd].innerHTML;
193 currentCmd = (currentCmd == cmdHistoryList.length) ? currentCmd : currentCmd + 1;
194 if (currentCmd < cmdHistoryList.length)
195 cmdText = cmdHistoryList[currentCmd].innerHTML;
197 document.querySelector("#command_field").value = cmdText;
204 function saveToFile() {
205 var commands = document.querySelectorAll(".command");
206 var responses = document.querySelectorAll(".response");
207 var textToWrite = "";
208 for (var i = 0; i < commands.length; i++) {
209 textToWrite += "> " + commands[i].innerHTML + "\r\n";
210 textToWrite += prettyResponse(responses[i].firstChild.innerHTML);
213 var ie = navigator.userAgent.match(/MSIE\s([\d.]+)/);
214 var ie11 = navigator.userAgent.match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/);
215 var ieVer=(ie ? ie[1] : (ie11 ? 11 : -1));
217 // if (ie && ieVer<10) {
218 // console.log("No blobs on IE ver<10");
222 var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
223 var fileName = "AAFcommands.log";
226 // window.navigator.msSaveBlob(textFileAsBlob, fileName);
227 window.navigator.msSaveOrOpenBlob(textFileAsBlob, fileName);
229 var downloadLink = document.createElement("a");
230 downloadLink.download = fileName;
231 downloadLink.innerHTML = "Download File";
232 if (window.webkitURL != null) {
233 // Chrome allows the link to be clicked
234 // without actually adding it to the DOM.
235 downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
237 // Firefox requires the link to be added to the DOM
238 // before it can be clicked.
239 downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
240 downloadLink.onclick = destroyClickedElement;
241 downloadLink.style.display = "none";
242 document.body.appendChild(downloadLink);
245 downloadLink.click();
249 function prettyResponse(response) {
250 var lines = response.split('\n');
251 var cleanResponse = "";
252 for (var i=0; i < lines.length; i++) {
253 cleanResponse += lines[i] + "\r\n";
255 cleanResponse = cleanResponse.replace(/(<)/g,"<").replace(/(>)/g,">");
256 return cleanResponse;
259 function destroyClickedElement(event){
260 document.body.removeChild(event.target);
263 function fakePlaceholder() {
264 document.querySelector("#command_field").setAttribute("value", "Type your AAFCLI commands here");
267 function maximizeConsole(img) {
268 var footer = document.querySelector("#footer");
269 var console_area = document.querySelector("#console_area");
270 var content = document.querySelector("#content");
271 var input_area = document.querySelector("#input_area");
272 var help_msg = document.querySelector("#help_msg");
273 var console_space = document.documentElement.clientHeight;
274 console_space -= input_area.outerHeight;
275 console_space -= help_msg.outerHeight;
276 var height = getStyle(console_area,'paddingTop') + getStyle(console_area,'paddingBottom');
277 console_space -= height;
280 if (content.getAttribute("class") != "maximized") {
281 content.setAttribute("class", "maximized");
282 footer.style.display="none";
283 console_area.style.resize="none";
284 console_area.style.height=console_space.toString()+"px";
286 content.removeAttribute("class");
287 footer.style.display="";
288 console_area.style.resize="vertical";
289 console_area.style.height="600px";