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 , {
27 onRender : function(ct, position){
29 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
30 //if(this.inputValue !== undefined){
31 this.wrap = this.el.wrap();
33 this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
38 this.viewEl.applyStyles(this.bodyStyle);
40 //this.viewEl.setStyle('padding', '2px');
42 this.setValue(this.value);
45 // let's create a pie chart...
46 var ge = Roo.select('.pb-book-time',true).first();
47 var paper = Raphael(ge.dom);
48 var sz = ge.getSize();
49 paper.setSize(sz.width,sz.height);
54 // say we open for 7 - 19
62 var clr = [ '#003' , '#FCC' , '#Fee', '#FCC'];
66 for (var i = (open*4); i < (close*4);i++) {
70 times.push( 'midnight' )
74 var min = ( i % 4) * 15;
75 min = !min ? ':00' : (':' + min);
76 var hr = Math.floor(i/4);
77 var tail = hr < 12 ? 'am' : 'pm';
79 times.push(hr + min + tail);
84 colors.push(clr[i % clr.length]);
86 data.push((24-close) * 4);
89 Roo.log(JSON.stringify(data));
90 Roo.log(JSON.stringify(colors));
91 Roo.log(colors.length);
93 var pie = paper.piechart(
96 (paper.height / 2) - 70,
105 paper.circle(pie.cx,pie.cy, (paper.height / 2) - 100).attr({fill: "#fff"})
107 var atime = "Pick\nTime";
110 var tdisplay = paper.text(pie.cx,pie.cy,atime).attr({ font: "32px 'Lucida Sans Unicode', 'Lucida Grande', sans-serif", weight: 'bold', fill: '#000' });
115 if (!this.j || this.j == data.length -1) {
119 if (this.sector != asector) {
120 this.sector.scale(1.1, 1.1, this.cx, this.cy);
122 tdisplay.attr( { text : times[this.j]} );
124 this.label[0].stop();
125 this.label[0].attr({ r: 7.5 });
126 this.label[1].attr({ "font-weight": 800 });
131 if (!this.j || this.j == data.length) {
134 if (this.sector != asector) {
135 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
139 this.label[0].animate({ r: 5 }, 500, "bounce");
140 this.label[1].attr({ "font-weight": 400 });
142 tdisplay.attr( { text : atime } );
145 pie.click(function() {
146 if (!this.j || this.j == data.length -1) {
149 atime = times[this.j];
150 tdisplay.attr( { text : atime } );
152 asector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
155 this.sector.scale(1.1, 1.1, this.cx, this.cy);
156 asector = this.sector;
164 for (var i = 0; i < (24/3); i++) {
165 var angle = ( (360/24) * i * -3 ) -90;
166 var p = pie.sector(pie.cx, pie.cy, 120, angle, angle, false);
167 Roo.log([p[4],p[5], (i*3)+':00']);
171 var txt = (hr < 12 ? hr : (hr-12)) + (hr < 12 ? 'am' : 'pm');
172 if (!hr) { txt = ""; }
173 if (hr == 12) { txt= '12 noon'}
174 paper.text(p[4],p[5], txt);
177 //pie.each(function() { Roo.log(this)});