Roo/form/DayPicker.js
[roojs1] / Roo / form / DayPicker.js
1 /*
2  * 
3  * Licence- LGPL
4  * 
5  */
6
7 /**
8  * @class Roo.form.DayPicker
9  * @extends Roo.form.Field
10  * A Day picker show [M] [T] [W] ....
11  * @constructor
12  * Creates a new Day Picker
13  * @param {Object} config Configuration options
14  */
15 Roo.form.DayPicker= function(config){
16     Roo.form.DayPicker.superclass.constructor.call(this, config);
17      
18 };
19
20 Roo.extend(Roo.form.DayPicker, Roo.form.Field,  {
21     /**
22      * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
23      */
24     focusClass : undefined,
25     /**
26      * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
27      */
28     fieldClass: "x-form-field",
29    
30     /**
31      * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
32      * {tag: "input", type: "checkbox", autocomplete: "off"})
33      */
34     defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
35     
36    
37     actionMode : 'viewEl', 
38     //
39     // private
40  
41     inputType : 'hidden',
42     
43      
44     inputElement: false, // real input element?
45     basedOn: false, // ????
46     
47     isFormField: true, // not sure where this is needed!!!!
48
49     onResize : function(){
50         Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
51         if(!this.boxLabel){
52             this.el.alignTo(this.wrap, 'c-c');
53         }
54     },
55
56     initEvents : function(){
57         Roo.form.Checkbox.superclass.initEvents.call(this);
58         this.el.on("click", this.onClick,  this);
59         this.el.on("change", this.onClick,  this);
60     },
61
62
63     getResizeEl : function(){
64         return this.wrap;
65     },
66
67     getPositionEl : function(){
68         return this.wrap;
69     },
70
71     
72     // private
73     onRender : function(ct, position){
74         Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
75        
76         this.wrap = this.el.wrap({cls: 'x-form-daypick-item '});
77         
78         var r1 = '<table><tr>'
79         var r2 = '<tr>';
80         for (var i=0; i < 7; i++) {
81             r1+= '<td>' + Date.dayNames[i].substring(0,3) + '</td>';
82             r2+= '<td><img class="x-menu-item-icon" src="' + Roo.BLANK_IMAGE_URL  +'"></td>';
83         }
84         
85         var viewEl = this.wrap.createChild( r1 + '</tr>' + r2 + '</tr></table>';);
86         
87         this.viewEl = viewEl;   
88         
89         this.wrap.on('click', this.onClick,  this); 
90         
91         this.el.on('DOMAttrModified', this.setFromHidden,  this); //ff
92         this.el.on('propertychange', this.setFromHidden,  this);  //ie
93         
94         
95           
96
97     },
98
99     // private
100     initValue : Roo.emptyFn,
101
102     /**
103      * Returns the checked state of the checkbox.
104      * @return {Boolean} True if checked, else false
105      */
106     getValue : function(){
107         return '';
108         
109     },
110
111         // private
112     onClick : function(){ 
113         //this.setChecked(!this.checked);
114
115         //if(this.el.dom.checked != this.checked){
116         //    this.setValue(this.el.dom.checked);
117        // }
118     },
119
120     /**
121      * Sets the checked state of the checkbox.
122      * On is always based on a string comparison between inputValue and the param.
123      * @param {Boolean/String} value - the value to set 
124      * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
125      */
126     setValue : function(v,suppressEvent){
127         
128        
129     },
130    
131     // handle setting of hidden value by some other method!!?!?
132     setFromHidden: function()
133     {
134         if(!this.el){
135             return;
136         }
137         //console.log("SET FROM HIDDEN");
138         //alert('setFrom hidden');
139         this.setValue(this.el.dom.value);
140     },
141     
142     onDestroy : function()
143     {
144         if(this.viewEl){
145             Roo.get(this.viewEl).remove();
146         }
147          
148         Roo.form.DayPicker.superclass.onDestroy.call(this);
149     }
150
151 });