Models.Date = Models.Base.extend({ classType: "MODELS.DATE", defaults: { value: "", //String initialValue: "" //String }, postInitialize: function() { if (!this.get("locale")) { if (edContext().locale) { this.set("locale", edContext().locale); } else { this.set("locale", "fr"); } } if (!this.get("displayFormat")) { this.set("displayFormat", "dd/MM/yyyy HH:mm:ss"); } if (!this.get("smartFormat")) { this.set("smartFormat", "SMART_FORMAT"); } }, restore: function() { this.set("value", this.get("initialValue")); }, addValue: function(oModelValue) { this.set("value", oModelValue.get("value")); if (oModelValue.get("label")) { this.set("label", oModelValue.get("label")); } }, clear: function() { this.set("value", ""); this.set("label", ""); }, getJSONObject : function () { var theLabel = this.get("label"); if (!theLabel) { theLabel = this.get("value"); } else { if (theLabel == "") { theLabel = this.get("value"); } } var toReturn = { value: this.get("value"), //displayableValue: this.formatValue(this.get("value"), this.get("displayFormat")), displayableValue: this.get("value"), smartValue: $.datepicker.getSmartDate(this.get("value")), label: theLabel } if (this.get("initialValue")) { toReturn.initialValue = this.get("initialValue"); } var additionalPropertiesFromModel = this.getAdditionalJSONObject(); if (additionalPropertiesFromModel) { for (var attrname in additionalPropertiesFromModel) { toReturn[attrname] = additionalPropertiesFromModel[attrname]; } } return toReturn; }, formatValue: function(aString, aFormat) { if (this.dateStrValidate(aString)) { return $.format.date(aString, aFormat, this.get("locale")); } else { return "Incorrect date"; } }, dateValidate: function(d,m,y) { y=y*1;m=m*1-1;d=d*1; with(new Date(y,m,d)) return getFullYear()==y && getMonth()==m && getDate()==d; }, dateStrValidate: function(str) { var a=str.match(/(\d+)/g); if (!a) return false; return this.dateValidate(a[0],a[1],a[2]); } }); Models.DateCollection = Models.BaseCollection.extend({ classType: "MODELS.DATECOLLECTION", model: Models.Date });