]> git.mjollnir.org Git - moodle.git/commitdiff
webservice MDL-17135 improve service function selection into administration page
authorjerome <jerome>
Mon, 19 Oct 2009 15:09:22 +0000 (15:09 +0000)
committerjerome <jerome>
Mon, 19 Oct 2009 15:09:22 +0000 (15:09 +0000)
admin/external_service_functions.php
lang/en_utf8/servicedescription.php [new file with mode: 0644]
lang/en_utf8/webservice.php

index 298fb30672f7c55b331f7c6948d8f1c0ab7b2481..9a9945e28eae1c77f4df972544df250e66f0bb82 100644 (file)
@@ -56,29 +56,80 @@ if ($action === 'delete' and confirm_sesskey() and $service and empty($service->
     $DB->delete_records('external_services_functions', array('externalserviceid'=>$service->id, 'functionname'=>$function->name));
     redirect($thisurl);
 
-} else if ($action === 'add') {
-    $mform = new external_service_functions_form(null, array('action'=>'add', 'id'=>$service->id));
+}
+else if ($action === 'add') {
+
+    if (optional_param('save', 0, PARAM_ACTION)) {
 
-    if ($mform->is_cancelled()) {
-        redirect($thisurl);
-    } else if ($data = $mform->get_data()) {
         ignore_user_abort(true); // no interruption here!
-        $function = $DB->get_record('external_functions', array('id'=>$data->fid), '*', MUST_EXIST);
-        // make sure the function is not there yet
-        if ($DB->record_exists('external_services_functions', array('externalserviceid'=>$service->id, 'functionname'=>$function->name))) {
+        $functionname = optional_param('function', 0, PARAM_ACTION);
+        if (!empty($functionname)) {
+            $function = $DB->get_record('external_functions', array('name'=> $functionname), '*', MUST_EXIST);
+            // make sure the function is not there yet
+            if ($DB->record_exists('external_services_functions', array('externalserviceid'=>$service->id, 'functionname'=>$function->name))) {
+                redirect($thisurl);
+            }
+            $new = new object();
+            $new->externalserviceid = $service->id;
+            $new->functionname      = $functionname;
+            $DB->insert_record('external_services_functions', $new);
             redirect($thisurl);
+        } 
+        else {
+            $errormessage = get_string('nofunctionselected', 'webservice');
         }
-        $new = new object();
-        $new->externalserviceid = $service->id;
-        $new->functionname      = $function->name;
-        $DB->insert_record('external_services_functions', $new);
-        redirect($thisurl);
+
+    }
+
+    // Prepare the list of function to choose from
+   $select = "name NOT IN (SELECT s.functionname
+                                  FROM {external_services_functions} s
+                                 WHERE s.externalserviceid = :sid
+                               )";
+    $functions = $DB->get_records_select_menu('external_functions', $select, array('sid'=>$id), 'name', 'id, name');
+    $functionchoices = array();
+
+    foreach ($functions as $functionname) {
+        $functionchoices[$functionname] = $functionname . ': ' . get_string($functionname, 'servicedescription');
     }
 
-    //ask for function id
+    // Javascript for the function 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'))); //TODO generalize javascript
+
     admin_externalpage_print_header();
+    if (!empty($errormessage)) {
+        echo $OUTPUT->notification($errormessage);
+    }
     echo $OUTPUT->heading($service->name);
-    $mform->display();
+     echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter centerpara');
+    //the service form
+    $form = new html_form();
+    $form->url = new moodle_url('/admin/external_service_functions.php', array('id' => $id, 'action' => 'add', 'save' => 1)); // Required
+    $form->button = new html_button();
+    $form->button->id = 'settingssubmit';
+    $form->button->text = get_string('addfunction', 'webservice'); // Required
+    $form->button->disabled = false;
+    $form->button->title = get_string('addfunction', 'webservice');
+    $form->method = 'post';
+    $form->id = 'settingsform';
+    //help text
+    $contents = '<p id="intro">'. get_string('addfunctionhelp', 'webservice') . '</p>';
+    //function section (search field + selection field)
+    $select = new html_select();
+    $select->options = $functionchoices;
+    $select->name = 'function';
+    $select->id = 'menucapability'; //TODO generalize javascript
+    $select->nothingvalue = '';
+    $select->listbox = true;
+    $select->tabindex = 0;
+    $contents .= $OUTPUT->select($select);
+    $contents .= "<br/><br/>";
+    echo $OUTPUT->form($form, $contents);
+
+    echo $OUTPUT->box_end();
+
     echo $OUTPUT->footer();
     die;
 }
@@ -103,6 +154,9 @@ $table->head  = array($strfunction);
 $table->align = array('left');
 $table->width = '100%';
 $table->data  = array();
+$table->head[] = get_string('description');
+$table->align[] = 'left';
+
 if (empty($service->component)) {
     $table->head[] = $stredit;
     $table->align[] = 'center';
@@ -111,11 +165,13 @@ if (empty($service->component)) {
 $durl = "$CFG->wwwroot/$CFG->admin/external_service_functions.php?sesskey=".sesskey();
 
 foreach ($functions as $function) {
+    //TODO: manage when the description is into a module/plugin lang file
+    $description = "<span style=\"font-size:90%\">".get_string($function->name,'servicedescription')."</span>";
     if (empty($service->component)) {
         $delete = "<a href=\"$durl&amp;action=delete&amp;fid=$function->id&amp;id=$service->id\">$strdelete</a>";
-        $table->data[] = array($function->name, $delete);
+        $table->data[] = array($function->name, $description, $delete);
     } else {
-        $table->data[] = array($function->name);
+        $table->data[] = array($function->name, $description);
     }
 }
 
diff --git a/lang/en_utf8/servicedescription.php b/lang/en_utf8/servicedescription.php
new file mode 100644 (file)
index 0000000..af23bec
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+$string['moodle_group_add_groupmembers'] = 'Add multiple member to a same group';
+$string['moodle_group_create_groups'] = 'Create multiple groups';
+$string['moodle_group_delete_groupmembers'] = 'Delete multiple member to a same group';
+$string['moodle_group_delete_groups'] = 'Delete multiple groups';
+$string['moodle_group_get_groupmembers'] = 'Return multiple member from a same group';
+$string['moodle_group_get_groups'] = 'Return multiple groups';
+$string['moodle_user_create_users'] = 'Create multiple users';
+$string['moodle_user_delete_users'] = 'Delete multiple users';
+$string['moodle_user_get_users'] = 'Get multiple users';
+$string['moodle_user_update_users'] = 'Update multiple users';
+
index be3a80a0b71f2706d4beccb907ac4cac8759ed75..6f3264a67abd8d764cf8561c5a42973fb35ba7b1 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 $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
@@ -20,6 +21,7 @@ $string['function'] = 'Function';
 $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';