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;
235 asector.transform( 's1 1');
238 //this.sector.scale(1.1, 1.1, this.cx, this.cy);
239 asector = this.sector;
251 if (!this.j || this.j == data.length -1) {
256 if (this.sector != bsector) {
257 this.sector.scale(1.1, 1.1, this.cx, this.cy);
260 min = min ? min : '00';
262 var ov = _t.getValue();
263 var hr = ov ? _t.getValue().split(':').shift() : '12';
264 var ntime = hr + ':' + min;
265 tdisplay.attr( { text : _t.formatTime(ntime) });
272 if (!this.j || this.j == data.length) {
276 if (this.sector != bsector) {
277 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
280 tdisplay.attr( { text : _t.formatTime(_t.getValue()) } );
283 innerpie.click(function() {
287 min = min ? min : '00';
290 var ov = _t.getValue();
291 var hr = ov ? _t.getValue().split(':').shift() : '12';
292 var ntime = hr + ':' + min;
294 //tdisplay.attr( { text : _t.formatTime(ntime) });
296 //var ov = _t.getValue();
297 //var min = ov ? _t.getValue().split(':').pop() : '00';
298 //var ntime = times[this.j] + ':' + min;
299 //_t.setValue(ntime);
302 bsector.transform( 's1 1');
305 //this.sector.scale(1.1, 1.1, this.cx, this.cy);
306 bsector = this.sector;
310 this.setValue(this.value);
316 //pie.each(function() { Roo.log(this)});
317 //this.setValue(this.value);
319 setValue : function(v){
324 //this.viewEl.dom.innerHTML = html;
325 Roo.form.DisplayField.superclass.setValue.call(this, v);
327 this.tdisplay.attr( { text : this.formatTime(v) } );
331 formatTime : function(ntime)
336 if (ntime == '00:00') {
339 if (ntime == '12:00') {
343 var d = Date.parseDate(ntime, "H:i");
344 return d.format('h:i') + "\n" + d.format('a') ;