Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / WEB-INF / fusion / raptor / wizard_filters_edit.jsp
1 <%--
2   ================================================================================
3   eCOMP Portal SDK
4   ================================================================================
5   Copyright (C) 2017 AT&T Intellectual Property
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   ================================================================================
19   --%>
20 <%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %>
21 <%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %>
22 <%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %>
23 <%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %>
24 <%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %>
25 <%@ page import="java.util.List" %>
26 <%@ page import="java.util.Iterator" %>
27 <%@ page import="org.openecomp.portalsdk.analytics.system.Globals" %>
28 <%@ page import="org.openecomp.portalsdk.analytics.util.Utils" %>
29 <%@ page import="java.util.Vector" %>
30 <%@ page import="org.openecomp.portalsdk.analytics.model.ReportLoader" %>
31 <%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %>
32 <%@ page import="org.openecomp.portalsdk.analytics.xmlobj.ColFilterType" %>
33 <%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %>
34 <%@ page import="org.openecomp.portalsdk.analytics.model.runtime.FormField" %>
35 <%@ page errorPage="error_page.jsp" %>
36 <%      
37     ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION);
38     WizardSequence ws = rdef.getWizardSequence();
39     String curSubStep = ws.getCurrentSubStep();
40         String reportID   = rdef.getReportID();
41
42         boolean isEdit  = curSubStep.equals(AppConstants.WSS_EDIT);
43         
44         String filterId = AppUtils.getRequestNvlValue(request, AppConstants.RI_DETAIL_ID);
45         String colId    = isEdit?filterId.substring(0, filterId.indexOf('|')):null;
46         int filterPos = -1;
47         if(isEdit)
48                 try {
49                         filterPos = Integer.parseInt(filterId.substring(colId.length()+1));
50                 } catch(NumberFormatException e) {}
51         
52         DataColumnType currColumn = isEdit?rdef.getColumnById(colId):null;
53         ColFilterType  currFilter = isEdit?rdef.getFilterById(colId, filterPos):null;
54         
55         String arg = null; %>
56
57 <script language="JavaScript">
58 <!--
59 function showFormFieldPopup() {
60         var w = window.open("", "filterPopup", "width=400,height=400,location=no,menubar=no,toolbar=no,status=no,resizable=yes,scrollbars=yes");
61         w.focus();
62         w.opener = this;
63         
64         w.document.writeln("<html><head>");
65         w.document.writeln("<title>Form Fields</title>");
66         w.document.writeln("<link rel=stylesheet type=text/css href='<%= AppUtils.getBaseFolderURL() %>css/raptor.css'>");
67         w.document.writeln("<script language=JavaScript>");
68         w.document.writeln("function setValue(newValue, fieldType) {");
69         w.document.writeln("    window.opener.document.forma.argValue.value      = newValue;");
70         w.document.writeln("    window.opener.document.forma.formFieldType.value = fieldType;");
71         w.document.writeln("    window.close();");
72         w.document.writeln("}   // setValue");
73         w.document.writeln("</"+"script>");
74         w.document.writeln("</head><body>");
75         
76         w.document.writeln("<table width=94% border=0 cellspacing=1 align=center>");
77         w.document.writeln("    <tr class=rbg1>");
78         w.document.writeln("            <td height=30>&nbsp;</td>");
79         w.document.writeln("            <td><b class=rtableheader>Report Form Fields</b></td>");
80         w.document.writeln("    </tr>");
81 <%      int iCnt = 0;
82         if(rdef.getFormFieldList()!=null)
83                 for(Iterator iter=rdef.getFormFieldList().getFormField().iterator(); iter.hasNext(); iCnt++) { 
84                         FormFieldType fft = (FormFieldType) iter.next(); %>
85         w.document.writeln("    <tr<%= (iCnt%2==0)?" class=rbg8":"" %>>");
86         w.document.writeln("            <td align=center valign=middle height=30><font class=rtabletext><%= (iCnt+1) %></font></td>");
87         w.document.writeln("            <td valign=middle>");
88         w.document.writeln("                    <b class=rtabletext><a href=\"javascript:setValue('[<%= fft.getFieldName() %>]', '<%= fft.getFieldType() %>')\"><%= fft.getFieldName() %></a></b>");
89         w.document.writeln("            </td>");
90         w.document.writeln("    </tr>");
91 <%                      }       // for
92         if(iCnt==0) { %>
93         w.document.writeln("    <tr class=rbg3 height=30>");
94         w.document.writeln("            <td colspan=2 align=center valign=middle><b class=rtabletext>There are no form fields defined</b></td>");
95         w.document.writeln("    </tr>");
96         w.document.writeln("    <tr>");
97         w.document.writeln("            <td colspan=2 align=center><br><input type=Submit class=Button value=Close onClick=\"window.close();\"></td>");
98         w.document.writeln("    </tr>");
99 <%      } else { %>
100         w.document.writeln("    <tr class=rbg1 height=30>");
101         w.document.writeln("            <td>&nbsp;</td>");
102         w.document.writeln("            <td>&nbsp;</td>");
103         w.document.writeln("    </tr>");
104 <%      }       // if 
105 %>
106         w.document.writeln("</table>");
107         
108         w.document.writeln("</body></html>");
109         w.document.close();
110 }   // showFormFieldPopup
111
112 function showArgPopup() {
113         var argType = document.forma.argType.options[document.forma.argType.selectedIndex].value;
114         if(argType=="<%= AppConstants.AT_FORMULA %>") {
115                 alert("Please select Argument Type to be one of the following:\n - Simple Value\n - Another Column\n - List of Values\n - Run-time Form Field");
116                 document.forma.argType.focus();
117                 return;
118         }
119         
120         if(argType=="<%= AppConstants.AT_FORM %>") {
121                 showFormFieldPopup();
122                 return;
123         }
124         
125 <% if(isEdit) { %>
126         var colId = "<%= colId %>";
127 <% } else { %>
128         var colId = document.forma.filterColId.options[document.forma.filterColId.selectedIndex].value;
129 <% } %>
130         
131         var w = window.open("<%= AppUtils.getRaptorActionURL() %>report.popup.filter."+((argType=="<%= AppConstants.AT_COLUMN %>")?"col":"data&<%= AppConstants.RI_ARG_TYPE %>="+argType+"&<%= AppConstants.RI_COLUMN_ID %>="+colId)+"&<%= AppConstants.RI_JS_TARGET_FIELD %>=document.forma.argValue&<%= AppConstants.RI_RESET_PARAMS %>=Y", "filterPopup", "width=440,height=400,location=no,menubar=no,toolbar=no,status=no,resizable=yes,scrollbars=yes");
132         w.focus();
133         w.opener = this;
134 }   // showArgPopup
135 //-->
136 </script>
137
138
139 <table width="100%"  class="tableBorder" border="0" cellspacing="1" cellpadding="3" align=center>
140         <tr>
141                 <td class=rbg1 colspan=2 valign="Middle"><b class=rtableheader>Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %> - <%= curSubStep %></b></td>
142         </tr>
143 <% if((isEdit?filterPos:rdef.getAllFilters().size())==0) { %>
144         <input type="hidden" name="filterJoin" value="AND">
145 <% } else { %>
146         <tr>
147                 <td class=rbg2 align="right" width="25%" height="30"><font class=rtabletext>Join Condition: </font></td> 
148                 <td class=rbg3 align="left" width="50%"><font class=rtabletext>
149                         <%  arg = (request.getParameter("filterJoin")!=null)?request.getParameter("filterJoin"):(isEdit?currFilter.getJoinCondition():""); %>
150                         <select name="filterJoin">
151                                 <option value="AND"<%= arg.equals("AND")?" selected":"" %>>AND
152                                 <option value="OR"<%=  arg.equals("OR") ?" selected":"" %>>OR
153                         </select></font></td>
154         </tr>
155 <% } %>
156         <tr>
157                 <td class=rbg2 align="right" width="25%" height="30"><font class=rtabletext>Opening Brackets: </font></td> 
158                 <td class=rbg3 align="left" width="50%"><font class=rtabletext>
159                         <%  arg = (request.getParameter("openBrackets")!=null)?request.getParameter("openBrackets"):(isEdit?nvl(currFilter.getOpenBrackets()):""); %>
160                         <select name="openBrackets">
161                                 <option value=""<%=      arg.equals("")     ?" selected":"" %>>
162                                 <option value="("<%=     arg.equals("(")    ?" selected":"" %>>(
163                                 <option value="(("<%=    arg.equals("((")   ?" selected":"" %>>((
164                                 <option value="((("<%=   arg.equals("(((")  ?" selected":"" %>>(((
165                                 <option value="(((("<%=  arg.equals("((((") ?" selected":"" %>>((((
166                                 <option value="((((("<%= arg.equals("(((((")?" selected":"" %>>(((((
167                         </select></font></td>
168         </tr>
169         <tr>
170                 <td class=rbg2 align="right" width="25%" height="30" style="background-image:url(<%= AppUtils.getImgFolderURL() %>required.gif); background-position:top right; background-repeat:no-repeat;"><font class=rtabletext>Filter By Column: </font></td> 
171                 <td class=rbg3 align="left" width="50%"><font class=rtabletext>
172                 <% if(isEdit) { %>
173                         <%= currColumn.getDisplayName() %>
174                     <input type="hidden" name="filterColId" value="<%= colId %>">
175                     <input type="hidden" name="filterPos" value="<%= filterPos %>">
176                 <% } else { %>
177                         <select name="filterColId">
178 <%                              int iCount = 0;
179                                 List reportCols = rdef.getAllColumns();
180                                 for(Iterator iter=reportCols.iterator(); iter.hasNext(); iCount++) { 
181                                         DataColumnType dct = (DataColumnType) iter.next(); %>
182                                     <option value="<%= dct.getColId() %>"<%= ((request.getParameter("filterColId")==null)?(iCount==0):dct.getColId().equals(request.getParameter("filterColId")))?" selected":"" %>><%= dct.getDisplayName() %>
183 <%                              }   // for 
184 %>
185                         </select>
186                 <% } %>
187                 </font></td>
188         </tr> 
189         <tr>
190                 <td class=rbg2 align="right" width="25%" height="30"><font class=rtabletext>Expression: </font></td> 
191                 <td class=rbg3 align="left" width="50%"><font class=rtabletext>
192                         <%  arg = (request.getParameter("filterExpr")!=null)?request.getParameter("filterExpr"):(isEdit?currFilter.getExpression():""); %>
193                         <select name="filterExpr">
194                                 <option value="="<%=           arg.equals("=")          ?" selected":"" %>>=
195                                 <option value="&lt;&gt;"<%=    arg.equals("<>")         ?" selected":"" %>>&lt;&gt;
196                                 <option value="&gt;"<%=        arg.equals(">")          ?" selected":"" %>>&gt;
197                                 <option value="&gt;="<%=       arg.equals(">=")         ?" selected":"" %>>&gt;=
198                                 <option value="&lt;"<%=        arg.equals("<")          ?" selected":"" %>>&lt;
199                                 <option value="&lt;="<%=       arg.equals("<=")         ?" selected":"" %>>&lt;=
200                                 <option value="LIKE"<%=        arg.equals("LIKE")       ?" selected":"" %>>LIKE
201                                 <option value="IS NULL"<%=     arg.equals("IS NULL")    ?" selected":"" %>>IS NULL
202                                 <option value="IS NOT NULL"<%= arg.equals("IS NOT NULL")?" selected":"" %>>IS NOT NULL
203                                 <option value="IN"<%=          arg.equals("IN")         ?" selected":"" %>>IN (list)
204                                 <option value="NOT IN"<%=      arg.equals("NOT IN")     ?" selected":"" %>>NOT IN (list)
205                         </select></font></td>
206         </tr>
207         <tr>
208                 <td class=rbg2 align="right" width="25%" height="30"><font class=rtabletext>Argument Type: </font></td> 
209                 <td class=rbg3 align="left" width="50%"><font class=rtabletext>
210                         <%  arg = (request.getParameter("argType")!=null)?request.getParameter("argType"):(isEdit?nvl(currFilter.getArgType()):""); %>
211                         <select name="argType" onChange="document.forma.formFieldType.value=''; if(options[selectedIndex].value=='<%= AppConstants.AT_COLUMN %>') document.forma.argValue.value='';">
212                                 <option value="<%= AppConstants.AT_VALUE %>"<%=   arg.equals(AppConstants.AT_VALUE)  ?" selected":"" %>>Simple Value
213                                 <option value="<%= AppConstants.AT_COLUMN %>"<%=  arg.equals(AppConstants.AT_COLUMN) ?" selected":"" %>>Another Column
214                                 <option value="<%= AppConstants.AT_FORMULA %>"<%= arg.equals(AppConstants.AT_FORMULA)?" selected":"" %>>Expression
215                                 <option value="<%= AppConstants.AT_LIST %>"<%=    arg.equals(AppConstants.AT_LIST)   ?" selected":"" %>>List of Values
216                                 <option value="<%= AppConstants.AT_FORM %>"<%=    arg.equals(AppConstants.AT_FORM)   ?" selected":"" %>>Run-time Form Field
217                         </select></font></td>
218         </tr>
219         <tr>
220                 <td class=rbg2 align="right" width="25%" height="30"><font class=rtabletext>Argument Value: </font></td> 
221                 <td class=rbg3 align="left" width="50%"><font class=rtabletext>
222                         <%      String argValue = nvl(request.getParameter("argValue"), isEdit?(nvl(currFilter.getArgType()).equals(AppConstants.AT_COLUMN)?"["+rdef.getColumnById(currFilter.getArgValue()).getDisplayName()+"]":nvl(currFilter.getArgValue())):"");
223                                 String formFieldType = "";
224                                 if(arg.equals(AppConstants.AT_FORM)&&rdef.getFormFieldList()!=null)
225                                         for(Iterator iter=rdef.getFormFieldList().getFormField().iterator(); iter.hasNext(); iCnt++) { 
226                                                 FormFieldType fft = (FormFieldType) iter.next();
227                                                 if(argValue.equals("["+fft.getFieldName()+"]")) {
228                                                         formFieldType = fft.getFieldType();
229                                                         break;
230                                                 }       // if
231                                         }       // for 
232                         %>
233                     <input type="hidden" name="formFieldType" value="<%= formFieldType %>">
234                         <input type="text" size="30" name="argValue" class=rtabletext value="<%= argValue %>" 
235                                 onFocus="if(document.forma.argType.options[document.forma.argType.selectedIndex].value=='<%= AppConstants.AT_COLUMN %>') blur();" onChange="document.forma.formFieldType.value='';"></font>
236                     <a href="javascript:showArgPopup()"><img border="0" src="<%= AppUtils.getImgFolderURL() %>shareicon.gif" alt="Select from list" width="12" height="12"></a>
237                 </td>
238         </tr>
239         <tr>
240                 <td class=rbg2 align="right" width="25%" height="30"><font class=rtabletext>Closing Brackets: </font></td> 
241                 <td class=rbg3 align="left" width="50%"><font class=rtabletext>
242                         <%  arg = (request.getParameter("closeBrackets")!=null)?request.getParameter("closeBrackets"):(isEdit?nvl(currFilter.getCloseBrackets()):""); %>
243                         <select name="closeBrackets">
244                                 <option value=""<%=      arg.equals("")     ?" selected":"" %>>
245                                 <option value=")"<%=     arg.equals(")")    ?" selected":"" %>>)
246                                 <option value="))"<%=    arg.equals("))")   ?" selected":"" %>>))
247                                 <option value=")))"<%=   arg.equals(")))")  ?" selected":"" %>>)))
248                                 <option value="))))"<%=  arg.equals("))))") ?" selected":"" %>>))))
249                                 <option value=")))))"<%= arg.equals(")))))")?" selected":"" %>>)))))
250                         </select></font></td>
251         </tr>
252 </table>
253 <br>
254
255 <script language="JavaScript">
256 <!--
257 function dataValidate() {
258         var selExpr = "";
259         selExpr = document.forma.filterExpr.options[document.forma.filterExpr.selectedIndex].value;
260         var selArgType = "";
261         selArgType = document.forma.argType.options[document.forma.argType.selectedIndex].value;
262         
263         var isListArgument = false;
264         if(selArgType=="<%= AppConstants.AT_LIST %>")
265                 isListArgument = true;
266         
267         var isFormSingleValueArgument = false;  // text with popup, drop-down, list-box and radio-buttons are always single value
268         var isFormMultiValueArgument  = false;  // check boxes and multi-select list box are always multi-value; text box and text area can be either
269         var isFormArgument            = false;  // text box and text area can be used for both single-value and multi-value
270         if(selArgType=="<%= AppConstants.AT_FORM %>") {
271                 isFormArgument = true;
272                 
273                 if( document.forma.formFieldType.value=="<%= FormField.FFT_TEXT_W_POPUP %>"||
274                         document.forma.formFieldType.value=="<%= FormField.FFT_COMBO_BOX %>"||
275                         document.forma.formFieldType.value=="<%= FormField.FFT_LIST_BOX %>"||
276                         document.forma.formFieldType.value=="<%= FormField.FFT_RADIO_BTN %>")
277                         isFormSingleValueArgument = true;
278                 
279                 if( document.forma.formFieldType.value=="<%= FormField.FFT_CHECK_BOX %>"||
280                         document.forma.formFieldType.value=="<%= FormField.FFT_LIST_MULTI %>")
281                         isFormMultiValueArgument = true;
282         }       // if
283         
284         if((selExpr!="IS NULL")&&(selExpr!="IS NOT NULL")) {
285                 if((selExpr=="IN")||(selExpr=="NOT IN")) {
286                         if(! (isListArgument||(isFormArgument&&(! isFormSingleValueArgument)))) {
287                                 alert("This expression requires argument which is List of Values.\nPlease either select the argument type List of Values or\nselect argument type Run-time Form Field and then select Form Field which is Text Box, Text Area, Check Boxes or Multi-select List Box.");
288                                 document.forma.argValue.focus();
289                                 document.forma.argValue.select();
290                                 
291                                 return false;
292                         }
293                 } else
294                         if(isListArgument||(isFormArgument&&isFormMultiValueArgument)) {
295                                 alert("This expression cannot have argument type List of Values.\nPlease select another argument type.\n\nNote: Form Field which is Check Boxes or Multi-select List Box is also considered to be List of Values.");
296                                 document.forma.argValue.focus();
297                                 document.forma.argValue.select();
298                                 
299                                 return false;
300                         }
301                 
302                 if(selArgType!="<%= AppConstants.AT_FORM %>")
303                         if(document.forma.argValue.value=="") {
304                                 alert("Please provide argument value");
305                                 document.forma.argValue.focus();
306                                 document.forma.argValue.select();
307                                 
308                                 return false;
309                         }
310         }       // if
311          
312         return true;
313 }   // dataValidate
314 //-->
315 </script>
316
317 <%!
318         private String nvl(String s)                  { return (s==null)?"":s; }
319         private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } 
320 %>