]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17135 reverting recent change in service management UI - since 1.7 the right...
authorskodak <skodak>
Wed, 21 Oct 2009 19:36:39 +0000 (19:36 +0000)
committerskodak <skodak>
Wed, 21 Oct 2009 19:36:39 +0000 (19:36 +0000)
admin/external_forms.php [new file with mode: 0644]
admin/external_service.php
admin/webservice/script.js
lang/en_utf8/webservice.php
lib/adminlib.php

diff --git a/admin/external_forms.php b/admin/external_forms.php
new file mode 100644 (file)
index 0000000..9d77469
--- /dev/null
@@ -0,0 +1,70 @@
+<?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/>.
+
+/**
+ * Web services admin UI forms
+ *
+ * @package   webservice
+ * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once $CFG->libdir.'/formslib.php';
+
+class external_service_form extends moodleform {
+    function definition() {
+        global $CFG, $USER;
+
+        $mform = $this->_form;
+        $service = $this->_customdata;
+
+        $mform->addElement('header', 'extservice', get_string('externalservice', 'webservice'));
+
+        $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'));
+        // 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'));
+
+        $mform->addElement('hidden', 'id');
+        $mform->setType('id', PARAM_INT);
+
+        $this->add_action_buttons(true);
+
+        $this->set_data($service);
+    }
+
+    function definition_after_data() {
+        $mform = $this->_form;
+        $service = $this->_customdata;
+
+        if (!empty($service->component)) {
+            // built-in components must not be modified except the enabled flag!!
+            $mform->hardFreeze('name,requiredcapability,restrictedusers');
+        }
+    }
+
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
+
+        //TODO: better make sure the service name is unique
+
+        return $errors;
+    }
+}
\ No newline at end of file
index 5ed89b4b4406241f588fa8e2822c3873e19954fa..089ef3fada9051a870751843fbb7b2b242713303 100644 (file)
@@ -25,6 +25,7 @@
 
 require_once('../config.php');
 require_once($CFG->libdir.'/adminlib.php');
+require_once('external_forms.php');
 
 $id      = required_param('id', PARAM_INT);
 $action  = optional_param('action', '', PARAM_ACTION);
@@ -42,8 +43,7 @@ if ($id) {
     $service = null;
 }
 
-// delete a service
-if (!empty($action) and $action == 'delete' and confirm_sesskey() and $service and empty($service->component)) {
+if ($action == 'delete' and confirm_sesskey() and $service and empty($service->component)) {
     if (!$confirm) {
         admin_externalpage_print_header();
         $optionsyes = array('id'=>$id, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey());
@@ -60,137 +60,25 @@ if (!empty($action) and $action == 'delete' and confirm_sesskey() and $service a
     redirect($returnurl);
 }
 
-$clear = optional_param('clearbutton', false, PARAM_BOOL);
-$servicename  = optional_param('servicename', '', PARAM_TEXT);
-$enableservice  = optional_param('enableservice', 0, PARAM_BOOL);
-$restrictedusers  = optional_param('restrictedusers', 0, PARAM_BOOL);
-$capability  = optional_param('capability', '', PARAM_CAPABILITY);
-
-// clear the capability field
-if (!empty($clear)) {
-        $service->name = $servicename;
-        $service->enabled = $enableservice;
-        $service->requiredcapability = "";
-        $service->restrictedusers = $restrictedusers;
-} else {
-// add/update a service
-    if ((!empty($action) and ($action == 'add' || $action == 'update') and confirm_sesskey())) {
-        
-        if (!empty($servicename)) {
-            $tempservice = new object();
-            $tempservice->name = $servicename;
-            $tempservice->enabled = $enableservice;
-            $tempservice->requiredcapability = $capability;
-            $tempservice->restrictedusers = $restrictedusers;
-
-            if ($action == 'add') {
-                $DB->insert_record('external_services', $tempservice);
-            }
-            else {
-                $tempservice->id = $service->id;
-                $DB->update_record('external_services', $tempservice);
-            }
-
-            redirect($returnurl);
-
-        }
-        //administrator has omitted service name => display error message
-        else {
-            $service->name = $servicename;
-            $service->enabled = $enableservice;
-            $service->requiredcapability = $capability;
-            $service->restrictedusers = $restrictedusers;
-            $errormessage = get_string('emptyname', 'webservice');
-        }
-    }
-
-} 
+$mform = new external_service_form(null, $service);
 
+if ($mform->is_cancelled()) {
+    redirect($returnurl);
 
-admin_externalpage_print_header();
-if (!empty($errormessage)) {
-    echo $OUTPUT->notification($errormessage);
-}
-
+} else if ($data = $mform->get_data()) {
+    $data = (object)$data;
 
-// Prepare the list of capabilites to choose from
-    $systemcontext = get_context_instance(CONTEXT_SYSTEM);
-    $allcapabilities = fetch_context_capabilities($systemcontext);
-    $capabilitychoices = array();
-    foreach ($allcapabilities as $cap) {
-        $capabilitychoices[$cap->name] = $cap->name . ': ' . get_capability_string($cap->name);
+    //TODO: add timecreated+modified and maybe logging too
+    if (empty($data->id)) {
+        $DB->insert_record('external_services', $data);
+    } else {
+        $DB->update_record('external_services', $data);
     }
 
-// Javascript for the capability search/selection fields
-    $PAGE->requires->yui_lib('event');
-    $PAGE->requires->js('admin/webservice/script.js');
-    $PAGE->requires->js_function_call('capability_service.cap_filter_init', array(get_string('search')));
-
-//  UI
-    $capability = optional_param('capability', '', PARAM_CAPABILITY);
-    echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter centerpara');
-
-    $action = (empty($id))?'add':'update'; //if 'id' GET parameter = 0 we're adding a service, otherwise updating
-
-    //the service form
-    $form = new html_form();
-    $form->url = new moodle_url('/admin/external_service.php', array('id' => $id, 'action' => $action)); // Required
-    $form->button = new html_button();
-    $form->button->id = 'settingssubmit';
-    $form->button->text = get_string('saveservice', 'webservice'); // Required
-    $form->button->disabled = false;
-    $form->button->title = get_string('saveservice', 'webservice');
-    $form->method = 'post';
-    $form->id = 'settingsform';
-
-    echo $OUTPUT->heading(get_string('externalservice', 'webservice'));
-    //service name field
-    $namefield =  "<label>".get_string('servicename','webservice')." </label>";
-    $nametextfield = new html_field();
-    $nametextfield->name = 'servicename';
-    $nametextfield->value = empty($service->name)?"":$service->name;
-    $nametextfield->style = 'width: 30em;';
-    $namefield .= $OUTPUT->textfield($nametextfield);
-    $contents = $namefield;
-    //enable field
-    $servicecheckbox = new html_select_option();
-    $servicecheckbox->value = true;
-    $servicecheckbox->selected = empty($service->enabled)?false:true;
-    $servicecheckbox->text = get_string('enabled', 'webservice');
-    $servicecheckbox->label->text = get_string('enabled', 'webservice');
-    $servicecheckbox->alt = get_string('enabled', 'webservice');
-    $contents .=  $OUTPUT->checkbox($servicecheckbox, 'enableservice');
-    //help text
-    $contents .= '<p id="intro">'. get_string('addservicehelp', 'webservice') . '</p>';
-    //restricted users option
-    $restricteduserscheckbox = new html_select_option();
-    $restricteduserscheckbox->value = true;
-    $restricteduserscheckbox->selected = empty($service->restrictedusers)?false:true;
-    $restricteduserscheckbox->text = get_string('restrictedusers', 'webservice');
-    $restricteduserscheckbox->label->text = get_string('restrictedusers', 'webservice');
-    $restricteduserscheckbox->alt = get_string('restrictedusers', 'webservice');
-    $contents .= $OUTPUT->checkbox($restricteduserscheckbox, 'restrictedusers');
-    //capability section (search field + selection field)
-    $contents .= '<p><label for="menucapability"> ' . get_string('requiredcapability', 'webservice') . '</label></p> ';
-    $capabilityname = new html_field();
-    $capabilityname->name = 'capabilityname';
-    $capabilityname->id = 'capabilityname';
-    $capabilityname->value = empty($service->requiredcapability)?"":$service->requiredcapability;
-    $capabilityname->disabled = true;
-    $capabilityname->style = 'width: 20em;';
-    $capability = empty($service->requiredcapability)?"":$service->requiredcapability;
-    $select = html_select::make($capabilitychoices, 'capability', $capability);
-    $select->nothingvalue = '';
-    $select->listbox = true;
-    $select->tabindex = 0;
-    $contents .= $OUTPUT->select($select);
-    $contents .= '<br/><label for="menucapability"> ' . get_string('selectedcapability', 'webservice') . '</label> ';
-    $contents .= $OUTPUT->textfield($capabilityname);
-    $contents .= '<input type="submit" name="clearbutton" id="clearbutton" value="' . get_string('clear') . '" />';
-    $contents .= "<br/><br/>";
-    echo $OUTPUT->form($form, $contents);
-
-    echo $OUTPUT->box_end();
+    redirect($returnurl);
+}
 
+admin_externalpage_print_header();
+$mform->display();
 echo $OUTPUT->footer();
 
index b604c24c1c9eb61ee464925af3243170fb36abe6..35a28abc97ed63f00c6d0567bc45cd4c5dbca1d9 100644 (file)
@@ -1,76 +1,3 @@
-capability_service = {
-    select: null,
-    input: null,
-    button: null,
-
-    cap_filter_init: function(strsearch) {
-        // Find the form controls.
-        capability_service.select = document.getElementById('menucapability');
-        capability_service.button = document.getElementById('settingssubmit');
-
-        // Create a div to hold the search UI.
-        var div = document.createElement('div');
-        div.id = 'capabilitysearchui';
-
-        // Find the capability search input.
-        var input = document.createElement('input');
-        input.type = 'text';
-        input.id = 'capabilitysearch';
-        capability_service.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);
-        capability_service.select.parentNode.insertBefore(div, capability_service.select);
-        YAHOO.util.Event.addListener(input, 'keyup', capability_service.cap_filter_change);
-        YAHOO.util.Event.addListener(capability_service.select, 'change', capability_service.validate);
-        capability_service.select.options[0].style.display = 'none';
-        capability_service.validate();
-    },
-
-    cap_filter_change: function() {
-        var filtertext = capability_service.input.value;
-        var options = capability_service.select.options;
-        var onlycapability = -1;
-        for (var i = 1; i < options.length; i++) {
-            if (options[i].text.indexOf(filtertext) >= 0) {
-                options[i].disabled = false;
-                options[i].style.display = 'block';
-                if (onlycapability == -1) {
-                    onlycapability = i;
-                } else {
-                    onlycapability = -2;
-                }
-            } else {
-                options[i].disabled = true;
-                options[i].selected = false;
-                options[i].style.display = 'none';
-            }
-        }
-        if (onlycapability >= 0) {
-            options[onlycapability].selected = true;
-        }
-        if (onlycapability == -1) {
-            capability_service.input.className = "error";
-        } else {
-            capability_service.input.className = "";
-        }
-        
-        capability_service.validate();
-    },
-
-    validate: function() {
-       capabilityname = document.getElementById('capabilityname');
-       capabilityname.value = capability_service.select.value;
-
-
-    }
-}
 
 /* This function disable the valid until field of a user into external_service_users.php*/
 function disablevaliduntil(event, userid) {
index fadf7582fbba3d1753c7310a110d15f2d2b84654..7d61457fb6488d00fa393335c232149891e56b47 100644 (file)
@@ -4,16 +4,11 @@ $string['accessexception'] = 'Access control exception';
 $string['addfunction'] = 'Add function';
 $string['addfunctionhelp'] = 'Select the function to add to the service.';
 $string['addrequiredcapability'] = 'Assign/Unassign the required capability';
-$string['addservicehelp'] = 'Set settings for your service. You can add a unique required capability. In this case any
-    user accessing to this service will need this capability. When you enable restricted users option, you will be able
-    to select some restricted users from the services administration page. These users will be the only one able to
-    access this service. Finally you can decide enable/disable the service at any time.';
 $string['actwebserviceshhdr'] = 'Active web service protocols';
 $string['configwebserviceplugins'] = 'For security reasons enable only protocols that are used.';
 $string['deleteserviceconfirm'] = 'Do you really want to delete external service \"$a\"?';
 $string['disabledwarning'] = 'All webs service protocols are disabled, the \Enable web services\" setting can be found in the \"Advanced features\" section.';
-$string['emptyname'] = 'The service name field cannot be empty.';
-$string['enabled'] = 'enabled';
+$string['enabled'] = 'Enabled';
 $string['externalservices'] = 'External services';
 $string['externalservice'] = 'External service';
 $string['externalservicefunctions'] = 'External service functions';
@@ -23,22 +18,19 @@ $string['functions'] = 'Functions';
 $string['iprestriction'] = 'IP restriction';
 $string['manageprotocols'] = 'Manage protocols';
 $string['nofunctionselected'] = 'Please select a function to add';
-$string['nouserrestriction'] = 'No restriction';
-$string['potusers'] = 'Not authorized users';
-$string['potusersmatching'] = 'Not authorized users matching';
+$string['potusers'] = 'Not authorised users';
+$string['potusersmatching'] = 'Not authorised users matching';
 $string['protocol'] = 'Protocol';
 $string['removefunction'] = 'Remove';
 $string['removefunctionconfirm'] = 'Do you really want to remove function \"$a->function\" from service \"$a->service\"?';
 $string['requiredcapability'] = 'Required capability';
-$string['restrictedusers'] = 'Restricted users';
-$string['saveservice'] = 'Save service';
-$string['selectedcapability'] = 'Selected';
+$string['restrictedusers'] = 'Authorised users only';
 $string['servicename'] = 'Service name';
 $string['servicesbuiltin'] = 'Built-in services';
 $string['servicescustom'] = 'Custom services';
-$string['serviceusers'] = 'Authorized users';
-$string['serviceusersmatching'] = 'Authorized users matching';
-$string['serviceuserssettings'] = 'Change settings for the Authorized users';
+$string['serviceusers'] = 'Authorised users';
+$string['serviceusersmatching'] = 'Authorised users matching';
+$string['serviceuserssettings'] = 'Change settings for the authorised users';
 $string['test'] = 'Test';
 $string['testclient'] = 'Web service test client';
 $string['validuntil'] = 'Valid until';
index 0e58ff7adb29128956f9c844e8450b1d5746fadf..974dbd44c8ec1e8bec348c985ebb0f432b2949a0 100644 (file)
@@ -6161,13 +6161,14 @@ class admin_setting_manageexternalservices extends admin_setting {
         $stradd = get_string('add');
         $strfunctions = get_string('functions', 'webservice');
         $strusers = get_string('restrictedusers', 'webservice');
+        $strserviceusers = get_string('serviceusers', 'webservice');
 
         $esurl = "$CFG->wwwroot/$CFG->admin/external_service.php";
         $efurl = "$CFG->wwwroot/$CFG->admin/external_service_functions.php";
         $euurl = "$CFG->wwwroot/$CFG->admin/external_service_users.php";
 
         // built in services
-        $return = $OUTPUT->heading(get_string('servicesbuiltin', 'webservice'), 3, 'main', true);
+        $return = $OUTPUT->heading(get_string('servicesbuiltin', 'webservice'), 3, 'main');
 
         $services = $DB->get_records_select('external_services', 'component IS NOT NULL', null, 'name');
 
@@ -6194,9 +6195,9 @@ class admin_setting_manageexternalservices extends admin_setting {
             $functions = "<a href=\"$efurl?id=$service->id\">$strfunctions</a>";
 
             if ($service->restrictedusers) {
-                $users = "<a href=\"$euurl?id=$service->id\">$strusers</a>";
+                $users = "<a href=\"$euurl?id=$service->id\">$strserviceusers</a>";
             } else {
-                $users = get_string('nouserrestriction','webservice');
+                $users = '-';
             }
 
             $edit = "<a href=\"$esurl?id=$service->id\">$stredit</a>";
@@ -6207,7 +6208,7 @@ class admin_setting_manageexternalservices extends admin_setting {
         $return .= $OUTPUT->table($table);
 
         // Custom services
-        $return .= $OUTPUT->heading(get_string('servicescustom', 'webservice'), 3, 'main', true);
+        $return .= $OUTPUT->heading(get_string('servicescustom', 'webservice'), 3, 'main');
         $services = $DB->get_records_select('external_services', 'component IS NULL', null, 'name');
 
         $table = new html_table();
@@ -6234,9 +6235,9 @@ class admin_setting_manageexternalservices extends admin_setting {
             $functions = "<a href=\"$efurl?id=$service->id\">$strfunctions</a>";
 
             if ($service->restrictedusers) {
-                $users = "<a href=\"$euurl?id=$service->id\">$strusers</a>";
+                $users = "<a href=\"$euurl?id=$service->id\">$strserviceusers</a>";
             } else {
-                $users = get_string('nouserrestriction','webservice');
+                $users = '-';
             }
 
             $edit = "<a href=\"$esurl?id=$service->id\">$stredit</a>";