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 , {
33 onRender : function(ct, position){
35 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
36 //if(this.inputValue !== undefined){
37 this.wrap = this.el.wrap();
39 this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
44 this.viewEl.applyStyles(this.bodyStyle);
46 //this.viewEl.setStyle('padding', '2px');
48 this.viewEl.setHeight(this.height);
49 this.viewEl.setWidth(this.width);
51 // let's create a pie chart...
53 var paper = this.paper = Raphael(this.viewEl.dom);
55 paper.setSize(this.width,this.height);
60 // say we open for 7 - 19
61 var open = this.startHour.split(':').shift();
62 var close = this.endHour.split(':').shift();
66 // colours should be configurable...
69 var clr = [ '#003' , '#FCC' , '#Fee', '#FCC'];
73 for (var i = (open*4); i < (close*4);i++) {
77 times.push( 'midnight' )
81 var min = ( i % 4) * 15;
82 min = !min ? ':00' : (':' + min);
83 var hr = Math.floor(i/4);
84 var tail = hr < 12 ? 'am' : 'pm';
86 times.push(hr + min + tail);
89 colors.push(clr[i % clr.length]);
91 data.push((24-close) * 4);
94 //Roo.log(data.length);
95 //Roo.log(JSON.stringify(data));
96 //Roo.log(JSON.stringify(colors));
97 //Roo.log(colors.length);
99 var pie = paper.piechart(
102 (paper.height / 2) - 70,
111 // fill in th emiddle...
115 paper.circle(pie.cx,pie.cy, (paper.height / 2) - 100).attr({fill: "#fff"})
117 var atime = "Pick\nTime";
120 var tdisplay = paper.text(pie.cx,pie.cy,atime).attr({ font: "32px 'Lucida Sans Unicode', 'Lucida Grande', sans-serif", weight: 'bold', fill: '#000' });
125 if (!this.j || this.j == data.length -1) {
129 if (this.sector != asector) {
130 this.sector.scale(1.1, 1.1, this.cx, this.cy);
132 tdisplay.attr( { text : times[this.j]} );
134 this.label[0].stop();
135 this.label[0].attr({ r: 7.5 });
136 this.label[1].attr({ "font-weight": 800 });
141 if (!this.j || this.j == data.length) {
144 if (this.sector != asector) {
145 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
149 this.label[0].animate({ r: 5 }, 500, "bounce");
150 this.label[1].attr({ "font-weight": 400 });
152 tdisplay.attr( { text : atime } );
155 pie.click(function() {
156 if (!this.j || this.j == data.length -1) {
159 atime = times[this.j];
160 tdisplay.attr( { text : atime } );
162 asector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
165 this.sector.scale(1.1, 1.1, this.cx, this.cy);
166 asector = this.sector;
174 for (var i = 0; i < (24/3); i++) {
175 var angle = ( (360/24) * i * -3 ) -90;
176 var p = pie.sector(pie.cx, pie.cy, 120, angle, angle, false);
177 Roo.log([p[4],p[5], (i*3)+':00']);
181 var txt = (hr < 12 ? hr : (hr-12)) + (hr < 12 ? 'am' : 'pm');
182 if (!hr) { txt = ""; }
183 if (hr == 12) { txt= '12 noon'}
184 paper.text(p[4],p[5], txt);
187 //pie.each(function() { Roo.log(this)});
188 this.setValue(this.value);