Edit C:\galaxie\Back\galaxie\js\grid\EdealGrid.js
function dbg_alert(msg) { // alert(msg); } var DisplayMode = new Object(); String.prototype.startsWith = function(str) { return (this.match("^" + str) == str) } var EdealGrid = function(ajaxUrl, objectType, contextName) { this.gridName = null; this.ajaxUrl = ajaxUrl; this.renderElement = null; this.arrColumns = new Array(); this.currentSortedColumn = null; this.currentSortedElement = null; this.currentSortOrderAsc = false; this.objectType = objectType; this.contextName = contextName; this.fieldToUpdate = {}; this.msgPreChangePage = null; this.fUserUpdateAllowed = false; // allow grid update for user this.fEditMode = false; this.maxHeightPreview = 0; this.massSelectable = false; // flag to tell if the grid is mass this.layer = false; // flag to tell if the action will be opened in a layer // selectable this.arrMassSelectID = new Array(); // array of selected ids this.baseUrl = null; // ajax base url (ie. before ?) this.urlParams = new Object(); // store all "url" passed params to be // reused later (&key=value) this.previewCache = new Object(); // store all preview html this.selectedGridRow = null; // used to save the previously selected row // for preview this.usedCallBack = null; // store the used call back this.softwareID = null; // to be added on list url for the grid with links this.gridHeight = null; // this.fDisplayPreview=false; this.msgNoSelection = ""; doAjax( "retrieveLabelAjax.fl?js=true&code=L6611&alt=Voulez vous sauvegarder vos modifications ?", this.callBackMsgPreChangePage(this), "GET"); doAjax( "retrieveLabelAjax.fl?js=true&code=M6025&alt=Veuillez sélectionner au moins un enregistrement.", this.noSelectionAlert(this), "GET"); } EdealGrid.getJsName = function(name) { return name ? "_grid__" + name + "_js_" : null; } EdealGrid.prototype.getJsName = function() { return this.gridName ? EdealGrid.getJsName(this.gridName) : null; } /* * call ajax and build html of the grid edit : if true the grid is in massEdit * mode parameters: if is a map, this paremeters can override parameters in * ajaxUrl fReplaceUrl: doesn't work yet */ EdealGrid.prototype.callAjaxForHtml = function(ajaxUrl, parameters, fReinitParameters, fEditMode, callBack, fPriorityToUrlParams, fDisplayPreview) { fReinitParameters = (fReinitParameters == null) ? false : fReinitParameters; this.fEditMode = (fEditMode != null) ? fEditMode : this.fEditMode; // this.fDisplayPreview=(fDisplayPreview==true); if (fReinitParameters) { dbg_alert("reinitialisation base url & params") this.reinitParams(); } this.usedCallBack = (callBack == null) ? this.usedCallBack : callBack; // this.displayFullUrl("10",ajaxUrl,parameters); var urlToCall = ajaxUrl ? ajaxUrl : this.baseUrl; dbg_alert("urlToCall:" + urlToCall); this.storeUrlAndParams(urlToCall, fPriorityToUrlParams); // this.displayFullUrl("20",urlToCall,parameters); var param2 = ""; parameters = (parameters == null) ? {} : parameters; parameters['editmode'] = (this.fEditMode ? "true" : "false"); parameters['allowupdate'] = (this.fUserUpdateAllowed ? "true" : "false"); if (fDisplayPreview != null) { parameters['$$preview'] = (fDisplayPreview ? "true" : "false"); } if (this.softwareID != null) { // ugly hack to add software id parameters['SfwID'] = this.softwareID; } if (this.gridHeight != null) { // ugly hack to add software id parameters['gridheight'] = this.gridHeight; } if (fReinitParameters) { // remove the olToken if a new search is run // (i.e. we click on the GO button (only)) parameters['olToken'] = ''; } urlToCall = this.paramsToUrl(parameters, (fPriorityToUrlParams ? fPriorityToUrlParams : false)); // this.displayFullUrl("30",urlToCall,parameters); // alert("callAjaxForHtml call really:\n"+urlToCall); var tmp = doAjax(urlToCall, this.ajaxDisplayClosure(this, this.fEditMode, this.usedCallBack), "GET"); // this.displayFullUrl("final",urlToCall,parameters); } EdealGrid.prototype.doGenerateCSVFile = function(ajaxUrl, parameters, fReinitParameters, fEditMode, callBack, fPriorityToUrlParams, fDisplayPreview) { var saveUrl = this.baseUrl; this.usedCallBack = (callBack == null) ? this.usedCallBack : callBack; var urlToCall = ajaxUrl ? ajaxUrl : this.baseUrl; this.storeUrlAndParams(urlToCall, fPriorityToUrlParams); parameters = (parameters == null) ? {} : parameters; urlToCall = this.paramsToUrl(parameters,(fPriorityToUrlParams ? fPriorityToUrlParams : false)); this.baseUrl = saveUrl; return urlToCall; } EdealGrid.prototype.displayFullUrl = function(msg, url, params) { var param1 = ""; var param2 = ""; for (x in params) { param1 += x + "=" + params[x] + "\n"; } for (x in this.urlParams) { param2 += x + "=" + this.urlParams[x] + "\n"; } dbg_alert(msg + " ajaxUrl:" + url + "\n\nbaseUrl:" + this.baseUrl + "\n\nparams passés:\n" + param1 + "\n\nurl params:\n" + param2); } EdealGrid.prototype.setSoftwareID = function(sfwID) { this.softwareID = sfwID; } EdealGrid.prototype.setGridHeight = function(height) { this.gridHeight = height; } EdealGrid.prototype.setLayer = function(layer) { this.layer = layer; } EdealGrid.prototype.callBackMsgPreChangePage = function(edealGrid) { return function execute(arrIndex) { if (eDealXmlhttpArr[arrIndex].readyState == 4) { hideWaiting(); edealGrid.msgPreChangePage = eDealXmlhttpArr[arrIndex].responseText; } var tmp = edealGrid; } } EdealGrid.prototype.bindTo = function(elementName) { this.renderElement = document.getElementById(elementName); this.gridName = this.renderElement.getAttribute("ed:grid-name"); } EdealGrid.prototype.getRenderElementJQuery = function(jqueryNode) { return $("#" + this.renderElement.id + ((jqueryNode == null) ? "" : " " + jqueryNode)); } EdealGrid.prototype.getAjaxUrl = function() { return this.ajaxUrl; } EdealGrid.prototype.setAjaxUrl = function(url) { this.ajaxUrl = url; } EdealGrid.prototype.sort = function(sortColumn, element) { // clean old eventual grid sort order sortColumn = sortColumn + ""; this.urlParams["$$ReverseOrderBy"] = "null"; this.urlParams["$$OrderBy"] = "null"; dbg_alert("sort for column:" + sortColumn + " type:" + typeof sortColumn); if (this.currentSortedElement) { $(this.currentSortedElement).removeClass(); } this.currentSortedElement = element; if (this.currentSortedColumn == sortColumn) { if (this.currentSortOrderAsc) { this.sortDesc(sortColumn); } else { this.sortAsc(sortColumn) } this.currentSortOrderAsc = !this.currentSortOrderAsc; } else { this.sortAsc(sortColumn); this.currentSortOrderAsc = true; this.currentSortedColumn = sortColumn; } } EdealGrid.prototype.sortAsc = function(sortColumn) { var ajaxUrl = this.baseUrl; var parameters = {}; parameters["$$OrderBy"] = sortColumn; this.callAjaxForHtml(ajaxUrl, parameters, false); } EdealGrid.prototype.sortDesc = function(sortColumn) { var ajaxUrl = this.getAjaxUrl(); var ajaxUrl = this.baseUrl; var parameters = {}; parameters["$$ReverseOrderBy"] = sortColumn; this.callAjaxForHtml(ajaxUrl, parameters, false); } EdealGrid.prototype.addColumn = function(column) { this.arrColumns.push(column); } EdealGrid.prototype.addJsonColumn = function(jsonColumn) { this.arrColumns.push(eval(jsonColumn)); } EdealGrid.prototype.render = function(req_param, req_value) { this.arrMassSelectID=new Array(); var ajaxUrl = this.getAjaxUrl(); var parameters = {}; parameters['_gridname'] = this.gridName if (req_param != null) { parameters[req_param] = req_value; } this.callAjaxForHtml(ajaxUrl, parameters, false); } EdealGrid.prototype.renderWithCriteria = function(parameters, jsonFobQuery) { var ajaxUrl = this.getAjaxUrl(); parameters['_gridname'] = this.gridName parameters['embedded_criteria'] = 'true'; parameters['_jsonfobquery'] = JSON.stringify(jsonFobQuery); // callAjaxForHtml=function(ajaxUrl,parameters,fReinitParameters,fEditMode,callBack,fPriorityToUrlParams,fDisplayPreview) // { this.callAjaxForHtml(ajaxUrl, parameters, false, false, null, false, null); } EdealGrid.prototype.renderLocal = function() { var jsonGridDefinition = JSON.stringify(this.arrColumns); var ajaxUrl = this.getAjaxUrl(); var parameters = 'LCSAJsonData=' + jsonGridDefinition + '&gridNameParam=' + this.gridName; var parameters = {}; parameters['LCSAJsonData'] = jsonGridDefinition; parameters['gridNameParam'] = this.gridName; this.callAjaxForHtml(ajaxUrl, parameters, false); } /* * rebuild html of the grid edit : if true the grid is in massEdit mode */ EdealGrid.prototype.reLoad = function(edit, cb) { this.callAjaxForHtml(this.baseUrl, null, null, edit, cb); } EdealGrid.prototype.loadPage = function(numPage, edit) { dbg_alert("loadPage " + numPage + " edit:" + edit); var empty = function(obj) { for (prop in obj) { return false; } return true; } if (!empty(this.fieldToUpdate)) { if (confirm(this.msgPreChangePage)) { var gridObject = this; this.save(function() { gridObject.loadPage(numPage, edit); }); } } else { this.fieldToUpdate = {}; var params = {}; params['$$idx'] = numPage; params[this.gridName + '_$$idx'] = numPage; this.callAjaxForHtml(this.baseUrl, params, null, null); } } EdealGrid.prototype.moveToRow = function(keyEvent) { dbg_alert("movetorow:" + keyEvent); var key = keyEvent.which ? keyEvent.which : keyEvent.keyCode; if (this.selectedGridRow == null) { this.selectedGridRow = $('tr[tabindex=0]', this.renderElement).get(0); } if (key == 38) { this.goToPrevRow(); } ; if (key == 40) { this.goToNextRow(); } ; } EdealGrid.prototype.goToNextRow = function() { var nextElem = $(this.selectedGridRow).next(); nextElem = nextElem.get(0); if (nextElem == null) { nextElem = $('tr[tabindex=0]', this.renderElement).get(0) } dbg_alert("goToNextRow" + nextElem); this.selectRow(nextElem); } EdealGrid.prototype.goToPrevRow = function() { var prevElem = $(this.selectedGridRow).prev(); prevElem = prevElem.get(0); if (prevElem == null) { prevElem = $('tr[tabindex=9999]', this.renderElement).get(0) // alert("on s'est mis à la fin:"+prevElem); } dbg_alert("goToPrevRow" + prevElem); this.selectRow(prevElem); } EdealGrid.prototype.selectRow = function(rowElement) { if (rowElement == null) { return; } if (rowElement.id == null || rowElement.id == "") { rowElement = rowElement.parentNode; } id = rowElement.id; if (id != null && id != "") { if (this.selectedGridRow != null) { dbg_alert("remove prev selection"); $(this.selectedGridRow).removeClass("active-selection-true"); } this.selectedGridRow = rowElement; if ($(rowElement).hasClass("odd")) { $(rowElement).addClass("odd active-selection-true"); } else { $(rowElement).addClass("even active-selection-true"); } this.showPreview(id, 'active-selection', rowElement); } } EdealGrid.prototype.showPreview_old = function(id, classe, rowElement) { var htmlPreview = this.getPreview(id); if (htmlPreview != null) { htmlPreview = htmlPreview.replace(/\\"/g, '"'); var preview = this.getRenderElementJQuery("#grid-preview").get(0); $(preview).html(htmlPreview); $(preview).css("visibility", "visible"); if (classe) { $(preview).addClass(classe); } } if (typeof setSizeOfGridData != 'undefined') { setSizeOfGridData(); } } EdealGrid.prototype.showPreview = function(id, classe, rowElement) { dbg_alert("old showpreview"); } /* * build html of the grid edit : if true the grid is in massEdit mode */ EdealGrid.prototype.ajaxDisplayClosure = function(gridObject, edit, callBack) { return function(arrIndex) { if (eDealXmlhttpArr[arrIndex].readyState == 4) { hideWaiting(); var response_login = eDealXmlhttpArr[arrIndex].getResponseHeader("EDEAL_login"); var response_pagetorender = eDealXmlhttpArr[arrIndex].getResponseHeader("EDEAL_grid_pagetorender"); // session expired, force to login if ("true" == response_login) { window.location.reload(); return; } // the action tells us that the last record of a page has been deleted: we must force // the pagination to the previous page if (response_pagetorender!=null && response_pagetorender!=""){ gridObject.loadPage(response_pagetorender,gridObject.fEditMode); return; } var html = eDealXmlhttpArr[arrIndex].responseText; gridObject.displayReturnedHtml(html); fEmbeddedList = ("true" == gridObject.getRenderElementJQuery("#grid-data").attr("ed:embedded")); if (edit) { // activeEnterKeyForEdit(gridObject); var onChangeFn = function(e) { var element = e.target; var input = $(element); if (input.hasClass("date")) { ctrlDateField(element, ""); } else if (input.hasClass("number")) { ctrlNumField(element, "float", ""); } if (input.hasClass("date")||input.hasClass("time")) { // Is a time stamp field (parent contains both date and time input)? /*if(input.parent().find(".input.date") && input.parent().find(".input.time")) { input = input.parent().find("input[type='hidden']"); }*/ } gridObject.storeForSave(input); }; // gridObject.getRenderElementJQuery("#grid-data // .listInput").change(onChangeFn); gridObject.getRenderElementJQuery("#grid-data input.input").change(onChangeFn); gridObject.getRenderElementJQuery("#grid-data textarea.input").change(onChangeFn); gridObject.getRenderElementJQuery("#grid-data select.input").change(onChangeFn); gridObject.getRenderElementJQuery("#grid-data input.checkbox").change(onChangeFn); // gridObject.getRenderElementJQuery("#grid-data // input[type=hidden].input ").change(onChangeFn); gridObject.getRenderElementJQuery("#grid-data input.input") .each(function(e) { if (this.name.startsWith("lbl")) { installFobACbasedOnID(this); // add the } }); // remove calendar icon for date input gridObject.getRenderElementJQuery("#grid-data a.cal-icon") .empty().remove(); } else { activeNavKeys(gridObject); // previewToken=gridObject.getRenderElementJQuery("#grid-data").attr("ed:previewtoken"); // if (previewToken!=null && previewToken!="") { // doAjax("get_list_preview_ajax.fl?_listtoken="+previewToken); // } } if (typeof getTooltips != "undefined") { getTooltips(); } if (callBack) { callBack(); } if (fEmbeddedList) { if (typeof prepareEmbeddedCriteria != 'undefined') { prepareEmbeddedCriteria(gridObject); } } } } function activeNavKeys(grid) { grid.getRenderElementJQuery("#grid-data").keyup(function(event) { grid.moveToRow(event); }); grid.getRenderElementJQuery("#grid-data").click(function(event) { grid.selectRow(event.target || event.srcElement); }); } function activeEnterKeyForEdit(grid) { grid.getRenderElementJQuery("#grid-data").keyup(function(keyEvent) { var key = keyEvent.which ? keyEvent.which : keyEvent.keyCode; // if (keyEvent) { keyEvent.stopPropagation(); // keyEvent.preventDefault();} // how to know if we are in auto complete mode or not ? if (key == 13 && acCurHighlightedDiv == null) { $(keyEvent.target).change(); grid.save(); } }); } } EdealGrid.prototype.displayReturnedHtml = function(html) { this.renderElement.innerHTML = html; // sort element if (this.currentSortedElement != null) { // the sort element should be a <a // *TODO* add icons management } } // store data for grid save EdealGrid.prototype.storeForSave = function(input) { var name = input.attr("ed:realname"); // deal with speacial cases of fob & // autocomplete if (name == undefined) { name = input.attr("name"); } var id = input.attr("id"); id = id.substr(id.lastIndexOf('-') + 1); var value = ""; if (input.is(':checkbox')) { value = input.is(':checked'); } else { value= input.val(); } if (this.fieldToUpdate[id] == null) { this.fieldToUpdate[id] = {}; } if (!name.startsWith('lbl')) { this.fieldToUpdate[id][name] = "" + value; // for a cast to string } } // send input data to server for saving beans EdealGrid.prototype.save = function(callBack) { var res = []; var i = 0; var edealGRid = this; if (this.objectType != "" && this.objectType != null) { for ( var id in this.fieldToUpdate) { res[i++] = { "type" : this.objectType, "id" : id, "fields" : this.fieldToUpdate[id] }; } if (res.length == 0) { edealGRid.reLoad(false); } else { var jsondata = JSON.stringify(res); // call back function for save function analyse_save_response(data) { if (data.msg != null) { if (data.msg.type != "info") { if (typeof gGridCriteria != 'undefined') { gGridCriteria.showInfoTab(data.msg.lbl, $("#grid-save-button")); } else { alert(data.msg.lbl); } } } if (data.beans != null) { edealGRid.fieldToUpdate = {}; if (callBack && typeof (callBack) == "function") { callBack(data); } else { edealGRid.reLoad(false); } } } $.ajax({ data : jsondata, type : "POST", url : edealGRid.contextName + "/editBeans.fl", timeout : 20000, contentType : "application/json;charset=utf-8", dataType : 'json', success : analyse_save_response, error : function(xhr, textStatus, errorThrown) { alert("Update Error: " + textStatus + "\n" + errorThrown); } }); } } } EdealGrid.prototype.reset = function() { this.fieldToUpdate = {}; this.reLoad(false); } EdealGrid.prototype.reloadForEdition = function() { this.reLoad(true); } EdealGrid.prototype.allowUserUpdate = function(fAllowUserUpdate) { this.fUserUpdateAllowed = fAllowUserUpdate; } EdealGrid.prototype.addMassSelect = function(id, doAdd) { if (doAdd) { $("p.actions_massselect").css({ color : "red" }); this.arrMassSelectID.push(id); } else { this.arrMassSelectID.splice(this.arrMassSelectID.indexOf(id), 1); if (this.arrMassSelectID.length == 0) { $("p.actions_massselect").css({ color : "black" }); } } } EdealGrid.prototype.addMassSelectAll = function(doAdd) { this.arrMassSelectID = new Array(); gridObject = this; $("p.actions_massselect").css({ color : (doAdd ? "red" : "black") }); this.getRenderElementJQuery("tr.bean").each(function() { id = this.id; $("#massselectcheck-" + id).attr('checked', doAdd); if (doAdd) { gridObject.arrMassSelectID.push(id); } }); } EdealGrid.prototype.sendMassSelect = function(urlAction, elementID, hasLayer) { if (this.arrMassSelectID.length > 0 || urlAction.contains('create_opportunity')) { if (!hasLayer) { var jsondata = JSON.stringify(this.arrMassSelectID); dbg_alert(elementID); var formDom = '<form action="' + urlAction + '" method="POST">'; formDom += '<input type="hidden" name="data">'; formDom += '</form>'; dbg_alert(formDom); $("#" + elementID).append(formDom); var f = $("#" + elementID + " form").get(0); if (f) { f["data"].value = jsondata; f.submit(); } } else { openPopupLayer(this.arrMassSelectID, this.objectType, urlAction); } } else { alert(this.msgNoSelection); } } EdealGrid.prototype.noSelectionAlert = function(edealGrid) { return function(index) { if (eDealXmlhttpArr[index].readyState == 4) { hideWaiting(); edealGrid.msgNoSelection = eDealXmlhttpArr[index].responseText; } } } EdealGrid.prototype.storePreview = function(id, preview) { this.previewCache[id] = preview; } EdealGrid.prototype.getPreview = function(id) { return this.previewCache[id]; } // return url and store parameters in the given outParams object EdealGrid.prototype.decodeUrlToObj = function(url, outParams, fPriorityToUrlParams) { var baseUrl = url; var paramStr = url; var query = url.split("?"); if (query.length > 1) { baseUrl = query[0]; paramStr = query[1]; } if (paramStr != null && paramStr != "") { var params = paramStr.split("&"); for (idxParam in params) { if (typeof params[idxParam] == "string") { var param = params[idxParam].split("="); var key = param[0]; var value = param[1]; if (outParams[key] == null) { outParams[key] = value + ""; } else if (fPriorityToUrlParams) { outParams[key] = value + ""; } } } } return { url : baseUrl, parameters : outParams }; } EdealGrid.prototype.storeUrlAndParams = function(url, fPriorityToUrlParams) { var res = this.decodeUrlToObj(url, this.urlParams, fPriorityToUrlParams); this.baseUrl = res.url; this.displayFullUrl("storeUrlAndParams", url, this.urlParams); } EdealGrid.prototype.paramsToUrl = function(additionalParams, fKeepUrlParameters) { // If string => parse to object var parameters = {}; if (additionalParams != null) { if (typeof additionalParams == 'string') { dbg_alert("params2Url: string:" + additionalParams); var res = this.decodeUrlToObj(additionalParams, parameters); } else if (typeof additionalParams == 'object') { dbg_alert("params2Url: object:" + additionalParams); parameters = additionalParams; // parameters=res.parameters; } } for (key in parameters) { // alert("parameter:"+key+"="+parameters[key]+" // urlparams:"+this.urlParams[key]+" "+fKeepUrlParameters); if (!(this.urlParams[key] && fKeepUrlParameters)) { this.urlParams[key] = parameters[key]; } } var paramString = ""; for (key in this.urlParams) { var value = this.urlParams[key]; if (value != "null" && value != "" && key != null && key != "") {// *TODO* Problem de tri colonne paramString += ("&" + key + "=" + value); } } return this.baseUrl + "?d" + paramString } EdealGrid.prototype.reinitParams = function() { this.baseUrl = null; this.urlParams = {}; this.arrMassSelectID = new Array(); this.usedCallBack = null; } var EdealGridColumn = function(position, width, style, format) { this.pos = position; this.width = width; this.style = style; this.format = format; this.linkAttr = null; this.override = null; this.pretext = null; this.posttext = null; this.linkCSS = null; this.visitedCSS = null; this.activeCSS = null; this.hoverCSS = null; } // special functions for fob triggering/ac // called by common/select.jsp to tells there is a change for a fob select function doTriggerChange(elementId) { var element = $("#" + elementId).get(0); $(element).change(); } function doTriggerChangeFromAc(elementId) { if (elementId.indexOf('$') > -1) { return; } var element = $("#" + elementId); if (element) { element = element.get(0); var realName = $(element).attr("ed:realname"); if (realName) { element.name = realName;// put the real name back (for the field // name to be correct); $(element).change(); } } } // called from the fob delete icon the grid edit mode function eraseField(elementID) { //alert(elementID); // $(element).siblings('input').each(function(e) { alert(e.id); }); $("#" + elementID).val('').change(); $("#lbl" + elementID).val(''); }
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de