Changeset 5637

Show
Ignore:
Timestamp:
09/11/06 21:09:00 (2 years ago)
Author:
peller
Message:

DropdownDatePicker? handling of locale-based formatting and parsing of dates (fixes #1008, fixes #821)
Use locale-independent serialization for dddp in a form (fixes #721)
Removed experimental from dojo.date.parse (fixes #835)

Location:
trunk
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/date/format.js

    r5619 r5637  
    11dojo.provide("dojo.date.format"); 
    2  
    3 dojo.require("dojo.experimental"); 
    42 
    53dojo.require("dojo.date.common"); 
     
    202200                                        break; 
    203201                                default: 
    204                                         dojo.raise("invalid format: "+pattern); 
     202                                        dojo.raise("dojo.date.parse: invalid format: "+pattern); 
    205203                        } 
    206204                        if(pad){ s = dojo.string.pad(s, l); } 
     
    245243// 
    246244// value: 
    247 //              The int string to be convertted 
     245//              The int string to be converted 
    248246// 
    249247// options: object {selector: string, formatLength: string, datePattern: string, timePattern: string, locale: string} 
     
    253251//              locale- override the locale used to determine formatting rules 
    254252// 
    255         dojo.experimental("dojo.date.parse"); 
     253 
    256254        //TODO: this is still quite rough - it only implements a small portion of the parsing algorithm needed, 
    257255        // and doesn't provide much flexibility in matching. 
     
    269267 
    270268        var match = dateRE.exec(value); 
     269        if(!match){return null;} /* null */ 
     270 
    271271        var result = new Date(); 
    272272        result.setHours(0,0,0,0); 
     
    304304        var literal = false; 
    305305        for(var i=0; i<chunks.length; i++){ 
    306                 if(!chunks[i]){chunks[i]='\'';} 
     306                if(!chunks[i]){chunks[i]='\'';} //FIXME 
    307307                else{ 
    308308                        chunks[i]=(literal ? applyLiteral : applyPattern)(chunks[i]); 
  • trunk/src/widget/DropdownContainer.js

    r5633 r5637  
    2727                containerAnimInProgress: false, 
    2828 
    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>', 
    3030                templateCssPath: "", 
    3131 
  • trunk/src/widget/DropdownDatePicker.js

    r5633 r5637  
    66dojo.require("dojo.event.*"); 
    77dojo.require("dojo.html.*"); 
     8dojo.require("dojo.date.format"); 
     9dojo.require("dojo.date.serialize"); 
    810 
    911dojo.require("dojo.i18n.common"); 
     
    1618                iconURL: dojo.uri.dojoUri("src/widget/templates/images/dateIcon.gif"), 
    1719                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: "", 
    2232 
    2333                postMixInProperties: function(localProperties, frag) { 
     
    2535                        var messages = dojo.i18n.getLocalization("dojo.widget", "DropdownDatePicker", this.lang); 
    2636                        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                        } 
    2746                }, 
    2847 
    2948                fillInTemplate: function(args, frag){ 
    3049                        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 
    3551                        var dpNode = document.createElement("div"); 
    3652                        this.containerNode.appendChild(dpNode); 
    37                          
     53 
    3854                        var dateProps = { widgetContainerId: this.widgetId }; 
    3955                        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'); 
    4357                        } 
    4458                        this.datePicker = dojo.widget.createWidget("DatePicker", dateProps, dpNode); 
    4559                        dojo.event.connect(this.datePicker, "onSetDate", this, "onSetDate"); 
     60                        if(this.date){ 
     61                                this.onSetDate(); 
     62                        } 
    4663                        this.containerNode.style.zIndex = this.zIndex; 
    4764                        this.containerNode.style.backgroundColor = "transparent"; 
     65                        this.valueNode.name=this.name; 
    4866                }, 
    49                  
     67 
    5068                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(); 
    5278                        this.hideContainer(); 
    5379                }, 
    54                  
     80 
    5581                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; 
    58114                }, 
    59115