%@page import="com.edeal.frontline.navigation.WebUtils"%>
<%@ page language="java" %>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@ page import="com.edeal.frontline.DataDictionary" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="java.util.Vector" %>
<%@ page import="com.edeal.frontline.ListBean" %>
<%@ page import="com.edeal.frontline.ListBean.SearchZone" %>
<%@page import="com.edeal.frontline.navigation.EdealBigTabsNavigation.BigTabsParams"%>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl"%>
<%
Vector vectPagination = pagination;
%>
var readyToResize;
var DIF_HEIGHT_WINDOWS_BIGTAB = 160;
var updateHeightRunning = false; /* TODO � suprimer quand j'aurais comrpis o� est la boucle infini sans*/
function debug(msg) {
alert(msg);
}
// global variable to set the gridCriteria object
var gGridCriteria;
function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement&&
document.documentElement.clientHeight) {
windowHeight = document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}
function offsetTopOrigin(elt){
if(elt.offsetParent)
return elt.offsetTop+offsetTopOrigin(elt.offsetParent);
else
return 0;
}
function getSearchCriteria(isSc,gridName) {
var f = window.document.forms[0];
var vectQuery = new FlVector();
var vectQuerySc = new FlVector();
var value = '';
<%
if (vectPagination != null) {
if(vectPagination.size() == 1) {
%>
vectQuery.addElement('$$nb=<%= pagePagination %>');
<%
} else {
%>
if (f.$$nb.selectedIndex >= 0 && f.$$nb.options[f.$$nb.selectedIndex].value != '') {
vectQuery.addElement('$$nb=' + f.$$nb.options[f.$$nb.selectedIndex].value);
}
<%
}
}
if (searchZone != null) {
for(int i = 0; i < searchZone.getNbLines(); i++) {
for(int j = 0; j < searchZone.getNbFields(i); j++) {
com.edeal.frontline.ListBean.Field fld = searchZone.getField(i, j);
String strDisp = "<" + fld.getDisplay(session) + ">";
if(fld.isDate() || fld.isTime() || fld.isDecimal() || fld.isInteger()) {
%>
if ( (value = f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>$From'].value) != '') {
vectQuerySc.addElement('<%= fld.getFullName() %>$From=' + value);
vectQuery.addElement('<%= fld.getFullName() %>$From=' + encodeURIComponent(value));
}
if ((value = f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>$To'].value) != '') {
vectQuerySc.addElement('<%= fld.getFullName() %>$To=' + value);
vectQuery.addElement('<%= fld.getFullName() %>$To=' + encodeURIComponent(value));
}
<%
} else if(fld.getFldFobSql() != null) {
%>
if ( (value = f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].value) != '') {
vectQuerySc.addElement('<%= fld.getFullName() %>=' + value);
vectQuery.addElement('<%= fld.getFullName() %>=' + encodeURIComponent(value));
}
if ( (value = f.elements['lbl<%= Utils.formatToJavascript(fld.getInputName()) %>'].value) != '<%= Utils.formatToJavascript(strDisp) %>') {
vectQuerySc.addElement('lbl<%= fld.getFullName() %>=' + value);
vectQuery.addElement('lbl<%= fld.getFullName() %>=' + encodeURIComponent(value));
}
<%
} else if (fld.isFldRef() || fld.getChoiceType() != ListBean.CHOICE_NONE) {
if (fld.isFldRef() || fld.getChoiceType() == ListBean.CHOICE_SELECT_MULTIPLE || fld.getChoiceType() == ListBean.CHOICE_SELECT) {
%>
if (f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].selectedIndex >= 0) {
var o = f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].options;
for(var i = 0; i < o.length; i++) {
if(o[i].selected && o[i].value != '') {
vectQuerySc.addElement('<%= fld.getFullName() %>=' + o[i].value);
vectQuery.addElement('<%= fld.getFullName() %>=' + encodeURIComponent(o[i].value));
}
}
}
<%
} else if (fld.getChoiceType() != ListBean.CHOICE_NONE) {
if (fld.getChoiceList().size() > 1) {
%>
for(var i = 0; i < f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].length; i++) {
if(f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'][i].checked && f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'][i].value != '') {
vectQuerySc.addElement('<%= fld.getFullName() %>=' + f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'][i].value);
vectQuery.addElement('<%= fld.getFullName() %>=' + encodeURIComponent(f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'][i].value));
}
}
<%
} else {
%>
if (f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].checked && f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].value != '') {
vectQuerySc.addElement('<%= fld.getFullName() %>=' + f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].value);
vectQuery.addElement('<%= fld.getFullName() %>=' + encodeURIComponent(f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].value));
}
<%
}
}
} else if(fld.isBoolean()) {
%>
if (f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].checked) {
vectQuerySc.addElement('<%= fld.getFullName() %>=1');
vectQuery.addElement('<%= fld.getFullName() %>=1');
}else{
vectQuerySc.addElement('<%= fld.getFullName() %>=0');
vectQuery.addElement('<%= fld.getFullName() %>=0');
}
<%
} else {
%>
if ( (value = f.elements['<%= Utils.formatToJavascript(fld.getInputName()) %>'].value) != '<%= Utils.formatToJavascript(strDisp) %>') {
vectQuerySc.addElement('<%= fld.getFullName() %>=' + stripSpaces(value));
vectQuery.addElement('<%= fld.getFullName() %>=' + encodeURIComponent(stripSpaces(value)));
}
<%
}
}
}
}
%>
<%-- vectQuery.addElement('$$idx=<%= pageIndex %>'); --%>
<%--vectQuery.addElement('$$preview=1');--%>
if (isSc && isSc == 1) {
//return encodeURIComponent(vectQuerySc.toString('&'));
return vectQuerySc.toString('&');
} else {
return vectQuery.toString('&');
}
}
function stripSpaces(strToStrip) {
if(strToStrip!=null){
while (strToStrip.substring(0,1) == ' ') strToStrip = strToStrip.substring(1);
while (strToStrip.substring(strToStrip.length-1,strToStrip.length) == ' ') strToStrip = strToStrip.substring(0,strToStrip.length-1);
}
return strToStrip;
}
function getSearchUrl() {
var f = window.document.forms[0];
// If we're doing an autocomplete operation, we need to catch
// the return key when selecting an object by keyboard
try {
if (acCurHighlightedDiv != null || editNoteStatus) {
return false;
}
} catch (error) {
}
<% String searchActionUrl=(Utils.isEmpty(au))? "/list_ajax.fl" : au ; %>
var url = "";
url += (url.length - url.indexOf("<%= searchActionUrl %>") == "<%= searchActionUrl %>".length ? "?" : "&") + "sc=" + encodeURIComponent(getSearchCriteria(1,'<%= gridName %>'));
url += "&" + getSearchCriteria(0,'<%= gridName %>');
return url;
}
function showEditableCrits(val) {
if(val!=false)
val=true;
if(val){
readyToResize = 2;
$('#criteriaTableRow').show('normal',stepReadyResize);
$('#ShowCritsLinkDiv').hide('normal',stepReadyResize);
}else{
$('#resultZone').show();
$('#criteriaTableRow').hide();
}
}
// executed after edealGrid saved
// data: json sended by server
function callBackSave(data){
if(data.beans!=null){
$("input.btMassEdit").attr("checked", false);
$("#resultZone input[type=submit]").hide();
$("#resultZone input[type=reset]").hide();
}
}
function doCallSearch(jsGrid,params,fPriorityToUrlParams,fDisplayPreview) {
jsGrid.callAjaxForHtml(getSearchUrl(), params, true, false,setSizeOfGridData,fPriorityToUrlParams,fDisplayPreview);
}
function executeSearch() {
if (typeof gGridCriteria=='undefined') {
return;
}
if(gGridCriteria.checkMandatory()){
var params=new Object();
params=<%=bTabNav.getBigTabsParameterJsObject()%>;
<%-- Resetting the search criteria here to fix the bug of having the
search criteria remembered between successive searches after having cleared
the search criteria in the user interface.We also reset the page number in
order to avoid a similar problem. --%>
params["sc"]="";
params["$$idx"]=0;
var fDisplayPreview=gGridCriteria.doDisplayPreview();
doCallSearch(_grid__<%= Utils.formatToWeb(lc, true) %>_js_,params,true,fDisplayPreview);
return false;
}else{
gGridCriteria.displayHelp('<%= Utils.formatToWeb(lc, true) %>');
}
}
<%-- Execute search providing additional parameters for search
@param array key: param name String value: param value
!!! param value has to be encoded if needed !!!
--%>
function executeSearchWithParam(additionalParams) {
if (typeof gGridCriteria=='undefined') {
return;
}
if(gGridCriteria.checkMandatory()){
var params=new Array();
params=<%=bTabNav.getBigTabsParameterJsObject()%>;
<%-- Resetting the search criteria here to fix the bug of having the
search criteria remembered between successive searches after having cleared
the search criteria in the user interface.We also reset the page number in
order to avoid a similar problem. --%>
params["sc"]="";
params["$$idx"]=0;
<%-- additional parameters addition --%>
var paramName;
for(paramName in additionalParams){
if(params[paramName] === undefined){
params[paramName] = additionalParams[paramName];
}
}
var fDisplayPreview=gGridCriteria.doDisplayPreview();
doCallSearch(_grid__<%= Utils.formatToWeb(lc, true) %>_js_,params,true,fDisplayPreview);
return false;
}else{
gGridCriteria.displayHelp('<%= Utils.formatToWeb(lc, true) %>');
}
}
function criteriaKeyPress(keyEvent) {
var key = keyEvent.which ? keyEvent.which : keyEvent.keyCode;
if (keyEvent) { keyEvent.stopPropagation(); }
// Someone pressed the enter key, AND we're not AC'ing
if (key== 13 && acCurHighlightedDiv == null) {
if(typeof additionalParams != "undefined" && additionalParams) {
executeSearchWithParam(additionalParams);
} else {
executeSearch();
}
}
}
function setSizeOfGridData() {
gGridCriteria.resizeGrid(true);
}
function doOnLoad() {
var gridCriteriaElement=document.getElementById('criteriaTableRow')
gGridCriteria=new EdealGridCriteria(gridCriteriaElement,false,document.getElementById("bShowHideCriteria"));
$(gridCriteriaElement).keyup(criteriaKeyPress);
<% if (!isFirstTimeIn) { %>
doCallSearch(_grid__<%= Utils.formatToWeb(lc, true) %>_js_,<%=bTabNav.getBigTabsParameterJsObject()%>,true,null);
<% } %>
gGridCriteria.hightLightMandatory();
$("#valid-button").removeClass("inactive");
}
//window.location = '/generate_csv.fl?code=<%= WebUtils.urlEncode(context, lc) %>';
function doGenerateCSV() {
if (typeof gGridCriteria=='undefined') {
return;
}
if(gGridCriteria.checkMandatory()){
var params=new Object();
params=<%=bTabNav.getBigTabsParameterJsObject()%>;
<%-- Resetting the search criteria here to fix the bug of having the
search criteria remembered between successive searches after having cleared
the search criteria in the user interface.We also reset the page number in
order to avoid a similar problem. --%>
params["sc"]="";
var fDisplayPreview=gGridCriteria.doDisplayPreview();
doCallGenerateCSV(_grid__<%= Utils.formatToWeb(lc, true) %>_js_,params,true,fDisplayPreview);
return false;
}else{
gGridCriteria.displayHelp('<%= Utils.formatToWeb(lc, true) %>');
}
}
function doCallGenerateCSV(jsGrid,params,fPriorityToUrlParams,fDisplayPreview) {
window.location = jsGrid.doGenerateCSVFile(getUrl(), params, true, false,setSizeOfGridData,fPriorityToUrlParams,fDisplayPreview);
}
function getUrl() {
var f = window.document.forms[0];
// If we're doing an autocomplete operation, we need to catch
// the return key when selecting an object by keyboard
try {
if (acCurHighlightedDiv != null || editNoteStatus) {
return false;
}
} catch (error) {
}
<% String generateActionUrl= "generate_csv.fl"; %>
var url = "";
url += (url.length - url.indexOf("<%= generateActionUrl %>") == "<%= generateActionUrl %>".length ? "?" : "&") + "sc=" + encodeURIComponent(getSearchCriteria(1,'<%= gridName %>'));
url += "&" + getSearchCriteria(0,'<%= gridName %>');
return url;
}