Merge branch 'MDL-78430-master-2' of https://github.com/ilyatregubov/moodle

This commit is contained in:
Sara Arjona 2023-08-01 13:02:47 +02:00
commit 3e4157b21f
No known key found for this signature in database
6 changed files with 73 additions and 4 deletions

View File

@ -1,10 +1,10 @@
define("core_grades/gradebooksetup_forms",["exports","core_form/modalform","core/str","core/notification"],(function(_exports,_modalform,_str,_notification){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
define("core_grades/gradebooksetup_forms",["exports","core_form/modalform","core/str","core/notification","core_form/changechecker"],(function(_exports,_modalform,_str,_notification,FormChangeChecker){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
* Prints the add item gradebook form
*
* @module core_grades
* @copyright 2023 Mathew May <mathew.solutions>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modalform=_interopRequireDefault(_modalform),_notification=_interopRequireDefault(_notification);_exports.init=()=>{document.addEventListener("click",(event=>{const args={};let formClass=null,title=null,trigger=null;if(event.target.closest('[data-trigger="add-item-form"]')?(event.preventDefault(),trigger=event.target.closest('[data-trigger="add-item-form"]'),formClass="core_grades\\form\\add_item",title="-1"===trigger.getAttribute("data-itemid")?(0,_str.get_string)("newitem","core_grades"):(0,_str.get_string)("itemsedit","core_grades"),args.itemid=trigger.getAttribute("data-itemid")):event.target.closest('[data-trigger="add-category-form"]')?(event.preventDefault(),trigger=event.target.closest('[data-trigger="add-category-form"]'),formClass="core_grades\\form\\add_category",title="-1"===trigger.getAttribute("data-category")?(0,_str.get_string)("newcategory","core_grades"):(0,_str.get_string)("categoryedit","core_grades"),args.category=trigger.getAttribute("data-category")):event.target.closest('[data-trigger="add-outcome-form"]')&&(event.preventDefault(),trigger=event.target.closest('[data-trigger="add-outcome-form"]'),formClass="core_grades\\form\\add_outcome",title="-1"===trigger.getAttribute("data-itemid")?(0,_str.get_string)("newoutcomeitem","core_grades"):(0,_str.get_string)("outcomeitemsedit","core_grades"),args.itemid=trigger.getAttribute("data-itemid")),trigger){args.courseid=trigger.getAttribute("data-courseid"),args.gpr_plugin=trigger.getAttribute("data-gprplugin");const modalForm=new _modalform.default({modalConfig:{title:title},formClass:formClass,args:args,saveButtonText:(0,_str.get_string)("save","core"),returnFocus:trigger});modalForm.addEventListener(modalForm.events.FORM_SUBMITTED,(event=>{event.detail.result?window.location.assign(event.detail.url):_notification.default.addNotification({type:"error",message:(0,_str.get_string)("saving_failed","core_grades")})})),modalForm.show()}}))}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modalform=_interopRequireDefault(_modalform),_notification=_interopRequireDefault(_notification),FormChangeChecker=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(FormChangeChecker);const Selectors_advancedFormLink="a.showadvancedform";_exports.init=()=>{document.addEventListener("click",(event=>{const args={};let formClass=null,title=null,trigger=null;if(event.target.closest('[data-trigger="add-item-form"]')?(event.preventDefault(),trigger=event.target.closest('[data-trigger="add-item-form"]'),formClass="core_grades\\form\\add_item",title="-1"===trigger.getAttribute("data-itemid")?(0,_str.get_string)("newitem","core_grades"):(0,_str.get_string)("itemsedit","core_grades"),args.itemid=trigger.getAttribute("data-itemid")):event.target.closest('[data-trigger="add-category-form"]')?(event.preventDefault(),trigger=event.target.closest('[data-trigger="add-category-form"]'),formClass="core_grades\\form\\add_category",title="-1"===trigger.getAttribute("data-category")?(0,_str.get_string)("newcategory","core_grades"):(0,_str.get_string)("categoryedit","core_grades"),args.category=trigger.getAttribute("data-category")):event.target.closest('[data-trigger="add-outcome-form"]')&&(event.preventDefault(),trigger=event.target.closest('[data-trigger="add-outcome-form"]'),formClass="core_grades\\form\\add_outcome",title="-1"===trigger.getAttribute("data-itemid")?(0,_str.get_string)("newoutcomeitem","core_grades"):(0,_str.get_string)("outcomeitemsedit","core_grades"),args.itemid=trigger.getAttribute("data-itemid")),trigger){args.courseid=trigger.getAttribute("data-courseid"),args.gpr_plugin=trigger.getAttribute("data-gprplugin");const modalForm=new _modalform.default({modalConfig:{title:title},formClass:formClass,args:args,saveButtonText:(0,_str.get_string)("save","core"),returnFocus:trigger});modalForm.addEventListener(modalForm.events.FORM_SUBMITTED,(event=>{event.detail.result?window.location.assign(event.detail.url):_notification.default.addNotification({type:"error",message:(0,_str.get_string)("saving_failed","core_grades")})})),modalForm.show()}const showAdvancedForm=event.target.closest(Selectors_advancedFormLink);if(showAdvancedForm){event.preventDefault();const form=event.target.closest("form");form.action=showAdvancedForm.href,FormChangeChecker.disableAllChecks(),form.submit()}}))}}));
//# sourceMappingURL=gradebooksetup_forms.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -24,6 +24,11 @@
import ModalForm from 'core_form/modalform';
import {get_string as getString} from 'core/str';
import Notification from 'core/notification';
import * as FormChangeChecker from 'core_form/changechecker';
const Selectors = {
advancedFormLink: 'a.showadvancedform'
};
/**
* Initialize module
@ -88,5 +93,14 @@ export const init = () => {
modalForm.show();
}
const showAdvancedForm = event.target.closest(Selectors.advancedFormLink);
if (showAdvancedForm) { // Navigate to the advanced form page and cary over any entered data.
event.preventDefault();
const form = event.target.closest('form');
form.action = showAdvancedForm.href;
// Disable the form change checker as we are going to carry over the data to the advanced form.
FormChangeChecker.disableAllChecks();
form.submit();
}
});
};

View File

@ -347,7 +347,7 @@ class add_item extends dynamic_form {
$url = new moodle_url('/grade/edit/tree/item.php', ['id' => $id, 'courseid' => $courseid]);
$url = $this->gpr->add_url_params($url);
$url = '<a href="' . $url . '">' . get_string('showmore', 'form') .'</a>';
$url = '<a class="showadvancedform" href="' . $url . '">' . get_string('showmore', 'form') .'</a>';
$mform->addElement('static', 'advancedform', $url);
// Add return tracking info.

View File

@ -106,6 +106,11 @@ $item->cancontrolvisibility = $grade_item->can_control_visibility();
$mform = new edit_item_form(null, array('current'=>$item, 'gpr'=>$gpr));
$simpleform = new \core_grades\form\add_item(null, ['itemid' => $grade_item->id, 'courseid' => $courseid, 'gpr' => $gpr]);
if ($simpledata = $simpleform->get_data()) {
$mform->set_data($simpledata);
}
if ($mform->is_cancelled()) {
redirect($returnurl);

View File

@ -0,0 +1,50 @@
@core @core_grades @javascript
Feature: We carry over data from modal to advanced grade item settings
In order to setup grade items quickly
As an teacher
I need to ensure data is carried over from modal to advanced grade item settings
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | t1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "grade categories" exist:
| fullname | course |
| Some cool grade category | C1 |
Given I log in as "teacher1"
And I am on the "Course 1" course page logged in as teacher1
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I press "Add grade item"
Scenario: Defaults are used when creating a new grade item
Given I click on "Show more..." "link" in the ".modal-dialog" "css_element"
Then the following fields match these values:
| Item name | |
| Minimum grade | 0 |
| Maximum grade | 100 |
| Weight adjusted | 0 |
| aggregationcoef2 | 0 |
| Grade category | Course 1 |
Scenario: We carry over data from modal to advanced grade item settings
Given I set the following fields to these values:
| Item name | Manual item 1 |
| Minimum grade | 1 |
| Maximum grade | 99 |
| Weight adjusted | 1 |
| aggregationcoef2 | 100 |
| Grade category | Some cool grade category |
When I click on "Show more..." "link" in the ".modal-dialog" "css_element"
Then the following fields match these values:
| Item name | Manual item 1 |
| Minimum grade | 1 |
| Maximum grade | 99 |
| Weight adjusted | 1 |
| aggregationcoef2 | 100 |
| Grade category | Some cool grade category |