webservice MDL-17135 revert the service function form to a Moodle form + user searchable selector + add default size to the searchable selector

This commit is contained in:
jerome mouneyrac
2009-11-09 03:38:50 +00:00
parent bf38af3f55
commit cd7a789181
3 changed files with 45 additions and 48 deletions
+33 -2
View File
@@ -59,7 +59,7 @@ class external_service_form extends moodleform {
}
}
$mform->addElement('searchableselector', 'requiredcapability', get_string('requiredcapability', 'webservice'), $capabilitychoices, array('size' => 12));
$mform->addElement('searchableselector', 'requiredcapability', get_string('requiredcapability', 'webservice'), $capabilitychoices);
/// display notification error if the current requiredcapability doesn't exist anymore
if(empty($currentcapabilityexist)) {
@@ -91,4 +91,35 @@ class external_service_form extends moodleform {
$errors = parent::validation($data, $files);
return $errors;
}
}
}
class external_service_functions_form extends moodleform {
function definition() {
global $CFG, $USER, $DB;
$mform = $this->_form;
$data = $this->_customdata;
$mform->addElement('header', 'addfunction', get_string('addfunction', 'webservice'));
$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'=>$data['id']), 'name', 'id, name');
$mform->addElement('searchableselector', 'fid', get_string('name'), $functions);
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'action');
$mform->setType('action', PARAM_ACTION);
$this->add_action_buttons(true);
$this->set_data($data);
}
}
+8 -46
View File
@@ -26,6 +26,7 @@
require_once('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/externallib.php');
require_once('forms.php');
$id = required_param('id', PARAM_INT);
$fid = optional_param('fid', 0, PARAM_INT);
@@ -57,9 +58,13 @@ if ($action === 'delete' and confirm_sesskey() and $service and empty($service->
redirect($thisurl);
} else if ($action === 'add' and confirm_sesskey() and $service and empty($service->component)) {
$mform = new external_service_functions_form(null, array('action'=>'add', 'id'=>$service->id));
if ($fid and $function = $DB->get_record('external_functions', array('id'=> $fid))) {
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))) {
redirect($thisurl);
@@ -71,53 +76,10 @@ if ($action === 'delete' and confirm_sesskey() and $service and empty($service->
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
)";
$functionchoices = $DB->get_records_select_menu('external_functions', $select, array('sid'=>$id), 'name', 'id, name');
// Javascript for the function search/selection fields
$PAGE->requires->yui_lib('event');
$PAGE->requires->js($CFG->admin.'/webservice/script.js');
$PAGE->requires->js_function_call('capability_service.cap_filter_init', array(get_string('search'))); //TODO generalize javascript
//ask for function id
admin_externalpage_print_header();
echo $OUTPUT->heading($service->name);
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter centerpara');
//TODO: hmm, is this supposed to be replaced by the roles UI, right? If not the use of output lib is definitely wrong, we need more buttons (Cancel!) and custom JS, etc.
//TODO: add JS disabling of submit button if no functio nselected, the error string is not user friendly
//the service form
$form = new html_form();
$form->url = new moodle_url('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 = 'fid';
$select->id = 'menucapability'; //TODO generalize javascript
$select->nothinglabel = '';
$select->nothingvalue = '';
$select->listbox = true;
$select->tabindex = 0;
$contents .= $OUTPUT->select($select);
$contents .= "<br/><br/>";
echo $OUTPUT->form($form, $contents);
echo $OUTPUT->box_end();
$mform->display();
echo $OUTPUT->footer();
die;
}
+4
View File
@@ -40,6 +40,10 @@ class MoodleQuickForm_searchableselector extends MoodleQuickForm_select{
if (!empty($attributes) && key_exists('multiple', $attributes)) {
throw new moodle_exception('searchableselectorcannotbemultiple');
}
//set size default to 12
if (empty($attributes) || empty($attributes['size'])) {
$attributes['size'] = 12;
}
parent::MoodleQuickForm_select($elementName, $elementLabel, $options, $attributes);
}