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);
70 this.renderPaper(this.startHour,this.endHour);
75 renderPaper : function( startHour , endHour )
77 // let's create a pie chart...
78 var open = startHour.split(':').shift() * 1;
79 var close = endHour.split(':').shift() * 1;
81 var paper = this.paper;
87 // say we open for 7 - 19
90 Roo.log([open, close]);
93 // colours should be configurable...
95 colors.push('#003'); // off hour..
96 //var clr = [ '#003' , '#FCC' , '#FEE', '#FCC'];
97 var clr = [ '#FEE', '#FCC' ];
101 for (var i = open; i < close ;i++) {
104 times.push( '0' + i);
108 colors.push(clr[i % clr.length]);
110 data.push( 24-close );
113 //Roo.log(data.length);
114 //Roo.log(JSON.stringify(data));
115 //Roo.log(JSON.stringify(colors));
116 //Roo.log(colors.length);
118 var outerpie = this.outerpie = paper.piechart(
132 // fill in th emiddle...
134 paper.circle(outerpie.cx,outerpie.cy, 90).attr({fill: "#fff"})
135 // fixme .. add the quater hour segments..
137 var innerpie = this.innerpie = paper.piechart(
144 colors : [ '#FEE', '#FCC' ,'#FEE', '#FCC' ] ,
150 paper.circle(outerpie.cx,outerpie.cy, 60).attr({fill: "#fff"})
154 var tdisplay = this.tdisplay = paper.text(outerpie.cx,outerpie.cy, "Pick\nTime").attr({
155 font: "32px 'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
156 weight: 'bold', fill: '#000' });
162 for (var i = 0; i < (24/3); i++) {
163 var angle = ( (360/24) * i * -3 ) -90;
164 var p = outerpie.sector(outerpie.cx, outerpie.cy, 105, angle, angle, false);
165 var innerp = outerpie.sector(outerpie.cx, outerpie.cy, 70, 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 = ""; }
177 paper.text(p[4],p[5], txt);
182 paper.text(innerp[4],innerp[5], ((Math.floor(i/2) * 15) + 30) % 60);
193 if (!this.j || this.j == data.length -1) {
196 var ov = _t.getValue();
201 if (this.sector != asector) {
202 this.sector.scale(1.1, 1.1, this.cx, this.cy);
205 var min = ov ? _t.getValue().split(':').pop() : '00';
206 var ntime = times[this.j] + ':' + min;
207 tdisplay.attr( { text : _t.formatTime(ntime) });
213 if (!this.j || this.j == data.length) {
216 if (this.sector != asector) {
217 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
220 tdisplay.attr( { text : _t.formatTime(_t.getValue()) } );
223 outerpie.click(function() {
224 if (!this.j || this.j == data.length -1) {
228 var ov = _t.getValue();
229 var min = ov ? _t.getValue().split(':').pop() : '00';
230 var ntime = times[this.j] + ':' + min;
232 this.fireEvent('select', ntime);
236 asector.transform( 's1 1');
239 //this.sector.scale(1.1, 1.1, this.cx, this.cy);
240 asector = this.sector;
252 if (!this.j || this.j == data.length -1) {
257 if (this.sector != bsector) {
258 this.sector.scale(1.1, 1.1, this.cx, this.cy);
261 min = min ? min : '00';
263 var ov = _t.getValue();
264 var hr = ov ? _t.getValue().split(':').shift() : '12';
265 var ntime = hr + ':' + min;
266 tdisplay.attr( { text : _t.formatTime(ntime) });
273 if (!this.j || this.j == data.length) {
277 if (this.sector != bsector) {
278 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
281 tdisplay.attr( { text : _t.formatTime(_t.getValue()) } );
284 innerpie.click(function() {
288 min = min ? min : '00';
291 var ov = _t.getValue();
292 var hr = ov ? _t.getValue().split(':').shift() : '12';
293 var ntime = hr + ':' + min;
295 //tdisplay.attr( { text : _t.formatTime(ntime) });
297 //var ov = _t.getValue();
298 //var min = ov ? _t.getValue().split(':').pop() : '00';
299 //var ntime = times[this.j] + ':' + min;
300 //_t.setValue(ntime);
303 bsector.transform( 's1 1');
306 //this.sector.scale(1.1, 1.1, this.cx, this.cy);
307 bsector = this.sector;
311 this.setValue(this.value);
317 //pie.each(function() { Roo.log(this)});
318 //this.setValue(this.value);
320 setValue : function(v){
325 //this.viewEl.dom.innerHTML = html;
326 Roo.form.DisplayField.superclass.setValue.call(this, v);
328 this.tdisplay.attr( { text : this.formatTime(v) } );
332 formatTime : function(ntime)
337 if (ntime == '00:00') {
340 if (ntime == '12:00') {
344 var d = Date.parseDate(ntime, "H:i");
345 return d.format('h:i') + "\n" + d.format('a') ;