Skip to content

Commit

Permalink
MDL-71051 core_user: create user profile field form is now modal form
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Apr 28, 2021
1 parent ac494c7 commit b597b49
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 132 deletions.
3 changes: 2 additions & 1 deletion admin/tool/uploaduser/tests/behat/upload_users.feature
Expand Up @@ -69,7 +69,8 @@ Feature: Upload users
# Create user profile field.
Given I log in as "admin"
And I navigate to "Users > Accounts > User profile fields" in site administration
And I set the field "datatype" to "Text area"
And I click on "Create a new profile field" "link"
And I click on "Text area" "link"
And I set the following fields to these values:
| Short name | superfield |
| Name | Super field |
Expand Down
Expand Up @@ -65,7 +65,8 @@ Feature: availability_profile
# Add custom field.
Given I log in as "admin"
And I navigate to "Users > Accounts > User profile fields" in site administration
And I set the field "datatype" to "Text input"
And I click on "Create a new profile field" "link"
And I click on "Text input" "link"
And I set the following fields to these values:
| Short name | superfield |
| Name | Super field |
Expand Down
3 changes: 2 additions & 1 deletion calendar/tests/calendartype_test.php
Expand Up @@ -272,12 +272,13 @@ private function datetime_field_submission_test($type, $date) {
$formdata['name'] = 'Name';
$formdata['param1'] = $date['inputminyear'];
$formdata['param2'] = $date['inputmaxyear'];
$formdata['datatype'] = 'datetime';

// Mock submitting this.
\core_user\form\profile_field_form::mock_submit($formdata);

// Create the user datetime form.
$form = new \core_user\form\profile_field_form(null, 'datetime');
$form = new \core_user\form\profile_field_form();

// Get the data from the submission.
$submissiondata = $form->get_data();
Expand Down
2 changes: 1 addition & 1 deletion lang/en/admin.php
Expand Up @@ -988,7 +988,7 @@
$string['profileconfirmcategorydeletion'] = 'There is/are {$a} field/s in this category which will be moved into the category above (or below if in the top category).<br />Do you still wish to delete this category?';
$string['profileconfirmfielddeletion'] = 'There is/are {$a} user record/s for this field which will be deleted.<br />Do you still wish to delete this field?';
$string['profilecreatecategory'] = 'Create a new profile category';
$string['profilecreatefield'] = 'Create a new profile field:';
$string['profilecreatefield'] = 'Create a new profile field';
$string['profilecreatenewcategory'] = 'Creating a new category';
$string['profilecreatenewfield'] = 'Creating a new \'{$a}\' profile field';
$string['profiledefaultcategory'] = 'Other fields';
Expand Down
2 changes: 1 addition & 1 deletion user/amd/build/edit_profile_fields.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion user/amd/build/edit_profile_fields.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion user/amd/src/edit_profile_fields.js
Expand Up @@ -28,12 +28,14 @@ import {get_string as getString} from 'core/str';
const Selectors = {
actions: {
editCategory: '[data-action="editcategory"]',
editField: '[data-action="editfield"]',
createField: '[data-action="createfield"]',
},
};

export const init = () => {
document.addEventListener('click', function(e) {
const element = e.target.closest(Selectors.actions.editCategory);
let element = e.target.closest(Selectors.actions.editCategory);
if (element) {
e.preventDefault();
const title = element.getAttribute('data-id') ?
Expand All @@ -48,5 +50,31 @@ export const init = () => {
form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
form.show();
}

element = e.target.closest(Selectors.actions.editField);
if (element) {
e.preventDefault();
const form = new ModalForm({
formClass: 'core_user\\form\\profile_field_form',
args: {id: element.getAttribute('data-id')},
modalConfig: {title: getString('profileeditfield', 'admin', element.getAttribute('data-name'))},
returnFocus: element,
});
form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
form.show();
}

element = e.target.closest(Selectors.actions.createField);
if (element) {
e.preventDefault();
const form = new ModalForm({
formClass: 'core_user\\form\\profile_field_form',
args: {datatype: element.getAttribute('data-datatype'), categoryid: element.getAttribute('data-categoryid')},
modalConfig: {title: getString('profilecreatenewfield', 'admin', element.getAttribute('data-datatypename'))},
returnFocus: element,
});
form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
form.show();
}
});
};

0 comments on commit b597b49

Please sign in to comment.