PageSourceSearch

https://www.vafb.com/resources/vfb/Scripts/baseModule.js?cdv=15

js vafb.com collected 2026-09-25 14:44:55 UTC 12,851 bytes, 323 lines download raw bytes

1(function ($, undefined) {
2    "use strict";
3    var vfb = window.vfb = window.vfb || {};
4    if (vfb.baseModule) {
5        return; //already defined - file included twice?
6    }
7    var defaultOptions = {
8        baseModel: {
9            formElementId: "Form",
10            displayForm: true,
11            displaySuccessMessage: false,
12            successMessage: '', //green
13            infoMessage: '', //blue
14            warningMessage: '', //orange
15            errorMessage: '', //red
16
17            setProperty: function (prop, val) {
18                this[prop](val);
19            },
20            getProperty: function (prop) {
21                return this[prop]();
22            },
23            resetMessages: function () {
24                this.setProperty("successMessage", "");
25                this.setProperty("errorMessage", "");
26                this.setProperty("infoMessage", "");
27                this.setProperty("warningMessage", "");
28
29            },
30            showSuccessMessage: function (message, delayedClear) {
31                var that = this;
32                if (delayedClear === "undefined") {
33                    delayedClear = false;
34                }
35                that.setProperty("successMessage", message);
36                if (delayedClear) {
37                    setTimeout(that.hideSuccessMessage.bind(that), 5000);
38                }
39            },
40            hideSuccessMessage: function () {
41                this.setProperty("successMessage", "");
42            },
43            showErrorMessage: function (message) {
44                if (message != null) {
45                    this.setProperty("errorMessage", message);
46                }
47            },
48            hideErrorMessage: function () {
49                this.setProperty("errorMessage", "");
50            },
51            showInfoMessage: function (message, delayedClear) {
52                if (message != null) {
53                    this.setProperty("infoMessage", message);
54                }
55            },
56            hideInfoMessage: function () {
57                this.setProperty("infoMessage", "");
58            },
59            showWarningMessage: function (message, delayedClear) {
60
61                if (message != null) {
62                    this.setProperty("warningMessage", message);
63                }
64            },
65            hideWarningMessage: function () {
66                this.setProperty("warningMessage", "");
67            },
68            createDTO: function (modelFields) {
69                var that = this;
70                var dto = {}
71                $.each(modelFields, function (idx, itm) {
72                    var name = itm;
73                    var val = that.getProperty(itm);
74                    dto[name] = val;
75                })
76                return dto;
77            },
78            /************************ SERVICE CALL *************************/
79            /// Does all the common tasks when calling the vfb service layer
80            ///  - manages the spinner
81            ///  - shows error and success messages
82            ///  - retrns the promise from the ajax call so the caller can 
83            ///    do custom additional logic based on success or fail.
84            serviceCall: function (dto, url, successMsg, errorMessage) {
85                var that = this;
86                vfb.utility.addSpinner();
87                var ajaxRtn = $.ajax({
88                    dataType: 'json',
89                    contentType: "application/json",
90                    type: "POST",
91                    url: url,
92                    beforeSend: $.ServicesFramework().setModuleHeaders,
93                    data: (JSON.stringify(dto))
94                })
95                    .done(function (data) {
96                        vfb.utility.removeSpinner();
97                        if (vfb.utility.isDefined(data.BoolIsSuccessful)) {
98                            if (data.BoolIsSuccessful) {
99                                if (successMsg != null && successMsg != "") {
100                                    that.showSuccessMessage(successMsg, true);
101                                }
102                            }
103                            else {
104                                if (data.ErrorMessage != null && data.ErrorMessage != "") {
105                                    that.showErrorMessage(data.ErrorMessage);
106                                }
107                            }
108                        }
109                    })
110                    .fail(function (xhr, status) {
111                        vfb.utility.removeSpinner();
112                        if (xhr.status == 401) {
113                            that.showErrorMessage("You must be logged in to access this function.");
114                        } else {
115                            errorMessage = errorMessage || "System unavailable currently, request was not successful. Please let us know by the C
115ontact Us link and try back later.";
116                            that.showErrorMessage(errorMessage);
117                        }
118                    });
119                return ajaxRtn;
120            },
121            removeUnwantedText: function(newVal){
122                newVal = newVal.replace(":", "")
123                .replace("--", "")
124                .replace("XOR", "").replace("xor", "")
125                .replace("' OR '", "").replace("' or '", "")
126                .replace("))", "")
127                .replace("..", "")
128                .replace("@@", "")
129                .replace('""', "")
130                .replace("**", "")
131                .replace(";", "")
132                .replace("/*", "")
133                .replace("*/", "")
134                .replace("()", "")
135                .replace("=", "")
136                .replace("^", "")
137                .replace("{", "")
138                .replace("}", "")
139                .replace("<", "")
140                .replace(">", "")
141                .replace("</", "")
142                .replace("waitfor delay", "")
143                .replace("sysdate(", "")
144                .replace("sleep(", "")
145                .replace("if(", "")
146                .replace("now(", "")
147                .replace("from(", "")
148                .replace("(SELECT", "")
149                .replace("PG_SLEEP(", "")
150                .replace("DBMS_PIPE", "")
151                .replace("MESSAGE(", "")
152                .replace("CHR(", "")
153                .replace("JOIN(", "")
154                .replace("COALESCE(", "");
155                return newVal;
156            },
157            removeUnwantedTextFromUserId: function(newVal){
158                newVal = newVal
159                .replace("))", "")
160                .replace("--", "")
161                .replace("..", "")
162                .replace("@@", "")
163                .replace('""', "")
164                .replace("**", "")
165                .replace(";", "")
166                .replace("/*", "")
167                .replace("*/", "")
168                .replace("()", "")
169                .replace(":0:", "")
170                .replace("waitfor delay", "")
171                .replace("sysdate(", "")
172                .replace("sleep(", "")
173                .replace("if(", "")
174                .replace("now(", "")
175                .replace("from(", "")
176                .replace("(SELECT", "")
177                .replace("PG_SLEEP(", "")
178                .replace("DBMS_PIPE", "")
179                .replace("MESSAGE(", "")
180                .replace("CHR(", "")
181                .replace("JOIN(", "")
182                .replace("COALESCE(", "");
183                return newVal;
184            }
185        },
186        validationRules: {},
187        validationMessages: {},
188        tooltipOptions: {},
189    }
190
191    //constructor
192    vfb.baseModule = function (elementSelector, baseModuleOptions, moduleParameters) {
193        var moduleParams = {};
194        if (moduleParameters != undefined) { }
195        {
196            moduleParams = {
197                baseModel: moduleParameters
198            }
199        }
200        $.extend(true, this, defaultOptions, baseModuleOptions, moduleParams);
201        this.elementSelector = elementSelector;
202        this.preInitDeferred = $.Deferred();
203        this.preBindDeferred = $.Deferred();
204        this.moduleReady = $.Deferred();
205    }
206    //override - 
207    // used to modify the module dom before the rest of the processing, etc.
208    // the override needs to resolve the deferred when it is done
209    vfb.baseModule.prototype.preinit = function () {
210        this.preInitDeferred.resolve();
211    }
212    //used to add items to the model (computed observables in particular) that rely
213    //on the model, but do it before binding
214    vfb.baseModule.prototype.prebind = function () {
215        this.preBindDeferred.resolve();
216    }
217    //override
218    // used to initialize the state of the form - what is visible, setting some observables, etc.
219    vfb.baseModule.prototype.postinit = function () {
220        this.moduleReady.resolve();
221    }
222    vfb.baseModule.prototype.init = function () {
223        var that = this;
224
225        var domReady = $.Deferred();
226        //if the module does not have an htmlUrl defined, we assume the html is already in the dom
227        if (!that.htmlUrl) {
228            domReady.resolve(); //dom is already setup
229        } else {
230            //if the module has an htmlUrl defined, load it into the dom where the caller told us to
231            //load the html
232            $(that.elementSelector).load(
233                that.htmlUrl,
234                function () {
235                    domReady.resolve();
236                });
237        };
238
239        domReady.then(function () {
240            that.preinit();
241        });
242        that.preInitDeferred.then(function () {
243            that.globals = vfb.globals;
244            that.form = $("#" + that.formElementId);
245            if (that.form.length != 1) {
246                //User should never see this.  It is only for development
247                //alert("Could not find form id " + "#" + that.formElementId);
248            }
249
250            vfb.tooltips.init("#" + that.formElementId);
251            that.setupModel();
252            that.setupFormValidation();
253            that.prebind();
254        });
255        that.preBindDeferred.then(function () {
256            that.bind();
257            that.postinit();
258        });
259        //return the module instance for chaining.
260        //If a parent module needs to wait for any initialization to finish, they can
261        //use the module.moduleReady promise.
262        return that;
263    }
264    vfb.baseModule.prototype.setProperty = function (prop, val) {
265        this.model[prop](val);
266    }
267    vfb.baseModule.prototype.getProperty = function (prop) {
268        return this.model[prop]();
269    }
270    vfb.baseModule.prototype.setupModel = function () {
271        this.model = ko.mapping.fromJS(this.baseModel);
272    }
273    vfb.baseModule.prototype.bind = function () {
274        ko.applyBindings(this.model, document.getElementById(this.formElementId));
275
276        //Need to remove some options from drop downs and possibly other things.  Easiest to just brand 'em and round 'em up
277        //need to wait until the current thread is done before trying to delete the select options...
278        setTimeout(function () {
279            $(".deleteMeAfterBind").remove();
280        }, 500);
281    }
282    vfb.baseModule.prototype.setupFormValidation = function () {
283        var that = this;
284        var $form = $("#Form");
285        var options = new vfb.validation.baseOptions();
286
287        vfb.validation.setupFormValidation(
288            that.validationRules,
289            that.validationMessages,
290            that.tooltipOptions
291            );
292        //options.rules = that.validationRules;
293        //options.messages = that.validationMessages;
294        //options.tooltip_options = that.tooltipOptions;
295        //$form.validate(options);
296
297        //Some UI elements do not validate on change automatically.  
298        // - BootstrapSwitch , bootstrap Radio
299        $("#" + that.formElementId + " .validateOnChange").each(function (index, element) {
300            var id = element.id;
301            that.model[id].subscribe(function (newVal) {
302                $("#" + id).valid();
303            }.bind(that));
304        });
305    }
306    vfb.baseModule.prototype.showErrorMessage = function (message) {
307        if (message == null) {
308            message = ""; //we test for length == 0 - can't do on null
309        }
310        this.setProperty("errorMessage", message);
311    },
312    vfb.baseModule.prototype.hideErrorMessage = function () {
313        this.setProperty("errorMessage", "");
314    }
315    vfb.baseModule.prototype.initializeView = function () {
316        this.hideErrorMessage();
317    }
318
319})(jQuery);
320
321
322
323

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.