diff --git a/amd/build/editcoursefab.min.js b/amd/build/editcoursefab.min.js new file mode 100644 index 0000000000000000000000000000000000000000..4f87c1b6a8d5b9f854c22db91eb1cf31d379e458 --- /dev/null +++ b/amd/build/editcoursefab.min.js @@ -0,0 +1 @@ +define(["jquery"],function($){"use strict";function editCourseFab(){if(!$(".edit-course-fab").length){return}var form,action,data,$button;form=document.querySelector(".edit-course-fab form");action=form.action.value;data={sesskey:form.sesskey.value,id:form.id.value,edit:form.edit.value};$button=$(".edit-course-fab .btn");if(data.edit==="on"){$button.html('<i class="fa fa-pencil"></i>')}else{$button.html('<i class="fa fa-pencil text-warning"></i>')}$button.click(function(event){event.preventDefault();$.post(action,data).done(function(){document.location.reload()})})}return{init:function(){editCourseFab()}}}); \ No newline at end of file diff --git a/amd/src/editcoursefab.js b/amd/src/editcoursefab.js new file mode 100644 index 0000000000000000000000000000000000000000..6120cd5f0895384559a2dbda06b8e9ca02b52d39 --- /dev/null +++ b/amd/src/editcoursefab.js @@ -0,0 +1,59 @@ +// 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/>. + +/** + * Theme Boost Campus - JS code for edit course fab + * + * @package theme_hsh_boost_campus + * @copyright 2020 Julian Wendling, Hochschule Hannover <julian.wendling@stud.hs-hannover.de> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define(['jquery'], function ($) { + "use strict"; + function editCourseFab() { + if (!$('.edit-course-fab').length) { + return; + } + var form, action, data, $button; + form = document.querySelector(".edit-course-fab form"); + action = form.action.value; + data = { + sesskey: form.sesskey.value, + id: form.id.value, + edit: form.edit.value + }; + $button = $('.edit-course-fab .btn'); + if (data.edit === "on") { + $button.html('<i class="fa fa-pencil"></i>'); + } else { + $button.html('<i class="fa fa-pencil text-warning"></i>'); + } + + $button.click(function (event) { + event.preventDefault(); + + $.post(action, data).done(function () { + document.location.reload(); + }); + }); + } + + return { + init: function () { + editCourseFab(); + } + }; +}); diff --git a/classes/output/core_renderer.php b/classes/output/core_renderer.php index 43229ad359cb91910199227ae9bfe3d3e98ae18d..99523433cd374f40b9242957b50a2f7e14ed4008 100644 --- a/classes/output/core_renderer.php +++ b/classes/output/core_renderer.php @@ -509,4 +509,55 @@ class core_renderer extends \core_renderer { ORIGINAL END. */ // @codingStandardsIgnoreEnd } + + public function standard_after_main_region_html() { + // MODIFICATION START. + global $PAGE, $COURSE; + // MODIFICATION END. + + $output = ''; + $output .= \core_renderer::standard_after_main_region_html(); + + // MODIFICATION START. + if (($PAGE->context->get_course_context(false) == true && $COURSE->id != SITEID) + && get_config('theme_boost_campus', 'enablecourseeditbutton') == 'yes' + && has_capability('moodle/course:manageactivities', context_course::instance($COURSE->id))) { + $output .= $this->custom_edit_button($PAGE->url, 'post', true); + } + // MODIFICATION END. + + return $output; + } + + public function custom_edit_button(moodle_url $url, $method='post', $isFab=false, array $options=null) { + if (!($url instanceof moodle_url)) { + $url = new moodle_url($url); + } + + $url->param('sesskey', sesskey()); + if ($this->page->user_is_editing()) { + $url->param('edit', 'off'); + $editstring = get_string('turneditingoff'); + } else { + $url->param('edit', 'on'); + $editstring = get_string('turneditingon'); + } + + $button = new single_button($url, $editstring, $method); + + $button->class .= " edit-course-fab"; + if($isFab) { + $button->class .= " btn-fab"; + } + + foreach ((array)$options as $key=>$value) { + if (property_exists($button, $key)) { + $button->$key = $value; + } else { + $button->set_attribute($key, $value); + } + } + + return $this->render($button); + } } diff --git a/lang/en/theme_boost_campus.php b/lang/en/theme_boost_campus.php index 60150835f9575b5284045c746403f257050d8f55..7a88238c8e4f24e23bbee42facb072e3b42ee4b2 100644 --- a/lang/en/theme_boost_campus.php +++ b/lang/en/theme_boost_campus.php @@ -327,3 +327,10 @@ $string['privacy:metadata:request:infobanner_dismissed_no'] = 'Perpetual info ba // CAPABILITIES. $string['boost_campus:viewhintcourseselfenrol'] = 'To be able to see a hint for unrestricted self enrolment in a visible course.'; $string['boost_campus:viewhintinhiddencourse'] = 'To be able to see a hint in a hidden course.'; + +// Custom Settings +$string['customsettingstabname'] = 'Custom Settings'; +// Edit Course Fab +$string['enablecourseeditbutton'] = 'Enable course edit button'; +$string['enablecourseeditbutton_desc'] = 'Shows Floating action button'; + diff --git a/scss/hsh_post.scss b/scss/hsh_post.scss new file mode 100644 index 0000000000000000000000000000000000000000..6dfaba67bab97d11d33356cc1cfcab71f363ffbe --- /dev/null +++ b/scss/hsh_post.scss @@ -0,0 +1,30 @@ +.edit-course-fab { + form { + margin: 0; + } +} +.singlebutton.btn-fab { + position: fixed; + bottom: 50px; + right: 70px; + visibility: hidden; + opacity: 0; + transition: opacity .7s ease 0s, visibility .1s ease .8s; + z-index: 1; + + body.scrolled & { + opacity: 1; + visibility: visible; + transition: visibility 0s ease 0s, opacity .7s ease .1s; + } + + .btn { + box-shadow: 0 3px 5px -1px rgba(0,0,0,.2),0 5px 8px 0 rgba(0,0,0,.14),0 1px 14px 0 rgba(0,0,0,.12); + } + + @include media-breakpoint-down(sm) { + & { + bottom: 0; + } + } +} \ No newline at end of file diff --git a/scss/post.scss b/scss/post.scss index 5c19d47bcb0ca1067eaadeef2b3d9d85c8419148..df1eec42912bfd4c6ccf7be2fb25cf9579a323a8 100644 --- a/scss/post.scss +++ b/scss/post.scss @@ -1,6 +1,8 @@ /* stylelint-disable declaration-no-important */ /* stylelint-disable max-line-length */ +@import "hsh_post"; + /*------------------------------------ Page -------------------------------------*/ diff --git a/settings.php b/settings.php index 594c8f684a66ef34990d1762317de3ddad3cb471..45abfeba19e800f5c51cd9f26c44a4246b6e589e 100644 --- a/settings.php +++ b/settings.php @@ -872,4 +872,19 @@ if ($ADMIN->fulltree) { // Add tab to settings page. $settings->add($page); + + // Custom Settings Tab + // Edit Course FAB + $name = 'theme_boost_campus_custom_settings'; + $title = get_string('customsettingstabname', 'theme_boost_campus', null, true); + $page = new admin_settingpage($name, $title); + + $name = 'theme_boost_campus/enablecourseeditbutton'; + $title = get_string('enablecourseeditbutton','theme_boost_campus'); + $description = get_string('enablecourseeditbutton_desc', 'theme_boost_campus'); + $setting = new admin_setting_configcheckbox($name, $title, $description, 'no', 'yes', 'no' ); // Overriding default values + $page->add($setting); + + // Add tab to settings page. + $settings->add($page); } diff --git a/templates/columns2.mustache b/templates/columns2.mustache index 0219afd764f4afc76afa06e4d7412e0b478540d6..117e9d3ad71a621b0c77de45dd5566ceb2f3a56c 100644 --- a/templates/columns2.mustache +++ b/templates/columns2.mustache @@ -181,4 +181,7 @@ require(['theme_boost_campus/catchshortcuts'], function(mod) { mod.init({{{perbibconfirmdialogue}}}); }); {{/perpinfobannershowonselectedpage}} +require(['theme_boost_campus/editcoursefab'], function(mod) { + mod.init(); +}); {{/js}}