PageSourceSearch

http://bringahirado.hu/file/global/common/1495437416/javascripts/formvalidator.js

js bringahirado.hu collected 2026-10-02 20:49:50 UTC 5,708 bytes, 164 lines download raw bytes

1var formValidator={
2    form:null,
3    options:null,
4    displayedFields: {},
5    saving: false,
6    data: {},
7
8    STATUS_ERROR: 0,
9    STATUS_SUCCESS: 1,
10    GLOBALFIELD: '_global',
11
12    initialize: function(form,options) {
13        this.form=jQuery(form);
14        var o={
15            messageHTML: {},
16            messageErrorClass: 'error',
17            messageSuccessClass: 'success',
18            defaultErrorMessage: 'Rendszerhiba! Kérjük próbálkozzon kés\u0151bb.',
19
20            url: (this.form ? this.form.attr('action'): ''),
21            method: (this.form ? this.form.attr('method') : 'post'),   //'get','post'
22            extraParams: {},
23
24            onBeforeSave: null,
25            onPrepareData: null,
26
27            //Ajax state
28            onSuccess: null,
29            onFailed: null,
30            onComplete: null,
31
32            onDisplayMessage: null, //(field,message,status)
33            onClearMessage : null
34        };
35        this.options=jQuery.extend(o,options);
36        if (this.form) this.form.bind('submit', function(e) {Event.stop(e);this.save();return false;}.bind(this));
37    },
38
39    getForm: function() {return this.form;},
40    getOption: function(name) {return this.options[name];},
41    trigger: function(functionname,param1,param2,param3) {
42        if (this.getOption(functionname) && this.getOption(functionname)(param1,param2,param3)==false) return true;
43        return false;
44    },
45
46    save:function(){
47        if(this.trigger('onBeforeSave', this)) return false;
48        this.clearMessages();
49
50        jQuery.ajax({
51            type:this.options.method,
52            url:this.options.url,
53            data:this.form.serialize(),
54            dataType:'json',
55            async:false,
56            success:jQuery.proxy(function(ret) {
57                this.data = (ret) ? ret : this.getDefaultErrorResult();
58                if (this.trigger('onSuccess', this)) return false;
59                this.evaluateResult();
60            },this),
61            complete:jQuery.proxy(function() {
62                this.saving=false;
63                this.trigger('onComplete', this);
64            },this)
65        });
66        return false;
67    },
68
69    evaluateResult: function() {
70        var messages=this.data['error_messages'];
71        if (messages) {
72            jQuery.each(messages,(function(key, val) {
73               this.displayMessage(key, val, this.STATUS_ERROR);
74            }).bind(this));
75        }
76
77        messages=this.data['success_messages'];
78        if (messages) {
79            jQuery.each(messages,(function(key, val) {
80               this.displayMessage(key, val, this.STATUS_SUCCESS);
81            }).bind(this));
82        }
83
84        //commands
85        var commands = this.data['commands'];
86        if (commands) {
87            jQuery.each(commands, function(key,pair) {
88                switch (key) {
89                    case 'redirect': {
90                      jQuery.each(pair, function(_key, _val) {
91                          if(_val) {
92                              window.location.href = _val;
93                          }
94                      });
95                    }break;
96                    case 'reload': {
97                      jQuery.each(pair, function(_key, _val) {
98                          window.location.reload();
99                      });
100                    }break;
101                    case 'alert': {
102                      jQuery.each(pair, function(_key, _val) {
103                          if(_val) {
104                              window.alert(_val);
105                          }
106                      });
107                    }break;
108                    case 'set': {
109                        jQuery.each(pair, function(_key, _val) {
110                            jQuery(_key).val(_val);
111                        })
112                    }break;
113                    case 'setdata': {
114                        jQuery.each(pair, function(_key, _val) {
115                            jQuery(_key).data(_val);
116                        })
117                    }break;
118                    case 'update': {
119                        $H(pair.value).each(function(data) {
120                            $(data.key).html(data.value);
121                        })
122                    }break;
123                }
124            })
125        }
126    },
127
128     clearMessages: function() {
129        jQuery.each(this.displayedFields,(function(key,pair) {
130            this.clearMessage(key);
131        }).bind(this));
132    },
133
134    clearMessage: function(field) {
135        if (this.getOption('onClearMessage') && this.getOption('onClearMessage')(field)==false) return;
136        jQuery('#' + field).html('');
137//        jQuery.each(this.getOption('messageHTML'),function(pair) {
138//            var element=jQuery('#'+pair.replace("{field}",field));
139//            if (element) element.html('');
140//        });
141        delete this.displayedFields[field];
142    },
143/*
144    clearMessages:function(){
145        jQuery.each(this.getOption('messageHTML'),function(key) {
146            jQuery('#'+key).html('');
147        });
148    },*/
149
150    displayMessage:function(field, message, status) {
151        var classname = this.getOption(status == this.STATUS_ERROR ? 'messageErrorClass' : 'messageSuccessClass');
152        jQuery.each(this.getOption('messageHTML'),jQuery.proxy(function(key,pair) {
153            var _field = 'error' + key.replace('{field}', field);
154            this.displayedFields[_field] = 1;
155            jQuery('#' + _field).append(pair.replace('{message}',message).replace('{class}',classname));
156        },this));
157    },
158
159    getDefaultErrorResult: function() {
160        return {status: this.STATUS_ERROR,
161                 errorMessages: {'_global' : [this.getOption('defaultErrorMessage')]}
162                };
163    }
164}

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.