4 * base class for bootstrap elements.
8 Roo.bootstrap = Roo.bootstrap || {};
10 * @class Roo.bootstrap.Component
11 * @extends Roo.Component
12 * Bootstrap Component base class
13 * @cfg {String} cls css class
14 * @cfg {String} style any extra css
15 * @cfg {Object} xattr extra attributes to add to 'element' (used by builder to store stuff.)
16 * @cfg {Boolean} can_build_overlaid True if element can be rebuild from a HTML page
17 * @cfg {string} dataId cutomer id
18 * @cfg {string} name Specifies name attribute
21 * Do not use directly - it does not do anything..
22 * @param {Object} config The config object
27 Roo.bootstrap.Component = function(config){
28 Roo.bootstrap.Component.superclass.constructor.call(this, config);
31 Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, {
34 allowDomMove : false, // to stop relocations in parent onRender...
42 initEvents : function() { },
48 can_build_overlaid : true,
55 // returns the parent component..
56 return Roo.ComponentMgr.get(this.parentId)
62 onRender : function(ct, position)
64 // Roo.log("Call onRender: " + this.xtype);
66 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
69 if (this.el.attr('xtype')) {
70 this.el.attr('xtypex', this.el.attr('xtype'));
71 this.el.dom.removeAttribute('xtype');
81 var cfg = Roo.apply({}, this.getAutoCreate());
84 // fill in the extra attributes
85 if (this.xattr && typeof(this.xattr) =='object') {
86 for (var i in this.xattr) {
87 cfg[i] = this.xattr[i];
92 cfg.dataId = this.dataId;
96 cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
99 if (this.style) { // fixme needs to support more complex style data.
100 cfg.style = this.style;
104 cfg.name = this.name;
107 this.el = ct.createChild(cfg, position);
109 if(this.tabIndex !== undefined){
110 this.el.dom.setAttribute('tabIndex', this.tabIndex);
117 getChildContainer : function()
123 addxtype : function(tree,cntr)
127 cn = Roo.factory(tree);
129 cn.parentType = this.xtype; //??
130 cn.parentId = this.id;
132 cntr = typeof(cntr == 'undefined' ) ? 'getChildContainer' : cntr;
134 var has_flexy_each = (typeof(tree['flexy:foreach']) != 'undefined');
136 var has_flexy_if = (typeof(tree['flexy:if']) != 'undefined');
138 var build_from_html = Roo.XComponent.build_from_html;
140 var is_body = (tree.xtype == 'Body') ;
142 var page_has_body = (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body');
144 var self_cntr_el = Roo.get(this[cntr]());
146 if (!has_flexy_each || !build_from_html || is_body || !page_has_body) {
147 if(!has_flexy_if || typeof(tree.name) == 'undefined' || !build_from_html || is_body || !page_has_body){
148 return this.addxtypeChild(tree,cntr);
151 var echild =self_cntr_el ? self_cntr_el.child('>*[name=' + tree.name + ']') : false;
154 return this.addxtypeChild(Roo.apply({}, tree),cntr);
157 Roo.log('skipping render');
165 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
171 if (echild && echild.attr('xtype').split('.').pop() != cn.xtype) {
175 ret = this.addxtypeChild(Roo.apply({}, tree),cntr);
180 addxtypeChild : function (tree, cntr)
183 cntr = typeof(cntr == 'undefined' ) ? 'getChildContainer' : cntr;
186 var has_flexy = (typeof(tree['flexy:if']) != 'undefined') ||
187 (typeof(tree['flexy:foreach']) != 'undefined');
192 // render the element if it's not BODY.
193 if (tree.xtype != 'Body') {
194 var test = Roo.factory(tree);
195 cn = Roo.factory(tree);
197 cn.parentType = this.xtype; //??
198 cn.parentId = this.id;
200 var build_from_html = Roo.XComponent.build_from_html;
203 // does the container contain child eleemnts with 'xtype' attributes.
204 // that match this xtype..
205 // note - when we render we create these as well..
206 // so we should check to see if body has xtype set.
207 if (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body') {
209 var self_cntr_el = Roo.get(this[cntr]());
210 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
212 if (echild && echild.attr('xtype').split('.').pop() == cn.xtype) {
213 // Roo.log("found child for " + this.xtype +": " + echild.attr('xtype') );
219 //echild.dom.removeAttribute('xtype');
221 Roo.log("MISSING " + cn.xtype + " on child of " + (this.el ? this.el.attr('xbuilderid') : 'no parent'));
228 // if object has flexy:if - then it may or may not be rendered.
229 if (build_from_html && has_flexy && !cn.el && cn.can_build_overlaid) {
230 // skip a flexy if element.
231 Roo.log('skipping render');
234 // actually if flexy:foreach is found, we really want to create
235 // multiple copies here...
237 cn.render(this[cntr]());
239 // then add the element..
246 if (typeof (tree.menu) != 'undefined') {
247 tree.menu.parentType = cn.xtype;
248 tree.menu.triggerEl = cn.el;
249 nitems.push(cn.addxtype(Roo.apply({}, tree.menu)));
253 if (!tree.items || !tree.items.length) {
257 var items = tree.items;
260 //Roo.log(items.length);
262 for(var i =0;i < items.length;i++) {
263 nitems.push(cn.addxtype(Roo.apply({}, items[i])));
279 * based on jquery fullcalendar
283 Roo.bootstrap = Roo.bootstrap || {};
285 * @class Roo.bootstrap.Calendar
286 * @extends Roo.bootstrap.Component
287 * Bootstrap Calendar class
290 * Create a new Container
291 * @param {Object} config The config object
296 Roo.bootstrap.Calendar = function(config){
297 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
301 * Fires when a date is selected
302 * @param {DatePicker} this
303 * @param {Date} date The selected date
308 * Fires when the displayed month changes
309 * @param {DatePicker} this
310 * @param {Date} date The selected month
315 * Fires when mouse over an event
316 * @param {Calendar} this
317 * @param {event} Event
322 * Fires when the mouse leaves an
323 * @param {Calendar} this
329 * Fires when the mouse click an
330 * @param {Calendar} this
339 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
342 * @cfg {Number} startDay
343 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
347 getAutoCreate : function(){
350 var fc_button = function(name, corner, style, content ) {
351 return Roo.apply({},{
353 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
355 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
358 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
366 style : 'width:100%',
373 cls : 'fc-header-left',
375 fc_button('prev', 'left', 'arrow', '‹' ),
376 fc_button('next', 'right', 'arrow', '›' ),
377 { tag: 'span', cls: 'fc-header-space' },
378 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
386 cls : 'fc-header-center',
390 cls: 'fc-header-title',
393 html : 'month / year'
401 cls : 'fc-header-right',
403 /* fc_button('month', 'left', '', 'month' ),
404 fc_button('week', '', '', 'week' ),
405 fc_button('day', 'right', '', 'day' )
417 var cal_heads = function() {
419 // fixme - handle this.
421 for (var i =0; i < Date.dayNames.length; i++) {
422 var d = Date.dayNames[i];
425 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
426 html : d.substring(0,3)
430 ret[0].cls += ' fc-first';
431 ret[6].cls += ' fc-last';
434 var cal_cell = function(n) {
437 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
442 cls: 'fc-day-number',
446 cls: 'fc-day-content',
450 style: 'position: relative;' // height: 17px;
462 var cal_rows = function() {
465 for (var r = 0; r < 6; r++) {
472 for (var i =0; i < Date.dayNames.length; i++) {
473 var d = Date.dayNames[i];
474 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
477 row.cn[0].cls+=' fc-first';
478 row.cn[0].cn[0].style = 'min-height:90px';
479 row.cn[6].cls+=' fc-last';
483 ret[0].cls += ' fc-first';
484 ret[4].cls += ' fc-prev-last';
485 ret[5].cls += ' fc-last';
492 cls: 'fc-border-separate',
493 style : 'width:100%',
501 cls : 'fc-first fc-last',
520 style : "position: relative;",
523 cls : 'fc-view fc-view-month fc-grid',
524 style : 'position: relative',
528 cls : 'fc-event-container',
529 style : 'position:absolute;z-index:8;top:0;left:0;'
547 initEvents : function()
550 throw "can not find store for calendar";
553 this.store = Roo.factory(this.store, Roo.data);
554 this.store.on('load', this.onLoad, this);
558 this.cells = this.el.select('.fc-day',true);
559 //Roo.log(this.cells);
560 this.textNodes = this.el.query('.fc-day-number');
561 this.cells.addClassOnOver('fc-state-hover');
563 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
564 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
565 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
566 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
568 this.on('monthchange', this.onMonthChange, this);
570 this.update(new Date().clearTime());
573 resize : function() {
574 var sz = this.el.getSize();
576 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
577 this.el.select('.fc-day-content div',true).setHeight(34);
582 showPrevMonth : function(e){
583 this.update(this.activeDate.add("mo", -1));
585 showToday : function(e){
586 this.update(new Date().clearTime());
589 showNextMonth : function(e){
590 this.update(this.activeDate.add("mo", 1));
594 showPrevYear : function(){
595 this.update(this.activeDate.add("y", -1));
599 showNextYear : function(){
600 this.update(this.activeDate.add("y", 1));
605 update : function(date)
607 var vd = this.activeDate;
608 this.activeDate = date;
609 // if(vd && this.el){
610 // var t = date.getTime();
611 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
612 // Roo.log('using add remove');
614 // this.fireEvent('monthchange', this, date);
616 // this.cells.removeClass("fc-state-highlight");
617 // this.cells.each(function(c){
618 // if(c.dateValue == t){
619 // c.addClass("fc-state-highlight");
620 // setTimeout(function(){
621 // try{c.dom.firstChild.focus();}catch(e){}
631 var days = date.getDaysInMonth();
633 var firstOfMonth = date.getFirstDateOfMonth();
634 var startingPos = firstOfMonth.getDay()-this.startDay;
636 if(startingPos < this.startDay){
640 var pm = date.add(Date.MONTH, -1);
641 var prevStart = pm.getDaysInMonth()-startingPos;
643 this.cells = this.el.select('.fc-day',true);
644 this.textNodes = this.el.query('.fc-day-number');
645 this.cells.addClassOnOver('fc-state-hover');
647 var cells = this.cells.elements;
648 var textEls = this.textNodes;
650 Roo.each(cells, function(cell){
651 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
656 // convert everything to numbers so it's fast
658 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
661 //Roo.log(prevStart);
663 var today = new Date().clearTime().getTime();
664 var sel = date.clearTime().getTime();
665 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
666 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
667 var ddMatch = this.disabledDatesRE;
668 var ddText = this.disabledDatesText;
669 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
670 var ddaysText = this.disabledDaysText;
671 var format = this.format;
673 var setCellClass = function(cal, cell){
675 //Roo.log('set Cell Class');
683 cell.className += " fc-today";
684 cell.className += " fc-state-highlight";
685 cell.title = cal.todayText;
688 // disable highlight in other month..
689 //cell.className += " fc-state-highlight";
694 cell.className = " fc-state-disabled";
695 cell.title = cal.minText;
699 cell.className = " fc-state-disabled";
700 cell.title = cal.maxText;
704 if(ddays.indexOf(d.getDay()) != -1){
705 cell.title = ddaysText;
706 cell.className = " fc-state-disabled";
709 if(ddMatch && format){
710 var fvalue = d.dateFormat(format);
711 if(ddMatch.test(fvalue)){
712 cell.title = ddText.replace("%0", fvalue);
713 cell.className = " fc-state-disabled";
717 if (!cell.initialClassName) {
718 cell.initialClassName = cell.dom.className;
721 cell.dom.className = cell.initialClassName + ' ' + cell.className;
726 for(; i < startingPos; i++) {
727 textEls[i].innerHTML = (++prevStart);
728 d.setDate(d.getDate()+1);
730 cells[i].className = "fc-past fc-other-month";
731 setCellClass(this, cells[i]);
736 for(; i < days; i++){
737 intDay = i - startingPos + 1;
738 textEls[i].innerHTML = (intDay);
739 d.setDate(d.getDate()+1);
741 cells[i].className = ''; // "x-date-active";
742 setCellClass(this, cells[i]);
747 textEls[i].innerHTML = (++extraDays);
748 d.setDate(d.getDate()+1);
750 cells[i].className = "fc-future fc-other-month";
751 setCellClass(this, cells[i]);
754 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
756 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
758 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
759 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
762 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
763 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
766 this.fireEvent('monthchange', this, date);
770 if(!this.internalRender){
771 var main = this.el.dom.firstChild;
772 var w = main.offsetWidth;
773 this.el.setWidth(w + this.el.getBorderWidth("lr"));
774 Roo.fly(main).setWidth(w);
775 this.internalRender = true;
776 // opera does not respect the auto grow header center column
777 // then, after it gets a width opera refuses to recalculate
778 // without a second pass
779 if(Roo.isOpera && !this.secondPass){
780 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
781 this.secondPass = true;
782 this.update.defer(10, this, [date]);
789 findCell : function(dt) {
790 dt = dt.clearTime().getTime();
792 this.cells.each(function(c){
793 //Roo.log("check " +c.dateValue + '?=' + dt);
794 if(c.dateValue == dt){
804 findCells : function(ev) {
805 var s = ev.start.clone().clearTime().getTime();
807 var e= ev.end.clone().clearTime().getTime();
810 this.cells.each(function(c){
811 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
825 findBestRow: function(cells)
829 for (var i =0 ; i < cells.length;i++) {
830 ret = Math.max(cells[i].rows || 0,ret);
837 addItem : function(ev)
839 // look for vertical location slot in
840 var cells = this.findCells(ev);
842 ev.row = this.findBestRow(cells);
844 // work out the location.
848 for(var i =0; i < cells.length; i++) {
856 if (crow.start.getY() == cells[i].getY()) {
874 for (var i = 0; i < cells.length;i++) {
875 cells[i].rows = Math.max(cells[i].rows || 0 , ev.row + 1 );
879 this.calevents.push(ev);
882 clearEvents: function() {
888 Roo.each(this.cells.elements, function(c){
892 Roo.each(this.calevents, function(e) {
893 Roo.each(e.els, function(el) {
894 el.un('mouseenter' ,this.onEventEnter, this);
895 el.un('mouseleave' ,this.onEventLeave, this);
902 renderEvents: function()
904 // first make sure there is enough space..
906 this.cells.each(function(c) {
908 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.rows * 20));
911 for (var e = 0; e < this.calevents.length; e++) {
912 var ev = this.calevents[e];
913 var cells = ev.cells;
916 for(var i =0; i < rows.length; i++) {
919 // how many rows should it span..
922 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
923 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
928 cls: 'fc-event-inner',
932 cls: 'fc-event-time',
933 html : cells.length > 1 ? '' : ev.time
937 cls: 'fc-event-title',
938 html : String.format('{0}', ev.title)
945 cls: 'ui-resizable-handle ui-resizable-e',
946 html : '  '
952 cfg.cls += ' fc-event-start';
954 if ((i+1) == rows.length) {
955 cfg.cls += ' fc-event-end';
958 var ctr = this.el.select('.fc-event-container',true).first();
959 var cg = ctr.createChild(cfg);
961 cg.on('mouseenter' ,this.onEventEnter, this, ev);
962 cg.on('mouseleave' ,this.onEventLeave, this, ev);
963 cg.on('click', this.onEventClick, this, ev);
967 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
968 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
970 cg.setXY([sbox.x +2, sbox.y +(ev.row * 20)]);
971 cg.setWidth(ebox.right - sbox.x -2);
979 onEventEnter: function (e, el,event,d) {
980 this.fireEvent('evententer', this, el, event);
983 onEventLeave: function (e, el,event,d) {
984 this.fireEvent('eventleave', this, el, event);
987 onEventClick: function (e, el,event,d) {
988 this.fireEvent('eventclick', this, el, event);
991 onMonthChange: function () {
995 onLoad: function () {
998 //Roo.log('calendar onload');
1000 this.calevents = [];
1002 if(this.store.getCount() > 0){
1003 this.store.data.each(function(d){
1006 start: new Date(d.data.start_dt),
1007 end : new Date(d.data.end_dt),
1008 time : d.data.start_time,
1009 title : d.data.title,
1010 description : d.data.description,
1011 venue : d.data.venue
1016 this.renderEvents();
1024 * based on jquery fullcalendar
1030 * @class Roo.Calendar
1031 * @extends Roo.Component
1032 * Bootstrap Calendar class
1035 * Create a new Container
1036 * @param {Object} config The config object
1039 Roo.CalendarPanel = function(config){
1041 Roo.log("cal panel ctr");
1043 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
1044 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
1046 //this.wrapper.dom.appendChild(grid.getGridEl().dom);
1048 Roo.CalendarPanel.superclass.constructor.call(this, this.wrapper, config);
1053 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
1055 // xtype created footer. - not sure if will work as we normally have to render first..
1056 if (this.footer && !this.footer.el && this.footer.xtype) {
1058 //this.footer.container = this.grid.getView().getFooterPanel(true);
1059 //this.footer.dataSource = this.grid.dataSource;
1060 //this.footer = Roo.factory(this.footer, Roo);
1063 this.view = new Roo.calendar.View(Roo.apply({
1064 skipNavHeader : true,
1065 skipMonthHeader : false
1070 this.on('activate', function()
1072 Roo.log('activate');
1074 //console.log('render tree');
1081 * Fires when a date is selected
1082 * @param {DatePicker} this
1083 * @param {Date} date The selected date
1087 * @event monthchange
1088 * Fires when the displayed month changes
1089 * @param {DatePicker} this
1090 * @param {Date} date The selected month
1092 'monthchange': true,
1095 * Fires when mouse over an event
1096 * @param {Calendar} this
1097 * @param {event} Event
1102 * Fires when the mouse leaves an
1103 * @param {Calendar} this
1109 * Fires when the mouse click an
1110 * @param {Calendar} this
1116 * Fires when the grid is rendered
1117 * @param {Calendar} this
1124 this.relayEvents(this.view, ["select","monthchange","evententer","eventleave","rendered"]);
1127 //this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
1131 Roo.extend(Roo.CalendarPanel, Roo.ContentPanel, {
1136 var ct = this.el.appendChild(document.createElement("div"));
1137 this.onRender(this.el, false)
1140 onRender : function(ct, position)
1142 if (this.rendered) {
1145 this.rendered = true;
1147 Roo.log("render calendar");
1150 //Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
1153 var cfg = Roo.apply({}, this.view.getAutoCreate());
1156 // fill in the extra attributes
1157 if (this.xattr && typeof(this.xattr) =='object') {
1158 for (var i in this.xattr) {
1159 cfg[i] = this.xattr[i];
1164 cfg.dataId = this.dataId;
1168 cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
1171 if (this.style) { // fixme needs to support more complex style data.
1172 cfg.style = this.style;
1176 cfg.name = this.name;
1179 this.view.el = ct.createChild(cfg, position);
1181 //if(this.tabIndex !== undefined){
1182 // this.el.dom.setAttribute('tabIndex', this.tabIndex);
1186 this.view.initEvents();
1187 this.fireEvent('rendered');