/** * lookup_multiple.js - process lookup in a group condition */ // Apply prototype Array.indexOf() ... if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt) { var len = this.length; // The following code is very fast, but we must check it in all browser ... // especially Internet Explorer 8 // The following code is slow for (var index = 0; index < len; index++) { // This comparing is very fast than == if (elt === this[index]) { return index; } } return -1; }; } // The actual header of GUI using for Lookup Condition var actualHeadersGUI4LookupCondition = new Array(); // Fix bug 0023793: Dispatch - Lookup list don't display if lookup condition of it is hiden in website // The object contain values of objHiddenControls['recordKey'] of current edit row var objHiddenControls4LkCond = {}; /** * Get result array with unique values * @param {} arrayData * @returns {} */ function getUniqueArray(arrayData) { var resultArray = new Array(); for (var k = 0; k < arrayData.length; k++) { if ($.inArray(arrayData[k], resultArray) < 0) { resultArray.push(arrayData[k]); } } return resultArray; } /** * Process initialize data, events for Lookup Multiple feature. */ function initLookupMultiple() { // Create the list of LimitToList lookup conditional var listConditionLookupField = glbHashObject['ListConditionLookupField']; var mapCondtionLookupStructure = glbHashObject['MapCondtionLookupStructure']; var listLimitToList4LkCondition = new Array(); for (var i = 0; i < listConditionLookupField.length; i++) { // Get the flag about limitToList var curName = listConditionLookupField[i]; var curData = mapCondtionLookupStructure['' + curName]; if (curData.limitToList === true) { listLimitToList4LkCondition.push(curName); } } glbHashObject['ListConditionLookupField_LimitToList'] = listLimitToList4LkCondition; // Only load data source for the first time // after clicking [View] and make Insert/Update data if (glbHashObject['is_loaded_datasource_lookupconditional'] === true) { return; } // Show the waiting progress waitForDataLoading(true); // Create the data source structure we want to load from server var datasourceRequest = new Object(); var listConditionLookupField = glbHashObject['ListConditionLookupField']; var mapCondtionLookupStructure = glbHashObject['MapCondtionLookupStructure']; // Process data into id map var mapCondtionLookupStructureById = convertMapCondtionLookupStructureById(); for (var i = 0; i < listConditionLookupField.length; i++) { var strLookupField = listConditionLookupField[i]; var currentData = mapCondtionLookupStructure[strLookupField]; var dataSourceId = currentData.dataSourceId; var arrData = datasourceRequest[dataSourceId]; if (arrData == undefined || arrData == null) { arrData = new Array(); } // Put the current dataSourceId into list keys for iteration later if (datasourceRequest.listDataSourceId == undefined || datasourceRequest.listDataSourceId == null) { datasourceRequest.listDataSourceId = new Array(); } datasourceRequest.listDataSourceId.push(dataSourceId); datasourceRequest.listDataSourceId = getUniqueArray(datasourceRequest.listDataSourceId); // Put the current lookupColumn of this LookupField into arrData arrData.push(currentData.lookupColumn); var arrLookupConditionFieldsInNames = new Array(); var arrLookupConditionFieldsInColumns = new Array(); var lookupConditionFieldsAnswer = currentData.lookupConditionFieldsAnswer; // Put the list of columns lookup field for (var t = 0; t < currentData.lookupConditionFields.length; t++) { var lkFieldId = currentData.lookupConditionFields[t]; // Prevent error when the lkFieldId is not inside mapCondtionLookupStructureById[] if (mapCondtionLookupStructureById[lkFieldId] === undefined || mapCondtionLookupStructureById[lkFieldId] === null) { continue; } var lkFieldName = mapCondtionLookupStructureById[lkFieldId].name; var lookupColumn = mapCondtionLookupStructureById[lkFieldId].lookupColumn; // Get lookupColumn based on current condition answer if (lookupConditionFieldsAnswer !== undefined && lookupConditionFieldsAnswer[t] !== undefined && lookupConditionFieldsAnswer[t] !== null && lookupConditionFieldsAnswer[t] !== '') { lookupColumn = convertColumnInMobileType2Web(lookupConditionFieldsAnswer[t]); } // Put default data if lookupColumn is undefined if (lookupColumn === undefined || lookupColumn === null) { lookupColumn = ''; } arrData.push(lookupColumn); // Update condition lookup fields for currentData in style [field_01, field02, ...] // instead of [6, 7, ...] arrLookupConditionFieldsInColumns.push(lookupColumn); arrLookupConditionFieldsInNames.push(lkFieldName); } arrData = getUniqueArray(arrData); arrData.sort(); // Put the result data back to original store datasourceRequest[dataSourceId] = arrData; currentData.lookupConditionFieldsInColumns = arrLookupConditionFieldsInColumns; currentData.lookupConditionFieldsInNames = arrLookupConditionFieldsInNames; } // Process loading all needed datasource by every datasourceId (if have at least one lookup condition field) if (datasourceRequest.listDataSourceId == undefined || datasourceRequest.listDataSourceId == null || datasourceRequest.listDataSourceId.length <= 0) { glbHashObject['datasourceRequest4LookupCondition'] = datasourceRequest; // Hide the waiting progress waitForDataLoading(false); return; } else { loadAllNeededDS4ConditionLookup(datasourceRequest, function() { //alert('OK, we complete ... :: ' + datasourceRequest); glbHashObject['datasourceRequest4LookupCondition'] = datasourceRequest; // Setting the flag completed loading data source for lookup conditional glbHashObject['is_loaded_datasource_lookupconditional'] = true; // Hide the waiting progress waitForDataLoading(false); }); } } /** * Helper function */ function convertMapCondtionLookupStructureById() { var mapCondtionLookupStructureById = new Object(); var mapCondtionLookupStructure = glbHashObject['MapCondtionLookupStructure']; for(var key in mapCondtionLookupStructure){ var currentObject = mapCondtionLookupStructure[key]; mapCondtionLookupStructureById[currentObject.id] = currentObject; } return mapCondtionLookupStructureById; } /** * Load all needed data source for using in Condition Lookup. * */ function loadAllNeededDS4ConditionLookup(datasourceRequest, completeFunctionAction) { // Start with current index = 0 glbHashObject['datasourceRequest.listDataSourceId.currentIndex'] = 0; // Apply getting data for Lookup Conditional apply4NextGettingData(datasourceRequest, completeFunctionAction); } /** * Checking for apply next getting data for Lookup Conditional DataSource * @param {} datasourceRequest * @param {} completeFunctionAction * @returns {} */ function apply4NextGettingData(datasourceRequest, completeFunctionAction) { var i = glbHashObject['datasourceRequest.listDataSourceId.currentIndex']; if (i >= datasourceRequest.listDataSourceId.length) { // OK, we have finished getting data // Getting from server by AJAX request if (completeFunctionAction != undefined && completeFunctionAction != null) { completeFunctionAction.apply(this); } return; } // Apply getting data var dataSourceId = datasourceRequest.listDataSourceId[i]; var qIndexMultipleCols = datasourceRequest[dataSourceId].join(','); // Default limit rows is 5000 with one cols // Multiple cols will be down to by division var limitRows4Request = 5000; if (datasourceRequest[dataSourceId].length > 1) { limitRows4Request = Math.round(limitRows4Request / datasourceRequest[dataSourceId].length); } loadLookupFormDatasource4Conditional(true, dataSourceId, qIndexMultipleCols, datasourceRequest, limitRows4Request, completeFunctionAction); } /** * Load all lookup data source for every formId using in Lookup Conditional * @param {} _first The flag, to find out the first time excecute this function for formId * @param {} _lkMstKey The lookup master key (in Lookup Manager screen) * @param {} _qIndex The column index string, ex : Column_0,Column_1, ... * @param {} datasourceRequest The datasourceRequest object * @param {} limitRows4Request The result limit rows for one request * * @returns {} * */ function loadLookupFormDatasource4Conditional(_first, _lkMstKey, _qIndex, datasourceRequest, limitRows4Request, completeFunctionAction) { // For the first time, we will init the result array if(_first){ posisionIndex = 0; datasourceRequest[_lkMstKey + '_DataSource'] = new Array(); } var moreRecordNum = 0; // Based on number of columns of _lstMstKey, we will set appropriate limit rows in a request // Default limitRows4Request = 5000 for one col var toIndex = posisionIndex + limitRows4Request; writeToLogInfo("loadLookupFormDatasource4Conditional - Position " + toIndex); $.ajax({ url: '/client/lookupXml', dataType: 'json', data: { kind : '1' ,id : _lkMstKey ,qValue : '' ,qIndex : _qIndex ,isUsingMultipleColumns : CONST_VALUE_TRUE_STR ,from : posisionIndex ,to : toIndex ,cl : 0 }, type: 'Get', cache: false, //async: false, complete: function() { if(moreRecordNum == 1){ // not complete posisionIndex = toIndex; loadLookupFormDatasource4Conditional(false, _lkMstKey, _qIndex, datasourceRequest, limitRows4Request, completeFunctionAction); } else { writeToLogInfo('Total rows :: ' + datasourceRequest[_lkMstKey + '_DataSource'].length); // The current data section is OK, we will goto next data section // Start with current index = 0 glbHashObject['datasourceRequest.listDataSourceId.currentIndex']++; // Process sort data based on last column (SUBMITTED_DATE) processSortLookupConditionalBySubmittedDate(datasourceRequest[_lkMstKey + '_DataSource']); // Apply getting data for Lookup Conditional apply4NextGettingData(datasourceRequest, completeFunctionAction); } }, success: function(response, status) { moreRecordNum = response.MoreRecord; // Merge current offset data into final result var _lkData = response.LookupData; datasourceRequest[_lkMstKey + '_DataSource'] = $.merge(datasourceRequest[_lkMstKey + '_DataSource'], _lkData) }, error: function(request, status, error) { //waitForDataLoading(false); } }); } /** * Get data source for Condition Lookup Field * @param {} lookupField * @returns {} array of string */ function getDataSource4ConditionLookup(lookupField, isAcceptNull, columnIndex, insideContainer, columnIndexInTable, rowIndexInTable) { var orgLookupField = lookupField.replace(/-.+/, ''); // Fix bug 0023793: Dispatch - Lookup list don't display if lookup condition of it is hiden in website var lookupFieldSuffix = lookupField.substring(orgLookupField.length, lookupField.length); var isEmptyFieldSuffix = true; if (lookupFieldSuffix !== '') { isEmptyFieldSuffix = false; } // Check the condition for re-creating new data source for current condition field lookup // var isNeededUpdateDS = true; // if (isNeededUpdateDS == false) { // return jsonLKDS[orgLookupField]; // } var mapCondtionLookupStructure = glbHashObject['MapCondtionLookupStructure']; // Process filter lookup field var resultArray = new Array(); // The currentData will contain following information : // .lookupColumn => The matching lookup column in DataSource, ex : Column_2 // .id => The control id of current lookup field, ex : 2 // .lookupConditionFields => The list of lookupCondtionFields in id values, ex : ["6", "7"] // .name => The dataName of current lookup field, ex : Lookup_field_2 // .dataSourceId => The data source id // .lookupConditionFieldsInNames // The list of lookupCondtionFields in names, ex : ["Lookup_field_6", "Lookup_field_7"] // .lookupConditionFieldsInColumns // The list of lookupCondtionFields in columns in DataSource, ex : ["Column_3", "Column_5"] var currentData = mapCondtionLookupStructure[orgLookupField]; var dataSourceId = currentData.dataSourceId; var datasourceRequest = glbHashObject['datasourceRequest4LookupCondition']; var currentHeaderDS = datasourceRequest[dataSourceId]; var currentDS = datasourceRequest[dataSourceId + '_DataSource']; // Store the first item var currentItemObject = null; if (glbHashObject['list_lookup_conditional_fields'].length === 1) { currentItemObject = glbHashObject['list_lookup_conditional_fields'][0]; glbHashObject['list_lookup_conditional_fields'] = new Array(0); } // Create index inside datasource (Convert from index of LookupConditionField => index inside DataSource) // The index map for Columns, ex : Column_0, Column_1, ... var indexMap = new Object(); var indexMapInGUI = new Object(); var indexTagNameGUI = new Object(); var numLookupConditions = currentData.lookupConditionFields.length; for (var index = 0; index < numLookupConditions; index++) { var lkColumnName = currentData.lookupConditionFieldsInColumns[index]; var isUsingUnderlineValue = currentData.usingUnderlineValue[index]; var conditionAnswer = currentData.lookupConditionFieldsAnswer[index]; // Create index inside DataSource based on conditionAnswer (new method) or old method (only lookup field) var indexInCurrentDS = currentHeaderDS.indexOf(lkColumnName); // Special treating with type Text/Numeric/ChooseOne/Trends if (conditionAnswer === undefined || conditionAnswer === null || conditionAnswer === '') { indexInCurrentDS = 0; } // Assign data indexMap[index] = indexInCurrentDS; // Get current data on GUI var controlLkFieldName = currentData.lookupConditionFieldsInNames[index]; var currentIndexMapInGUI = ''; if (insideContainer === CONST_CTRL_TYPE_CTRLTABLE) { // The lookup field is inside of FixTable currentIndexMapInGUI = getValueOfControlInGUI4FixTable(columnIndex, columnIndexInTable, rowIndexInTable, isUsingUnderlineValue, controlLkFieldName); } else if (insideContainer === CONST_CTRL_TYPE_CTRLGRID) { // The lookup field is inside of Grid currentIndexMapInGUI = getValueOfControlInGUI4Grid(columnIndex, isUsingUnderlineValue, controlLkFieldName); } else { // The normal case, the lookup field is outside of FixedTable, Grid // Get value in GUI, notice that the ChooseOne is using underline value or not currentIndexMapInGUI = getValueOfControlInGUI(columnIndex, isUsingUnderlineValue, controlLkFieldName); } // Fix bug 0023793: Dispatch - Lookup list don't display if lookup condition of it is hiden in website // Get the current value from Form Structure or Datastore (with field HideInWebsite) if (currentIndexMapInGUI === null) { // Get data from objHiddenControls4LkCond currentIndexMapInGUI = objHiddenControls4LkCond[controlLkFieldName]; // Special treating with Grid/Table if (insideContainer === CONST_CTRL_TYPE_CTRLGRID || insideContainer === CONST_CTRL_TYPE_CTRLTABLE) { isEmptyFieldSuffix = false; lookupFieldSuffix = '-1-'; } if (typeof currentIndexMapInGUI === 'undefined' && isEmptyFieldSuffix === false) { currentIndexMapInGUI = objHiddenControls4LkCond[controlLkFieldName + lookupFieldSuffix]; } if (typeof currentIndexMapInGUI === 'undefined') { currentIndexMapInGUI = ''; } } // Process ignore case //currentIndexMapInGUI = currentIndexMapInGUI.toLowerCase(); var currentGUIValue = currentIndexMapInGUI.toLowerCase(); indexMapInGUI[index] = currentGUIValue; // Fix bug 0020148: Lookup - List item show incorrectly in case Lookup inside Grid make Lookup conditions and "Evaluate..." checked if (glbCurrentGettingControlTagNameLowercase === null) { indexTagNameGUI[index] = 'unknown tag'; } else { indexTagNameGUI[index] = glbCurrentGettingControlTagNameLowercase; } // In case of an input lookup data in GUI is empty, we return empty array // (Only apply when isAcceptNull == false) // if (currentGUIValue === '' && isAcceptNull === false) { // resultArray = new Array(); // // writeToLogInfo('Return empty lookup DS because user do not input [' + controlLkFieldName + ']'); // return resultArray; // } // Store list of conditional lookup fields for using in Fetching data var item = new Object(); item['name'] = controlLkFieldName; item[CONST_VALUE] = currentIndexMapInGUI; glbHashObject['list_lookup_conditional_fields'].push(item); } // Adding current lookup data field if (currentItemObject != null) { glbHashObject['list_lookup_conditional_fields'].push(currentItemObject); } var currentFieldLookupIndex = currentHeaderDS.indexOf(currentData.lookupColumn); // Browse all lines of DataSource var numRows = currentDS.length; for (var rowIndex = 0; rowIndex < numRows; rowIndex++) { var line = currentDS[rowIndex]; // The current value of line we want to add // We will ignore it in case of EMPTY var currentItemValue = line[currentFieldLookupIndex]; if (currentItemValue == undefined || currentItemValue == '') { continue; } // Check condition var isMatchingFilter = true; for (var index = 0; index < numLookupConditions; index++) { var indexInCurrentDS = indexMap[index]; var value = line[indexInCurrentDS]; // The value of current data filter var valueInGUI = indexMapInGUI[index]; // Only checking when the valueInGUI != EMPTY // (or valueInGUI == EMPTY and [x]Accept NULL) if (valueInGUI !== '' || (valueInGUI === '' && true === isAcceptNull) ) { // Apply ignore case in filtering data value = value.toLowerCase(); // Modify value if (value !== valueInGUI) { // Checking for special case (ChooseOne checking) var tagOfGUI = indexTagNameGUI[index]; if (tagOfGUI === 'select') { var isUsingUnderlineValue = currentData.usingUnderlineValue[index]; // Process checking based on underlineValue or Caption var checkValue = null; var arrMixedValue = value.split('$$'); if (isUsingUnderlineValue === true) { // Underline Value if (arrMixedValue.length > 0) { checkValue = arrMixedValue[0]; } } else { // Caption if (arrMixedValue.length > 1) { checkValue = arrMixedValue[1]; } } if (checkValue !== valueInGUI) { isMatchingFilter = false; break; } } else { // The normal case isMatchingFilter = false; break; } } // if (value !== valueInGUI) { // isMatchingFilter = false; // break; // } } } // Filter conditions and ignore duplicate data // $.inArray(currentItemValue, resultArray) if (isMatchingFilter == true && $.inArray(currentItemValue, resultArray) < 0) { resultArray.push(currentItemValue); } } return resultArray; } /** * Process when user focus into a lookup field on GUI */ function processUpdateDataSource4ConditionLookup(objThis, ignoreLoadAutocomplete) { var dataName = objThis.id; var columnIndex = objThis.name; // We must ignore 2 first columns, so columnIndex = columnIndex - 2; if (columnIndex != '') { try { columnIndex = parseInt(columnIndex) - 2; } catch (e) {} } if (dataName.indexOf('lk_') == 0) { dataName = dataName.substring(3); } var jQueryThis = $(objThis); var isInsideGrid = false; // Check if the current lookup inside Grid if (jQueryThis.attr('isInsideGrid') === CONST_VALUE_TRUE_STR) { isInsideGrid = true; dataName = objThis.name; // Process columnIndex inside Grid try { columnIndex = parseInt(jQueryThis.attr('gridColumnIndex')) - 2; } catch (e) {} } var orgDataName = dataName.replace(/-.+/, ''); var mapCondtionLookupStructure = glbHashObject['MapCondtionLookupStructure']; var currentData = mapCondtionLookupStructure['' + orgDataName]; // Not inside Dispatch Tab // [x]Use lookup in website Dispatch tab only // => Do nothing. if (dispatchViewFlg !== true) { // Get the flag []Use lookup in website Dispatch tab only if (currentData.isUseDispOnly === true) { return; } } // With normal lookup field, we will ignore var listConditionLookupField = glbHashObject['ListConditionLookupField']; if ($.inArray(orgDataName, listConditionLookupField) < 0) { return; } // Store list of conditional lookup fields for using in Fetching data var item = new Object(); item['name'] = dataName; item[CONST_VALUE] = objThis.value; glbHashObject['list_lookup_conditional_fields'] = new Array(); glbHashObject['list_lookup_conditional_fields'].push(item); var isAcceptNull = false; if (currentData.isAcceptNull === true) { isAcceptNull = true; } // Filter new data source (if needed) var lk_datasource = null; if (isInsideGrid === true) { // Get datasource inside Grid lk_datasource = getDataSource4ConditionLookup(dataName, isAcceptNull, columnIndex, CONST_CTRL_TYPE_CTRLGRID); } else { // Get datasource in normal cases lk_datasource = getDataSource4ConditionLookup(dataName, isAcceptNull, columnIndex); } // Sort by anpha-numeric based on BuildForms setting if (currentData.isSortLookupList === true) { lk_datasource.sort(); } if (ignoreLoadAutocomplete === true) { return lk_datasource; } // Refresh new datasource for Condition Lookup Control if (isInsideGrid === true) { // Apply event for LookupConditional in Grid initializeLookupFields4LookupConditionInsideTable(objThis, lk_datasource, true, record_Id); } else { // Apply event for LookupConditional in normal cases initializeLookupFields4LookupCondition(record_Id, dataName, lk_datasource); } } /** * Process when user focus into a lookup field on GUI (Inside of FixTable) */ function processUpdateDataSource4ConditionLookupInsideTable(objThis, ignoreLoadAutocomplete) { var dataName = objThis.id; var columnIndexInTable = $(objThis).attr('column_index'); var rowIndexInTable = $(objThis).attr('name'); // We must ignore 2 first columns, so columnIndex = columnIndex - 2; var columnIndex = glbHashObject['currentFixTableColumnIndex']; if (columnIndex != '') { try { columnIndex = parseInt(columnIndex) - 2; } catch (e) {} } // Get data name of current control if (dataName.indexOf('idControlInFixTable_') == 0) { dataName = dataName.substring('idControlInFixTable_'.length); } var orgDataName = dataName.replace(/-.+/, ''); var mapCondtionLookupStructure = glbHashObject['MapCondtionLookupStructure']; var currentData = mapCondtionLookupStructure['' + orgDataName]; // Not inside Dispatch Tab // [x]Use lookup in website Dispatch tab only // => Do nothing. if (dispatchViewFlg !== true) { // Get the flag []Use lookup in website Dispatch tab only if (currentData.isUseDispOnly === true) { return; } } // With normal lookup field, we will ignore var listConditionLookupField = glbHashObject['ListConditionLookupField']; if ($.inArray(orgDataName, listConditionLookupField) < 0) { return; } // Store list of conditional lookup fields for using in Fetching data var item = new Object(); item['name'] = dataName; item[CONST_VALUE] = objThis.value; glbHashObject['list_lookup_conditional_fields'] = new Array(); glbHashObject['list_lookup_conditional_fields'].push(item); var isAcceptNull = false; if (currentData.isAcceptNull === true) { isAcceptNull = true; } // Filter new data source (if needed) var lk_datasource = getDataSource4ConditionLookup(dataName, isAcceptNull, columnIndex, CONST_CTRL_TYPE_CTRLTABLE, columnIndexInTable, rowIndexInTable); // Sort by anpha-numeric based on BuildForms setting if (currentData.isSortLookupList === true) { lk_datasource.sort(); } if (ignoreLoadAutocomplete === true) { return lk_datasource; } // Refresh new datasource for Condition Lookup Control initializeLookupFields4LookupConditionInsideTable(objThis, lk_datasource); } /** * Put Lookup Condition into specified field (Normal Case) * @param {} _rowId * @param {} _field * @param {} lk_datasource * @returns {} */ function initializeLookupFields4LookupCondition(_rowId, _field, lk_datasource) { var curLKQuestion = _field; var lkdsName = curLKQuestion; if(lkdsName.indexOf('-') > 0) lkdsName = lkdsName.substring(0, lkdsName.indexOf('-')); // get datasource if(lk_datasource == undefined) { return; } // register auto complete event $("#lk_" + curLKQuestion) .unautocomplete() .removeAttr('onchange') // remove onchange event (if any) .autocomplete_lk(lk_datasource, { // register autocomplete event minChars: 0, max: 100, autoFill: true, scrollHeight: 200 }) .result(function log(event, data, formatted) { var targetId = event.target.id; queryLKData(targetId.substring(3, targetId.length), formatted, _rowId); }) .flushCache() //.simulate("keydown", { keyCode: $.simulate.VK_DOWN }) ; // Trigger event keydown after 200ms setTimeout(function() { var objCurrentLKQuestion = $("#lk_" + curLKQuestion); // Check the visible of .ac_results // Trigger event KEY_DOWN when the pop do not show if ($('.ac_results:visible').length <= 0) { objCurrentLKQuestion.simulate("keydown", { keyCode: $.simulate.VK_DOWN }); } }, 200); } /** * Put Lookup Condition into specified field (Inside FixTable) * @param {} objThis * @param {} lk_datasource * @returns {} */ function initializeLookupFields4LookupConditionInsideTable(objThis, lk_datasource, isInsideGrid, rowId4Grid) { if(lk_datasource == undefined) { return; } // --- register auto complete event $(objThis) .unautocomplete() .removeAttr('onchange') // remove onchange event (if any) .autocomplete_lk(lk_datasource, { minChars: 0, max: 100, autoFill: true, scrollHeight: 200 }) .result(function log(event, data, formatted) { try { // Special processing with Grid if (isInsideGrid === true) { // Lookup field inside Grid //queryLKData(event.target.name, formatted, rowId4Grid); queryLKData(event.target.name, formatted, '_gridTable'); } else { // Lookup field inside FixedTable var targetClass = event.target.className.split(' ')[1]; var rowIndex = parseInt(event.target.name); queryLKData(targetClass.substring(3, targetClass.length), formatted, rowIndex); } } catch (e) { writeToLogInfo('Exception in fetching data inside LKConditional : ' + e); } }) .flushCache() //.simulate("keydown", { keyCode: $.simulate.VK_DOWN }) ; // Trigger event keydown after 200ms setTimeout(function() { var objCurrentLKQuestion = $(objThis); // Check the visible of .ac_results if ($('.ac_results:visible').length <= 0) { objCurrentLKQuestion.simulate("keydown", { keyCode: $.simulate.VK_DOWN }); } }, 200); } /** * Get value of Control in GUI * @param {} columnIndex The column index of current edit row (inlcude groups and sub groups) * @param {} controlLkFieldName The based control using in condition lookup field * @returns {} */ var glbCurrentGettingControlTagNameLowercase = null; function getValueOfControlInGUI(columnIndex, isUsingUnderlineValue, controlLkFieldName) { // Example about lookupField : Current_lookup_dataName-2_3_4- // orgLookupField : Current_lookup_dataName // theSuffix : -2_3_4- // The controlLkFieldName is alway in original data name, so we will match it in real id line // such as controlLkFieldName = Search_lookup, we will have some cases : // : lk_Search_lookup-2_3_4- // : lk_Search_lookup-2_3- // : lk_Search_lookup-2- // : lk_Search_lookup var realLkFieldId = "#lk_" + controlLkFieldName; var jQueryRealLkField = $(realLkFieldId); PROCESS__BLOCK : { // First, we find directly data through it's id // If we can get directly data, it's OK. if (jQueryRealLkField.length > 0) { break PROCESS__BLOCK; } // Get value of Text/Numeric/ChooseOne jQueryRealLkField = $(controlLkFieldName); if (jQueryRealLkField.length > 0) { break PROCESS__BLOCK; } // Browse inverse data from index [columnIndex] for getting real lookup field id value for (var i = columnIndex-1; i >= 0; i--) { // Fix bug 0023818: View Data - Lookup condition works in correctly. // Fix bug 0023819: Dispatch - Lookup condition works in correctly. //var currentHeader = jsonHeadersFull.Data[i]; var currentHeader = arrHeadersFullGUI4LookupCond[i]; var realOrgHeader = currentHeader.replace(/\(.+\)/, ''); if (controlLkFieldName == realOrgHeader) { realLkFieldId = '#lk_' + currentHeader.replace('(', '-').replace(')', '-') .replace(/,/g, '_'); // Check if the current field is a lookup field or (Text/Numeric/ChooseOne) jQueryRealLkField = $(realLkFieldId); if (jQueryRealLkField.length > 0) { break PROCESS__BLOCK; } // The current is one of following field : Text/Numeric/ChooseOne realLkFieldId = '[control_name="' + getControlNameFromHeaderText(currentHeader) + '"]'; jQueryRealLkField = $(realLkFieldId); break PROCESS__BLOCK; } } } // When the field is not available, we will get it from dataSrcInGUINameValueMapping{} if (jQueryRealLkField.length <= 0) { // TODO: Temporatory write log writeToLogInfo('Process special fields not in GUI : controlLkFieldName : ' + controlLkFieldName); var savedValue = dataSrcInGUINameValueMapping[controlLkFieldName]; // Fix bug 0023793: Dispatch - Lookup list don't display if lookup condition of it is hiden in website // Special treating with undefined/empty data if (typeof savedValue === 'undefined' || savedValue === '') { return null; } writeToLogInfo('Return savedValue : ' + savedValue); return savedValue; } // For getting current control GUI for using later glbCurrentGettingControlTagNameLowercase = jQueryRealLkField[0].tagName.toLowerCase(); // Get current value of field (in GUI) var resultValue = jQueryRealLkField.val(); // Check the case of getting Caption of SelectOne if (isUsingUnderlineValue === false && glbCurrentGettingControlTagNameLowercase === 'select') { resultValue = jQueryRealLkField.find('option:selected').text(); } return resultValue; } /** * Get value of Control in GUI (inside FixTable or outside) * * @param {} columnIndex The column index of current edit row (inlcude groups and sub groups, not in FixTable) * @param {} colIndexInFTable The start column index in FixTable for looking up data (backwards) * @param {} rowIndexInTable The row index in FixTable for looking up data * @param {} controlLkFieldName The based control using in condition lookup field * @returns {} */ function getValueOfControlInGUI4FixTable(columnIndex, colIndexInFTable, rowIndexInTable, isUsingUnderlineValue, controlLkFieldName) { // Track data from current columnIndex // Get all related cells from the current row var jQueryTarget = $('.fixed_Table input[name=' + rowIndexInTable + '][id=idControlInFixTable_' + controlLkFieldName + ']'); if (jQueryTarget.length > 0) { return jQueryTarget.val(); } // It's not inside fix table, so we will find outside return getValueOfControlInGUI(columnIndex, isUsingUnderlineValue, controlLkFieldName); } /** * Get value of Control in GUI (inside Grid) * * @param {} columnIndex The column index of current edit row (inlcude groups and sub groups, not in FixTable) * @param {} controlLkFieldName The based control using in condition lookup field * @returns {} */ function getValueOfControlInGUI4Grid(columnIndex, isUsingUnderlineValue, controlLkFieldName) { // For getting current control GUI for using later glbCurrentGettingControlTagNameLowercase = null; // Track data from current columnIndex // Get all related cells from the current row var jQueryTarget = $('#ctrGrid_content input[control_name=' + controlLkFieldName + ']'); if (jQueryTarget.length > 0) { // Save the current control in GUI glbCurrentGettingControlTagNameLowercase = jQueryTarget[0].tagName.toLowerCase(); // Check the case of getting Caption of SelectOne if (isUsingUnderlineValue === false && glbCurrentGettingControlTagNameLowercase === 'select') { return jQueryTarget.find('option:selected').text(); } return jQueryTarget.val(); } // It's not inside Grid, so we will find outside return getValueOfControlInGUI(columnIndex, isUsingUnderlineValue, controlLkFieldName); } /** * Convert data source name from style [col1,col2,col3,...] into [Column_1, Column_2, Column_3, ...] * @param {} mobileColumnName * @returns {} */ function convertColumnInMobileType2Web(mobileColumnName) { if (mobileColumnName === null) { return mobileColumnName; } // Make sure that the format is [col{number}] if (mobileColumnName.indexOf('col') === 0) { var number = 0; try { number = parseInt(mobileColumnName.replace('col', '')) - 1; return ('Column_' + number); } catch (ex) {} } return mobileColumnName; } /** * Get control name based on headerText, ex * Text_inside_Gr1(1,1) => Text_inside_Gr1-1_1- * @returns {} */ function getControlNameFromHeaderText(headerText) { // Replace Text_inside_Gr1(1)(1) => Text_inside_Gr1(1,1) => Text_inside_Gr1-1_1- return headerText.replace(/,/g,'_').replace(/[\(\)]/g, '-'); } /** * Check the current value is inside ToList of LookupConditional * @returns {true/false} <=> {OK/Error} */ function checkLimitToList4LookupConditional(objThis, lkName, cellValue, isInsideFixedTable) { var mapCondtionLookupStructure = glbHashObject['MapCondtionLookupStructure']; var currentData = mapCondtionLookupStructure['' + lkName]; if (currentData === undefined) { return true; } if (currentData.limitToList === false) {return true;} // Check current value with limit data var listLookupData = null; // Special get list data for lookup field inside FixedTable if (isInsideFixedTable === true) { listLookupData = processUpdateDataSource4ConditionLookupInsideTable(objThis, true); } else { // Get list lookup data outside FixedTable listLookupData = processUpdateDataSource4ConditionLookup(objThis, true); } if (listLookupData === undefined) { return true; } //if (listLookupData.indexOf(cellValue) < 0) { return false; } // Check ignore case value (we must change all character < into < ) var lowerCellValue = cellValue.toLowerCase().replace(/ Load default data in Build Forms */ function loadPreparedData4LookupConditional(recordKey) { var isUpdateMode = false; if (recordKey !== undefined && recordKey !== null && recordKey !== '') { isUpdateMode = true; } var formId = $('#cboFrom').val(); writeToLogInfo('loadPreparedData4LookupConditional >> isUpdateMode : ' + isUpdateMode + ' >> formId : ' + formId + ' >> recordKey : ' + recordKey); $.ajax({ url: '/dataview/lookupprocess', dataType: 'json', data: { action : 'load_prepared_data_4lookup_conditional' ,formId : formId ,isUpdateMode : isUpdateMode ,recordKey : recordKey }, type: 'GET', cache: false, //async: false, complete: function() { // Silent mode }, success: function(response, status) { // Silent mode writeToLogInfoRequired('Successful in loadPreparedData4LookupConditional()'); dataSrcInGUINameValueMapping = response.dataSrcInGUINameValueMapping; }, error: function(request, status, error) { // Slient do not show any error writeToLogInfoRequired('Error occur in loadPreparedData4LookupConditional()'); } }); } /** * Update GUI headers for lookup conditional * Fix bug 0023818: View Data - Lookup condition works in correctly. * Fix bug 0023819: Dispatch - Lookup condition works in correctly. */ function updateArrayHeadersFullGUI4LookupCond() { try { arrHeadersFullGUI4LookupCond = new Array(); // The list of field []Hide In Website arrHeadersHideInWebsite = new Array(); // We will use the jsonHeadersFull.Data[] as input data var rowHeaders = document.getElementById(tableId).rows[0]; var allHeaders = jsonHeadersFull.Data; for (var ud = 2; ud < rowHeaders.cells.length; ud++ ){ // var curHeaderText = getTextContent(rowHeaders.cells[ud], ud) // .replace(/,/g,')(') // ; // Special treating for field inside Group level 2, 3, ... var curHeaderText = getTextContent(rowHeaders.cells[ud], ud); arrHeadersFullGUI4LookupCond.push(curHeaderText); } for (var idx = 0; idx < allHeaders.length; idx++) { var currentItem = allHeaders[idx]; // Extract []Hide in website fields if (arrHeadersFullGUI4LookupCond.indexOf(currentItem) < 0) { arrHeadersHideInWebsite.push(currentItem); } } // Add buffer header for preventing error with index + 2 arrHeadersFullGUI4LookupCond.push('#'); arrHeadersFullGUI4LookupCond.push('#'); } catch (e) { } } /** * Process extract data from objHiddenControls['recordKey'] into current object * for using in lookup conditional for current edit row */ function updateObjHiddenControlsCurrent4LKCondition() { // Fix bug 0023793: Dispatch - Lookup list don't display if lookup condition of it is hiden in website // Fix bug 0023955: View Data - Text field is checked Hide in website property display value incorrectly // Reset the objHiddenControls4LkCond objHiddenControls4LkCond = {}; writeToLogInfoRequired('entityKey use for updateObjHiddenControls : ' + entityKey); var currentObjHiddenControls = {}; if (ftAction == 'edit') { // Check the existing of current objHiddenControls[key] if (typeof objHiddenControls[entityKey] !== 'undefined') { currentObjHiddenControls = objHiddenControls[entityKey]; } } writeToLogInfoRequired('currentObjHiddenControls : ' + currentObjHiddenControls); // Copy all information into new object, with converting property as following rules : // Do nothing with empty hidden headers var hiddenHeaders = objHiddenControls['Headers']; if (typeof hiddenHeaders === 'undefined') { return; } for (var i = 0; i < hiddenHeaders.length; i++) { var dataName = hiddenHeaders[i]; var value = currentObjHiddenControls[dataName]; // Put default value in case value == undefined if (typeof value === 'undefined') { // Get default value from fbConstraints try { var orgDataName = getOriginalDataName(dataName); value = fbconstraints[orgDataName].defaultValue; } catch (e) { } } if (typeof value === 'undefined') { value = ''; } // Convert data from Lookup_Cond_G2(1,4) into Lookup_Cond_G2-1_4- var dataNameId = dataName.replace('(', '-').replace(')', '-').replace(/,/g, '_'); // Update data into temp object for using later in Lookup Conditional objHiddenControls4LkCond[dataNameId] = value; } }