Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.Framework / JSResources / ZebdaValidation.resx
blob955ea7ab4c4234aba4674b7d9310a2a30d7276b5
1 <?xml version="1.0" encoding="utf-8"?>
2 <root>
3 <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
4 <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
5 <xsd:element name="root" msdata:IsDataSet="true">
6 <xsd:complexType>
7 <xsd:choice maxOccurs="unbounded">
8 <xsd:element name="metadata">
9 <xsd:complexType>
10 <xsd:sequence>
11 <xsd:element name="value" type="xsd:string" minOccurs="0" />
12 </xsd:sequence>
13 <xsd:attribute name="name" use="required" type="xsd:string" />
14 <xsd:attribute name="type" type="xsd:string" />
15 <xsd:attribute name="mimetype" type="xsd:string" />
16 <xsd:attribute ref="xml:space" />
17 </xsd:complexType>
18 </xsd:element>
19 <xsd:element name="assembly">
20 <xsd:complexType>
21 <xsd:attribute name="alias" type="xsd:string" />
22 <xsd:attribute name="name" type="xsd:string" />
23 </xsd:complexType>
24 </xsd:element>
25 <xsd:element name="data">
26 <xsd:complexType>
27 <xsd:sequence>
28 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
29 <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
30 </xsd:sequence>
31 <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
32 <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
33 <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
34 <xsd:attribute ref="xml:space" />
35 </xsd:complexType>
36 </xsd:element>
37 <xsd:element name="resheader">
38 <xsd:complexType>
39 <xsd:sequence>
40 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
41 </xsd:sequence>
42 <xsd:attribute name="name" type="xsd:string" use="required" />
43 </xsd:complexType>
44 </xsd:element>
45 </xsd:choice>
46 </xsd:complexType>
47 </xsd:element>
48 </xsd:schema>
49 <resheader name="resmimetype">
50 <value>text/microsoft-resx</value>
51 </resheader>
52 <resheader name="version">
53 <value>2.0</value>
54 </resheader>
55 <resheader name="reader">
56 <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
57 </resheader>
58 <resheader name="writer">
59 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
60 </resheader>
61 <data name="jsfunctions" xml:space="preserve">
62 <value><![CDATA[
66 Zebda javascript library, version 0.3.1
67 http://labs.cavorite.com/zebda
68 Copyright (C) 2006 Juan Manuel Caicedo
70 Contributors:
71 - Chris Wilson http://www.christopherwilson.net
73 This library is free software; you can redistribute it and/or
74 modify it under the terms of the GNU Lesser General Public
75 License as published by the Free Software Foundation; either
76 version 2.1 of the License, or (at your option) any later version.
78 This library is distributed in the hope that it will be useful,
79 but WITHOUT ANY WARRANTY; without even the implied warranty of
80 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
81 Lesser General Public License for more details.
83 You should have received a copy of the GNU Lesser General Public
84 License along with this library; if not, write to the Free Software
85 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
88 See http://www.gnu.org/copyleft/lesser.html for more information
92 var Zebda = {
93 Version: '0.3.1'
98 /*--------------------------------------------------------------------------*/
100 Zebda javascript library
101 http://labs.cavorite.com/zebda
102 Copyright (C) 2006 Juan Manuel Caicedo
104 See zebda.js for full licence
108 // Common functions
111 * Simple JSON parser
113 if (!window.JSON){
114 JSON = {
115 parse: function(str){
116 return eval('(' + str + ')');
122 * Removes trailing withspace
124 String.prototype.trim = function(){
125 return this.replace(/ /g, '');
130 * Javascript sets
132 * Example:
133 * var typeInSet = nodeType in set(2, 3, 4, 7, 8);
135 * http://laurens.vd.oever.nl/weblog/items2005/setsinjavascript/
137 function set (){
138 var result = {};
139 for (var i = 0; i < arguments.length; i++){
140 result[arguments[i]] = true;
142 return result;
146 /**
147 * Finds the position of a node
150 Element.getSiblingPosition = function(element){
151 var pos = 0;
152 while (element.previousSibling) {
153 if (element.previousSibling.nodeType != 3){
154 pos++;
156 element = element.previousSibling;
158 return pos;
166 Element.getParentNodeByName = function(element, tagName){
167 var par = element;
168 while(par.tagName.toLowerCase() != tagName && par.parentNode) {
169 par = par.parentNode;
171 return par;
176 * @see http://www.litotes.demon.co.uk/example_scripts/fastTableSort_src.html
178 Element.getInnerText = function(element){
179 if (!element || (typeof element).search(/string|undefined/) > -1)
180 return element;
182 if (element.innerText)
183 return element.innerText;
185 var rtn = '';
186 var nodes = element.childNodes;
187 var len = nodes.length;
188 for (var i = 0; i < len; i++) {
189 switch (nodes[i].nodeType) {
190 case 1: //ELEMENT_NODE
191 rtn += Element.getInnerText(nodes[i]);
192 break;
193 case 3: //TEXT_NODE
194 rtn += nodes[i].nodeValue;
195 break;
198 return rtn;
203 * Sets the value of a form field
206 Form.Element.setValue = function(element, value){
207 element = $(element);
208 els = ((element.tagName)) && [element] || element;
210 $A(els).each(function(element){
211 var elmType = element.tagName.toLowerCase();
212 switch(elmType){
213 case 'select':
214 if (typeof(value) != 'object')
215 value = [value];
217 $A(element.options).each(function(opt){
218 opt.selected = value.include(opt.value);
220 break;
221 case 'input':
222 if (element.type in set('radio', 'checkbox')){
223 element.checked = (element.value == value);
224 }else{
225 element.value = value;
232 /*--------------------------------------------------------------------------*/
234 Zebda javascript library
235 http://labs.cavorite.com/zebda
236 Copyright (C) 2006 Juan Manuel Caicedo
238 See zebda.js for full licence
242 var FormValidator = {
245 Namespace prefix
247 NSprefix: 'z',
249 defaultOptions : {
250 inline: false,
251 inlineFilters: false,
252 dateFormat:'m-d-yyyy',
253 thousandSeparator: ',',
254 decimalSeparator: '.'
258 * Load the defined condition and filters
259 * Find all the forms with a validation rule and modify theirs onsubmit function
261 init: function(){
262 this._definedConditions = [];
263 for (name in FormValidator.Conditions){
264 this._definedConditions.push(name);
267 this._definedFilters = [];
268 for (name in FormValidator.Filters){
269 this._definedFilters.push(name);
272 var forms = $A(document.forms);
274 //Modify onsubmit function for forms with defined rules
275 forms.each(function(f){
277 // attach the validators to the elements on the form
278 FormValidator.initForm(f);
280 f.onsubmit = function(){
281 try {
282 f.beforeValidate();
283 if (FormValidator.validate(f)){
284 return f.afterValidate();
285 }else{
286 return false;
288 } catch (e){
289 return false;
293 f.originalsubmit = f.submit;
295 f.submit = function(){
296 try {
297 if(f.onsubmit())
299 f.originalsubmit();
301 } catch (e){
302 return false;
306 var disp = f.getAttribute('z:display');
307 f._displayFunction = (FormValidator.Display[disp] || FormValidator.Display.alert);
310 FormValidator.initializeDateCollection();
315 * create a datematch object (js doesn't support named captures...)
318 createDateInfo :function(regex, year, month, day){
319 var dateInfo = new Object;
321 dateInfo.regex = new RegExp(regex);
322 dateInfo.year = year;
323 dateInfo.month = month;
324 dateInfo.day = day;
326 return dateInfo;
331 * create the date match objects
334 initializeDateCollection: function(){
335 this._datePatterns = [];
337 this._datePatterns["dd.mm.yyyy"] = FormValidator.createDateInfo("^\([0-3][0-9]\)\\.\([0-1][0-9]\)\\.\([0-9]{4}\)$", 3, 2, 1);
338 this._datePatterns["d.m.yyyy"] = FormValidator.createDateInfo("^\([0-3]?[0-9]\)\\.\([0-1]?[0-9]\)\\.\([0-9]{4}\)$", 3, 2, 1);
339 this._datePatterns["dd/mm/yyyy"] = FormValidator.createDateInfo("^\([0-3][0-9]\)\/\([0-1][0-9]\)\/\([0-9]{4}\)$", 3, 2, 1);
340 this._datePatterns["d/m/yyyy"] = FormValidator.createDateInfo("^\([0-3]?[0-9]\)\/\([0-1]?[0-9]\)\/\([0-9]{4}\)$", 3, 2, 1);
341 this._datePatterns["dd-mm-yyyy"] = FormValidator.createDateInfo("^\([0-3][0-9]\)\\-\([0-1][0-9]\)\\-\([0-9]{4}\)$", 3, 2, 1);
342 this._datePatterns["d-m-yyyy"] = FormValidator.createDateInfo("^\([0-3]?[0-9]\)\\-\([0-1]?[0-9]\)\\-\([0-9]{4}\)$", 3, 2, 1);
344 this._datePatterns["mm.dd.yyyy"] = FormValidator.createDateInfo("^\([0-1][0-9]\)\\.\([0-3][0-9]\)\\.\([0-9]{4}\)$", 3, 1, 2);
345 this._datePatterns["m.d.yyyy"] = FormValidator.createDateInfo("^\([0-1]?[0-9]\)\\.\([0-3]?[0-9]\)\\.\([0-9]{4}\)$", 3, 1, 2);
346 this._datePatterns["mm/dd/yyyy"] = FormValidator.createDateInfo("^\([0-1][0-9]\)\/\([0-3][0-9]\)\/\([0-9]{4}\)$", 3, 1, 2);
347 this._datePatterns["m/d/yyyy"] = FormValidator.createDateInfo("^\([0-1]?[0-9]\)\/\([0-3]?[0-9]\)\/\([0-9]{4}\)$", 3, 1, 2);
348 this._datePatterns["mm-dd-yyyy"] = FormValidator.createDateInfo("^\([0-21][0-9]\)\\-\([0-3][0-9]\)\\-\([0-9]{4}\)$", 3, 1, 2);
349 this._datePatterns["m-d-yyyy"] = FormValidator.createDateInfo("^\([0-1]?[0-9]\)\\-\([0-3]?[0-9]\)\\-\([0-9]{4}\)$", 3, 1, 2);
351 this._datePatterns["yyyy-mm-dd"] = FormValidator.createDateInfo("^\([0-9]{4}\)\\-\([0-1][0-9]\)\\-\([0-3][0-9]\)$", 1, 2, 3);
352 this._datePatterns["yyyy/mm/dd"] = FormValidator.createDateInfo("^\([0-9]{4}\)\\/\([0-1][0-9]\)\\/\([0-3][0-9]\)$", 1, 2, 3);
353 this._datePatterns["yyyy-m-d"] = FormValidator.createDateInfo("^\([0-9]{4}\)\\-\([0-1]?[0-9]\)\\-\([0-3]?[0-9]\)$", 1, 2, 3);
354 this._datePatterns["yyyy/m/d"] = FormValidator.createDateInfo("^\([0-9]{4}\)\\/\([0-1]?[0-9]\)\\/\([0-3]?[0-9]\)$", 1, 2, 3);
360 * Configures a form
363 initForm: function(frm){
365 //Validation options
366 frm._options = {};
367 for (opc in FormValidator.defaultOptions){
368 frm._options[opc] = FormValidator.defaultOptions[opc];
370 opts = eval('(' + frm.getAttribute('z:options') + ')') || {};
371 for (opc in opts){
372 frm._options[opc] = opts[opc];
375 //Before and after validate functions
376 if (!frm.beforeValidate){
377 func = frm.getAttribute('z:beforeValidate') || 'return true';
378 frm.beforeValidate = new Function(func);
381 if (!frm.afterValidate){
382 func = frm.getAttribute('z:afterValidate') || 'return true';
383 frm.afterValidate = new Function(func);
386 rtn = false;
387 //Configure elements
388 Form.getElements(frm).each(function(elm){
389 FormValidator.Element.init(elm);
390 if (!rtn && FormValidator.Element.hasRules(elm)){
391 rtn = true;
394 return rtn;
398 * Validates a form
401 validate: function(form){
402 var errs = Form.getElements(form).map(FormValidator.Element.validate).flatten();
403 if (errs.length > 0){
404 form._displayFunction(errs);
405 return false;
407 return true;
411 * Functions for display errors
414 Display: {
417 * Show inline errors.
418 * Based on examples by Cameron Adams:
419 * http://www.themaninblue.com/writing/perspective/2005/10/05/
421 inline: function(errs){
422 $A(document.getElementsByClassName('_zebda_message')).each(function (elm){
423 elm.parentNode.removeChild(elm);
425 errs.map(function(e){
426 var t = document.createElement('span');
427 t.className = '_zebda_message correctionText warning';
428 t.appendChild(document.createTextNode(e.message));
429 e.element.parentNode.insertBefore(t, e.element.nextSibling);
434 * Show an alert with all errors
436 alert: function(errs){
437 alert(errs.pluck('message').join('\n'));
442 * Conditions for the rules
444 Conditions: {
446 required: function(value){
447 return String(value).length > 0;
450 length: function(value){
451 var rtn = true;
452 value = (value || '');
453 if (this.options.max)
454 rtn = (value.length <= this.options.max);
456 if (this.options.min)
457 rtn = rtn && (value.length >= this.options.min);
459 return rtn;
462 numeric: function(value){
463 var rtn, val,numberTest;
464 rtn = true;
466 var ts = this.element.form._options.thousandSeparator;
467 var ds = this.element.form._options.decimalSeparator;
469 if(this.options.isFloat)
471 numberTest = new RegExp("^-?(\\d*(" + ts + "?\\d{3})*\\" + ds + "?\\d+|\\d+(" + ts + "?\\d{3})*\\" + ds + "?\\d*)$");
472 if(numberTest.test(value) == false)
473 return false;
475 // remove the thousand separator and replace the decimal separator with an .
476 value = value.replace(new RegExp( ts + "/g"), String.Empty);
477 value = value.replace(ds, ".");
479 // parse the value
480 val = parseFloat(value)
482 else
484 numberTest = new RegExp("^-?\\d*$");
485 if(numberTest.test(value) == false)
486 return false;
487 val = parseInt(value);
490 if (isNaN(val))
491 return false;
493 if (!(this.options.maxValue === undefined))
494 rtn = rtn && (this.options.maxValue >= val);
496 if (!(this.options.minValue === undefined))
497 rtn = rtn && (val >= this.options.minValue);
499 return rtn;
505 regexp: function(value){
506 var reg = (this.options.constructor == RegExp) ? this.options : this.options.exp;
507 return reg.test(value);
511 * Email regular expression
512 * bilou mcgyver
513 * http://www.regexlib.com/REDetails.aspx?regexp_id=333
515 email: function(value){
516 var expMail = /^[\w](([_\.\-\+]?[\w]+)*)@([\w]+)(([\.-]?[\w]+)*)\.([A-Za-z]{2,})$/;
517 return expMail.test(value);
521 * Compare current value with other element
524 compare: function(value){
525 return value == $F(this.options.field);
529 * Apply the rule only when a condition is satisfied
530 * TODO
532 conditional: function(value){
533 return false;
537 * test if the value matches the default date pattern
540 date: function(value){
542 var dateInfo = this.element.form._options.dateFormat;
544 var matches = dateInfo.regex.exec(value);
545 if (!matches) return false;
547 var composedDate = new Date(matches[dateInfo.year], (matches[dateInfo.month] - 1), matches[dateInfo.day]);
549 return ((composedDate.getMonth() == (matches[dateInfo.month] - 1)) &&
550 (composedDate.getDate() == matches[dateInfo.day]) &&
551 (composedDate.getFullYear() == matches[dateInfo.year]));
556 * Filter for text inputs
559 Filters: {
560 trim: function(value){
561 return FormValidator.Filters.trimleft(FormValidator.Filters.trimright(value));
564 trimleft: function(value){
565 return new String(value).replace(/^\s+/, '');
568 trimright: function(value){
569 return new String(value).replace(/\s+$/, '');
573 * Replaces the double spaces for single space
576 singlespace: function(value){
577 return new String(value).replace(/(\s{2,})/g,' ');
580 lowercase: function(value){
581 return new String(value).toLowerCase();
584 uppercase: function(value){
585 return new String(value).toUpperCase();
588 numbers: function(value){
589 return new String(value).replace(/([^0-9])/g, '');
594 var Rule = Class.create();
595 Rule.prototype = {
596 initialize: function(element, ruleName, options, message){
597 this.condition = Prototype.K;
598 this.message = (message || '');
599 this.enabled = true;
601 options = options || {};
602 this.options = (typeof(options) == 'string') && eval('(' + options + ')') || options;
603 this.element = element;
605 if (typeof(ruleName) == 'string'){
606 this.condition = FormValidator.Conditions[ruleName]; //no bind needed
607 } else {
608 this.condition = ruleName;
612 evaluate: function(){
613 if(this.enabled == false)
614 return true;
616 return this['condition'].call(this, Form.Element.getValue(this.element));
619 disable: function(){
620 this.enabled = false;
622 enable: function(){
623 this.enabled = true;
627 Rule.Conditions = {
630 * The value is required
632 required: function(value){
633 return value;
635 length: function(value){
636 var rtn = true;
637 value = (value || '');
638 if (this.options.max)
639 rtn = (value.length <= this.options.max);
641 if (this.options.min)
642 rtn = rtn && (value.length >= this.options.min);
644 return rtn;
648 var Filter = Class.create()
649 Filter.prototype = {
650 initialize: function(element, filter, options){
651 this.element = element;
652 this.options = eval('(' + options + ')');
653 this.evaluate = FormValidator.Filters[filter];
657 FormValidator.Error = Class.create();
658 FormValidator.Error.prototype = {
659 initialize: function(element, message){
660 this.element = element;
661 this.message = message;
664 inspect: function() {
665 return '#<FormValidator.Error:element=' + this.element + ',message=' + this.message + '>';
669 Object.extend(FormValidator,{Element: {
673 init: function(element){
674 element._rules = _definedConditions.map(function(cond){
675 if (condOptions = element.getAttribute(FormValidator.NSprefix + ':' + cond)){
676 var msg = (element.getAttribute(FormValidator.NSprefix + ':' + cond + '_message')
677 || element.getAttribute(FormValidator.NSprefix + ':' + 'message'));
678 return new Rule(element, cond, condOptions, msg);
680 }).compact()
682 element._filters = _definedFilters.map(function(filter){
683 if (filterValue = element.getAttribute(FormValidator.NSprefix + ':filter_' + filter)){
684 return new Filter(element, filter, filterValue);
686 }).compact()
688 //Inline validation
689 if (element.form._options.inline){
690 Event.observe(element, 'change', function(){
691 element.form['_displayFunction'](FormValidator.Element.validate(this));
692 element.focus();
696 //Inline filters
697 if (element.form._options.inlineFilters){
698 Event.observe(element, 'change', function(){
699 FormValidator.Element.applyFilters(element);
704 addRule: function(element, rule, inline){
705 element._rules.push(rule);
708 addFilter: function(element, filter, inline){
709 element._filters.push(filter);
713 * Returns true if the element has any attribute with the namespace
714 * prefix
716 hasRules: function(element){
717 return (element._rules || false);
724 getRules: function(element){
725 return (element._rules || []);
728 getFilters: function(element){
729 return (element._filters || []);
732 isText: function(element){
733 if(element.tagName == null)
734 return false;
736 return ((element.tagName.toLowerCase() == 'input' &&
737 (element.type.toLowerCase() in set('text','hidden','password'))) ||
738 (element.tagName.toLowerCase() == 'textarea'));
742 * Filter can only be applied on textboxes, passwords and textarea
744 applyFilters: function(element){
745 if (FormValidator.Element.isText(element)){
746 FormValidator.Element.getFilters(element).each(function(filter){
747 element.value = filter.evaluate(element.value)
753 * Returns the error objects produced during the validation
756 validate: function(element){
757 FormValidator.Element.applyFilters(element);
758 return FormValidator.Element.getRules(element).map(function(rule){
759 if (!rule.evaluate())
760 return new FormValidator.Error(element, rule.message);
761 }).compact()
766 Initialize FormValidator after the page has loaded
768 Event.observe(window,'load',FormValidator.init);
769 /*--------------------------------------------------------------------------*/
771 </value>
772 </data>
773 </root>