$mform->addElement('text', 'name', get_string('name'));
$mform->addRule('name', get_string('required'), 'required', null, 'client');
$mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'webservice'));
- $mform->addElement('text', 'requiredcapability', get_string('requiredcapability', 'webservice'));
+
+ // Prepare the list of capabilites to choose from
+ $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+ $allcapabilities = fetch_context_capabilities($systemcontext);
+ $capabilitychoices = array();
+ $capabilitychoices['norequiredcapability'] = get_string('norequiredcapability', 'webservice');
+ foreach ($allcapabilities as $cap) {
+ $capabilitychoices[$cap->name] = $cap->name . ': ' . get_capability_string($cap->name);
+ }
+
+ $mform->addElement('searchableselector', 'requiredcapability', get_string('requiredcapability', 'webservice'),$capabilitychoices, array('size' => 12));
// TODO: change to capability selection or even better if new forms element used,
// we also need to indicate if current capability does not exist in system!
$mform->addElement('advcheckbox', 'restrictedusers', get_string('restrictedusers', 'webservice'));
$this->add_action_buttons(true);
+ ///this three lines are needed to select automatically the 'No required capability" option
+ if (empty($service->requiredcapability))
+ {
+ $service->requiredcapability = "norequiredcapability";
+ }
+
$this->set_data($service);
}
} else if ($data = $mform->get_data()) {
$data = (object)$data;
+ if (!empty($data->requiredcapability) && $data->requiredcapability == "norequiredcapability")
+ {
+ $data->requiredcapability = "";
+ }
//TODO: add timecreated+modified and maybe logging too
if (empty($data->id)) {
} else {
$DB->update_record('external_services', $data);
}
-
+
redirect($returnurl);
}
$string['reverseproxyabused'] = 'Reverse proxy enabled, server can not be accessed directly, sorry.<br />Please contact server administrator.';
$string['rpcerror'] = 'RPC enrol/mnet/available_courses: ($a)';
$string['scheduledbackupsdisabled'] = 'Scheduled backups have been disabled by the server admin';
+$string['searchableselectorcannotbemultiple'] = 'A searchableselector form element cannot be multiple. Remove the \'multiple\' attribute from your call.';
$string['sectionnotexist'] = 'This section does not exist';
$string['secretalreadyused'] = 'Change password confirmation link was already used, password was not changed';
$string['sendmessage'] = 'Send message';
$string['requiredelement'] = 'Required field';
$string['revealpassword'] = 'Reveal';
$string['security'] = 'Security';
+$string['selected'] = 'Selected';
$string['selectallornone'] = 'Select all/none';
$string['showadvanced']='Show Advanced';
$string['somefieldsrequired'] = 'There are required fields in this form marked$a.';
$string['functions'] = 'Functions';
$string['iprestriction'] = 'IP restriction';
$string['manageprotocols'] = 'Manage protocols';
+$string['norequiredcapability'] = 'No required capability';
$string['potusers'] = 'Not authorised users';
$string['potusersmatching'] = 'Not authorised users matching';
$string['protocol'] = 'Protocol';
$string['removefunctionconfirm'] = 'Do you really want to remove function \"$a->function\" from service \"$a->service\"?';
$string['requiredcapability'] = 'Required capability';
$string['restrictedusers'] = 'Authorised users only';
+$string['selectedcapability'] = 'Selected';
$string['servicename'] = 'Service name';
$string['servicesbuiltin'] = 'Built-in services';
$string['servicescustom'] = 'Custom services';
--- /dev/null
+// 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/>.
+
+/**
+ * javascript for a searchable select type element
+ *
+ * @package formlib
+ * @copyright 2009 Jerome Mouneyrac
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+selector = {
+ select: null,
+ input: null,
+ button: null,
+
+ filter_init: function(strsearch, selectinputid) {
+ // selector.id = selectinputid
+ selector.select = document.getElementById(selectinputid);
+ selector.button = document.getElementById('settingssubmit');
+
+ // Create a div to hold the search UI.
+ var div = document.createElement('div');
+ div.id = 'searchui';
+
+ // Find the capability search input.
+ var input = document.createElement('input');
+ input.type = 'text';
+ input.id = selectinputid+'_search';
+ selector.input = input;
+
+ // Create a label for the search input.
+ var label = document.createElement('label');
+ label.htmlFor = input.id;
+ label.appendChild(document.createTextNode(strsearch + ' '));
+
+ // Tie it all together
+ div.appendChild(label);
+ div.appendChild(input);
+ selector.select.parentNode.insertBefore(div, selector.select);
+ YAHOO.util.Event.addListener(input, 'keyup', selector.filter_change);
+ },
+
+ filter_change: function() {
+ var searchtext = selector.input.value.toLowerCase();
+ var options = selector.select.options;
+ var matchingoption = -1;
+ for (var i = 0; i < options.length; i++) {
+ var optiontext = options[i].text.toLowerCase();
+ if (optiontext.indexOf(searchtext) >= 0) { //the option is matching the search text
+ options[i].disabled = false; //the option must be visible
+ options[i].style.display = 'block';
+ if (matchingoption == -1) { //we found at least one
+ matchingoption = i;
+ }
+ } else {
+ options[i].disabled = true;
+ options[i].selected = false;
+ options[i].style.display = 'none';
+ }
+ }
+
+ if (matchingoption == -1) { //the search didn't find any matching, color the search text in red
+ selector.input.className = "error";
+ } else {
+ selector.input.className = "";
+ }
+
+ }
+
+}
+
--- /dev/null
+<?php
+
+// 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/>.
+
+/**
+ * HTML class for a searchable select type element
+ *
+ * @package formlib
+ * @copyright 2009 Jerome Mouneyrac
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once('select.php');
+
+/**
+ * Display a select input with a search textfield input on the top
+ * The search textfield is created by the javascript file searchselector.js
+ * (so when javascript is not activated into the browser, the search field is not displayed)
+ * If ever the select can be reset/unselect/blank/nooption, you will have to add an option "noselected"
+ * and manage this special case when you get/set the form data (i.e. $mform->get_data()/$this->set_data($yourobject)).
+ */
+class MoodleQuickForm_searchableselector extends MoodleQuickForm_select{
+
+
+ function MoodleQuickForm_searchableselector($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
+ //return exception if the selector is set as multiple (TODO: implement multiple support)
+ if (!empty($attributes) && key_exists('multiple', $attributes)) {
+ throw new moodle_exception('searchableselectorcannotbemultiple');
+ }
+ parent::MoodleQuickForm_select($elementName, $elementLabel, $options, $attributes);
+ }
+
+ function toHtml(){
+ global $OUTPUT;
+ if ($this->_hiddenLabel){
+ return parent::toHtml();
+ } else {
+ // Javascript for the search/selection fields
+ global $PAGE;
+ $PAGE->requires->yui_lib('event');
+ $PAGE->requires->js('lib/form/searchableselector.js');
+ $PAGE->requires->js_function_call('selector.filter_init', array(get_string('search'),$this->getAttribute('id')));
+
+ $strHtml = '';
+ $strHtml .= parent::toHtml(); //the select input
+ return $strHtml;
+ }
+ }
+
+}
MoodleQuickForm::registerElementType('advcheckbox', "$CFG->libdir/form/advcheckbox.php", 'MoodleQuickForm_advcheckbox');
MoodleQuickForm::registerElementType('button', "$CFG->libdir/form/button.php", 'MoodleQuickForm_button');
MoodleQuickForm::registerElementType('cancel', "$CFG->libdir/form/cancel.php", 'MoodleQuickForm_cancel');
+MoodleQuickForm::registerElementType('searchableselector', "$CFG->libdir/form/searchableselector.php", 'MoodleQuickForm_searchableselector');
MoodleQuickForm::registerElementType('checkbox', "$CFG->libdir/form/checkbox.php", 'MoodleQuickForm_checkbox');
MoodleQuickForm::registerElementType('choosecoursefile', "$CFG->libdir/form/choosecoursefile.php", 'MoodleQuickForm_choosecoursefile');
MoodleQuickForm::registerElementType('choosecoursefileorimsrepo', "$CFG->libdir/form/choosecoursefileorimsrepo.php", 'MoodleQuickForm_choosecoursefileorimsrepo');