5 Roo.form.TimePicker = function(config){
7 Roo.log("CTOR CALLED");
8 // these are required... error out if not avail..
10 if (typeof(Raphael) == 'undefined') {
13 if (deps && typeof(Raphael.prototype) == 'undefined') {
17 Roo.log("Error - required components not found - Raphael and piechart");
21 Roo.form.TimePicker.superclass.constructor.call(this, config);
26 * Fires when a date is selected
27 * @param {DatePicker} this
28 * @param {Date} date The selected date
36 Roo.extend(Roo.form.TimePicker , Roo.form.DisplayField , {
47 onRender : function(ct, position){
49 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
50 //if(this.inputValue !== undefined){
51 this.wrap = this.el.wrap();
53 this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
58 this.viewEl.applyStyles(this.bodyStyle);
60 //this.viewEl.setStyle('padding', '2px');
62 this.viewEl.setHeight(this.height);
63 this.viewEl.setWidth(this.width);
66 var paper = this.paper = Raphael(this.viewEl.dom);
68 paper.setSize(this.width,this.height);
72 this.renderPaper(this.startHour,this.endHour);
77 renderPaper : function( startHour , endHour )
79 // let's create a pie chart...
80 var open = startHour.split(':').shift() * 1;
81 var close = endHour.split(':').shift() * 1;
83 if (close < open || close >= 24) {
89 var paper = this.paper;
95 // say we open for 7 - 19
98 Roo.log([open, close]);
101 // colours should be configurable...
103 colors.push('#003'); // off hour..
104 //var clr = [ '#003' , '#FCC' , '#FEE', '#FCC'];
105 var clr = [ '#FEE', '#FCC' ];
109 for (var i = open; i < close ;i++) {
112 times.push( '0' + i);
116 colors.push(clr[i % clr.length]);
118 data.push( 24-close );
121 //Roo.log(data.length);
122 //Roo.log(JSON.stringify(data));
123 //Roo.log(JSON.stringify(colors));
124 //Roo.log(colors.length);
126 var outerpie = this.outerpie = paper.piechart(
140 // fill in th emiddle...
142 paper.circle(outerpie.cx,outerpie.cy, 90).attr({fill: "#fff"})
143 // fixme .. add the quater hour segments..
145 var innerpie = this.innerpie = paper.piechart(
152 colors : [ '#FEE', '#FCC' ,'#FEE', '#FCC' ] ,
158 paper.circle(outerpie.cx,outerpie.cy, 60).attr({fill: "#fff"})
162 var tdisplay = this.tdisplay = paper.text(outerpie.cx,outerpie.cy, "Pick\nTime").attr({
163 font: "32px 'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
164 weight: 'bold', fill: '#000' });
170 for (var i = 0; i < (24/3); i++) {
171 var angle = ( (360/24) * i * -3 ) -90;
172 var p = outerpie.sector(outerpie.cx, outerpie.cy, 105, angle, angle, false);
173 var innerp = outerpie.sector(outerpie.cx, outerpie.cy, 70, angle, angle, false);
175 Roo.log([p[4],p[5], (i*3)+':00']);
179 var txt = (hr < 12 ? hr : (hr-12)) + (hr < 12 ? 'am' : 'pm');
180 if (!hr) { txt = ""; }
185 paper.text(p[4],p[5], txt);
190 paper.text(innerp[4],innerp[5], ((Math.floor(i/2) * 15) + 30) % 60);
201 if (!this.j || this.j == data.length -1) {
204 var ov = _t.getValue();
209 if (this.sector != asector) {
210 this.sector.scale(1.1, 1.1, this.cx, this.cy);
213 var min = ov ? _t.getValue().split(':').pop() : '00';
214 var ntime = times[this.j] + ':' + min;
215 tdisplay.attr( { text : _t.formatTime(ntime) });
221 if (!this.j || this.j == data.length) {
224 if (this.sector != asector) {
225 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
228 tdisplay.attr( { text : _t.formatTime(_t.getValue()) } );
231 outerpie.click(function() {
232 if (!this.j || this.j == data.length -1) {
236 var ov = _t.getValue();
237 var min = ov ? _t.getValue().split(':').pop() : '00';
238 var ntime = times[this.j] + ':' + min;
240 _t.fireEvent('select', ntime);
244 asector.transform( 's1 1');
247 //this.sector.scale(1.1, 1.1, this.cx, this.cy);
248 asector = this.sector;
260 if (!this.j || this.j == data.length -1) {
265 if (this.sector != bsector) {
266 this.sector.scale(1.1, 1.1, this.cx, this.cy);
269 min = min ? min : '00';
271 var ov = _t.getValue();
272 var hr = ov ? _t.getValue().split(':').shift() : '12';
273 var ntime = hr + ':' + min;
274 tdisplay.attr( { text : _t.formatTime(ntime) });
281 if (!this.j || this.j == data.length) {
285 if (this.sector != bsector) {
286 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
289 tdisplay.attr( { text : _t.formatTime(_t.getValue()) } );
292 innerpie.click(function() {
296 min = min ? min : '00';
299 var ov = _t.getValue();
300 var hr = ov ? _t.getValue().split(':').shift() : '12';
301 var ntime = hr + ':' + min;
303 _t.fireEvent('select', ntime);
305 //tdisplay.attr( { text : _t.formatTime(ntime) });
307 //var ov = _t.getValue();
308 //var min = ov ? _t.getValue().split(':').pop() : '00';
309 //var ntime = times[this.j] + ':' + min;
310 //_t.setValue(ntime);
313 bsector.transform( 's1 1');
316 //this.sector.scale(1.1, 1.1, this.cx, this.cy);
317 bsector = this.sector;
321 this.setValue(this.value);
327 //pie.each(function() { Roo.log(this)});
328 //this.setValue(this.value);
330 setValue : function(v){
335 //this.viewEl.dom.innerHTML = html;
336 Roo.form.DisplayField.superclass.setValue.call(this, v);
338 this.tdisplay.attr( { text : this.formatTime(v) } );
342 formatTime : function(ntime)
347 if (ntime == '00:00') {
350 if (ntime == '12:00') {
354 var d = Date.parseDate(ntime, "H:i");
355 return d.format('h:i') + "\n" + d.format('a') ;