MDL-71051 core_user: create user profile field form is now modal form
This commit is contained in:
@@ -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 |
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -272,12 +272,13 @@ class core_calendar_type_testcase extends advanced_testcase {
|
||||
$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();
|
||||
|
||||
+1
-1
@@ -988,7 +988,7 @@ $string['profilecommonsettings'] = 'Common settings';
|
||||
$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';
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
define ("core_user/edit_profile_fields",["exports","core_form/modalform","core/str"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var d={actions:{editCategory:"[data-action=\"editcategory\"]"}};a.init=function init(){document.addEventListener("click",function(a){var e=a.target.closest(d.actions.editCategory);if(e){a.preventDefault();var f=e.getAttribute("data-id")?(0,c.get_string)("profileeditcategory","admin",e.getAttribute("data-name")):(0,c.get_string)("profilecreatenewcategory","admin"),g=new b.default({formClass:"core_user\\form\\profile_category_form",args:{id:e.getAttribute("data-id")},modalConfig:{title:f},returnFocus:e});g.addEventListener(g.events.FORM_SUBMITTED,function(){return window.location.reload()});g.show()}})}});
|
||||
define ("core_user/edit_profile_fields",["exports","core_form/modalform","core/str"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var d={actions:{editCategory:"[data-action=\"editcategory\"]",editField:"[data-action=\"editfield\"]",createField:"[data-action=\"createfield\"]"}};a.init=function init(){document.addEventListener("click",function(a){var e=a.target.closest(d.actions.editCategory);if(e){a.preventDefault();var f=e.getAttribute("data-id")?(0,c.get_string)("profileeditcategory","admin",e.getAttribute("data-name")):(0,c.get_string)("profilecreatenewcategory","admin"),g=new b.default({formClass:"core_user\\form\\profile_category_form",args:{id:e.getAttribute("data-id")},modalConfig:{title:f},returnFocus:e});g.addEventListener(g.events.FORM_SUBMITTED,function(){return window.location.reload()});g.show()}e=a.target.closest(d.actions.editField);if(e){a.preventDefault();var h=new b.default({formClass:"core_user\\form\\profile_field_form",args:{id:e.getAttribute("data-id")},modalConfig:{title:(0,c.get_string)("profileeditfield","admin",e.getAttribute("data-name"))},returnFocus:e});h.addEventListener(h.events.FORM_SUBMITTED,function(){return window.location.reload()});h.show()}e=a.target.closest(d.actions.createField);if(e){a.preventDefault();var i=new b.default({formClass:"core_user\\form\\profile_field_form",args:{datatype:e.getAttribute("data-datatype"),categoryid:e.getAttribute("data-categoryid")},modalConfig:{title:(0,c.get_string)("profilecreatenewfield","admin",e.getAttribute("data-datatypename"))},returnFocus:e});i.addEventListener(i.events.FORM_SUBMITTED,function(){return window.location.reload()});i.show()}})}});
|
||||
//# sourceMappingURL=edit_profile_fields.min.js.map
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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') ?
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -14,49 +14,42 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core_user\form;
|
||||
|
||||
use context;
|
||||
use core_form\dynamic_form;
|
||||
use moodle_url;
|
||||
use profile_define_base;
|
||||
|
||||
/**
|
||||
* This file contains the Field Form used for profile fields.
|
||||
* Class field_form used for profile fields.
|
||||
*
|
||||
* @package core_user
|
||||
* @copyright 2007 onwards Shane Elliot {@link http://pukunui.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_user\form;
|
||||
|
||||
use profile_define_base;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
require_once($CFG->dirroot.'/lib/formslib.php');
|
||||
|
||||
/**
|
||||
* Class field_form
|
||||
*
|
||||
* @copyright 2007 onwards Shane Elliot {@link http://pukunui.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class profile_field_form extends \moodleform {
|
||||
class profile_field_form extends dynamic_form {
|
||||
|
||||
/** @var profile_define_base $field */
|
||||
public $field;
|
||||
/** @var \stdClass */
|
||||
protected $fieldrecord;
|
||||
|
||||
/**
|
||||
* Define the form
|
||||
*/
|
||||
public function definition () {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot.'/user/profile/definelib.php');
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
// Everything else is dependant on the data type.
|
||||
$datatype = $this->_customdata;
|
||||
$datatype = $this->get_field_record()->datatype;
|
||||
require_once($CFG->dirroot.'/user/profile/field/'.$datatype.'/define.class.php');
|
||||
$newfield = 'profile_define_'.$datatype;
|
||||
$this->field = new $newfield();
|
||||
|
||||
$strrequired = get_string('required');
|
||||
|
||||
// Add some extra hidden fields.
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
@@ -66,8 +59,6 @@ class profile_field_form extends \moodleform {
|
||||
$mform->setType('datatype', PARAM_ALPHA);
|
||||
|
||||
$this->field->define_form($mform);
|
||||
|
||||
$this->add_action_buttons(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,10 +83,100 @@ class profile_field_form extends \moodleform {
|
||||
|
||||
/**
|
||||
* Returns the defined editors for the field.
|
||||
* @return mixed
|
||||
* @return array
|
||||
*/
|
||||
public function editors() {
|
||||
return $this->field->define_editors();
|
||||
public function editors(): array {
|
||||
$editors = $this->field->define_editors();
|
||||
return is_array($editors) ? $editors : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns context where this form is used
|
||||
*
|
||||
* @return context
|
||||
*/
|
||||
protected function get_context_for_dynamic_submission(): context {
|
||||
return \context_system::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current user has access to this form, otherwise throws exception
|
||||
*/
|
||||
protected function check_access_for_dynamic_submission(): void {
|
||||
require_capability('moodle/site:config', $this->get_context_for_dynamic_submission());
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission, used if form was submitted via AJAX
|
||||
*/
|
||||
public function process_dynamic_submission() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot.'/user/profile/definelib.php');
|
||||
profile_save_field($this->get_data(), $this->editors());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load in existing data as form defaults
|
||||
*/
|
||||
public function set_data_for_dynamic_submission(): void {
|
||||
$field = $this->get_field_record();
|
||||
|
||||
// Clean and prepare description for the editor.
|
||||
$field->description = clean_text($field->description, $field->descriptionformat);
|
||||
$field->description = array('text' => $field->description, 'format' => $field->descriptionformat, 'itemid' => 0);
|
||||
// Convert the data format for.
|
||||
if (is_array($this->editors())) {
|
||||
foreach ($this->editors() as $editor) {
|
||||
if (isset($field->$editor)) {
|
||||
$field->$editor = clean_text($field->$editor, $field->{$editor.'format'});
|
||||
$field->$editor = array('text' => $field->$editor, 'format' => $field->{$editor.'format'}, 'itemid' => 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_data($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns url to set in $PAGE->set_url() when form is being rendered or submitted via AJAX
|
||||
*
|
||||
* @return moodle_url
|
||||
*/
|
||||
protected function get_page_url_for_dynamic_submission(): moodle_url {
|
||||
$id = $this->optional_param('id', 0, PARAM_INT);
|
||||
$datatype = $this->optional_param('datatype', 'text', PARAM_PLUGIN);
|
||||
return new moodle_url('/user/profile/index.php',
|
||||
['action' => 'editfield', 'id' => $id, 'datatype' => $id ? null : $datatype]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Record for the field from the database (or generic record for a new field)
|
||||
*
|
||||
* @return false|mixed|\stdClass
|
||||
* @throws \coding_exception
|
||||
* @throws \dml_exception
|
||||
*/
|
||||
public function get_field_record() {
|
||||
global $DB;
|
||||
|
||||
if (!$this->fieldrecord) {
|
||||
$id = $this->optional_param('id', 0, PARAM_INT);
|
||||
if (!$id || !($this->fieldrecord = $DB->get_record('user_info_field', ['id' => $id]))) {
|
||||
$datatype = $this->optional_param('datatype', 'text', PARAM_PLUGIN);
|
||||
$this->fieldrecord = new \stdClass();
|
||||
$this->fieldrecord->datatype = $datatype;
|
||||
$this->fieldrecord->description = '';
|
||||
$this->fieldrecord->descriptionformat = FORMAT_HTML;
|
||||
$this->fieldrecord->defaultdata = '';
|
||||
$this->fieldrecord->defaultdataformat = FORMAT_HTML;
|
||||
$this->fieldrecord->categoryid = $this->optional_param('categoryid', 0, PARAM_INT);
|
||||
}
|
||||
if (!\core_component::get_component_directory('profilefield_'.$this->fieldrecord->datatype)) {
|
||||
throw new \moodle_exception('fieldnotfound', 'customfield');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->fieldrecord;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+58
-58
@@ -514,13 +514,18 @@ function profile_save_category(stdClass $data) {
|
||||
/**
|
||||
* Edit a category
|
||||
*
|
||||
* @deprecated since Moodle 3.11 MDL-71051 - please do not use this function any more.
|
||||
* @todo MDL-71413 This will be deleted in Moodle 4.3.
|
||||
* @see profile_save_category()
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $redirect
|
||||
*/
|
||||
function profile_edit_category($id, $redirect) {
|
||||
global $DB, $OUTPUT, $CFG;
|
||||
|
||||
debugging('Function profile_edit_category() deprecated without replacement', DEBUG_DEVELOPER);
|
||||
debugging('Function profile_edit_category() is deprecated without replacement, see also profile_save_category()',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
$categoryform = new \core_user\form\profile_category_form();
|
||||
|
||||
@@ -552,78 +557,73 @@ function profile_edit_category($id, $redirect) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Save updated field definition or create a new field
|
||||
*
|
||||
* @param stdClass $data data from the form profile_field_form
|
||||
* @param array $editors editors for this form field type
|
||||
*/
|
||||
function profile_save_field(stdClass $data, array $editors): void {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot.'/user/profile/field/'.$data->datatype.'/define.class.php');
|
||||
$newfield = 'profile_define_'.$data->datatype;
|
||||
/** @var profile_define_base $formfield */
|
||||
$formfield = new $newfield();
|
||||
|
||||
// Collect the description and format back into the proper data structure from the editor.
|
||||
// Note: This field will ALWAYS be an editor.
|
||||
$data->descriptionformat = $data->description['format'];
|
||||
$data->description = $data->description['text'];
|
||||
|
||||
// Check whether the default data is an editor, this is (currently) only the textarea field type.
|
||||
if (is_array($data->defaultdata) && array_key_exists('text', $data->defaultdata)) {
|
||||
// Collect the default data and format back into the proper data structure from the editor.
|
||||
$data->defaultdataformat = $data->defaultdata['format'];
|
||||
$data->defaultdata = $data->defaultdata['text'];
|
||||
}
|
||||
|
||||
// Convert the data format for.
|
||||
if (is_array($editors)) {
|
||||
foreach ($editors as $editor) {
|
||||
if (isset($field->$editor)) {
|
||||
$field->{$editor.'format'} = $field->{$editor}['format'];
|
||||
$field->$editor = $field->{$editor}['text'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$formfield->define_save($data);
|
||||
profile_reorder_fields();
|
||||
profile_reorder_categories();
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a profile field.
|
||||
*
|
||||
* @deprecated since Moodle 3.11 MDL-71051 - please do not use this function any more.
|
||||
* @todo MDL-71413 This will be deleted in Moodle 4.3.
|
||||
* @see profile_save_field()
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $datatype
|
||||
* @param string $redirect
|
||||
*/
|
||||
function profile_edit_field($id, $datatype, $redirect) {
|
||||
global $CFG, $DB, $OUTPUT, $PAGE;
|
||||
global $OUTPUT, $PAGE;
|
||||
|
||||
if (!$field = $DB->get_record('user_info_field', array('id' => $id))) {
|
||||
$field = new stdClass();
|
||||
$field->datatype = $datatype;
|
||||
$field->description = '';
|
||||
$field->descriptionformat = FORMAT_HTML;
|
||||
$field->defaultdata = '';
|
||||
$field->defaultdataformat = FORMAT_HTML;
|
||||
}
|
||||
debugging('Function profile_edit_field() is deprecated without replacement, see also profile_save_field()',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
// Clean and prepare description for the editor.
|
||||
$field->description = clean_text($field->description, $field->descriptionformat);
|
||||
$field->description = array('text' => $field->description, 'format' => $field->descriptionformat, 'itemid' => 0);
|
||||
|
||||
$fieldform = new \core_user\form\profile_field_form(null, $field->datatype);
|
||||
|
||||
// Convert the data format for.
|
||||
if (is_array($fieldform->editors())) {
|
||||
foreach ($fieldform->editors() as $editor) {
|
||||
if (isset($field->$editor)) {
|
||||
$field->$editor = clean_text($field->$editor, $field->{$editor.'format'});
|
||||
$field->$editor = array('text' => $field->$editor, 'format' => $field->{$editor.'format'}, 'itemid' => 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fieldform->set_data($field);
|
||||
$fieldform = new \core_user\form\profile_field_form();
|
||||
$fieldform->set_data_for_dynamic_submission();
|
||||
|
||||
if ($fieldform->is_cancelled()) {
|
||||
redirect($redirect);
|
||||
|
||||
} else {
|
||||
if ($data = $fieldform->get_data()) {
|
||||
require_once($CFG->dirroot.'/user/profile/field/'.$datatype.'/define.class.php');
|
||||
$newfield = 'profile_define_'.$datatype;
|
||||
/** @var profile_define_base $formfield */
|
||||
$formfield = new $newfield();
|
||||
|
||||
// Collect the description and format back into the proper data structure from the editor.
|
||||
// Note: This field will ALWAYS be an editor.
|
||||
$data->descriptionformat = $data->description['format'];
|
||||
$data->description = $data->description['text'];
|
||||
|
||||
// Check whether the default data is an editor, this is (currently) only the textarea field type.
|
||||
if (is_array($data->defaultdata) && array_key_exists('text', $data->defaultdata)) {
|
||||
// Collect the default data and format back into the proper data structure from the editor.
|
||||
$data->defaultdataformat = $data->defaultdata['format'];
|
||||
$data->defaultdata = $data->defaultdata['text'];
|
||||
}
|
||||
|
||||
// Convert the data format for.
|
||||
if (is_array($fieldform->editors())) {
|
||||
foreach ($fieldform->editors() as $editor) {
|
||||
if (isset($field->$editor)) {
|
||||
$field->{$editor.'format'} = $field->{$editor}['format'];
|
||||
$field->$editor = $field->{$editor}['text'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$formfield->define_save($data);
|
||||
profile_reorder_fields();
|
||||
profile_reorder_categories();
|
||||
profile_save_field($data, $fieldform->editors());
|
||||
redirect($redirect);
|
||||
}
|
||||
|
||||
@@ -632,7 +632,7 @@ function profile_edit_field($id, $datatype, $redirect) {
|
||||
if (empty($id)) {
|
||||
$strheading = get_string('profilecreatenewfield', 'admin', $datatypes[$datatype]);
|
||||
} else {
|
||||
$strheading = get_string('profileeditfield', 'admin', format_string($field->name));
|
||||
$strheading = get_string('profileeditfield', 'admin', format_string($fieldform->get_field_record()->name));
|
||||
}
|
||||
|
||||
// Print the page.
|
||||
|
||||
+18
-14
@@ -88,13 +88,6 @@ switch ($action) {
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
break;
|
||||
case 'editfield':
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$datatype = optional_param('datatype', '', PARAM_ALPHA);
|
||||
|
||||
profile_edit_field($id, $datatype, $redirect);
|
||||
die;
|
||||
break;
|
||||
default:
|
||||
// Normal form.
|
||||
}
|
||||
@@ -116,7 +109,10 @@ echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('profilefields', 'admin'));
|
||||
|
||||
$outputcategories = [];
|
||||
$options = profile_list_datatypes();
|
||||
|
||||
foreach ($categories as $category) {
|
||||
// Category fields.
|
||||
$outputfields = [];
|
||||
if ($fields = $DB->get_records('user_info_field', array('categoryid' => $category->id), 'sortorder ASC')) {
|
||||
foreach ($fields as $field) {
|
||||
@@ -129,6 +125,7 @@ foreach ($categories as $category) {
|
||||
$outputfields[] = [
|
||||
'id' => $field->id,
|
||||
'shortname' => $field->shortname,
|
||||
'datatype' => $field->datatype,
|
||||
'name' => $fieldname,
|
||||
'isfirst' => !count($outputfields),
|
||||
'islast' => count($outputfields) == count($fields) - 1,
|
||||
@@ -136,6 +133,19 @@ foreach ($categories as $category) {
|
||||
}
|
||||
}
|
||||
|
||||
// Add new field menu.
|
||||
$menu = new \action_menu();
|
||||
$menu->set_alignment(\action_menu::BL, \action_menu::BL);
|
||||
$menu->set_menu_trigger($strcreatefield);
|
||||
foreach ($options as $type => $fieldname) {
|
||||
$action = new \action_menu_link_secondary(new \moodle_url('#'), null, $fieldname,
|
||||
['data-action' => 'createfield', 'data-categoryid' => $category->id, 'data-datatype' => $type,
|
||||
'data-datatypename' => $fieldname]);
|
||||
$menu->add($action);
|
||||
}
|
||||
$menu->attributes['class'] .= ' float-left mr-1';
|
||||
|
||||
// Add category information to the template.
|
||||
$outputcategories[] = [
|
||||
'id' => $category->id,
|
||||
'name' => format_string($category->name),
|
||||
@@ -144,18 +154,12 @@ foreach ($categories as $category) {
|
||||
'isfirst' => !count($outputcategories),
|
||||
'islast' => count($outputcategories) == count($categories) - 1,
|
||||
'candelete' => count($categories) > 1,
|
||||
'addfieldmenu' => $menu->export_for_template($OUTPUT),
|
||||
];
|
||||
}
|
||||
|
||||
// Create a new field link.
|
||||
$options = profile_list_datatypes();
|
||||
$popupurl = new moodle_url('/user/profile/index.php?id=0&action=editfield');
|
||||
$singleselect = new single_select($popupurl, 'datatype', $options, '', ['' => get_string('choosedots')], 'newfieldform');
|
||||
$singleselect->set_label($strcreatefield);
|
||||
|
||||
echo $OUTPUT->render_from_template('core_user/edit_profile_fields', [
|
||||
'categories' => $outputcategories,
|
||||
'elementselect' => $singleselect->export_for_template($OUTPUT),
|
||||
'sesskey' => sesskey(),
|
||||
'baseurl' => (new moodle_url('/user/profile/index.php'))->out(false)
|
||||
]);
|
||||
|
||||
@@ -47,30 +47,45 @@
|
||||
"islast": true,
|
||||
"candelete": true
|
||||
}
|
||||
],
|
||||
"elementselect": {"options": [{"name": "Choose..."}]}
|
||||
]
|
||||
}
|
||||
}}
|
||||
|
||||
<div class="row profileeditor">
|
||||
<div class="col align-self-end">
|
||||
<a tabindex="0" role="button" class="btn btn-secondary float-right" data-action="editcategory">{{#str}}profilecreatecategory, admin{{/str}}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="categorieslist">
|
||||
{{#categories}}
|
||||
<h2>
|
||||
{{{name}}}
|
||||
<a href="#" data-action="editcategory" data-id="{{id}}" data-name="{{name}}">
|
||||
{{#pix}}t/edit, core, {{#str}}edit{{/str}}{{/pix}}</a>
|
||||
{{#candelete}}
|
||||
<a href="{{baseurl}}?action=deletecategory&id={{id}}&sesskey={{sesskey}}">
|
||||
{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}</a>
|
||||
{{/candelete}}
|
||||
{{^isfirst}}
|
||||
<a href="{{baseurl}}?id={{id}}&action=movecategory&dir=up&sesskey={{sesskey}}">
|
||||
{{#pix}}t/up, core, {{#str}}moveup{{/str}}{{/pix}}</a>
|
||||
{{/isfirst}}
|
||||
{{#isfirst}}{{#pix}}spacer, moodle{{/pix}}{{/isfirst}}
|
||||
{{^islast}}
|
||||
<a href="{{baseurl}}?id={{id}}&action=movecategory&dir=down&sesskey={{sesskey}}">
|
||||
{{#pix}}t/down, core, {{#str}}movedown{{/str}}{{/pix}}</a>
|
||||
{{/islast}}
|
||||
</h2>
|
||||
<div data-category-id="{{id}}" id="category-{{id}}" class="mt-2">
|
||||
<div class="row justify-content-between align-items-end">
|
||||
<div class="col-6 categoryinstance">
|
||||
<h3>
|
||||
{{{name}}}
|
||||
<a href="#" data-action="editcategory" data-id="{{id}}" data-name="{{name}}">
|
||||
{{#pix}}t/edit, core, {{#str}}edit{{/str}}{{/pix}}</a>
|
||||
{{#candelete}}
|
||||
<a href="{{baseurl}}?action=deletecategory&id={{id}}&sesskey={{sesskey}}">
|
||||
{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}</a>
|
||||
{{/candelete}}
|
||||
{{^isfirst}}
|
||||
<a href="{{baseurl}}?id={{id}}&action=movecategory&dir=up&sesskey={{sesskey}}">
|
||||
{{#pix}}t/up, core, {{#str}}moveup{{/str}}{{/pix}}</a>
|
||||
{{/isfirst}}
|
||||
{{#isfirst}}{{#pix}}spacer, moodle{{/pix}}{{/isfirst}}
|
||||
{{^islast}}
|
||||
<a href="{{baseurl}}?id={{id}}&action=movecategory&dir=down&sesskey={{sesskey}}">
|
||||
{{#pix}}t/down, core, {{#str}}movedown{{/str}}{{/pix}}</a>
|
||||
{{/islast}}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="col-auto text-right">
|
||||
{{#addfieldmenu}}{{> core/action_menu}}{{/addfieldmenu}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="generaltable fullwidth profilefield">
|
||||
{{#hasfields}}
|
||||
<thead>
|
||||
@@ -86,7 +101,7 @@
|
||||
{{{name}}}
|
||||
</td>
|
||||
<td class="col-3 text-right">
|
||||
<a href="{{baseurl}}?action=editfield&id={{id}}">
|
||||
<a href="#" data-action="editfield" data-id="{{id}}" data-name="{{name}}">
|
||||
{{#pix}}t/edit, core, {{#str}}edit{{/str}}{{/pix}}</a>
|
||||
<a href="{{baseurl}}?action=deletefield&id={{id}}&sesskey={{sesskey}}">
|
||||
{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}</a>
|
||||
@@ -115,14 +130,8 @@
|
||||
</thead>
|
||||
{{/hasfields}}
|
||||
</table>
|
||||
</div>
|
||||
{{/categories}}
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="profileeditor">
|
||||
{{#elementselect}}{{> core/single_select}}{{/elementselect}}
|
||||
{{#str}}or, lesson{{/str}}
|
||||
<a tabindex="0" role="button" class="btn btn-secondary" data-action="editcategory">{{#str}}profilecreatecategory, admin{{/str}}</a>
|
||||
</div>
|
||||
|
||||
{{#js}}
|
||||
|
||||
@@ -17,7 +17,8 @@ Feature: Custom profile fields should be visible and editable by those with the
|
||||
|
||||
And 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 | notvisible_field |
|
||||
| Name | notvisible_field |
|
||||
@@ -25,7 +26,8 @@ Feature: Custom profile fields should be visible and editable by those with the
|
||||
| Who is this field visible to? | Not visible |
|
||||
And I click on "Save changes" "button"
|
||||
|
||||
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 | uservisible_field |
|
||||
| Name | uservisible_field |
|
||||
@@ -33,7 +35,8 @@ Feature: Custom profile fields should be visible and editable by those with the
|
||||
| Who is this field visible to? | Visible to user |
|
||||
And I click on "Save changes" "button"
|
||||
|
||||
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 | everyonevisible_field |
|
||||
| Name | everyonevisible_field |
|
||||
@@ -41,7 +44,8 @@ Feature: Custom profile fields should be visible and editable by those with the
|
||||
| Who is this field visible to? | Visible to everyone |
|
||||
And I click on "Save changes" "button"
|
||||
|
||||
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 | teachervisible_field |
|
||||
| Name | teachervisible_field |
|
||||
|
||||
Reference in New Issue
Block a user