MDL-57557 calendar: convert from yui module to bootstrap popovers
authorDan Poltawski <dan@moodle.com>
Mon, 2 Jan 2017 17:05:28 +0000 (17:05 +0000)
committerDan Poltawski <dan@moodle.com>
Fri, 17 Feb 2017 14:05:29 +0000 (14:05 +0000)
calendar/lib.php
calendar/templates/minicalendar_day_link.mustache [new file with mode: 0644]
theme/boost/templates/core_calendar/minicalendar_day_link.mustache [new file with mode: 0644]
theme/bootstrapbase/templates/core_calendar/minicalendar_day_link.mustache [new file with mode: 0644]

index f1e09a0..ddf2a8c 100644 (file)
@@ -420,7 +420,6 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
             } else {
                 $popupdata = calendar_get_popup(false, $daytime, $popupcontent);
             }
-            $cellattributes = array_merge($cellattributes, $popupdata);
 
             // Class and cell content
             if(isset($typesbyday[$day]['startglobal'])) {
@@ -435,7 +434,14 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
             if ($finishclass) {
                 $class .= ' duration_finish';
             }
-            $cell = html_writer::link($dayhref, $day);
+
+            $data = array(
+                'url' => $dayhref,
+                'day' => $day,
+                'content' => $popupdata['data-core_calendar-popupcontent'],
+                'title' => $popupdata['data-core_calendar-title']
+            );
+            $cell = $OUTPUT->render_from_template('core_calendar/minicalendar_day_link', $data);
         } else {
             $cell = $day;
         }
@@ -477,8 +483,13 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
             if (!isset($eventsbyday[$day]) && !isset($durationbyday[$day])) {
                 $class .= ' eventnone';
                 $popupdata = calendar_get_popup(true, false);
-                $cellattributes = array_merge($cellattributes, $popupdata);
-                $cell = html_writer::link('#', $day);
+                $data = array(
+                    'url' => '#',
+                    'day' => $day,
+                    'content' => $popupdata['data-core_calendar-popupcontent'],
+                    'title' => $popupdata['data-core_calendar-title']
+                );
+                $cell = $OUTPUT->render_from_template('core_calendar/minicalendar_day_link', $data);
             }
             $cell = get_accesshide($today . ' ') . $cell;
         }
@@ -495,12 +506,6 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
     $content .= '</tr>'; // Last row ends
 
     $content .= '</table>'; // Tabular display of days ends
-
-    static $jsincluded = false;
-    if (!$jsincluded) {
-        $PAGE->requires->yui_module('moodle-calendar-info', 'Y.M.core_calendar.info.init');
-        $jsincluded = true;
-    }
     return $content;
 }
 
diff --git a/calendar/templates/minicalendar_day_link.mustache b/calendar/templates/minicalendar_day_link.mustache
new file mode 100644 (file)
index 0000000..bdb5e67
--- /dev/null
@@ -0,0 +1,38 @@
+{{!
+    This file is part of Moodle - http://moodle.org/
+
+    Moodle is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Moodle is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+}}
+{{!
+    @template core_calendar/minicalendar_day_link
+
+    Displays link to calendar day in mini calendar, with hover tooltip.
+
+    Example context (json):
+    {
+        "day": "Today",
+        "url": "http://example.com/",
+        "title": "Monday 2nd January",
+        "content": "<img class='icon smallicon' alt='icon' src='../../../pix/i/siteevent.svg'>Test site event"
+    }
+}}
+{{< core/hover_tooltip }}
+    {{$anchor}}
+        <a href="{{url}}">{{day}}</a>
+    {{/anchor}}
+    {{$tooltip}}
+        <b>{{title}}</b>
+        {{{content}}}
+    {{/tooltip}}
+{{/ core/hover_tooltip }}
diff --git a/theme/boost/templates/core_calendar/minicalendar_day_link.mustache b/theme/boost/templates/core_calendar/minicalendar_day_link.mustache
new file mode 100644 (file)
index 0000000..d4ce07c
--- /dev/null
@@ -0,0 +1,38 @@
+{{!
+    This file is part of Moodle - http://moodle.org/
+
+    Moodle is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Moodle is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+}}
+{{!
+    @template core_calendar/minicalendar_day_link
+
+    Displays link to calendar day in mini calendar, with hover tooltip.
+
+    Example context (json):
+    {
+        "day": "Today",
+        "url": "http://example.com/",
+        "title": "Monday 2nd January",
+        "content": "<img class='icon smallicon' src='../../../pix/i/siteevent.svg'>Test site event"
+    }
+}}
+<a href="{{url}}"
+    data-container="body"
+    data-toggle="popover"
+    data-html="true"
+    data-trigger="hover"
+    data-placement="top"
+    data-title="{{title}}"
+    data-content="{{content}}"
+>{{day}}</a>
diff --git a/theme/bootstrapbase/templates/core_calendar/minicalendar_day_link.mustache b/theme/bootstrapbase/templates/core_calendar/minicalendar_day_link.mustache
new file mode 100644 (file)
index 0000000..c3a0034
--- /dev/null
@@ -0,0 +1,44 @@
+{{!
+    This file is part of Moodle - http://moodle.org/
+
+    Moodle is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Moodle is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+}}
+{{!
+    @template core_calendar/minicalendar_day_link
+
+    Displays link to calendar day in mini calendar, with hover tooltip.
+
+    Example context (json):
+    {
+        "day": "Today",
+        "url": "http://example.com/",
+        "title": "Monday 2nd January",
+        "content": "<img class='icon smallicon' src='../../../pix/i/siteevent.svg'>Test site event"
+    }
+}}
+<a id="{{uniqid}}" href="{{url}}"
+    data-container="body"
+    data-toggle="popover"
+    data-html="true"
+    data-trigger="hover"
+    data-placement="top"
+    data-title="{{title}}"
+    data-content="{{content}}">{{day}}</a>
+{{#js}}
+require(['jquery'], function($) {
+    require(['theme_bootstrapbase/bootstrap'], function() {
+        $('#{{uniqid}}').popover();
+    });
+});
+{{/js}}