Skip to content

Commit

Permalink
calendar MDL-21240 Converted calendar JS to YUI3 module
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Jan 22, 2010
1 parent 840912d commit bdbae76
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 33 deletions.
2 changes: 1 addition & 1 deletion blocks/calendar_month/block_calendar_month.php
Expand Up @@ -60,7 +60,7 @@ function get_content() {
// Be VERY careful with the format for default courses arguments!
// Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false);
$this->page->requires->js('/calendar/calendar.js');
$this->page->requires->js_module('blocks_calendar', array('fullpath'=>$CFG->wwwroot.'/calendar/calendar.js', 'requires'=>array('dom', 'event', 'node', 'yui2-animation')));
if ($courseshown == SITEID) {
// For the front page
$this->content->text .= calendar_top_controls('frontpage', array('id' => $courseshown, 'm' => $cal_m, 'y' => $cal_y));
Expand Down
39 changes: 15 additions & 24 deletions calendar/calendar.js
Expand Up @@ -2,36 +2,27 @@
* Define a blocks namespace if it has not already been defined
* @namespace
*/
var blocks = blocks || {};
M = M || {};
M.blocks = M.blocks || {};

/**
* A calendar namespace for the calendar block
* @namespace
*/
blocks.calendar = {
M.blocks.calendar = {
// The seconds to delay the show of a calendar event by
showdelaysecs: 1,
// The calendar event currently pending display
showdelayevent: null,
// An array containing all calendar events
events : [],
/**
* Adds a new event
* @function
* @param {object} properties
*/
add_event: function(properties) {
Y.use('dom', 'event', 'node', function(){
blocks.calendar.events[properties.id] = new blocks.calendarevent(properties);
});
},
/**
* Callback function for the showback method
* @function
*/
show_event_callback : function() {
if (blocks.calendar.showdelayevent !== null) {
blocks.calendar.events[blocks.calendar.showdelayevent].show();
if (M.blocks.calendar.showdelayevent !== null) {
M.blocks.calendar.events[M.blocks.calendar.showdelayevent].show();
}
}
}
Expand All @@ -41,7 +32,7 @@ blocks.calendar = {
* @class
* @constructor
*/
blocks.calendarevent = function(properties) {
M.blocks.calendar.event = function(properties) {
this.id = properties.id;
this.title = properties.title;
this.content = properties.content;
Expand All @@ -56,8 +47,8 @@ blocks.calendarevent = function(properties) {
* Hides the events panel if it is being displayed
* @function
*/
blocks.calendarevent.prototype.hide = function(e) {
blocks.calendar.showdelayevent = null;
M.blocks.calendar.event.prototype.hide = function(e) {
M.blocks.calendar.showdelayevent = null;
if (this.displayed) {
this.displayed = false;
this.panel.hide();
Expand All @@ -69,21 +60,21 @@ blocks.calendarevent.prototype.hide = function(e) {
* @function
* @param {event} e
*/
blocks.calendarevent.prototype.show_init = function(e) {
if (blocks.calendar.showdelayevent !== this.id) {
if (blocks.calendar.showdelayevent !== null) {
blocks.calendar.events[blocks.calendar.showdelayevent].hide(e);
M.blocks.calendar.event.prototype.show_init = function(e) {
if (M.blocks.calendar.showdelayevent !== this.id) {
if (M.blocks.calendar.showdelayevent !== null) {
M.blocks.calendar.events[M.blocks.calendar.showdelayevent].hide(e);
}
blocks.calendar.showdelayevent = this.id;
setTimeout(blocks.calendar.show_event_callback, blocks.calendar.showdelaysecs*1000);
M.blocks.calendar.showdelayevent = this.id;
setTimeout(M.blocks.calendar.show_event_callback, M.blocks.calendar.showdelaysecs*1000);
}
}

/**
* Shows the calendar event
* @function
*/
blocks.calendarevent.prototype.show = function() {
M.blocks.calendar.event.prototype.show = function() {
this.panel = new YAHOO.widget.Panel(this.id+'_panel', {
width:"240px",
visible:false,
Expand Down
9 changes: 4 additions & 5 deletions calendar/event.php
Expand Up @@ -186,22 +186,21 @@
$data->timeduration = $data->timedurationminutes * MINSECS;
} else {
$data->timeduration = 0;
}
}

$event->update($data);
$eventurl = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'day'));
if (!empty($event->courseid)) {
$eventurl->param('course', $event->courseid);
}
}
$eventurl->param('cal_d', date('j', $event->timestart));
$eventurl->param('cal_m', date('n', $event->timestart));
$eventurl->param('cal_y', date('Y', $event->timestart));
$eventurl->set_anchor('event_'.$event->id);
redirect($eventurl);
}
}

$PAGE->requires->yui2_lib('animation');
$PAGE->requires->js('/calendar/calendar.js');
$PAGE->requires->js_module('blocks_calendar', array('fullpath'=>$CFG->wwwroot.'/calendar/calendar.js', 'requires'=>array('dom', 'event', 'node', 'yui2-animation','event-mouseenter')));

$PAGE->navbar->add($strcalendar, $link);
$PAGE->navbar->add($title);
Expand Down
4 changes: 3 additions & 1 deletion calendar/lib.php
Expand Up @@ -380,7 +380,9 @@ function calendar_get_popup($is_today, $event_timestart, $popupcontent='') {
}
$id = 'calendar_tooltip_'.$popupcount;
$PAGE->requires->yui2_lib('container');
$PAGE->requires->js_function_call('blocks.calendar.add_event', Array(Array('id'=>$id,'title'=>$popupcaption, 'content'=>$popupcontent)))->on_dom_ready();

$PAGE->requires->js_object_init("M.blocks.calendar.events['$id']", 'M.blocks.calendar.event', array(array('id'=>$id,'title'=>$popupcaption, 'content'=>$popupcontent)), array('blocks_calendar'));

$popupcount++;
return 'id="'.$id.'"';
}
Expand Down
3 changes: 1 addition & 2 deletions calendar/view.php
Expand Up @@ -154,8 +154,7 @@
$PAGE->set_heading($strcalendar);
$PAGE->set_button($prefsbutton);

$PAGE->requires->yui2_lib('animation');
$PAGE->requires->js('/calendar/calendar.js');
$PAGE->requires->js_module('blocks_calendar', array('fullpath'=>$CFG->wwwroot.'/calendar/calendar.js', 'requires'=>array('dom', 'event', 'node', 'yui2-animation','event-mouseenter')));

echo $OUTPUT->header();

Expand Down

0 comments on commit bdbae76

Please sign in to comment.