Changeset 5637
- Timestamp:
- 09/11/06 21:09:00 (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 modified
-
src/date/format.js (modified) (6 diffs)
-
src/widget/DropdownContainer.js (modified) (1 diff)
-
src/widget/DropdownDatePicker.js (modified) (3 diffs)
-
tests/widget/test_DropdownDatePicker_localize.html (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/date/format.js
r5619 r5637 1 1 dojo.provide("dojo.date.format"); 2 3 dojo.require("dojo.experimental");4 2 5 3 dojo.require("dojo.date.common"); … … 202 200 break; 203 201 default: 204 dojo.raise(" invalid format: "+pattern);202 dojo.raise("dojo.date.parse: invalid format: "+pattern); 205 203 } 206 204 if(pad){ s = dojo.string.pad(s, l); } … … 245 243 // 246 244 // value: 247 // The int string to be convert ted245 // The int string to be converted 248 246 // 249 247 // options: object {selector: string, formatLength: string, datePattern: string, timePattern: string, locale: string} … … 253 251 // locale- override the locale used to determine formatting rules 254 252 // 255 dojo.experimental("dojo.date.parse"); 253 256 254 //TODO: this is still quite rough - it only implements a small portion of the parsing algorithm needed, 257 255 // and doesn't provide much flexibility in matching. … … 269 267 270 268 var match = dateRE.exec(value); 269 if(!match){return null;} /* null */ 270 271 271 var result = new Date(); 272 272 result.setHours(0,0,0,0); … … 304 304 var literal = false; 305 305 for(var i=0; i<chunks.length; i++){ 306 if(!chunks[i]){chunks[i]='\'';} 306 if(!chunks[i]){chunks[i]='\'';} //FIXME 307 307 else{ 308 308 chunks[i]=(literal ? applyLiteral : applyPattern)(chunks[i]); -
trunk/src/widget/DropdownContainer.js
r5633 r5637 27 27 containerAnimInProgress: false, 28 28 29 templateString: '<span style="white-space:nowrap"><input type=" text" value="" style="vertical-align:middle;" dojoAttachPoint="inputNode" autocomplete="off" /> <img src="${this.iconURL}" alt="${this.iconAlt}" dojoAttachEvent="onclick: onIconClick;" dojoAttachPoint="buttonNode" style="vertical-align:middle; cursor:pointer; cursor:hand;" /></span>',29 templateString: '<span style="white-space:nowrap"><input type="hidden" name="" value="" dojoAttachPoint="valueNode" /><input name="" type="text" value="" style="vertical-align:middle;" dojoAttachPoint="inputNode" autocomplete="off" /> <img src="${this.iconURL}" alt="${this.iconAlt}" dojoAttachEvent="onclick: onIconClick" dojoAttachPoint="buttonNode" style="vertical-align:middle; cursor:pointer; cursor:hand" /></span>', 30 30 templateCssPath: "", 31 31 -
trunk/src/widget/DropdownDatePicker.js
r5633 r5637 6 6 dojo.require("dojo.event.*"); 7 7 dojo.require("dojo.html.*"); 8 dojo.require("dojo.date.format"); 9 dojo.require("dojo.date.serialize"); 8 10 9 11 dojo.require("dojo.i18n.common"); … … 16 18 iconURL: dojo.uri.dojoUri("src/widget/templates/images/dateIcon.gif"), 17 19 zIndex: "10", 18 datePicker: null, 19 20 dateFormat: "%m/%d/%Y", 21 date: null, 20 21 // pattern used in display of formatted date. See dojo.date.format. 22 displayFormat: "", 23 dateFormat: "", // deprecated in 0.5 24 // formatting used when submitting form. A pattern string like display format or one of the following: 25 // rfc|iso|posix|unix By default, uses rfc3339 style date formatting. 26 saveFormat: "", 27 // type of format appropriate to locale. see dojo.date.format 28 formatLength: "short", // only parsing of short is supported at this time 29 date: "", 30 // name of the form element 31 name: "", 22 32 23 33 postMixInProperties: function(localProperties, frag) { … … 25 35 var messages = dojo.i18n.getLocalization("dojo.widget", "DropdownDatePicker", this.lang); 26 36 this.iconAlt = messages.selectDate; 37 38 if(this.date && isNaN(this.date)){ 39 var orig = this.date; 40 this.date = dojo.date.fromRfc3339(this.date); 41 if(!this.date){this.date = new Date(orig); dojo.deprecated("dojo.widget.DropdownDatePicker", "date attributes must be passed in Rfc3339 format", "0.5");} 42 } 43 if(this.date && !isNaN(this.date)){ 44 this.date = new Date(this.date); 45 } 27 46 }, 28 47 29 48 fillInTemplate: function(args, frag){ 30 49 dojo.widget.DropdownDatePicker.superclass.fillInTemplate.call(this, args, frag); 31 var source = this.getFragNodeRef(frag); 32 33 if(args.date){ this.date = new Date(args.date); } 34 50 35 51 var dpNode = document.createElement("div"); 36 52 this.containerNode.appendChild(dpNode); 37 53 38 54 var dateProps = { widgetContainerId: this.widgetId }; 39 55 if(this.date){ 40 dateProps["date"] = this.date; 41 dateProps["selectedDate"] = dojo.date.toRfc3339(this.date); 42 this.inputNode.value = dojo.date.strftime(this.date, this.dateFormat); 56 dateProps.selectedDate = dojo.date.toRfc3339(this.date, 'dateOnly'); 43 57 } 44 58 this.datePicker = dojo.widget.createWidget("DatePicker", dateProps, dpNode); 45 59 dojo.event.connect(this.datePicker, "onSetDate", this, "onSetDate"); 60 if(this.date){ 61 this.onSetDate(); 62 } 46 63 this.containerNode.style.zIndex = this.zIndex; 47 64 this.containerNode.style.backgroundColor = "transparent"; 65 this.valueNode.name=this.name; 48 66 }, 49 67 50 68 onSetDate: function(){ 51 this.inputNode.value = dojo.date.format(this.datePicker.date, this.dateFormat); 69 if(this.dateFormat){ 70 dojo.deprecated("dojo.widget.DropdownDatePicker", 71 "Must use displayFormat attribute instead of dateFormat. See dojo.date.format for specification.", "0.5"); 72 this.inputNode.value = dojo.date.strftime(this.datePicker.date, this.dateFormat, this.lang); 73 }else{ 74 this.inputNode.value = dojo.date.format(this.datePicker.date, 75 {formatLength:this.formatLength, datePattern:this.displayFormat, selector:'dateOnly', locale:this.lang}); 76 } 77 this._synchValueNode(); 52 78 this.hideContainer(); 53 79 }, 54 80 55 81 onInputChange: function(){ 56 this.datePicker.date = new Date(this.inputNode.value); 57 this.datePicker.setDate(this.datePicker.date); 82 if(this.dateFormat){ 83 dojo.deprecated("dojo.widget.DropdownDatePicker", 84 "Cannot parse user input. Must use displayFormat attribute instead of dateFormat. See dojo.date.format for specification.", "0.5"); 85 }else{ 86 var inputDate = dojo.date.parse(this.inputNode.value, 87 {formatLength:this.formatLength, datePattern:this.displayFormat, selector:'dateOnly', locale:this.lang}); 88 if(inputDate){ 89 this.datePicker.setDate(inputDate); 90 this._synchValueNode(); 91 } 92 } 93 // If the date entered didn't parse, reset to the old date. KISS, for now. 94 //TODO: usability? should we provide more feedback somehow? an error notice? 95 // seems redundant to do this if the parse failed, but at least until we have validation, 96 // this will fix up the display of entries like 01/32/2006 97 this.onSetDate(); 98 }, 99 100 _synchValueNode: function(){ 101 var date = this.datePicker.date; 102 var value; 103 switch(this.saveFormat.toLowerCase()){ 104 case "rfc": case "iso": case "": 105 value = dojo.date.toRfc3339(date, 'dateOnly'); 106 break; 107 case "posix": case "unix": 108 value = Number(date); 109 break; 110 default: 111 value = dojo.date.format(date, {datePattern:this.saveFormat, selector:'dateOnly', locale:this.lang}); 112 } 113 this.valueNode.value = value; 58 114 }, 59 115