MDL-59392 calendar: Move template to parent Node

This commit is contained in:
Andrew Nicols 2017-09-05 15:14:54 +08:00
parent 6397ec5452
commit 2281a835c9
5 changed files with 44 additions and 4 deletions

View File

@ -1 +1 @@
define(["jquery","core/templates","core/notification","core_calendar/repository","core_calendar/events"],function(a,b,c,d,e){var f={ROOT:"[data-region='calendar']",CALENDAR_NAV_LINK:".calendarwrapper .arrow_link",CALENDAR_MONTH_WRAPPER:".calendarwrapper",LOADING_ICON_CONTAINER:'[data-region="overlay-icon-container"]'},g=function(b){b=a(b),b.on("click",f.CALENDAR_NAV_LINK,function(c){var d=a(b).find(f.CALENDAR_MONTH_WRAPPER).data("courseid"),e=a(c.currentTarget);i(b,e.attr("href"),e.data("time"),d),c.preventDefault()})},h=function(a,e,g){return k(a),d.getCalendarMonthData(e,g).then(function(a){return b.render("core_calendar/month_detailed",a)}).then(function(c,d){return b.replaceNode(a.find(f.CALENDAR_MONTH_WRAPPER),c,d)}).always(function(){return l(a)}).fail(c.exception)},i=function(b,c,d,f){return h(b,d,f).then(function(){return window.history.pushState({},"",c),arguments}).then(function(){return a("body").trigger(e.monthChanged,[d,f]),arguments})},j=function(a,b){var c=a.find(f.CALENDAR_MONTH_WRAPPER).data("current-time");return b||(b=a.find(f.CALENDAR_MONTH_WRAPPER).data("courseid")),h(a,c,b)},k=function(a){var b=a.find(f.LOADING_ICON_CONTAINER);b.removeClass("hidden")},l=function(a){var b=a.find(f.LOADING_ICON_CONTAINER);b.addClass("hidden")};return{init:function(a){g(a)},reloadCurrentMonth:j,changeMonth:i,refreshMonthContent:h}});
define(["jquery","core/templates","core/notification","core_calendar/repository","core_calendar/events"],function(a,b,c,d,e){var f={ROOT:"[data-region='calendar']",CALENDAR_NAV_LINK:".calendarwrapper .arrow_link",CALENDAR_MONTH_WRAPPER:".calendarwrapper",LOADING_ICON_CONTAINER:'[data-region="overlay-icon-container"]'},g=function(b){b=a(b),b.on("click",f.CALENDAR_NAV_LINK,function(c){var d=a(b).find(f.CALENDAR_MONTH_WRAPPER).data("courseid"),e=a(c.currentTarget);i(b,e.attr("href"),e.data("time"),d),c.preventDefault()})},h=function(a,e,g){return k(a),d.getCalendarMonthData(e,g).then(function(c){return b.render(a.attr("data-template"),c)}).then(function(c,d){return b.replaceNode(a.find(f.CALENDAR_MONTH_WRAPPER),c,d)}).always(function(){return l(a)}).fail(c.exception)},i=function(b,c,d,f){return h(b,d,f).then(function(){return window.history.pushState({},"",c),arguments}).then(function(){return a("body").trigger(e.monthChanged,[d,f]),arguments})},j=function(a,b){var c=a.find(f.CALENDAR_MONTH_WRAPPER).data("current-time");return b||(b=a.find(f.CALENDAR_MONTH_WRAPPER).data("courseid")),h(a,c,b)},k=function(a){var b=a.find(f.LOADING_ICON_CONTAINER);b.removeClass("hidden")},l=function(a){var b=a.find(f.LOADING_ICON_CONTAINER);b.addClass("hidden")};return{init:function(a){g(a)},reloadCurrentMonth:j,changeMonth:i,refreshMonthContent:h}});

View File

@ -60,7 +60,7 @@ define(['jquery', 'core/templates', 'core/notification', 'core_calendar/reposito
return CalendarRepository.getCalendarMonthData(time, courseid)
.then(function(context) {
return Templates.render('core_calendar/month_detailed', context);
return Templates.render(root.attr('data-template'), context);
})
.then(function(html, js) {
return Templates.replaceNode(root.find(SELECTORS.CALENDAR_MONTH_WRAPPER), html, js);

View File

@ -3518,7 +3518,7 @@ function calendar_get_view(\calendar_information $calendar, $view) {
$month = new \core_calendar\external\month_exporter($calendar, $type, $related);
$data = $month->export($renderer);
$template = 'core_calendar/month_detailed';
$template = 'core_calendar/calendar_month';
return [$data, $template];
}

View File

@ -0,0 +1,41 @@
{{!
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 calendar/calendar_month
Calendar month view for blcoks.
The purpose of this template is to render the main, detailed monthly view.
Classes required for JS:
* none
Data attributes required for JS:
* none
Example context (json):
{
}
}}
<div id="calendar-month-{{uniqid}}" data-template="core_calendar/month_detailed">
{{> core_calendar/month_detailed}}
</div>
{{#js}}
require(['jquery', 'core_calendar/calendar'], function($, Calendar) {
Calendar.init($("#calendar-month-{{uniqid}}"));
});
{{/js}}

View File

@ -161,5 +161,4 @@ echo html_writer::end_tag('div');
list($data, $template) = calendar_get_footer_options($calendar);
echo $renderer->render_from_template($template, $data);
$PAGE->requires->js_call_amd('core_calendar/calendar', 'init');
echo $OUTPUT->footer();