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...
68 colors.push('#003'); // off hour..
69 //var clr = [ '#003' , '#FCC' , '#FEE', '#FCC'];
70 var clr = [ '#FEE', '#FCC' ];
74 for (var i = open; i < close ;i++) {
78 times.push( 'midnight')
86 colors.push(clr[i % clr.length]);
88 data.push( 24-close );
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...
110 paper.circle(pie.cx,pie.cy, (paper.height / 2) - 100).attr({fill: "#fff"})
112 // fixme .. add the quater hour segments..
114 var atime = "Pick\nTime";
117 var tdisplay = paper.text(pie.cx,pie.cy,atime).attr({ font: "32px 'Lucida Sans Unicode', 'Lucida Grande', sans-serif", weight: 'bold', fill: '#000' });
122 if (!this.j || this.j == data.length -1) {
126 if (this.sector != asector) {
127 this.sector.scale(1.1, 1.1, this.cx, this.cy);
129 tdisplay.attr( { text : times[this.j]} );
131 this.label[0].stop();
132 this.label[0].attr({ r: 7.5 });
133 this.label[1].attr({ "font-weight": 800 });
138 if (!this.j || this.j == data.length) {
141 if (this.sector != asector) {
142 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
146 this.label[0].animate({ r: 5 }, 500, "bounce");
147 this.label[1].attr({ "font-weight": 400 });
149 tdisplay.attr( { text : atime } );
152 pie.click(function() {
153 if (!this.j || this.j == data.length -1) {
156 atime = times[this.j];
157 tdisplay.attr( { text : atime } );
159 asector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
162 this.sector.scale(1.1, 1.1, this.cx, this.cy);
163 asector = this.sector;
171 for (var i = 0; i < (24/3); i++) {
172 var angle = ( (360/24) * i * -3 ) -90;
173 var p = pie.sector(pie.cx, pie.cy, 120, angle, angle, false);
174 Roo.log([p[4],p[5], (i*3)+':00']);
178 var txt = (hr < 12 ? hr : (hr-12)) + (hr < 12 ? 'am' : 'pm');
179 if (!hr) { txt = ""; }
180 if (hr == 12) { txt= '12 noon'}
181 paper.text(p[4],p[5], txt);
184 //pie.each(function() { Roo.log(this)});
185 this.setValue(this.value);