function render() { if (!$this->name) { throw new \Exception('must set a name'); } $header = XhtmlHeader::getInstance(); $header->includeCss('core_dev/js/ext/yui/2.9.0/build/calendar/assets/skins/sam/calendar.css'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/calendar/calendar-min.js'); $locale = LocaleHandler::getInstance(); $div_holder = 'yui_date_hold' . mt_rand(); $res = 'YAHOO.namespace("example.calendar");' . 'YAHOO.example.calendar.init = function() {' . 'var inTxt = YAHOO.util.Dom.get("' . $this->name . '");' . ($this->selected_date ? 'inTxt.value = "' . sql_date($this->selected_date) . '";' : '') . 'var cal = YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("' . $div_holder . '");' . ($this->selected_date ? 'cal.cfg.setProperty("selected", "' . js_date($this->selected_date) . '");' . 'cal.cfg.setProperty("pagedate", "' . date('n/Y', $this->selected_date) . '");' : '') . 'cal.cfg.setProperty("start_weekday",' . $this->start_weekday . ');' . 'cal.cfg.setProperty("MONTHS_SHORT",' . Json::encode($locale->handle->month_short, false) . ');' . 'cal.cfg.setProperty("MONTHS_LONG",' . Json::encode($locale->handle->month_long, false) . ');' . 'cal.cfg.setProperty("WEEKDAYS_1CHAR",' . Json::encode($locale->handle->weekday_1char, false) . ');' . 'cal.cfg.setProperty("WEEKDAYS_SHORT",' . Json::encode($locale->handle->weekday_short, false) . ');' . 'cal.cfg.setProperty("WEEKDAYS_MEDIUM",' . Json::encode($locale->handle->weekday_medium, false) . ');' . 'cal.cfg.setProperty("WEEKDAYS_LONG",' . Json::encode($locale->handle->weekday_long, false) . ');' . 'cal.selectEvent.subscribe(function() {' . 'var dates = this.getSelectedDates();' . 'var inDate = dates[0];' . 'inTxt.value = inDate.getFullYear() + "-" + (inDate.getMonth() + 1) + "-" + inDate.getDate();' . '}, cal, true);' . 'cal.render();' . '}' . "\n" . 'YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);'; return '<div id="' . $div_holder . '"></div>' . '<div style="clear:both"></div>' . xhtmlInput($this->name) . '<br/>' . js_embed($res); }
function render() { if (!$this->name) { throw new \Exception('name must be configured'); } $header = XhtmlHeader::getInstance(); $header->includeCss('core_dev/js/ext/yui/2.9.0/build/calendar/assets/skins/sam/calendar.css'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/calendar/calendar-min.js'); $res = '(function()' . '{' . 'function IntervalCalendar(container, cfg)' . '{' . 'this._iState = 0;' . 'cfg = cfg || {};' . 'cfg.multi_select = true;' . 'IntervalCalendar.superclass.constructor.call(this, container, cfg);' . 'this.beforeSelectEvent.subscribe(this._intervalOnBeforeSelect, this, true);' . 'this.selectEvent.subscribe(this._intervalOnSelect, this, true);' . 'this.beforeDeselectEvent.subscribe(this._intervalOnBeforeDeselect, this, true);' . 'this.deselectEvent.subscribe(this._intervalOnDeselect, this, true);' . '}' . 'IntervalCalendar._DEFAULT_CONFIG = YAHOO.widget.CalendarGroup._DEFAULT_CONFIG;' . 'YAHOO.lang.extend(IntervalCalendar, YAHOO.widget.CalendarGroup,' . '{' . '_dateString : function(d) {' . 'var a = [];' . 'a[this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.MDY_MONTH_POSITION.key)-1] = (d.getMonth() + 1);' . 'a[this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.MDY_DAY_POSITION.key)-1] = d.getDate();' . 'a[this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.MDY_YEAR_POSITION.key)-1] = d.getFullYear();' . 'var s = this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.DATE_FIELD_DELIMITER.key);' . 'return a.join(s);' . '},' . '_dateIntervalString : function(l, u) {' . 'var s = this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.DATE_RANGE_DELIMITER.key);' . 'return (this._dateString(l) + s + this._dateString(u));' . '},' . 'getInterval : function() {' . 'var dates = this.getSelectedDates();' . 'if(dates.length > 0) {' . 'var l = dates[0];' . 'var u = dates[dates.length - 1];' . 'return [l, u];' . '} else {' . 'return [];' . '}' . '},' . 'setInterval : function(d1, d2) {' . 'var b = (d1 <= d2);' . 'var l = b ? d1 : d2;' . 'var u = b ? d2 : d1;' . 'this.cfg.setProperty("selected", this._dateIntervalString(l, u), false);' . 'this._iState = 2;' . '},' . 'resetInterval : function() {' . 'this.cfg.setProperty("selected", [], false);' . 'this._iState = 0;' . '},' . '_intervalOnBeforeSelect : function(t,a,o) {' . 'this._iState = (this._iState + 1) % 3;' . 'if(this._iState == 0) {' . 'this.deselectAll();' . 'this._iState++;' . '}' . '},' . '_intervalOnSelect : function(t,a,o) {' . 'var dates = this.getSelectedDates();' . 'if(dates.length > 1) {' . 'var l = dates[0];' . 'var u = dates[dates.length - 1];' . 'this.cfg.setProperty("selected", this._dateIntervalString(l, u), false);' . '}' . 'this.render();' . '},' . '_intervalOnBeforeDeselect : function(t,a,o) {' . 'if(this._iState != 0) {' . 'return false;' . '}' . '},' . '_intervalOnDeselect : function(t,a,o) {' . 'if(this._iState != 0) {' . 'this._iState = 0;' . 'this.deselectAll();' . 'var d = a[0];' . 'var date = YAHOO.widget.DateMath.getDate(d[0], d[1] - 1, d[2]);' . 'var page = this.getCalendarPage(date);' . 'if(page) {' . 'page.beforeSelectEvent.fire();' . 'this.cfg.setProperty("selected", this._dateString(date), false);' . 'page.selectEvent.fire([d]);' . '}' . 'return false;' . '}' . '}' . '});' . 'YAHOO.namespace("example.calendar");' . 'YAHOO.example.calendar.IntervalCalendar = IntervalCalendar;' . '})();'; $locale = LocaleHandler::getInstance(); $div_holder = 'yui_di_hold' . mt_rand(); $res .= 'YAHOO.util.Event.onDOMReady(function()' . '{' . 'var inTxt = YAHOO.util.Dom.get("' . $this->name . '_from");' . 'var outTxt = YAHOO.util.Dom.get("' . $this->name . '_to");' . 'var inDate, outDate, interval;' . ($this->select_from ? 'inTxt.value = "' . sql_date($this->select_from) . '";' : '') . ($this->select_to ? 'outTxt.value = "' . sql_date($this->select_to) . '";' : '') . 'var myConfigs =' . '{' . 'pages:2,' . ($this->select_from && $this->select_to ? 'selected:"' . js_date($this->select_from) . '-' . js_date($this->select_to) . '",' . 'pagedate:"' . date('n/Y', $this->select_from) . '",' : '') . 'start_weekday:' . $this->start_weekday . ',' . 'MONTHS_SHORT:' . Json::encode($locale->handle->month_short, false) . ',' . 'MONTHS_LONG:' . Json::encode($locale->handle->month_long, false) . ',' . 'WEEKDAYS_1CHAR:' . Json::encode($locale->handle->weekday_1char, false) . ',' . 'WEEKDAYS_SHORT:' . Json::encode($locale->handle->weekday_short, false) . ',' . 'WEEKDAYS_MEDIUM:' . Json::encode($locale->handle->weekday_medium, false) . ',' . 'WEEKDAYS_LONG:' . Json::encode($locale->handle->weekday_long, false) . ',' . '};' . 'var cal = new YAHOO.example.calendar.IntervalCalendar("' . $div_holder . '",myConfigs);' . 'cal.selectEvent.subscribe(function()' . '{' . 'interval = this.getInterval();' . 'if (interval.length == 2) {' . 'inDate = interval[0];' . 'inTxt.value = inDate.getFullYear() + "-" + (inDate.getMonth() + 1) + "-" + inDate.getDate();' . 'if (interval[0].getTime() != interval[1].getTime()) {' . 'outDate = interval[1];' . 'outTxt.value = outDate.getFullYear() + "-" + (outDate.getMonth() + 1) + "-" + outDate.getDate();' . '} else {' . 'outTxt.value = "";' . '}' . '}' . '}, cal, true);' . 'cal.render();' . '});'; return '<div id="' . $div_holder . '"></div>' . '<div style="clear:both"></div>' . js_embed($res) . xhtmlInput($this->name . '_from') . ' - ' . xhtmlInput($this->name . '_to'); }
function render() { if (!$this->name) { throw new \Exception('must set a name'); } $header = XhtmlHeader::getInstance(); $header->includeCss('core_dev/js/ext/yui/2.9.0/build/fonts/fonts-min.css'); $header->includeCss('core_dev/js/ext/yui/2.9.0/build/button/assets/skins/sam/button.css'); $header->includeCss('core_dev/js/ext/yui/2.9.0/build/container/assets/skins/sam/container.css'); $header->includeCss('core_dev/js/ext/yui/2.9.0/build/calendar/assets/skins/sam/calendar.css'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/dragdrop/dragdrop-min.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/element/element-min.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/button/button-min.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/container/container-min.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/calendar/calendar-min.js'); $header->embedCss('#container .bd form {' . 'clear:left;' . '}' . '#container .bd {' . 'padding:0;' . '}' . '#container .hd {' . 'text-align:left;' . '}' . '#container .ft .button-group {' . 'text-align:center;' . '}' . '#container_c.yui-overlay-hidden table {' . '*display:none;' . '}' . '#cal {' . 'border:none;' . 'padding:1em;' . '}'); $locale = LocaleHandler::getInstance(); $button_name = 'yui_dp_show_' . mt_rand(); $res = 'YAHOO.util.Event.onDOMReady(function(){' . 'var Event = YAHOO.util.Event,' . 'Dom = YAHOO.util.Dom,' . 'dialog,' . 'calendar;' . 'var showBtn = Dom.get("' . $button_name . '");' . 'Event.on(showBtn, "click", function() {' . 'if (!dialog) {' . 'Event.on(document, "click", function(e) {' . 'var el = Event.getTarget(e);' . 'var dialogEl = dialog.element;' . 'if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn && !Dom.isAncestor(showBtn, el)) {' . 'dialog.hide();' . '}' . '});' . 'function resetHandler() {' . 'var selDates = calendar.getSelectedDates();' . 'var resetDate;' . 'if (selDates.length > 0) {' . 'resetDate = selDates[0];' . '} else {' . 'resetDate = calendar.today;' . '}' . 'calendar.cfg.setProperty("pagedate", resetDate);' . 'calendar.render();' . '}' . 'function closeHandler() {' . 'dialog.hide();' . '}' . 'dialog = new YAHOO.widget.Dialog("container", {' . 'visible:false,' . 'context:["' . $button_name . '", "tl", "bl"],' . 'buttons:[ {text:"Reset", handler: resetHandler, isDefault:true}, {text:"Close", handler: closeHandler}],' . 'draggable:false,' . 'close:true' . '});' . 'dialog.setHeader("Pick A Date");' . 'dialog.setBody(\'<div id="cal"></div>\');' . 'dialog.render(document.body);' . 'dialog.showEvent.subscribe(function() {' . 'if (YAHOO.env.ua.ie) {' . 'dialog.fireEvent("changeContent");' . '}' . '});' . '}' . 'if (!calendar) {' . 'calendar = new YAHOO.widget.Calendar("cal", {' . 'iframe:false,' . 'hide_blank_weeks:true,' . ($this->selected_date ? 'selected:"' . js_date($this->selected_date) . '",' . 'pagedate:"' . date('n/Y', $this->selected_date) . '",' : '') . 'start_weekday:' . $this->start_weekday . ',' . 'MONTHS_SHORT:' . Json::encode($locale->handle->month_short, false) . ',' . 'MONTHS_LONG:' . Json::encode($locale->handle->month_long, false) . ',' . 'WEEKDAYS_1CHAR:' . Json::encode($locale->handle->weekday_1char, false) . ',' . 'WEEKDAYS_SHORT:' . Json::encode($locale->handle->weekday_short, false) . ',' . 'WEEKDAYS_MEDIUM:' . Json::encode($locale->handle->weekday_medium, false) . ',' . 'WEEKDAYS_LONG:' . Json::encode($locale->handle->weekday_long, false) . ',' . '});' . 'calendar.render();' . 'calendar.selectEvent.subscribe(function() {' . 'if (calendar.getSelectedDates().length > 0) {' . 'var selDate = calendar.getSelectedDates()[0];' . 'Dom.get("' . $this->name . '").value = selDate.getFullYear() + "-" + (selDate.getMonth() + 1) + "-" + selDate.getDate();' . '} else {' . 'Dom.get("' . $this->name . '").value = "";' . '}' . 'dialog.hide();' . '});' . 'calendar.renderEvent.subscribe(function() {' . 'dialog.fireEvent("changeContent");' . '});' . '}' . 'var seldate = calendar.getSelectedDates();' . 'if (seldate.length > 0) {' . 'calendar.cfg.setProperty("pagedate", seldate[0]);' . 'calendar.render();' . '}' . 'dialog.show();' . '});' . '});'; return xhtmlInput($this->name, sql_date($this->selected_date), 8) . ' ' . '<button type="button" id="' . $button_name . '" title="Pick a date">' . '<img src="' . relurl('core_dev/gfx/icon_date-picker.png') . '" alt="Pick a date"/>' . '</button>' . js_embed($res); }