0e60825f77eae0ac0e858ef93de758816dedd7c9
[aaf/authz.git] / auth / auth-gui / src / main / java / org / onap / aaf / auth / gui / pages / WebCommand.java
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
22 package org.onap.aaf.auth.gui.pages;
23
24 import java.io.IOException;
25
26 import org.onap.aaf.auth.env.AuthzTrans;
27 import org.onap.aaf.auth.gui.AAF_GUI;
28 import org.onap.aaf.auth.gui.BreadCrumbs;
29 import org.onap.aaf.auth.gui.NamedCode;
30 import org.onap.aaf.auth.gui.Page;
31 import org.onap.aaf.auth.rserv.CachingFileAccess;
32 import org.onap.aaf.misc.env.APIException;
33 import org.onap.aaf.misc.env.StaticSlot;
34 import org.onap.aaf.misc.xgen.Cache;
35 import org.onap.aaf.misc.xgen.DynamicCode;
36 import org.onap.aaf.misc.xgen.Mark;
37 import org.onap.aaf.misc.xgen.html.HTMLGen;
38
39 public class WebCommand extends Page {
40     public static final String HREF = "/gui/cui";
41     public static final String INPUT = "input";
42     public static final String TYPE_BUTTON = "type=button";
43
44     public WebCommand(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
45         super(gui.env, "Web Command Client",HREF, NO_FIELDS,
46                 new BreadCrumbs(breadcrumbs),
47                 new NamedCode(true, "content") {
48             StaticSlot sThemeWebPath = gui.env.staticSlot(CachingFileAccess.CFA_WEB_PATH);
49             StaticSlot sTheme = gui.env.staticSlot(AAF_GUI.AAF_GUI_THEME);
50             @Override
51             public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
52                 hgen.leaf("p","id=help_msg")
53                     .text("Questions about this page? ")
54                     .leaf("a", "href="+gui.env.getProperty(AAF_URL_CUIGUI,""), "target=_blank")
55                     .text("Click here")
56                     .end()
57                     .text(". Type 'help' below for a list of AAF commands")
58                     .end()
59
60                     .divID("console_and_options");
61                 hgen.divID("console_area");
62                 hgen.end(); //console_area
63
64                 hgen.divID("options_link", "class=closed");
65                 cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI,AuthzTrans>() {
66                     @Override
67                     public void code(AAF_GUI state, AuthzTrans trans, Cache<HTMLGen> cache, HTMLGen xgen)
68                             throws APIException, IOException {
69                         String imageRoot = "src=../../"+state.env.get(sThemeWebPath).toString() + '/' + state.env.get(sTheme) + "/images/icons";
70                         hgen.img(imageRoot + "/options_down.png", "onclick=handleDivHiding('options',this);",
71                                 "id=options_img", "alt=Options", "title=Options")
72                             .end(); //options_link
73
74                         hgen.divID("options");
75
76                         switch(browser(trans,trans.env().slot(getBrowserType()))) {
77                             case IE:
78                             case IEOLD:
79                                 // IE doesn't support file save
80                                 break;
81                             default:
82                                 xgen.img(imageRoot+"/AAF_download.png", "onclick=saveToFile();",
83                                         "alt=Save log to file", "title=Save log to file");
84                         }
85                         xgen.img(imageRoot+"/AAF_font_size.png", "onclick=handleDivHiding('text_slider',this);",
86                                 "id=fontsize_img", "alt=Change text size", "title=Change text size");
87                         xgen.img(imageRoot+"/AAF_details.png", "onclick=selectOption(this,0);",
88                                 "id=details_img", "alt=Turn on/off details mode", "title=Turn on/off details mode");
89                         xgen.img(imageRoot+"/AAF_maximize.png", "onclick=maximizeConsole(this);",
90                                 "id=maximize_img", "alt=Maximize Console Window", "title=Maximize Console Window");
91                     }
92                 });
93                 hgen.divID("text_slider");
94                 hgen.tagOnly(INPUT, TYPE_BUTTON, "class=change_font", "onclick=buttonChangeFontSize('dec')", "value=-")
95                     .tagOnly(INPUT, "id=text_size_slider", "type=range", "min=75", "max=200", "value=100",
96                         "oninput=changeFontSize(this.value)", "onchange=changeFontSize(this.value)", "title=Change Text Size")
97                     .tagOnly(INPUT, TYPE_BUTTON, "class=change_font", "onclick=buttonChangeFontSize('inc')", "value=+")
98                     .end(); //text_slider
99
100                 hgen.end(); //options
101                 hgen.end(); //console_and_options
102
103                 hgen.divID("input_area");
104                 hgen.tagOnly(INPUT, "type=text", "id=command_field",
105                         "autocomplete=off", "autocorrect=off", "autocapitalize=off", "spellcheck=false",
106                         "onkeypress=keyPressed()", "placeholder=Type your AAFCLI commands here", "autofocus")
107                     .tagOnly(INPUT, "id=submit", TYPE_BUTTON, "value=Submit",
108                             "onclick=http('put','../../gui/cui',getCommand(),callCUI);")
109                     .end();
110
111                 Mark callCUI = new Mark();
112                 hgen.js(callCUI);
113                 hgen.text("function callCUI(resp) {")
114                     .text("moveCommandToDiv();")
115                     .text("printResponse(resp);")
116                     .text("}");
117                 hgen.end(callCUI);
118
119             }
120         });
121
122     }
123
124 }