How to use optionsJson method in storybook-root

Best JavaScript code snippet using storybook-root

fieldDisplayer2.js

Source:fieldDisplayer2.js Github

copy

Full Screen

1/**2* @fileoverview fieldDisplayer2.js3* @description Contains all the functionalities for creating fields.4* This fields can be read only or input fields, what the modules does is to decide what to5* create from the information the programmer provides to the module, and implements few6* functionalities like format check (for example in the case the field type is integer number7* won't be possible to insert text)8*/910/**11* FieldDisplayerFactory will return a FieldDisplayer object according to the options given12* as an argument.13* @constructor14*/1516var FieldDisplayerFactory = Class.create(origin,17/**18* @lends FielDisplayer19*/20{21/**22* It has a visual dependence in another field. (based on depend_type)23*/24DEPENDENCY_NEXT_TO: "X",25/**26* It has a visual and logic dependence in another field. (based on depend_type)27*/28DEPENDENCY_NEXT_TO_AND_LOGIC: "B",29/**30* It has a logic dependence in another field. (based on depend_type)31*/32DEPENDENCY_LOGIC: "",33/**34* Field type possible values.35*/36FIELD_TYPES: $H({37 A: "fieldTypeAutocompleter",38 B: "fieldTypeBubble",39 C: "fieldTypeCheckBox",40 D: "fieldTypeOutput",41 O: "fieldTypeOutput",42 V: "fieldTypeOutput",43 H: "fieldTypeHour",44 I: "fieldTypeText",45 L: "fieldTypeLink",46 E: "fieldTypeLinkToHandler",47 M: "fieldTypeImage",48 P: "fieldTypeDate",49 R: "fieldTypeRadioButton",50 //S: "fieldTypeSelectBox",51 S: "fieldTypeAutocompleter",52 T: "fieldTypeTextArea"53}),54/**55* The input doesn't have a label (based on label_type)56*/57LABEL_TYPE_NO_LABEL: "N",58/**59* Use the label on field settings fieldlabel (based on label_type)60*/61LABEL_TYPE_USE_SETTINGS: "V",62/**63* Use the label coming with the service in the standard way ((based on label_type)64*/65LABEL_TYPE_USE_LABEL_TAG: "",66/**67* Create mode.68*/69MODE_CREATE: "create",70/**71* Display mode.72*/73MODE_DISPLAY: "display",74/**75* Edit mode.76*/77MODE_EDIT: "edit",78/**79* Show text only (based on show_text)80*/81SHOW_TEXT_ONLY_TEXT_X: "X",82/**83* Show text only (based on show_text)84*/85SHOW_TEXT_ONLY_TEXT_I: "I",86/**87* Show text and value (based on show_text)88*/89SHOW_TEXT_VALUE_AND_TEXT: "B",90/**91* Show value only (based on show_text)92*/93SHOW_TEXT_ONLY_VALUE: null,9495initialize: function() {96},97/**98* Returns a fieldDisplayer according to the JSON given in the options99* @param {JSON} optionsJSON The options coming from the service in JSON format.100* @param {String} screen The screen reference.101* @param {String} record The record reference.102* @param {String} mode the mode for the field displayer.103*/104getFieldDisplayer: function(optionsJSON, screen, record, key_str, appid, mode, labels, fieldDisplayerModified, cssClasses, xml_in, handler, name, getFieldValueAppend, randomId, rowSeqnr, variant, FPObject) {105 var options = this._parseOptions(optionsJSON, screen, record, key_str, appid, mode, labels, fieldDisplayerModified, cssClasses, xml_in, handler, name, getFieldValueAppend, randomId, rowSeqnr, variant, FPObject);106 var className = options.fieldType;107 return new window[className](options);108},109/**110* Takes the options in JSON format and convert them into a more easy readable format.111* @param {JSON} optionsJSON optionsJSON The options coming from the service in JSON format.112* @param {String} screen The screen reference.113* @param {String} record The record reference.114* @param {String} mode The operation mode115* @param {JSON|String} xml_in The xml_in which will be sent to the service. Can be both a JSON116* or a String.117* @return {JSON} the options parsed into an easily readable JSON object.118*/119_parseOptions: function(optionsJSON, screen, record, key_str, appid, mode, labels, fieldDisplayerModified, cssClasses, xml_in, handler, name, getFieldValueAppend, randomId, rowSeqnr, variant, FPObject) {120 this.labels = labels;121 if (!Object.isEmpty(optionsJSON.settings['visualOpt']))122 var visualOpt = optionsJSON.settings['visualOpt'];123 else124 var visualOpt = false;125 var options = {126 appId: appid,127 //cssClasses specific for this application, it overwrites the standard ones128 cssClasses: cssClasses,129 customXmlIn: xml_in,130 //data about the dependency, the field id and the dependency type.131 dependency: this._getDependency(optionsJSON),132 //get the template for the display format in the field displayer133 displayFormat: this._getDisplayFormat(optionsJSON, mode),134 //if defined, the fieldDisplayers will throw this event when changed135 fieldDisplayerModified: fieldDisplayerModified,136 //get the proper fieldType137 fieldType: this._getFieldType(optionsJSON),138 //if it's a hidden field or not139 hidden: this._getIsHidden(optionsJSON),140 //the id of the field141 id: optionsJSON.values["@fieldid"],142 //field format143 fieldFormat: optionsJSON.settings["@fieldformat"],144 keyStr: key_str,145 //the label to be shown for the field146 label: this._getLabel(optionsJSON),147 //if it's mandatory or not148 mandatory: this._getIsMandatory(optionsJSON),149 //the mode (create, edit or display150 mode: mode,151 objectType: this._getObjectType(),152 objectId: this._getObjectId(),153 //service_pai154 onChangeEvent: optionsJSON.settings["@service_pai"],155 //the JSON with the options. It will be updated with the user's interaction data.156 optionsJSON: optionsJSON,157 //if the field is output only or not158 outputOnly: this._getIsOutputOnly(optionsJSON),159 //the record (if any)160 record: record,161 //the screen (if any)162 screen: screen,163 //field techName (used to build dependencies)164 techName: optionsJSON.values["@fieldtechname"],165 //get the text and the value either from default_text/default_value on field settings166 //or the #text/value on field value167 text: this._getText(optionsJSON, screen, record, mode),168 value: this._getValue(optionsJSON, screen, record, mode),169 //service_values the service to the get the values list.170 valueListService: optionsJSON.settings["@service_values"],171 //field_type the field subtype172 type: optionsJSON.settings["@type"],173 //field handler (fieldTypeLinkToHandler)174 handler: handler,175 name: name,176 getFieldValueAppend: getFieldValueAppend,177 randomId: randomId,178 rowSeqnr: rowSeqnr,179 visualOpt: visualOpt,180 variant: variant, 181 FPObject: FPObject182 };183 if (optionsJSON.values["@fieldid"] == 'SPRSL' && appid == 'PD_DATA') {184 options.rechargeAll = true185 }186 return options;187},188/**189* Gets the dependency data according to options from the service.190* @param {JSON} optionsJSON optionsJSON The options coming from the service in JSON format.191* @return {JSON} The dependency data for this field displayer (from which field it depends and the type).192*/193_getDependency: function(optionsJSON) {194 var dependencyData;195 var dependType = optionsJSON.settings["@depend_type"];196 var dependField = optionsJSON.settings["@depend_field"];197 switch (dependType) {198 //only logic dependency is handled in field displayer. 199 case this.DEPENDENCY_NEXT_TO:200 dependencyData = {201 type: '',202 field: ''203 };204 break;205 case this.DEPENDENCY_NEXT_TO_AND_LOGIC:206 case this.DEPENDENCY_LOGIC:207 dependencyData = {208 type: dependType,209 field: dependField210 };211 break;212 //if none of the previous, give empty data. 213 default:214 dependencyData = {215 type: dependType,216 field: dependField217 };218 break;219 }220221 return dependencyData;222},223/**224* Get the correct format to show text and value for a field225* @param {JSON} optionsJSON the options coming from the service in JSON format226* @return {Template} The template with the format for the field. This template will have227* two fields: #{text} and #{value} which are self explained.228*/229_getDisplayFormat: function(optionsJSON, mode) {230 var template;231 var showText = optionsJSON.settings["@show_text"];232 switch (showText) {233 case this.SHOW_TEXT_ONLY_TEXT_I:234 if (optionsJSON.settings["@fieldid"] == "BETRG")235 template = new Template("#{value}");236 else237 template = new Template("#{text}");238239 break;240241 case this.SHOW_TEXT_ONLY_TEXT_X:242 template = new Template("#{text}");243 break;244245 case this.SHOW_TEXT_ONLY_VALUE:246 //Fix to show the id correctly, in display mode we need "value" and in edit or create we need "data"247 if (mode == "display" || optionsJSON.settings["@display_attrib"] == "OUO" || (mode != "display" && optionsJSON.settings["@fieldformat"] == "V") || (mode != "display" && optionsJSON.settings["@fieldformat"] == "D")) {248 template = new Template("#{value}");249 } else {250 template = new Template("#{data}");251 }252 break;253254 case this.SHOW_TEXT_VALUE_AND_TEXT:255 default:256 //Fix to show the id correctly, in display mode we need "value" and in edit or create we need "data"257 if (mode == "display" || optionsJSON.settings["@display_attrib"] == "OUO" || (mode != "display" && optionsJSON.settings["@fieldformat"] == "V") || (mode != "display" && optionsJSON.settings["@fieldformat"] == "D")) {258 template = new Template("#{text}" + " " + global.idSeparatorLeft + "#{value}" + global.idSeparatorRight);259 } else {260 template = new Template("#{text}" + " " + global.idSeparatorLeft + "#{data}" + global.idSeparatorRight);261 }262 break;263 }264265 return template;266},267/**268* Gets the field type according to the options in optionsJSON.269* @param {JSON} optionsJSON the options coming from the service in JSON format.270* @return {String} the field type name.271*/272_getFieldType: function(optionsJSON, mode) {273 var type = optionsJSON.settings["@fieldformat"];274 if (optionsJSON.settings['@fieldid'] && optionsJSON.settings['@fieldid'].toLowerCase() == 'translation')275 return "fieldTypeHidden";276 // if(this._getIsOutputOnly(optionsJSON) || mode == this.MODE_DISPLAY){277 if (this._getIsOutputOnly(optionsJSON)) {278 return "fieldTypeOutput";279 } else if (type && !this._getIsHidden(optionsJSON)) {280 type = this.FIELD_TYPES.get(type);281 if (!type) {282 throw "fieldformat is an unexistent type for field: " + optionsJSON.settings['@fieldid'];283 } else {284 return type;285 }286 } else if (!this._getIsHidden(optionsJSON)) {287 throw "fieldformat is empty for field: " + optionsJSON.settings['@fieldid'];288 } else {289 return "fieldTypeHidden";290 }291},292/**293* Get's if this is a hidden field or not294* @return {Boolean} true when it's hidden. False otherwise.295*/296_getIsHidden: function(optionsJSON) {297 var displayAttribute = optionsJSON.settings["@display_attrib"];298 if (displayAttribute == "HID" || displayAttribute == "HOU") {299 return true;300 } else {301 return false;302 }303},304/**305* Get's whether a field is mandatory to be filled or not.306* @param {JSON} optionsJSON optionsJSON The options coming from the service in JSON format.307* @return {Boolean} Whether the field is mandatory or not308*/309_getIsMandatory: function(optionsJSON) {310 var displayAttribute = optionsJSON.settings["@display_attrib"];311 if (displayAttribute == "MAN") {312 return true;313 } else {314 return false;315 }316},317/**318* Get's whether a field is output only or not.319* @param {JSON} optionsJSON optionsJSON The options coming from the service in JSON format.320* @return {Boolean} Whether the field is output only or not321*/322_getIsOutputOnly: function(optionsJSON) {323 var displayAttribute = optionsJSON.settings["@display_attrib"];324 var fieldFormat = optionsJSON.settings["@fieldformat"];325 //Checkboxes that are outout only should be treated as checkboxes, not output only326 if (displayAttribute == "OUO" && fieldFormat !="C") {327 return true;328 } else {329 return false;330 }331},332/**333* Gets the correct label from the optionsJSON according to the needed logic.334* @param {JSON} optionsJSON the options coming from the service in JSON format.335* @return {String} the label.336*/337_getLabel: function(optionsJSON) {338339 var label;340 var labelType = optionsJSON.settings["@label_type"];341 switch (labelType) {342 case this.LABEL_TYPE_NO_LABEL:343 label = "";344 break;345346 case this.LABEL_TYPE_USE_SETTINGS:347 label = optionsJSON.settings["@fieldlabel"];348 break;349350 case this.LABEL_TYPE_USE_LABEL_TAG:351 default:352 //if there's no labels, return the fieldid.353 if (this.labels && this.labels.get(optionsJSON.values["@fieldid"])) {354 label = this.labels.get(optionsJSON.values["@fieldid"]);355 } else {356 label = global.getLabel(optionsJSON.values["@fieldid"]);357 }358 break;359 }360361 return label;362},363/**364* Gets the object type, either from global or from the JSON options.365* @return {String} the object type.366*/367_getObjectType: function() {368 if (global.getPopulationName(global.currentApplication.appId) == 'NOPOP') {369 return global.objectType;370 } else {371 return global.getEmployee(global.getSelectedEmployees().first()).type;372 }373},374/**375* Gets the object ID, from global. The object id is the id of the selected employee376* If we are in multiple selection, we will use the logged user377* @return {String} The object ID, global.objectId if there is no one selected.378*/379_getObjectId: function() {380 //If we are in multiple selection381 if (!Object.isEmpty(global.currentSelectionType) && global.currentSelectionType == "multi") {382 return global.objectId;383 } else {384 var selected = global.getSelectedEmployees();385 if (Object.isEmpty(selected)) {386 return global.objectId;387 }388 if (selected.size() == 0) {389 return global.objectId;390 }391 return selected[0];392 }393},394/**395* Gets the correct text for the field according to options from the service and the mode396* @param {JSON} optionsJSON optionsJSON The options coming from the service in JSON format.397* @param {String} screen The screen reference.398* @param {String} record The record reference.399* @param {String} mode The operation mode, can be400* @return {String} the correct field text.401*/402_getText: function(optionsJSON, screen, record, mode) {403 var text;404 switch (mode) {405 case this.MODE_CREATE:406 text = optionsJSON.settings["@default_text"];407 break;408409 case this.MODE_EDIT:410 case this.MODE_DISPLAY:411 default:412413 text = optionsJSON.values["#text"];414415 break;416 }417 return text;418},419/**420* Gets the correct value for the field according to options from the service and the mode421* @param {JSON} optionsJSON optionsJSON The options coming from the service in JSON format.422* @param {String} screen The screen reference.423* @param {String} record The record reference.424* @param {String} mode The operation mode, can be425* @return {String} the correct field value.426*/427_getValue: function(optionsJSON, screen, record, mode) {428 var value;429 switch (mode) {430 case this.MODE_CREATE:431 if (!Object.isEmpty(optionsJSON.settings["@default_value"])) {432 if ((optionsJSON.settings['@type'] == "DEC" || optionsJSON.settings['@type'] == "CURR") && displayToLong(optionsJSON.settings["@default_value"]).toString() != "NaN") {433 if (optionsJSON.settings["@default_value"].split('.')[1]) {434 var decimalLong = optionsJSON.settings["@default_value"].split('.')[1].length;435 dispMode = longToDisplay(parseFloat(optionsJSON.settings["@default_value"], 10), decimalLong);436 }437 else {438 dispMode = longToDisplay(parseFloat(optionsJSON.settings["@default_value"], 10));439 }440 value = dispMode;441 }442 else {443 value = optionsJSON.settings["@default_value"];444 }445 }446 else {447 value = optionsJSON.settings["@default_value"];448 }449 break;450451 case this.MODE_EDIT:452 if (!Object.isEmpty(optionsJSON.values["@value"])) {453454 if ((optionsJSON.settings['@type'] == "DEC" || optionsJSON.settings['@type'] == "CURR") && displayToLong(optionsJSON.values["@value"]).toString() != "NaN") {455 if (optionsJSON.values["@value"].split('.')[1]) {456 var decimalLong = optionsJSON.values["@value"].split('.')[1].length;457 dispMode = longToDisplay(parseFloat(optionsJSON.values["@value"], 10), decimalLong);458 }459 else {460 dispMode = longToDisplay(parseFloat(optionsJSON.values["@value"], 10));461 }462 value = dispMode;463 }464 else {465 value = optionsJSON.values["@value"];466 }467 }468 else {469 value = optionsJSON.values["@value"];470 }471 break;472 case this.MODE_DISPLAY:473 default:474475 value = optionsJSON.values["@value"];476477 break;478 }479 return value;480},481/**482* This function gets the actual value selected on the field, it should be extended by each one of the types483* to get the value484* @return {String} The actual value on the field485*/486getText: function() {487488},489/**490* This function gets the actual ID of the selected value on the field, It should be extended by each one of the type491* to get the proper ID492* @return {String} The actual ID selected on the field493*/494getValue: function() {495496}497});498499/**500* fieldDisplayer is a parent class for all the field displayer. It contains common code needed501* for all of them.502* @constructor503*/504var parentFieldDisplayer = Class.create(origin,505/**506* @lends fieldDisplayer507*/508{509DISPLAY_MODE: 'display',510/**511* It sets how the fieldDisplayer JSON has to be updated depending on its Class.512*/513jsonInsertion: $H({514515 fieldTypeText: {516 text: '@value',517 id: null518 },519 fieldTypeAutocompleter: {520 text: '#text',521 id: '@value'522 },523 fieldTypeCheckBox: {524 id: '@value'525 },526 fieldTypeRadioButton: {527 id: '@value',528 text: null529 },530 fieldTypeSelectBox: {531 text: '#text',532 id: '@value',533 textNode: 'text'534 },535 fieldTypeHidden: {536 text: '#text',537 id: '@value'538 },539 fieldTypeOutput: {540 text: '#text',541 id: '@value'542 },543 fieldTypeTextArea: {544 text: '@value',545 id: null546 },547 fieldTypeDate: {548 text: '@value',549 id: '@value'550 },551 fieldTypeHour: {552 text: '@value',553 id: null554 }555}),556/**557* All the events and events being listened and it's handler functions.558* @type Hash559*/560_events: null,561/**562* The HTML Element object which contains the layout for this field displayer563* @type Element564*/565_element: null,566/**567* The Module instance used for the field displayer if any.568* @type Object569*/570_moduleInstance: null,571/**572* The html Element in which the module will be inserted573*/574_moduleElement: null,575/**576* The html Element in which the label will be inserted577*/578_labelElement: null,579/**580* Hash in order to store the last value selected on every fieldDisplayer, since sometimes a field581* depends of another one of which onFieldChange event has been fired before because it is582* in the xml before.583* //TODO: REFACTOR: _lastValueSelected is no longer used. We should remove everywhere where it appears584*/585_lastValueSelected: $H(),586/**587* Indicates if the field has o hasn't got its value for the first time.588* This is useful to avoid calling paiEvents the first time the field is displayed.589*/590_firstTimeGettingValue: true,591/**592* Unique Id for every fieldDisplayer so that events do not get mixed593*/594_id: null,595596597initialize: function($super, options) {598 $super();599 this.options = options;600 this._id = Math.floor(Math.random() * 100000) + "";601602 if ((options.mode != this.DISPLAY_MODE603 || options.fieldType == 'fieldTypeRadioButton'604 || options.fieldType == 'fieldTypeCheckBox'605 || options.fieldType == 'fieldTypeBubble'606 || options.fieldType == 'fieldTypeImage')607 && options.fieldType != 'fieldTypeOutput') {608 this._events = $H();609 this._setLayout();610 this._initializeModule();611 this._setOnChange();612 this._setHowToGetValue();613 } else {614 this._setLayoutDisplay();615 }616},617//METHODS TO DISPLAY THE OBJECT618//***********************************************************************************************************************************************619/**620* Prepare the layout for the field displayer621*/622_setLayoutDisplay: function() {623 if (this.options.hidden) {624 this._element = new Element("div").hide();625 } else {626 if (this.options.optionsJSON.settings['@depend_type'] == 'X' || this.options.optionsJSON.settings['@depend_type'] == 'V') {627 this._element = new Element("div", {628 "class": "fieldWrap fieldDispFloatLeft __there"629 });630 } else {631 this._element = new Element("div", {632 "class": "fieldWrapDisplayMode fieldClearBoth fieldDispFloatLeft",633 "id": this.options.id + '_' + this.options.appId + '_' + this.options.screen + '_' + this.options.record634 });635 }636 this._labelElement = new Element("div", {637 "class": "fieldCaption fieldDispHeight fieldDispLabel fieldDispFloatLeft fieldDispNoWrap application_main_soft_text",638 "title": this.options.label639 });640 this._labelElement.insert(this.options.label);641 if (this.options.mandatory && !this.options.visualOpt) {642 this._labelElement.insert("");643 }644645 var content = this.options.displayFormat.evaluate({ text: this.options.text, value: this._formattedValue(this.options) });646647 if (Object.isEmpty(this.options.value)) {648 content = content.gsub(" " + global.idSeparatorLeft + global.idSeparatorRight, '');649 }650 if (content.startsWith(" " + global.idSeparatorLeft) && content.endsWith(global.idSeparatorRight))651 content = content.substring(2, content.length - 1);652 this._moduleElement = new Element("div", {653 "class": "fieldDispFloatLeft",654 "id": this.options.appId + '_' + this.options.screen + '_' + this.options.record + '_' + this.options.id655 }).insert(content);656657 // No label should be added if the field is a tcontent one658 //if (!this._isTContent(this.options))659 this._element.insert(this._labelElement);660661 this._element.insert(this._moduleElement);662 }663},664665/* 666* @method _isTContent667* @desc Checks if a field is a tcontent one668* @param options Field's options669* @return true if the field is a tcontent one, false otherwise670*/671672_isTContent: function(options) {673 return !Object.isEmpty(options.optionsJSON.settings['@fieldsource'])674 && (options.optionsJSON.settings['@fieldsource'].toLowerCase() == 't');675},676677/* @method _formattedValue678* @desc Returns a formatted value according to its type679* @param Options JSON options680* @return The formatted value681*/682683_formattedValue: function(options) {684685 var hour;686 var min;687688 if (!Object.isEmpty(options) && !Object.isEmpty(options.value)) {689690 if (options.type == "TIMS") {691 if (options.value.include(':')) {692 var time = options.value.split(':');693 fValue = time[0] + ":" + time[1];694 } else {695 hour = options.value.substring(0, 2);696 min = options.value.substring(2, 4);697 fValue = hour + ":" + min;698 }699 }700 else {701 fValue = options.value;702 }703 }704 else705 fValue = "";706707 return fValue;708709},710711checkDate: function(options) {712713 var dateOK = false;714715 if ((options.objectType == 'D') || (options.fieldFormat == "P"))716 dateOK = true;717718 return dateOK;719},720/**721* Prepare the layout for the field displayer722*/723_setLayout: function() {724 this.mandatoryIndicator = new Element('span', {725 'class': 'fieldDispMandatoryIndicator application_main_soft_text fieldDispFloatLeft'726 });727 this.mandatoryIndicator.insert('*');728 if (this.options.outputOnly) {729 this._element = new Element("div", {730 "class": "fieldWrapDisplayMode fieldClearBoth fieldDispFloatLeft"731 });732 this._labelElement = new Element("div", {733 "class": "fieldCaption fieldDispHeight fieldDispLabel fieldDispFloatLeft fieldDispNoWrap application_main_soft_text",734 "title": this.options.label735 });736 } else {737 if (this.options.optionsJSON.settings['@depend_type'] == 'X' || this.options.optionsJSON.settings['@depend_type'] == 'V') {738 this._element = new Element("div", {739 "class": "fieldWrap fieldDispFloatLeft __there"740 });741 this._labelElement = new Element("div", { // TO REFACTOR: this labelElement case is exactly the same as here above in the "this.options.outputOnly" case.742 "class": "fieldCaption fieldDispHeight fieldDispLabel fieldDispFloatLeft fieldDispNoWrap application_main_soft_text",743 "title": this.options.label744 });745 } else {746 this._element = new Element("div", {747 "class": "fieldWrap fieldDispFloatLeft __here",748 "id": this.options.id + '_' + this.options.appId + '_' + this.options.screen + '_' + this.options.record749 });750 this._labelElement = new Element("div", {751 "class": "fieldCaption fieldDispHeight fieldDispLabel fieldDispFloatLeft fieldDispNoWrap application_main_soft_text",752 "title": this.options.label753 });754 }755 }756 if ((this.options.mandatory && !this.options.visualOpt) && this.options.outputOnly) {757 this._labelElement.insert(" (*)");758 }759 if (this._labelElement)760 this._labelElement.insert(this.options.label);761 this._moduleElement = new Element("div", {762 "class": "fieldDispFloatLeft fieldDispField",763 "id": this.options.appId + '_' + this.options.screen + '_' + this.options.record + '_' + this.options.id764 });765 if (this._labelElement)// && !this._isTContent(this.options))766 this._element.insert(this._labelElement);767768 this._element.insert(this._moduleElement);769 if ((this.options.mandatory && !this.options.visualOpt) && !this.options.outputOnly) {770 this._element.insert(this.mandatoryIndicator);771 }772 else {773 this.mandatoryIndicator.update("&nbsp");774 this._element.insert(this.mandatoryIndicator);775 }776},777/**778* Initializes the module needed for the field displayer (if any).779* //REFACTOR: this function is no longer used (but it's used the one from the child Classes)780*/781_initializeModule: function() {782783},784785/**786* Gets the values of the field, if it has a service associated787*/788getFieldValues: function() {789 //Just get the values if we're not in display mode, and the fieldType is one that actually can get the values790 //TODO: If there are fields that depend on a radio button or a check box?791 if (this.options.mode != "display" || this.options.fieldType == 'fieldTypeRadioButton' ||792 this.options.fieldType == 'fieldTypeCheckBox' || this.options.fieldType == 'fieldTypeBubble' ||793 this.options.fieldType == 'fieldTypeImage') {794795 //If the field is going to ask for values and is not of a kind of fields that can't gent values:796 if ((this._getFieldValuesSuccess && this.options.valueListService && (this.options.fieldType != 'fieldTypeText') && (this.options.fieldType != 'fieldTypeOutput'))) {797 this._getFieldValues(this.getDependencyInfo());798 } else {799 //If the field is not going to ask for values, ask for the values of the fields that depend on it:800 this.getValuesDependantFields();801 this._firstTimeGettingValue = false; //Indicate that this is no longer its first time to get values802 }803 }804},805806807/**808* Function to get information about dependency: it's a hash that contains:809* - fieldid: the id of the field it depends on810* - fieldtechname: the techname of the field it depends on811* - value: the value of the field it depends on812* - nestedDep: this information, but about the field it depends on, called recursively813*814* This information is used to create the XML to look for values815*/816getDependencyInfo: function() {817 if (Object.isEmpty(this.parentField)) {818 return null;819 } else {820 var parentFieldDependency = this.parentField.getDependencyInfo();821 var dependencyInfo = $H({822 "fieldid": this.parentField.options.id,823 "fieldtechname": this.parentField.options.techName,824 "value": Object.isEmpty(this.parentField.getValue().id) ? "" : this.parentField.getValue().id,825 "nestedDep": parentFieldDependency826 });827 return dependencyInfo;828 }829},830/**831* Obtains the Element object ready to be inserted in any container.832* @return {Element} returns the Element object with the field displayer.833*/834getHtml: function() {835 return this._element;836},837//METHODS TO GET VALUES FROM SAP838//***********************************************************************************************************************************************839/**840* Makes a request to the service specified in options to get the values for the field.841* @param {Object} event842* @param {Object} xmlin If we want to use a different xmlin than the default843*/844_getFieldValues: function(depFieldInfo, xmlin) {845 if (Object.isEmpty(xmlin)) {846 //If we didn't set an alternative xmlin847 this.makeAJAXrequest($H({848 xml: this._getXMLIn(depFieldInfo),849 successMethod: this._getFieldValuesSuccess.bind(this)850 }));851852853 } else {854 //If we set an alternative xmlin855 this.makeAJAXrequest($H({856 xml: xmlin,857 successMethod: this._getFieldValuesSuccess.bind(this)858 }));859 }860},861/**862* It handles the success response from the request made in _getFieldValues method.863* @param {JSON} response the response from the service.864*/865_getFieldValuesSuccess: function() {866 if (this.options.cssClasses && Object.isHash(this.options.cssClasses)) {867 this.options.cssClasses.each(function(cssClass) {868 var a = 0;869 this._element.descendants().each(function(element) {870 if (element.hasClassName(cssClass.key)) {871 element.removeClassName(cssClass.key);872 element.addClassName(cssClass.value);873 }874 } .bind(this));875 } .bind(this));876 }877},878/**879* It generates the XML needed to make a request to a service to get the value list for880* the field displayer881* @param {String} dependencyField the field on which this one depends' id882* @return {String} The String with the XML to make a request to the service.883*/884_getXMLIn: function(depFieldsInfo) {885 var depFields = "";886 var depField = "";887 if (!Object.isEmpty(depFieldsInfo)) {888 depFields = '<FIELD FIELDID="' + depFieldsInfo.get('fieldid') + '" FIELDTECHNAME="' + depFieldsInfo.get('fieldtechname') + '" VALUE="' + depFieldsInfo.get('value') + '" />';889 while (depFieldsInfo.get('nestedDep')) {890 depFields += '<FIELD FIELDID="' + depFieldsInfo.get('nestedDep').get('fieldid') + '" FIELDTECHNAME="' + depFieldsInfo.get('nestedDep').get('fieldtechname') + '" VALUE="' + depFieldsInfo.get('nestedDep').get('value') + '" />';891 depFieldsInfo = depFieldsInfo.get('nestedDep');892 }893 }894 //build the service request if there's not a customized one895 if (!this.options.customXmlIn || !this.options.customXmlIn.get(this.options.id)) {896 //Check if we have something to add to the XML897 var xmlToAppend = "";898 if (!Object.isEmpty(this.options.getFieldValueAppend)) {899 xmlToAppend = this.options.getFieldValueAppend;900 }901902 var oType = !Object.isEmpty(this.options.objectType) ? this.options.objectType : "";903 var oId = !Object.isEmpty(this.options.objectId) ? this.options.objectId : "";904 var appId = !Object.isEmpty(this.options.appId) ? this.options.appId : "";905 var strKey = !Object.isEmpty(this.options.keyStr) ? this.options.keyStr : "";906 var screenId = !Object.isEmpty(this.options.screen) ? this.options.screen : "";907 var jsonIn = '<EWS>' +908 '<SERVICE>' + this.options.valueListService + '</SERVICE>' +909 '<OBJECT TYPE="' + oType + '">' + oId + '</OBJECT>' +910 '<PARAM>' +911 '<APPID>' + appId + '</APPID>' +912 '<WID_SCREEN>' + screenId + '</WID_SCREEN>' +913 '<STR_KEY>' + strKey + '</STR_KEY>' +914 '<FIELD FIELDID="' + this.options.id + '" FIELDTECHNAME="' + this.options.techName + '" VALUE="" /> ' +915 '<DEP_FIELDS>' +916 depFields +917 '</DEP_FIELDS>' +918 '<SEARCH_PATTERN />' +919 xmlToAppend +920 '</PARAM>' +921 '</EWS>';922923 return jsonIn;924 }925 //use the customized request to the service according to its format926 else if (Object.isString(this.options.customXmlIn)) {927 return this.options.customXmlIn;928 } else {929 if (Object.isString(this.options.customXmlIn.get(this.options.id)))930 return this.options.customXmlIn.get(this.options.id);931 else932 return json2xml.writeXML(this.options.customXmlIn.get(this.options.id));933 }934},935//METHODS TO MODIFY AND HANDLE JSON INTERACTION936//***********************************************************************************************************************************************937/**938* It updates the fieldDisplayer related piece of JSON.939* @param {Object (id:'string',text:'string')} The values to be inserted.940*/941updateJSON: function(val) {942 var changed = false;943 switch (this.options.optionsJSON.settings['@show_text']) {944 case 'I':945 case 'B':946 //saving both947 if (!Object.isEmpty(this.jsonInsertion.get(this.options.fieldType).id)) {948 if (this.options.optionsJSON.values[this.jsonInsertion.get(this.options.fieldType).id] != val.id) {949 //If both are null, then it should not change the value, and should not mark as "changed"950 if (!Object.isEmpty(this.options.optionsJSON.values[this.jsonInsertion.get(this.options.fieldType).id]) || !Object.isEmpty(val.id)) {951 this.options.optionsJSON.values[this.jsonInsertion.get(this.options.fieldType).id] = val.id;952 changed = true;953 }954 }955 }956 if (!Object.isEmpty(this.jsonInsertion.get(this.options.fieldType).text)) {957 if (this.options.optionsJSON.values[this.jsonInsertion.get(this.options.fieldType).text] != val.text) {958 //If both are null, then it should not change the text, and should not mark as "changed"959 if (!Object.isEmpty(this.options.optionsJSON.values[this.jsonInsertion.get(this.options.fieldType).text]) || !Object.isEmpty(val.text)) {960 if (!Object.isEmpty(val.text)) {961 this.options.optionsJSON.values[this.jsonInsertion.get(this.options.fieldType).text] = val.text.escapeHTML().gsub("'", '&#39;').gsub('"', '&#34;');962 } else {963 this.options.optionsJSON.values[this.jsonInsertion.get(this.options.fieldType).text] = val.text;964 }965 changed = true;966 }967 }968 }969 break;970 case 'X':971 //saving text972 if (this.options.optionsJSON.values['#text'] != val.text) {973 //If both are null, then it should not change the text, and should not mark as "changed"974 if (!Object.isEmpty(this.options.optionsJSON.values['@text']) || !Object.isEmpty(val.text)) {975 if (!Object.isEmpty(val.text)) {976 this.options.optionsJSON.values['#text'] = val.text.escapeHTML().gsub("'", '&#39;').gsub('"', '&#34;');977 } else {978 this.options.optionsJSON.values['#text'] = val.text;979 }980 changed = true;981 }982 }983 break;984 default:985 //When it's a decimal number, or a currency number we make sure the format is correct:986 if (!Object.isEmpty(val.id)) {987 if ((this.options.type == "DEC" || this.options.type == "CURR") && displayToLong(val.id).toString() != "NaN") {988 val.id = val.id.gsub(global.thousandsSeparator, '').gsub(global.commaSeparator, '.');989 if (val.id.split('.')[1]) {990 var decimalLong = val.id.split('.')[1].length;991 dispMode = longToDisplay(parseFloat(val.id, 10), decimalLong);992 }993 else {994 dispMode = longToDisplay(parseFloat(val.id, 10));995 }996 val.id = displayToLong(dispMode);997 }998 }999 //saving value1000 if (this.options.optionsJSON.values['@value'] != val.id) {1001 //If both are null, then it should not change the value, and should not mark as "changed"1002 if (!Object.isEmpty(this.options.optionsJSON.values['@value']) || !Object.isEmpty(val.id)) {1003 this.options.optionsJSON.values['@value'] = val.id;1004 changed = true;1005 }1006 }1007 }1008 return changed;1009},1010_setOnChange: function(element, event) {1011 if (Object.isEmpty(event)) event = 'change';1012 if (!Object.isEmpty(element)) {1013 if (Object.isElement(element)) {1014 this._registerEvent(event, this._onFieldChange.bind(this, true), element);1015 } else if (Object.isString(element)) {1016 this._registerEvent(element, this._onFieldChange.bind(this, true));1017 }1018 } else {1019 this._registerEvent(event, this._onFieldChange.bind(this, true), this._element);1020 }1021},1022getValue: function() {1023 return {1024 id: this.idGetter(),1025 text: this.textGetter()1026 };1027},1028_setHowToGetValue: function(param) {1029 if (!Object.isEmpty(param)) {1030 var showText = this.options.optionsJSON.settings['@show_text'];1031 if (Object.isEmpty(showText) || (showText == 'B') || (showText == 'I'))1032 this.idGetter = param.id;1033 if ((showText == 'B') || (showText == 'I') || (showText == 'X'))1034 this.textGetter = param.text;1035 }1036},1037idGetter: function() {1038 return this.options.value1039},1040textGetter: function() {1041 return this.options.text1042},10431044//METHODS TO HANDLE EVENT INTERACTION1045//***********************************************************************************************************************************************1046/**1047* It catches the field changed event.1048* @param {Object} throwPaiEvent1049* @param {Object} forceChanged1050*/1051_onFieldChange: function(throwPaiEvent, forceChanged) {1052 if (Object.isEmpty(forceChanged) || (typeof forceChanged) != "boolean") {1053 forceChanged = false;1054 }1055 var value = this.getValue();1056 var changed = this.updateJSON(value);1057 //Fix to avoid calling SAP when it's not neccesary1058 if (!changed && !forceChanged) {1059 //If it's the first time, but the value doesn't change, we make sure it counts as first time grtting value:1060 this._firstTimeGettingValue = false;1061 return;1062 }1063 if (throwPaiEvent && !Object.isEmpty(this.options.optionsJSON.settings['@service_pai'])) {1064 var obj = {1065 appId: this.options.appId,1066 screen: this.options.screen,1067 record: this.options.record,1068 mode: this.options.mode,1069 servicePai: this.options.optionsJSON.settings['@service_pai'],1070 currentValue: value,1071 fieldId: this.options.id1072 };1073 if (changed && !this._firstTimeGettingValue) {1074 global.focusFieldID = {1075 appId: this.options.appId,1076 screen: this.options.screen,1077 mode: this.options.mode,1078 id: this.options.id,1079 record: this.options.record1080 };1081 //If the field is inside a tContent, a different pai will be fired.1082 if (this._isTContent(this.options)) {1083 obj.rowSeqnr = this.options.rowSeqnr;1084 document.fire('EWS:getContentModule_tContentPaiEvent_' + this.options.appId + this.options.name + this.options.randomId, obj);1085 } else {1086 document.fire('EWS:getContentModule_paiEvent_' + this.options.appId + this.options.name + this.options.randomId, obj);1087 }1088 }1089 }1090 if (!this._checkValidFormat()) {1091 this.setInvalid();1092 } else {1093 this.setValid();1094 }1095 if (this.options.fieldDisplayerModified && changed)1096 document.fire(this.options.fieldDisplayerModified, { field: this, value: value, first: this._firstTimeGettingValue, screen: this.options.screen, record: this.options.record, fieldName: this.options.id, type: this.options.fieldType });10971098 this._firstTimeGettingValue = false; //Indicate that this is no longer its first time to get values1099 this.getValuesDependantFields();1100 if (!Object.isEmpty(this.options.rechargeAll))1101 if (this.options.rechargeAll)1102 this.setRecharge(value);1103 if (!Object.isEmpty(this.options.variant.get(this.options.appId + '_' + this.options.screen))) {1104 if (this.options.variant.get(this.options.appId + '_' + this.options.screen).variantId == this.options.id && changed) {1105 this.manageVariant(value);1106 }1107 }1108},1109manageVariant: function(value) {1110 var type = this.options.variant.get(this.options.appId + '_' + this.options.screen).variantType;1111 if (type == 'S') {1112 //document.fire('EWS:variantS_' + this.options.appId, { 'variant': this.options.variant, objType: this.options.objectType, objId: this.options.objectId, record: this.options.record, screen: this.options.screen, keyStr: this.options.keyStr });1113 this.options.FPObject.manageVariantService({ 'variant': this.options.variant, objType: this.options.objectType, objId: this.options.objectId, record: this.options.record, screen: this.options.screen, keyStr: this.options.keyStr, mode: this.options.mode });1114 }1115 else if (type == 'F') {1116 var value = value.id;1117 this.options.FPObject.manageVariantValue(this.options.record, this.options.screen, this.options.mode, this.options.keyStr, null, value);1118 }1119},11201121setRecharge: function(value) {1122 var oldValue = this.options.value;1123 var oldText = this.options.text;1124 var selectedEmployee = global.getSelectedEmployees().first();1125 var loggedEmployee = global.objectId;1126 var userLanguage = global.userLanguage;1127 if (((oldText != value.text) || (oldValue != value.id)) && (selectedEmployee == loggedEmployee) && (userLanguage == '2'))1128 global.reloadEWS = true;1129 else1130 global.reloadEWS = false;1131},1132/**1133* Calls to getFieldValues for all the fields that depend on it.1134*/1135getValuesDependantFields: function() {1136 //Loop through the dependant fields, calling getFieldValues for them1137 if (!Object.isEmpty(this.dependantFields)) {1138 var dependantFieldsKeys = this.dependantFields.keys();1139 for (var i = 0; i < dependantFieldsKeys.size(); i++) {1140 this.dependantFields.get(dependantFieldsKeys[i]).options.updateValue = true;1141 this.dependantFields.get(dependantFieldsKeys[i]).getFieldValues();1142 }1143 }1144},11451146/**1147* Observes the given event on an element. If no element is given the event is observed on document.1148* @param {String} eventName the name of the event to be observed.1149* @param {Function} handler the handler function.1150* @param {Element} (Optional) The Element object which will listen to the event. Will use document if it's not specified1151*/1152_registerEvent: function(eventName, handler, element) {1153 //if the element isn't specified we take document1154 if (Object.isUndefined(element)) {1155 //observe the event1156 document.observe(eventName, handler);1157 //and store it1158 this._events.set(eventName, {1159 handler: handler,1160 element: document1161 });1162 }1163 //if specified we take the element given as argument1164 else {1165 element.observe(eventName, handler);1166 this._events.set(eventName, {1167 handler: handler,1168 element: element1169 });1170 }1171},1172/**1173* Stop observing all the events which're being listened by this field displayer.1174*/1175_stopObserve: function() {1176 if (this._events)1177 this._events.each(function(event) {1178 var element = event.value.element;1179 var handler = event.value.handler;1180 var eventName = event.key;1181 element.stopObserving(eventName, handler);1182 });11831184 this._events = $H();1185},1186//GENERAL METHODS1187//***********************************************************************************************************************************************1188setInvalid: function() {1189 //temporal invalid style1190 this._element.addClassName('fieldError');1191 if ($('errorDiv_' + this.options.id + this.options.appId + this.options.screen + this.options.record))1192 $('errorDiv_' + this.options.id + this.options.appId + this.options.screen + this.options.record).show();1193},1194setValid: function() {1195 //temporal valid style1196 if (this._element) {1197 this._element.removeClassName('fieldError');1198 if ($('errorDiv_' + this.options.id + this.options.appId + this.options.screen + this.options.record))1199 $('errorDiv_' + this.options.id + this.options.appId + this.options.screen + this.options.record).hide();1200 }1201},1202/**1203* Puts focus on the fieldDisplayer1204* Should be overriden for fieldDisplayers that need to implement it1205*/1206setFocus: function() {1207},1208/**1209* Checks if this field has valid values according to the options.1210* @returns Boolean true when valid format, false otherwise.1211*/1212_checkValidFormat: function() {1213 return Prototype.emptyFunction();1214},1215/**1216* Destroys a field displayer by stopObserving all its events and removing its container.1217*/1218destroy: function(html) {1219 this._stopObserve();1220 if (Object.isEmpty(html)) {1221 if (this._element && this._element.parentNode) {1222 this._element.remove();1223 delete this._element;1224 }1225 }1226 else {1227 this._element.parentNode.update(html);1228 }1229},1230/**1231* Test the validity of a field displayer data.1232* @return {Boolean} true when valid, false if it's not valid.1233*/1234isValid: function() {1235 return this._checkValidFormat();1236},12371238/**1239* Sets the fields that depend on that field (only logical dependence)1240* @param {Object} dependantField1241*/1242setDependantFields: function(dependantField) {1243 this.dependantFields = dependantField;1244},12451246/**1247* Sets the field that this field depends on1248* @param {Object} parentField1249*/1250setParentField: function(parentField) {1251 this.parentField = parentField;1252}12531254});12551256/**1257* fieldTypeAutocompleter will return a FieldDisplayer object representing an autocompleter.1258* @constructor1259* @augments FieldDisplayer1260*/1261var fieldTypeAutocompleter = Class.create(parentFieldDisplayer,1262/**1263* @lends fieldTypeAutocompleter1264*/1265{1266initialize: function($super, options) {1267 if (Object.isEmpty(options.valueListService)) {1268 //setting 'get_field_val' as default service, since all the selectboxes need one service1269 options.valueListService = "GET_FIELD_VAL";1270 }1271 $super(options);1272},1273/**1274* Takes the values for the autocompleter from the service.1275*/1276_getFieldValuesSuccess: function($super, response) {1277 var valuesList = {1278 autocompleter: {1279 object: $A()1280 }1281 };1282 this._moduleInstance.clearInput();1283 if (response.EWS.o_values) {1284 objectToArray(response.EWS.o_values.item).each(function(item) {1285 valuesList.autocompleter.object.push({1286 "data": item["@id"],1287 "text": item["@value"]1288 });1289 } .bind(this));1290 }1291 this._moduleInstance.updateInput(valuesList);1292 if (!Object.isEmpty(this.options.value)) {1293 this._moduleInstance.setDefaultValue(this.options.value, false, false);1294 if (Object.isEmpty(this.options.onChangeEvent) || this._firstTimeGettingValue || this.options.updateValue) {//in order to avoid that an autocompleter will block the page refreshing the page without end.1295 this.options.updateValue = false;1296 this._onFieldChange(true, true);1297 }1298 }1299 else {1300 if (!Object.isEmpty(this.options.text)) {1301 this._moduleInstance.setDefaultValue(this.options.text, true, false);1302 if (Object.isEmpty(this.options.onChangeEvent) || this._firstTimeGettingValue || this.options.updateValue) {//in order to avoid that an autocompleter will block the page refreshing the page without end.1303 this.options.updateValue = false;1304 this._onFieldChange(true, true);1305 }1306 }1307 else {1308 //if (this._firstTimeGettingValue)1309 this._onFieldChange(true, true);1310 }1311 }1312 this._moduleInstance.stopLoading();1313 //If the response does not include all the results, then the autocompleter has to call the service for future searches1314 if(response.EWS.o_max_num_exceeded == 'X') {1315 this._moduleInstance.setSearchWithService(true);1316 //Setting the XML for the autocompleter that is to be sent to backend for searches1317 var xmlin = this._getXMLIn(this.getDependencyInfo());1318 this._moduleInstance.setXmlToSend(xmlin);1319 }1320 else1321 this._moduleInstance.setSearchWithService(false);1322 //method commented, since it deletes the values of all the autompleters in the json when1323 //ANY interaction with the user is done1324 //this._onFieldChange(false);1325 this.setValid();1326 $super(response);1327 if(this.needsFocus) {1328 if(!Object.isEmpty(this._moduleInstance) &&1329 !Object.isEmpty(this._moduleInstance.element)) {1330 this._moduleInstance.element.focus();1331 if (Prototype.Browser.IE) {1332 this._moduleInstance.element.focus();1333 }1334 }1335 this.needsFocus = false;1336 }1337},1338/**1339* Initializes the autocompleter1340*/1341_initializeModule: function($super) {1342 var json = {1343 autocompleter: {1344 object: $A()1345 }1346 };1347 //Setting the XML for the autocompleter that is to be sent to backend for searches1348 var xmlin = this._getXMLIn(this.getDependencyInfo());1349 this._moduleInstance = new JSONAutocompleter(this._moduleElement, {1350 showEverythingOnButtonClick: true,1351 fireEventWhenDefaultValueSet: true,1352 xmlToSend: xmlin,1353 searchWithService: false,1354 url: this.url,1355 method: this.method,1356 timeout: 500,1357 templateResult: this.options.displayFormat.template,1358 templateOptionsList: this.options.displayFormat.template,1359 maxShown: 5,1360 virtualVariables: true,1361 events: $H({1362 onResultSelected: 'EWS:autocompleter_resultSelected_' + this.options.id + this.options.appId + this.options.screen + this.options.record + this.options.randomId,1363 onDataLoaded: 'EWS:autocompleter_dataLoaded_' + this.options.id + this.options.appId + this.options.screen + this.options.record + this.options.randomId1364 })1365 }, json);1366 this._moduleInstance.loading();1367 $super();1368 this._moduleInstance.stopLoading.bind(this._moduleInstance).delay(3);1369},1370_setOnChange: function($super) {1371 $super('EWS:autocompleter_resultSelected_' + this.options.id + this.options.appId + this.options.screen + this.options.record + this.options.randomId);1372},1373_getFieldValues: function($super, depFieldInfo, xmlin){1374 if((!Object.isEmpty(this.options.text) || !Object.isEmpty(this.options.value))) {1375 var search = '';1376 if(!Object.isEmpty(this.options.value))1377 search = search + "<DEFAULT_VALUE>" + this.options.value.escapeHTML() + "</DEFAULT_VALUE>";1378 if(!Object.isEmpty(this.options.text))1379 search = search + "<DEFAULT_TEXT>" + this.options.text.escapeHTML() + "</DEFAULT_TEXT>";1380 if(Object.isEmpty(xmlin))1381 xmlin = this._getXMLIn(depFieldInfo);1382 var xml = xmlin.replace('<SEARCH_PATTERN />', search + '<SEARCH_PATTERN />');1383 $super(depFieldInfo, xml);1384 } else {1385 $super(depFieldInfo, xmlin);1386 }1387},1388_setHowToGetValue: function($super) {1389 obj =1390 {1391 id: function() {1392 if (!Object.isEmpty(this._moduleInstance.getValue()))1393 return this._moduleInstance.getValue().idAdded;1394 else1395 return '';13961397 } .bind(this),1398 text: function() {1399 if (!Object.isEmpty(this._moduleInstance.getValue()))1400 return unescape(this._moduleInstance.getValue().textAdded);1401 else1402 return '';1403 } .bind(this)1404 }1405 $super(obj);1406},1407setFocus: function() {1408 this.needsFocus = true;1409 if(!Object.isEmpty(this._moduleInstance) &&1410 !Object.isEmpty(this._moduleInstance.element) &&1411 this._moduleInstance.enabled) {1412 this._moduleInstance.element.focus();1413 if (Prototype.Browser.IE) {1414 this._moduleInstance.element.focus();1415 }1416 }1417},1418/**1419* @description Checks the field format1420* @param $super1421* Parent function1422*/1423_checkValidFormat: function($super) {1424 if (this.options.mandatory && this._moduleInstance && (Object.isEmpty(this._moduleInstance.getValue()) || this._moduleInstance.getValue().isEmpty) && !this.options.visualOpt)1425 return false;1426 else1427 return true;1428}1429});14301431/**1432* fieldTypeBubble will return a FieldDisplayer object representing a color bubble.1433* @constructor1434* @augments FieldDisplayer1435*/14361437var fieldTypeBubble = Class.create(parentFieldDisplayer,1438/**1439* @lends fieldTypeBubble1440*/1441{1442/**1443* Indexes the icon types according to the value given in the service1444* @type Array1445*/1446ICON_TYPES: $A([1447 "application_emptyBubble",1448 "application_icon_red",1449 "application_icon_orange",1450 "application_icon_green"1451 ]),14521453initialize: function($super, options) {1454 $super(options);1455},14561457/**1458* Gets the class for the bubble icon from the icon types Array.1459* @return {String} The class name if the value is correct. An empty String otherwise.1460*/1461_getBubbleClass: function() {1462 var value = parseInt(this.options.value, 10);1463 //Make sure the value is in the icons classes Array1464 if (value >= this.ICON_TYPES.size()) {1465 return "";1466 }1467 //return the class from the icons classes array1468 else {1469 return this.ICON_TYPES[value];1470 }1471},1472/**1473* Sets the bubble layout by using the original field displayer layout1474* and giving it the proper class name1475*/1476_initializeModule: function($super) {1477 this._moduleElement.addClassName(this._getBubbleClass);1478 $super();1479},1480_checkValidFormat: function($super) {1481 return true;1482}1483});14841485/**1486* fieldTypecheckBox will return a FieldDisplayer object representing a checkBox.1487* @constructor1488* @augments FieldDisplayer1489*/14901491var fieldTypeCheckBox = Class.create(parentFieldDisplayer,1492/**1493* @lends fieldTypecheckBox1494*/1495{1496initialize: function($super, options) {1497 $super(options);1498},1499/**1500* Initializes the check box1501*/1502_initializeModule: function($super) {1503 //Main container, The checkBoxes will be placed here1504 this._checkBoxesContainer = new Element('div', {});1505 //Inserting the container on the parent element container1506 this._moduleElement.update(this._checkBoxesContainer);1507 if (Object.isEmpty(this.options.valueListService))1508 this._createSingleComponent();1509 else1510 this._getFieldValues();1511 var value = this.getValue();1512 var changed = this.updateJSON(value);1513 $super();1514},1515_getFieldValuesSuccess: function($super, response) {1516 //Getting the field values from the response1517 if (response.EWS.o_values && response.EWS.o_values.item) {1518 this._checkBoxesContainer.update('');1519 //Converting the object into an array just in case we have one record1520 var values = objectToArray(response.EWS.o_values.item);1521 //Going throught all the results1522 values.each(function(_elem) {1523 //Creating the checkBox element1524 var checkBoxElement = new Element('input', {1525 type: 'checkbox',1526 name: _elem['@id'],1527 disabled: (this.options.mode == this.DISPLAY_MODE) ? 'disabled' : ''1528 });1529 //Creating the item container1530 var checkBoxSpan = new Element('span', {});1531 checkBoxSpan.insert(_elem['@value']);1532 //Inserting label and checkbox in an element1533 var checkBoxContainer = new Element('div', {});1534 checkBoxContainer.insert(checkBoxElement);1535 checkBoxContainer.insert(checkBoxSpan);1536 //Inserting the whole generated element in the parent container1537 this._checkBoxesContainer.insert(checkBoxContainer)1538 if (_elem['@default_value'] && (_elem['@default_value'] == 'X' || _elem['@default_value'] == 'Yes'))1539 checkBoxElement.checked = true;1540 } .bind(this));1541 $super(response);1542 if(this.needsFocus) {1543 if(!Object.isEmpty(this._checkBoxesContainer) &&1544 !Object.isEmpty(this._checkBoxesContainer.down())) {1545 this._checkBoxesContainer.down().focus();1546 if (Prototype.Browser.IE) {1547 this._checkBoxesContainer.down().focus();1548 }1549 }1550 this.needsFocus = false;1551 }1552 }1553 else1554 return;1555},1556_createSingleComponent: function() {1557 this._singleComponent = true;1558 var disabled = (this.options.mode == this.DISPLAY_MODE || this.options.optionsJSON.settings['@display_attrib'] == 'OUO') ? true : false1559 var checkBoxElement = new Element('input', {1560 type: 'checkbox',1561 disabled: disabled1562 });1563 this._checkBoxesContainer.insert(checkBoxElement);1564 if(this.options.optionsJSON.settings['@show_text'] == 'X') {1565 if (!Object.isEmpty(this.options.text) && (this.options.text == 'X' || this.options.text == 'Yes'))1566 checkBoxElement.checked = true;1567 } else {1568 if (!Object.isEmpty(this.options.value) && (this.options.value == 'X' || this.options.value == 'Yes'))1569 checkBoxElement.checked = true;1570 }1571 },1572 setFocus: function() {1573 this.needsFocus = true;1574 if(!Object.isEmpty(this._checkBoxesContainer) &&1575 !Object.isEmpty(this._checkBoxesContainer.down())) {1576 this._checkBoxesContainer.down().focus();1577 if (Prototype.Browser.IE) {1578 this._checkBoxesContainer.down().focus();1579 }1580 }1581},1582/**1583* @description Checks the field format1584* @param $super Parent function1585*/1586_checkValidFormat: function($super) {1587 return true;1588},1589_setOnChange: function($super) {1590 if (this._singleComponent)1591 $super(this._checkBoxesContainer.down(), 'click');1592 else1593 $super(this._checkBoxesContainer, 'click');1594},1595_setHowToGetValue: function($super) {1596 obj =1597 {1598 id: function() {1599 if (this._singleComponent) {1600 var checked = (this._checkBoxesContainer.down().checked) ? 'X' : '';1601 return checked;1602 } else {1603 var value = $A();1604 $A(this._checkBoxesContainer.childNodes).each(function(item) {1605 if (item.firstChild.checked)1606 value.push(item.firstChild.getAttribute('name'));1607 });1608 return value;1609 }1610 } .bind(this),1611 text: function() {1612 if (this._singleComponent) {1613 var checked = (this._checkBoxesContainer.down().checked) ? 'X' : '';1614 return checked;1615 } else {1616 var value = $A();1617 $A(this._checkBoxesContainer.childNodes).each(function(item) {1618 if (item.firstChild.checked)1619 value.push(item.firstChild.getAttribute('name'));1620 });1621 return value;1622 }1623 } .bind(this)1624 }1625 $super(obj);1626}1627});16281629/**1630* fieldTypeDate will return a FieldDisplayer object representing a select box.1631* @constructor1632* @augments FieldDisplayer1633*/16341635var fieldTypeDate = Class.create(parentFieldDisplayer,1636/**1637* @lends fieldTypeDate1638*/1639{1640//To keep track of the validity of the Date1641correctDate: false,1642initialize: function($super, options) {1643 $super(options);1644 //This is to make sure that if we have a value, it gets to the json1645 this._updateJSONDate();1646 this.setValid();1647},1648/**1649* Initializes the date picker1650*/1651_initializeModule: function($super) {1652 //Changing the default date format for the defaultDate variable of the datepicker1653 var date = null;1654 if (!Object.isEmpty(this.options.value) && this.options.value != '0000-00-00') {1655 date = this.options.value.gsub("-", "");1656 }1657 //Observes the event that is fired when a field of the date picker is blurred, so we update the JSON1658 this._registerEvent('EWS:datePickerCorrectDate_' + this.options.id + '_' + this._id + '_' + this.options.appId + this.options.screen + this.options.record + this.options.randomId, this._correctDate.bind(this));1659 this._registerEvent('EWS:datePickerWrongDate_' + this.options.id + this.options.appId + this.options.screen + this.options.record + this.options.randomId, this._wrongDate.bind(this));1660 this._moduleInstance = new DatePicker(this._moduleElement, {1661 emptyDateValid: !this.options.mandatory,1662 correctDateOnBlur: true,1663 fireEventOnInitialize: true,1664 defaultDate: date,1665 events: $H({1666 correctDate: 'EWS:datePickerCorrectDate_' + this.options.id + '_' + this._id + '_' + this.options.appId + this.options.screen + this.options.record + this.options.randomId,1667 wrongDate: 'EWS:datePickerWrongDate_' + this.options.id + this.options.appId + this.options.screen + this.options.record + this.options.randomId1668 })1669 });1670 $super();1671},1672_setValue: function($super, value) {1673 var date;1674 if (!Object.isEmpty(value)) {1675 date = Date.parseExact(value, ['yyyy-MM-dd', 'yyyy-MM-dd']);16761677 this._moduleInstance.setDate(date);1678 }1679},1680/**1681* Updates the correctDate variable to reflect the changes of the datePicker1682*/1683_correctDate: function() {1684 this.correctDate = true;1685 this._onFieldChange(true, true);1686},1687/**1688* Updates the JSON and the correctDate variable to reflect the changes of the datePicker1689*/1690_wrongDate: function() {1691 this.correctDate = false;1692 this._onFieldChange(false);1693},1694/**1695* Updates the JSON with the current value1696*/1697_updateJSONDate: function() {1698 var value = this.getValue();1699 this.updateJSON(value);1700},1701_checkValidFormat: function($super) {1702 if (this._moduleInstance && !this.correctDate && !this.options.visualOpt)1703 return false;1704 else1705 return true;1706},1707setFocus: function() {1708 if (!Object.isEmpty(this._moduleInstance) && !Object.isEmpty(this._moduleInstance.dayField)) {1709 this._moduleInstance.dayField.focus();1710 if (Prototype.Browser.IE) {1711 this._moduleInstance.dayField.focus();1712 }1713 }1714},1715_setOnChange: function($super) {1716},17171718_setHowToGetValue: function($super) {1719 obj =1720 {1721 id: function() {1722 if (this._moduleInstance.actualDate) {1723 return this._moduleInstance.actualDate.toString("yyyy-MM-dd");1724 }1725 if(this._moduleInstance.dateIsEmpty()) {1726 return '';1727 } else1728 return this._moduleInstance.yearField.value + '-' + this._moduleInstance.monthField.value + '-' + this._moduleInstance.dayField.value;1729 } .bind(this),1730 text: function() {1731 if(this._moduleInstance.dateIsEmpty()) {1732 return '';1733 } else1734 return this._moduleInstance.yearField.value + '-' + this._moduleInstance.monthField.value + '-' + this._moduleInstance.dayField.value;1735 } .bind(this)1736 }1737 $super(obj);1738},173917401741_formattedValue: function(options) {17421743 return (!Object.isEmpty(options) && !Object.isEmpty(options.value)) ? sapToDisplayFormat(options.value) : "";1744}17451746});17471748/**1749* fieldTypeHidden will return a FieldDisplayer hidden (no graphical representation)1750* @constructor1751* @augments fieldTypeHidden1752*/1753var fieldTypeHidden = Class.create(parentFieldDisplayer,1754/**1755* @lends fieldTypeHidden1756*/1757{1758_setLayout: function() {1759 this._element = new Element("div");1760},1761_initializeModule: function() {1762 var depValue = !Object.isEmpty(this.options.value) ? this.options.value : this.options.optionsJSON.settings['@default_value'];1763 document.fire("EWS:fieldChanged_" + this.options.techName + this.options.appId + this.options.screen + this.options.record + this.options.randomId, $H({1764 fieldid: this.options.id,1765 fieldtechname: this.options.techName,1766 value: depValue1767 }));1768 this._lastValueSelected.set(this.options.techName + this.options.appId + this.options.screen + this.options.record, $H({1769 fieldid: this.options.id,1770 fieldtechname: this.options.techName,1771 value: depValue1772 }));1773 if (this.options.techName != this.options.id) {1774 //in PFM, it is taken into account the fieldId for dependencies, instead of the fieldTechName1775 document.fire("EWS:fieldChanged_" + this.options.id + this.options.appId + this.options.screen + this.options.record + this.options.randomId, $H({1776 fieldid: this.options.id,1777 fieldtechname: this.options.techName,1778 value: depValue1779 }));1780 this._lastValueSelected.set(this.options.id + this.options.appId + this.options.screen + this.options.record, $H({1781 fieldid: this.options.id,1782 fieldtechname: this.options.techName,1783 value: depValue1784 }));1785 }1786 if (this.options.mode != 'edit') {1787 if (Object.isEmpty(this.options.optionsJSON.values['@value']) && Object.isEmpty(this.options.optionsJSON.values['#text'])) {1788 text = !Object.isEmpty(this.options.optionsJSON.settings['@default_text']) ? this.options.optionsJSON.settings['@default_text'] : '';1789 id = !Object.isEmpty(this.options.optionsJSON.settings['@default_value']) ? this.options.optionsJSON.settings['@default_value'] : '';1790 var changed = this.updateJSON({1791 id: id,1792 text: text1793 })1794 }1795 }1796 else {1797 if (Object.isEmpty(this.options.optionsJSON.values['@value'])) {1798 id = '';1799 }1800 else {1801 id = this.options.optionsJSON.values['@value'];1802 }18031804 if (Object.isEmpty(this.options.optionsJSON.values['#text'])) {1805 text = '';1806 }1807 else {1808 text = this.options.optionsJSON.values['#text'];1809 }1810 }1811},1812_checkValidFormat: function($super) {1813 return true;1814},1815_getFieldValues: function() {1816 this._onFieldChange(false, true);1817 return Prototype.emptyFunction();1818}1819});18201821/**1822* fieldTypeHour will return a FieldDisplayer a time entry field1823* @constructor1824* @augments FieldDisplayer1825*/18261827var fieldTypeHour = Class.create(parentFieldDisplayer,1828/**1829* @lends fieldTypeHour1830*/1831{1832initialize: function($super, options) {1833 $super(options);1834 //This is to make sure that if we have a value, it gets to the json1835 var value = this.getValue();1836 this.updateJSON(value);1837 this.setValid();1838},18391840/**1841* Initializes the hour field properly.1842*/1843_initializeModule: function($super) {1844 this._moduleInstance = new HourField(this._moduleElement, {1845 viewSecs: 'no',1846 format: "24",1847 defaultTime: (!Object.isEmpty(this.options.value)) ? this.options.value.gsub(':', '') : '000000',1848 events: $H({1849 //onCorrectTime: 'EWS:hourfield_correct_' + this.options.id + this.options.appId + this.options.screen + this.options.record + this.options.randomId,1850 onCorrectTime: 'EWS:hourfield_correct_' + this.options.id + '_' + this._id + '_' + this.options.appId + this.options.screen + this.options.record + this.options.randomId,1851 onIncorrectTime: 'EWS:hourfield_incorrect_' + this.options.id + this.options.appId + this.options.screen + this.options.record + this.options.randomId1852 })18531854 });1855 var value = this.getValue();1856 var changed = this.updateJSON(value);1857 $super();1858},1859 setFocus: function() {1860 if(!Object.isEmpty(this._moduleInstance) && !Object.isEmpty(this._moduleInstance.contentHour)) {1861 this._moduleInstance.contentHour.focus();1862 if (Prototype.Browser.IE) {1863 this._moduleInstance.contentHour.focus();1864 }1865 }1866 },1867/**1868* @description Checks the field format1869* @param $super1870* Parent function1871*/1872_checkValidFormat: function($super) {1873 return true;1874},1875_setOnChange: function($super) {1876 $super('EWS:hourfield_correct_' + this.options.id + '_' + this._id + '_' + this.options.appId + this.options.screen + this.options.record + this.options.randomId);1877},1878_setHowToGetValue: function($super) {1879 obj =1880 {1881 id: function() {1882 return this._moduleInstance.getSapTime();1883 } .bind(this),1884 text: function() {1885 return this._moduleInstance.getSapTime();1886 } .bind(this)1887 }1888 $super(obj);1889}1890});18911892/**1893* fieldTypeImage will return a FieldDisplayer object representing an image1894* @constructor1895* @augments FieldDisplayer1896*/18971898var fieldTypeImage = Class.create(parentFieldDisplayer,1899/**1900* @lends fieldTypeImage1901*/1902{1903initialize: function($super, options) {1904 $super(options);1905},19061907/**1908* Creates the HTML element needed for the image.1909*/1910_setLayout: function($super) {1911 //$super();1912 //value will specify the URL to load the image1913 if (this.options.value) {1914 this._element = new Element("img", {1915 "src": options.value,1916 "border": 01917 });1918 }1919 //If the URL isn't specified give it a standard style.1920 else {1921 this._element.addClassName("application_noPicture");1922 }1923},1924_checkValidFormat: function($super) {1925 return true;1926}1927}1928);1929193019311932/**1933* fieldTypeLinkToHandler will return a FieldDisplayer object representing an application link.1934* @constructor1935* @augments FieldDisplayer1936*/19371938var fieldTypeLinkToHandler = Class.create(parentFieldDisplayer,1939/**1940* @lends fieldTypeLink1941*/1942{1943initialize: function($super, options) {1944 $super(options);1945},1946/**1947* Creates the element and gives it the proper class name1948*/1949_setLayout: function($super) {1950 $super();1951 this._element = new Element("span", {1952 "class": "application_action_link"1953 }).update(this.options.label);1954 if (this.options.handler && this.options.handler.get(this.options.id))1955 this._element.observe('click', this.options.handler.get(this.options.id));1956 else1957 this._element.observe('click', this.defaultHandler);1958},1959/*1960* @description Checks the field format1961* @param $super1962* Parent function1963*/1964_checkValidFormat: function($super) {1965 return true;1966},1967defaultHandler: function() {1968 alert('This is the fieldTypeLinkToHandler default handler. You should pass the buttonsHandler option to the fieldsPanel constructor, using this field id as the hash key.');1969}1970});197119721973/**1974* fieldTypeLink will return a FieldDisplayer object representing an application link.1975* @constructor1976* @augments FieldDisplayer1977*/19781979var fieldTypeLink = Class.create(parentFieldDisplayer,1980/**1981* @lends fieldTypeLink1982*/1983{1984initialize: function($super, options) {1985 $super(options);1986},1987/**1988* Creates the element and gives it the proper class name1989*/1990_setLayout: function($super) {1991 $super();1992 this.element = new Element("a", {1993 "class": "application_action_link",1994 "href": this.options.value1995 }).update(this.options.text);1996},1997/*1998* @description Checks the field format1999* @param $super2000* Parent function2001*/2002_checkValidFormat: function($super) {2003 return true;2004}2005});20062007/**2008* fieldTypeRadioButton will return a FieldDisplayer object representing a radio button.2009* @constructor2010* @augments FieldDisplayer2011*/20122013var fieldTypeRadioButton = Class.create(parentFieldDisplayer,2014/**2015* @lends fieldTypeRadioButton2016*/2017{2018/**2019* @description Contains que parent DIV of the type where the radio buttons will be placed2020* @type Prototype.Element2021*/2022_radioButtonContainer: null,2023/**2024* @description Initializes the field type2025* @param $super The parent funciton2026* @param options The field settings2027*/2028initialize: function($super, options) {2029 $super(options);2030},2031/**2032* @description Parses the JSON values and converts it into field values2033* @param $super The parent class2034* @param response The JSON response2035*/2036_getFieldValuesSuccess: function($super, response) {2037 //Getting the field values from the response2038 if (!Object.isEmpty(response.EWS.o_values) && !Object.isEmpty(response.EWS.o_values.item)) {2039 //Converting the object into an array just in case we have one record2040 var values = objectToArray(response.EWS.o_values.item);2041 //Going throught all the results2042 values.each(function(_elem, index) {2043 //Creating the radio element2044 var radioElement;2045 var disabled = (this.options.mode == this.DISPLAY_MODE) ? 'disabled' : '';2046 if ((Object.isEmpty(this.options.value) && (index == 0)) || (this.options.value == _elem['@id'])) {2047 radioElement = "<input checked " + disabled + " type='radio' value='" + _elem['@id'] + "' name='" + this.options.id + this.options.appId + this.options.screen + this.options.record + "' />";2048 } else {2049 radioElement = "<input type='radio' " + disabled + " value='" + _elem['@id'] + "' name='" + this.options.id + this.options.appId + this.options.screen + this.options.record + "' />";2050 }2051 //Creating the item container2052 var radioButtonSpan = new Element('span', {2053 'class': 'fieldDisplayer_radioLabel'2054 });2055 //Inserting the radio button in the item container2056 radioButtonSpan.insert(_elem['@value']);2057 //Inserting the whole generated element in the parent container2058 var container = new Element('div', {2059 'class': 'fieldDispClearBoth fieldDispFloatLeft'2060 });2061 container.insert(radioElement);2062 container.insert(radioButtonSpan);2063 this._radioButtonContainer.insert(container);2064 } .bind(this));2065 if (this._firstTimeGettingValue) {2066 var value = this.getValue();2067 var changed = this.updateJSON(value);2068 }2069 this._firstTimeGettingValue = false;2070 $super(response);2071 if(this.needsFocus) {2072 if(!Object.isEmpty(this._radioButtonContainer) &&2073 !Object.isEmpty(this._radioButtonContainer.firstChild) && 2074 !Object.isEmpty(this._radioButtonContainer.firstChild.firstChild)) {2075 this._radioButtonContainer.firstChild.firstChild.focus();2076 if (Prototype.Browser.IE) {2077 this._radioButtonContainer.firstChild.firstChild.focus();2078 }2079 }2080 this.needsFocus = false;2081 }2082 }2083},2084_initializeModule: function($super) {2085 //Main container, The radio buttons will be placed here2086 this._radioButtonContainer = new Element('div', {});2087 //Inserting the container on the parent element container2088 this._moduleElement.update(this._radioButtonContainer);2089 $super();2090 },2091 setFocus: function() {2092 this.needsFocus = true;2093 if(!Object.isEmpty(this._radioButtonContainer) &&2094 !Object.isEmpty(this._radioButtonContainer.firstChild) && 2095 !Object.isEmpty(this._radioButtonContainer.firstChild.firstChild)) {2096 this._radioButtonContainer.firstChild.firstChild.focus();2097 if (Prototype.Browser.IE) {2098 this._radioButtonContainer.firstChild.firstChild.focus();2099 }2100 }2101},2102/*2103* @description Checks the field format2104* @param $super2105* Parent function2106*/2107_checkValidFormat: function($super) {2108 return true;2109},2110_setOnChange: function($super) {2111 $super(this._radioButtonContainer, 'click');2112},2113_setHowToGetValue: function($super) {2114 obj =2115 {2116 id: function() {2117 var checkedValue = '';2118 var radios = objectToArray(this._radioButtonContainer.select('[name=' + this.options.id + this.options.appId + this.options.screen + this.options.record + ']'));2119 if (!Object.isEmpty(radios) && (radios.size() > 0)) {2120 radios.each(function(r) {2121 if (r.checked) {2122 checkedValue = r.getValue();2123 return;2124 }2125 } .bind(this));2126 return checkedValue;2127 } else {2128 return '';2129 }2130 } .bind(this),2131 text: function() {2132 var checkedValue = '';2133 var radios = objectToArray(this._radioButtonContainer.select('[name=' + this.options.id + this.options.appId + this.options.screen + this.options.record + ']'));2134 if (!Object.isEmpty(radios) && (radios.size() > 0)) {2135 radios.each(function(r) {2136 if (r.checked) {2137 checkedValue = r.getValue();2138 return;2139 }2140 } .bind(this));2141 return checkedValue;2142 } else {2143 return '';2144 }2145 } .bind(this)2146 }2147 $super(obj);2148}2149});21502151/**2152* fieldTypeSelectBox will return a FieldDisplayer object representing a select box.2153* @constructor2154* @augments FieldDisplayer2155*/21562157var fieldTypeSelectBox = Class.create(parentFieldDisplayer,2158/**2159* @lends fieldTypeSelectBox2160*/2161{2162/**2163* The select box html element2164* @type {Element}2165*/2166select: null,2167initialize: function($super, options) {2168 if (Object.isEmpty(options.valueListService)) {2169 //setting 'get_field_val' as default service, since all the selectboxes need one service2170 options.valueListService = "GET_FIELD_VAL";2171 }2172 $super(options);2173},2174/**2175* Handles the response from the GET_FIELD_VALUES service to fill the select box.2176* @param {JSON} response The response from the service.2177*/2178_getFieldValuesSuccess: function($super, response) {2179 if (response.EWS.o_values) {2180 if (!this.options.mandatory) {2181 this.select.insert(new Element("option", {2182 "value": "",2183 "selected": true2184 }));2185 }2186 objectToArray(response.EWS.o_values.item).each(function(item) {2187 var selected = (item['@id'] == this.options.value) ? true : false;2188 this.select.insert(new Element("option", {2189 "value": item["@id"],2190 "selected": selected2191 }).insert(item["@value"]));2192 } .bind(this));2193 this._onFieldChange(false);2194 this.setValid();2195 $super(response);2196 }21972198},2199/**2200* Initializes the select box with the proper options2201*/2202_initializeModule: function($super) {2203 this.select = new Element("select", {2204 "name": this._moduleElement.identify() + "_select"2205 });2206 this._moduleElement.insert(this.select);2207 $super();2208},2209_setOnChange: function($super) {2210 $super(this.select, 'change');2211},2212_setHowToGetValue: function($super) {2213 obj =2214 {2215 id: function() {2216 if (this.select.selectedIndex != -1)2217 return (this.select.options[this.select.selectedIndex]).value;2218 else2219 return null;2220 } .bind(this),2221 text: function() {2222 if (this.select.selectedIndex != -1)2223 return (this.select.options[this.select.selectedIndex]).text;2224 else2225 return null;2226 } .bind(this)2227 }2228 $super(obj);2229},2230 setFocus: function() {2231 if(!Object.isEmpty(this.select)) {2232 this.select.focus();2233 if (Prototype.Browser.IE) {2234 this.select.focus();2235 }2236 }2237 },2238/**2239* @description Checks the field format2240* @param $super2241* Parent function2242*/2243_checkValidFormat: function($super) {2244 return true;2245}2246});22472248/**2249* fieldTypeText will return a FieldDisplayer object representing a text field.2250* @constructor2251* @augments FieldDisplayer2252*/22532254var fieldTypeText = Class.create(parentFieldDisplayer,2255/**2256* @lends fieldTypeText2257*/2258{2259/**2260* @description Stores the regular expresion to check certain text format2261*/2262TEXT_FORMATS_REGEXP: {2263 CHAR: true, // Checks if the text is a string2264 NUMC: /^\s*\d+\s*$/, // Checks if the text is an int2265 DEC: /^(?:\d+)(?:\.\d+)?$/ // Checks if the text is a decimal number2266},2267/**2268* @description Initializes the class2269* @param $super Parent class initialize method2270* @param Field type settings2271*/2272initialize: function($super, options) {2273 $super(options);2274 //this._onFieldChange(false);2275 this.setValid();2276},2277/**2278* Initializes the text input properly.2279*/2280_initializeModule: function($super) {2281 //If we have defined a maximum length2282 var maxLength = null;2283 if (!Object.isEmpty(this.options.optionsJSON.settings['@length'])) {2284 maxLength = parseInt(this.options.optionsJSON.settings['@length'], 10);2285 if (maxLength == 0) {2286 maxLength = null;2287 }2288 }2289 this.textFieldElement = new Element("input", {2290 "type": "text",2291 "class": "fieldDispWidth",2292 "value": (!Object.isEmpty(this.options.value)) ? this.options.value.gsub('&#37;', '%') : this.options.text2293 });2294 if (!Object.isEmpty(maxLength)) {2295 this.textFieldElement.writeAttribute("maxlength", maxLength);2296 }2297 this._moduleElement.update(this.textFieldElement);22982299 var value = this.getValue();2300 var changed = this.updateJSON(value);2301 //Calling the parent function2302 $super();2303},2304setFocus: function() {2305 if(!Object.isEmpty(this.textFieldElement)) {2306 this.textFieldElement.focus();2307 if (Prototype.Browser.IE) {2308 this.textFieldElement.focus();2309 }2310 }2311},2312/**2313* @description Checks the field format2314* @param $super2315* Parent function2316*/2317_checkValidFormat: function($super) {2318 var regExp = this.TEXT_FORMATS_REGEXP[this.options.type];2319 if (this.options.mode == this.DISPLAY_MODE)2320 return true;2321 if (!this.options.mandatory)2322 return true;2323 else if ((Object.isEmpty(this.textGetter())) && (Object.isEmpty(this.idGetter())) && !this.options.visualOpt)2324 return false;2325 else2326 return true2327 // in case regExp is undefined it was return false. Therefor condition !regExp added [EefjeC]2328 if (!Object.isEmpty(this.textGetter())) {2329 if ((!Object.isEmpty(regExp) && this.textGetter().strip().match(regExp)) || (regExp == true || !regExp)) {2330 return true;2331 } else {2332 return false;2333 }2334 }2335 if (!Object.isEmpty(this.idGetter())) {2336 if ((!Object.isEmpty(regExp) && this.idGetter().strip().match(regExp)) || (regExp == true || !regExp)) {2337 return true;2338 } else {2339 return false;2340 }2341 }2342},2343_setOnChange: function($super) {2344 $super(this._moduleElement.down(), 'blur');2345},2346_setHowToGetValue: function($super) {2347 obj =2348 {2349 id: function() {2350 return this._moduleElement.down().getValue();2351 } .bind(this),2352 text: function() {2353 return this._moduleElement.down().getValue();2354 } .bind(this)2355 }2356 $super(obj);2357},23582359_formattedValue: function(options) {2360 var returnValue;2361 var valueTrim;23622363 if (!Object.isEmpty(options) && !Object.isEmpty(options.value)) {23642365 valueTrim = options.value.strip();23662367 if (options.type && ((options.type == "CURR") || (options.type == "DEC"))) {2368 if (valueTrim.split('.')[1]) {2369 var decimalLong = valueTrim.split('.')[1].length;2370 returnValue = longToDisplay(parseFloat(valueTrim, 10), decimalLong);2371 }2372 else {2373 returnValue = longToDisplay(parseFloat(valueTrim, 10));2374 }2375 }2376 else {2377 returnValue = options.value;2378 }2379 }2380 else2381 returnValue = "";23822383 return returnValue;2384}23852386});23872388var fieldTypeTextArea = Class.create(fieldTypeText,2389/**2390* @lends fieldTypeTextArea2391*/2392{2393initialize: function($super, options) {2394 $super(options);2395 //this._onFieldChange(false);2396 this.setValid();2397},23982399/**2400* Initializes the text input properly.2401*/2402_initializeModule: function($super) {2403 $super();2404 this.textAreaElement = new Element("textarea", {2405 'class': 'fieldDisplayer_textArea'2406 });2407 this._moduleElement.update(this.textAreaElement);2408 //If we have defined a maximum length2409 if (!Object.isEmpty(this.options.optionsJSON.settings['@length'])) {2410 var maxLength = parseInt(this.options.optionsJSON.settings['@length'], 10);2411 if (!Object.isEmpty(maxLength) && maxLength > 0) {2412 //Create a text area to inform of the maximum length:2413 this.textAreaError = new Element("div", { "class": "application_main_soft_text" }).insert("The maximum length for this field is " + maxLength + " characters");2414 this.textAreaError.hide();2415 this._moduleElement.insert(this.textAreaError);2416 //Create a event listener to check the max length2417 this.textAreaElement.observe('keyup', this._checkTextAreaLength.bind(this, maxLength));2418 }2419 }24202421 //Calling the parent function2422 var value = (!Object.isEmpty(this.options.value)) ? this.options.value : this.options.text;2423 if (!Object.isEmpty(value))2424 this._moduleElement.down().insert(value);2425 var valueForJSON = this.getValue();2426 this.updateJSON(valueForJSON);2427},2428_checkTextAreaLength: function(maxLength) {2429 if (this.textAreaElement.value.length > maxLength - 1) {2430 this.textAreaElement.value = this.textAreaElement.value.truncate(maxLength, "");2431 this.textAreaError.show();2432 }2433 else {2434 this.textAreaError.hide();2435 }2436},2437setFocus: function() {2438 if(!Object.isEmpty(this.textAreaElement)) {2439 this.textAreaElement.focus();2440 if (Prototype.Browser.IE) {2441 this.textAreaElement.focus();2442 }2443 }2444},2445_checkValidFormat: function($super) {2446 if (this.options.mandatory && this.textAreaElement.value == '' && !this.options.visualOpt)2447 return false;2448 else2449 return true;2450}2451});24522453/**2454* FielTypeOuput2455*/2456var fieldTypeOutput = Class.create(parentFieldDisplayer,2457/**2458* @lends fieldTypeOutput2459*/2460{2461initialize: function($super, options) {2462 $super(options);2463},24642465/**2466* _setLayoutDisplay2467*/2468_setLayoutDisplay: function($super) {2469 $super();2470 //After setting the layout we initialize the values:2471 var content = this.options.displayFormat.evaluate(this.options);2472 var text = '';2473 var id = '';2474 if (Object.isEmpty(this.options.value))2475 content = content.gsub(" " + global.idSeparatorLeft + global.idSeparatorRight, '');2476 if (content.startsWith(" " + global.idSeparatorLeft) && content.endsWith(global.idSeparatorRight))2477 content = content.substring(2, content.length - 1);2478 //this._moduleElement.update(new Element("span").insert(content));2479 if (Object.isEmpty(this.options.optionsJSON.values['@value']) && Object.isEmpty(this.options.optionsJSON.values['#text'] && !content.blank())) {2480 text = !Object.isEmpty(this.options.optionsJSON.settings['@default_text']) ? this.options.optionsJSON.settings['@default_text'] : '';2481 id = !Object.isEmpty(this.options.optionsJSON.settings['@default_value']) ? this.options.optionsJSON.settings['@default_value'] : '';2482 var changed = this.updateJSON({2483 id: id,2484 text: text2485 })2486 }2487},2488_checkValidFormat: function($super) {2489 return true;2490},24912492_formattedValue: function(options) {2493 var value;24942495 if (!Object.isEmpty(options) && !Object.isEmpty(options.value)) {2496 if (!Object.isEmpty(options.type)) {2497 if (options.type == "DATS")2498 value = sapToDisplayFormat(options.value);2499 else {2500 if ((options.type == "DEC") || (options.type == "CURR")) {2501 if (options.value.split('.')[1]) {2502 var decimalLong = options.value.split('.')[1].length;2503 value = longToDisplay(parseFloat(options.value, 10), decimalLong);2504 }2505 else {2506 value = longToDisplay(parseFloat(options.value, 10));2507 }2508 }2509 else {2510 value = options.value;2511 }2512 }2513 } else {2514 value = options.value;2515 }2516 }2517 else2518 value = "";25192520 return value;2521}2522});25232524fdFactory = new FieldDisplayerFactory();25252526/**2527* Alias for FieldDisplayerFactory#getFieldDisplayer() method2528*2529* @param {JSON}2530* optionsJSON The options coming from the service in JSON format.2531* @param {String}2532* screen The screen reference.2533* @param {String}2534* record The record reference.2535* @param {String}2536* mode the mode for the field displayer.2537* @return FieldDisplayer a new FieldDisplayer object configured according to the options given.2538*/2539function $FD(optionsJSON, screen, record, key_str, appid, mode, labels, fieldDisplayerModified, cssClasses, xml_in, handler, name, getFieldValueAppend, ramdomId, rowSeqnr, variant, FPObject) {2540 return fdFactory.getFieldDisplayer(optionsJSON, screen, record, key_str, appid, mode, labels, fieldDisplayerModified, cssClasses, xml_in, handler, name, getFieldValueAppend, ramdomId, rowSeqnr, variant, FPObject); ...

Full Screen

Full Screen

app.component.ts

Source:app.component.ts Github

copy

Full Screen

1import { Component, DoCheck } from '@angular/core';2import { DesktopItemsService } from './services/desktop-items.service';3import { OverlayDesktopMenuService } from './services/overlay-desktop-menu.service';4import { BrowserStorageService } from './services/storage.service';5@Component({6 selector: 'app-root',7 templateUrl: './app.component.html',8 styleUrls: ['./app.component.scss'],9})10export class AppComponent implements DoCheck {11 iconRoute: string = '';12 expandedFlag: boolean = false;13 nightLightValue: string = '';14 colorAccent: string = '';15 isChanged: boolean = false;16 ngOnInit(): void {17 this.setNightLight();18 this.setSavedSettings();19 }20 ngDoCheck() {21 if (this.isChanged) {22 this.setNightLight();23 }24 }25 constructor(26 private overlayMenu: OverlayDesktopMenuService,27 private storage: BrowserStorageService,28 ) {29 this.storage30 .getStorageSubject()31 .subscribe((item) =>32 item ? (this.isChanged = true) : (this.isChanged = false)33 );34 }35 setNightLight() {36 const optionsJson = this.storage.get('options') || '{}';37 const value =38 optionsJson !== null ? JSON.parse(optionsJson)['nightDisplayValue'] : '0';39 const isActive =40 optionsJson !== null ? JSON.parse(optionsJson)['nightDisplay'] : false;41 this.nightLightValue = isActive ? value : '0';42 }43 setSavedSettings() {44 const optionsJson = this.storage.get('options') || '{}';45 const value =46 optionsJson !== null ? JSON.parse(optionsJson)['colorAccent'] : '';47 const transparency =48 optionsJson !== null ? JSON.parse(optionsJson)['isTransparent'] : '';49 const theme =50 optionsJson !== null ? JSON.parse(optionsJson)['theme'] : '';51 const background =52 optionsJson !== null ? JSON.parse(optionsJson)['background'] : '';53 const backgroundFit =54 optionsJson !== null ? JSON.parse(optionsJson)['backgroundFit'] : '';55 if (value) {56 document.body.classList.add(`${value}`);57 }58 if (typeof transparency !== 'undefined') {59 if (transparency) {60 document.body.classList.remove('isNotTransparent');61 } else {62 document.body.classList.add('isNotTransparent');63 }64 }65 if (theme === 'Light') {66 document.body.classList.add('light-theme');67 } else {68 document.body.classList.remove('light-theme');69 }70 if (background) {71 document.documentElement.style.setProperty(`--background`, background);72 }73 if (backgroundFit) {74 document.documentElement.style.setProperty(`--background-fit`, backgroundFit);75 }76 }77 hideMenu() {78 this.overlayMenu.hideMenu();79 }...

Full Screen

Full Screen

body-parser_v1.x.x.js

Source:body-parser_v1.x.x.js Github

copy

Full Screen

1// flow-typed signature: 18dadbe162b608c79b9b31c3d2f1c8222// flow-typed version: b43dff3e0e/body-parser_v1.x.x/flow_>=v0.17.x3import type { Middleware, $Request, $Response } from 'express';4declare type bodyParser$Options = {5 inflate?: boolean,6 limit?: number | string,7 type?: string | string[] | ((req: $Request) => any),8 verify?: (9 req: $Request,10 res: $Response,11 buf: Buffer,12 encoding: string13 ) => void,14};15declare type bodyParser$OptionsText = bodyParser$Options & {16 reviver?: (key: string, value: any) => any,17 strict?: boolean,18};19declare type bodyParser$OptionsJson = bodyParser$Options & {20 reviver?: (key: string, value: any) => any,21 strict?: boolean,22};23declare type bodyParser$OptionsUrlencoded = bodyParser$Options & {24 extended?: boolean,25 parameterLimit?: number,26};27declare module 'body-parser' {28 declare type Options = bodyParser$Options;29 declare type OptionsText = bodyParser$OptionsText;30 declare type OptionsJson = bodyParser$OptionsJson;31 declare type OptionsUrlencoded = bodyParser$OptionsUrlencoded;32 declare function json(options?: OptionsJson): Middleware;33 declare function raw(options?: Options): Middleware;34 declare function text(options?: OptionsText): Middleware;35 declare function urlencoded(options?: OptionsUrlencoded): Middleware;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { optionsJson } from '@storybook/addon-options';2optionsJson({3});4import { options } from '@storybook/addon-options';5options({6});7import { configure, setAddon } from '@storybook/react';8import { setOptions } from '@storybook/addon-options';9setOptions({10});11configure(loadStories, module);12import { configure, setAddon } from '@storybook/react';13import { setOptions } from '@storybook/addon-options';14setOptions({15});16configure(loadStories, module);17import { configure, setAddon } from '@storybook/react';18import { setOptions } from '@storybook/addon-options';19setOptions({20});21configure(loadStories, module);

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { optionsJson } from 'storybook-root';4storiesOf('Test', module)5 .add('Test', () => {6 return (7 );8 })9 .add('Test 2', () => {10 return (11 );12 })13 .add('Test 3', () => {14 return (15 );16 })17 .add('Test 4', () => {18 return (19 );20 })21 .add('Test 5', () => {22 return (23 );24 })25 .add('Test 6', () => {26 return (27 );28 })29 .add('Test 7', () => {30 return (31 );32 })33 .add('Test 8', () => {34 return (35 );36 })37 .add('Test 9', () => {38 return (39 );40 })41 .add('Test 10', () => {42 return (43 );44 })45 .add('Test 11', () => {46 return (47 );48 })49 .add('Test 12', () => {50 return (51 );52 })53 .add('Test 13', () => {54 return (55 );56 })57 .add('Test 14', () => {58 return (59 );60 })61 .add('Test 15', () => {62 return (63 );64 })65 .add('Test 16', () => {66 return (67 );68 })69 .add('Test 17', () => {70 return (

Full Screen

Using AI Code Generation

copy

Full Screen

1const { optionsJson } = require('storybook-root');2const options = optionsJson();3const { optionsJson } = require('storybook-root');4const options = optionsJson();5const { optionsJson } = require('storybook-root');6const options = optionsJson();7const { optionsJson } = require('storybook-root');8const options = optionsJson();9const { optionsJson } = require('storybook-root');10const options = optionsJson();11const { optionsJson } = require('storybook-root');12const options = optionsJson();13const { optionsJson } = require('storybook-root');14const options = optionsJson();15const { optionsJson } = require('storybook-root');16const options = optionsJson();17const { optionsJson } = require('storybook-root');18const options = optionsJson();19const { optionsJson } = require('storybook-root');20const options = optionsJson();21const { optionsJson } = require('storybook-root');22const options = optionsJson();23const { optionsJson } = require('storybook-root');24const options = optionsJson();25const { optionsJson } = require('storybook-root');26const options = optionsJson();27const { optionsJson } = require('storybook-root

Full Screen

Using AI Code Generation

copy

Full Screen

1import { optionsJson } from 'storybook-root';2const options = optionsJson();3console.log(options);4module.exports = {5 {6 options: {7 babelOptions: {},8 },9 },10};11import { addParameters } from '@storybook/react';12import { DocsContainer, DocsPage } from '@storybook/addon-docs/blocks';13import { optionsJson } from 'storybook-root';14addParameters({15 docs: {16 },17 options: optionsJson(),18});19import { addons } from '@storybook/addons';20import { optionsJson } from 'storybook-root';21addons.setConfig({22 options: optionsJson(),23});24 window.STORYBOOK_REACT_CLASSES = {};25 window.STORYBOOK_REACT_CLASSES = {};26 window.STORYBOOK_REACT_CLASSES = {};27 window.STORYBOOK_REACT_CLASSES = {};28module.exports = ({ config }) => {29 config.module.rules.push({30 test: /\.(ts|tsx)$/,31 {32 loader: require.resolve('babel-loader'),33 options: {34 require.resolve('babel-preset-react-app'),35 {36 },37 },38 },39 {40 loader: require.resolve('react-docgen-typescript-loader'),41 },42 });43 config.resolve.extensions.push('.ts', '.tsx');44 return config;45};46import React from 'react';47import { addParameters, addDecorator } from '@storybook/react';48import { DocsContainer, DocsPage } from '@storybook/addon-docs/blocks';49import { ThemeProvider } from 'styled-components';50import

Full Screen

Using AI Code Generation

copy

Full Screen

1const { optionsJson } = require('storybook-root');2const options = optionsJson('./test/storybook-options.json');3module.exports = options;4{5 "../src/**/*.stories.@(js|jsx|ts|tsx)"6}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful