5 Roo.ux.TimePicker = function(config){
8 // these are required... error out if not avail..
10 if (typeof(Raphael) == 'undefined') {
13 if (deps && typeof(Raphael.prototype) == 'undefined') {
17 alert("Error - required components not found - Raphael and piechart");
21 Roo.ux.TimePicker.superclass.constructor.call(this, config);
24 Roo.extend(Roo.ux.TimePicker , Roo.form.DisplayField , {
30 onRender : function(ct, position){
32 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
33 //if(this.inputValue !== undefined){
34 this.wrap = this.el.wrap();
36 this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
41 this.viewEl.applyStyles(this.bodyStyle);
43 //this.viewEl.setStyle('padding', '2px');
45 this.viewEl.setHeight(this.height);
46 this.viewEl.setWidth(this.width);
48 // let's create a pie chart...
50 var paper = this.paper = Raphael(this.viewEl.dom);
52 paper.setSize(this.width,this.height);
57 // say we open for 7 - 19
63 // colours should be configurable...
66 var clr = [ '#003' , '#FCC' , '#Fee', '#FCC'];
70 for (var i = (open*4); i < (close*4);i++) {
74 times.push( 'midnight' )
78 var min = ( i % 4) * 15;
79 min = !min ? ':00' : (':' + min);
80 var hr = Math.floor(i/4);
81 var tail = hr < 12 ? 'am' : 'pm';
83 times.push(hr + min + tail);
86 colors.push(clr[i % clr.length]);
88 data.push((24-close) * 4);
91 //Roo.log(data.length);
92 //Roo.log(JSON.stringify(data));
93 //Roo.log(JSON.stringify(colors));
94 //Roo.log(colors.length);
96 var pie = paper.piechart(
99 (paper.height / 2) - 70,
108 // fill in th emiddle...
109 paper.circle(pie.cx,pie.cy, (paper.height / 2) - 100).attr({fill: "#fff"})
111 var atime = "Pick\nTime";
114 var tdisplay = paper.text(pie.cx,pie.cy,atime).attr({ font: "32px 'Lucida Sans Unicode', 'Lucida Grande', sans-serif", weight: 'bold', fill: '#000' });
119 if (!this.j || this.j == data.length -1) {
123 if (this.sector != asector) {
124 this.sector.scale(1.1, 1.1, this.cx, this.cy);
126 tdisplay.attr( { text : times[this.j]} );
128 this.label[0].stop();
129 this.label[0].attr({ r: 7.5 });
130 this.label[1].attr({ "font-weight": 800 });
135 if (!this.j || this.j == data.length) {
138 if (this.sector != asector) {
139 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
143 this.label[0].animate({ r: 5 }, 500, "bounce");
144 this.label[1].attr({ "font-weight": 400 });
146 tdisplay.attr( { text : atime } );
149 pie.click(function() {
150 if (!this.j || this.j == data.length -1) {
153 atime = times[this.j];
154 tdisplay.attr( { text : atime } );
156 asector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
159 this.sector.scale(1.1, 1.1, this.cx, this.cy);
160 asector = this.sector;
168 for (var i = 0; i < (24/3); i++) {
169 var angle = ( (360/24) * i * -3 ) -90;
170 var p = pie.sector(pie.cx, pie.cy, 120, angle, angle, false);
171 Roo.log([p[4],p[5], (i*3)+':00']);
175 var txt = (hr < 12 ? hr : (hr-12)) + (hr < 12 ? 'am' : 'pm');
176 if (!hr) { txt = ""; }
177 if (hr == 12) { txt= '12 noon'}
178 paper.text(p[4],p[5], txt);
181 //pie.each(function() { Roo.log(this)});
182 this.setValue(this.value);