Commit 2c79d608 authored by Robert Lyon's avatar Robert Lyon Committed by Aaron Wells
Browse files

Bug 1393536: More tidying up



Including:
- making add connection form cancel back to connections page
with correct institution selected
- Adding a help icon/page (needs content) for add connections
- Display tick/cross next to connection name to see if it is enabled
- Have the 'enable connection manager' master switch bunched with the
others
- Changing some strings to make thing clearer

behatnotneeded

Change-Id: I875ad6ec745cd136338017e27ef49542157cac7c
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 104d14fd
......@@ -53,8 +53,9 @@ $string['usernameinvalidadminform'] = 'Usernames may contain letters, numbers an
$string['youmaynotregisterwithouttandc'] = 'You may not register unless you agree to abide by the <a href="terms.php">Terms and Conditions</a>.';
$string['pluginconnections'] = 'Plugin connection objects';
$string['pcdescription'] = 'Create connections connected to the Connection Objects of registered plugins.';
$string['pluginconnections'] = 'Connection objects';
$string['pcdescription'] = 'Select a connection';
$string['instancelistempty'] = 'No connection objects for this institution.';
$string['addconnection'] = 'Add Client Connection';
$string['editconnection'] = 'Edit Client Connection';
......
<!-- @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -->
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>Connection manager</h3>
<p>Connections are designed to allow ...[more text to come]</p>
......@@ -2060,11 +2060,16 @@ abstract class Plugin implements IPlugin {
public static function get_webservice_connections($user=null) {
global $USER;
// are web service connections enabled?
// is the web service connection switch enabled?
if (!get_config('webservice_connections_enabled')) {
log_debug('get_webservice_connections: disabled');
return array();
}
// do we have any defined connections enabled?
if (!get_records_array('client_connections_institution', 'enable', 1, '', 'id', 0, 1)) {
log_debug('get_webservice_connections: no active connections');
return array();
}
require_once(get_config('docroot') . 'webservice/lib.php');
......@@ -2182,7 +2187,6 @@ abstract class Plugin implements IPlugin {
$connections[]= $client;
}
}
return $connections;
}
......
......@@ -14,7 +14,7 @@
}
sendjsonrequest('{{$WWWROOT}}webservice/admin/connections.php', {'i': '{{$institution}}', 'ids': outputArray.join(','), 'reorder': 1, 'j': 1}, 'GET', function (data) {
rebuildInstanceList(outputArray);
});
});
return false;
}
......@@ -33,38 +33,48 @@
}
sendjsonrequest('{{$WWWROOT}}webservice/admin/connections.php', {'i': '{{$institution}}', 'ids': outputArray.join(','), 'reorder': 1, 'j': 1}, 'GET', function (data) {
rebuildInstanceList(outputArray);
});
});
return false;
}
function rebuildInstanceList(outputArray) {
var displayArray = new Array();
var instanceListDiv = document.getElementById('instanceList');
// Take each auth instance div, remove its span tag (containing arrow links) and clone it
// adding the clone to the displayArray list
for (i = 0; i < outputArray.length; i++) {
var myDiv = document.getElementById('instanceDiv' + outputArray[i]);
replaceChildNodes(getFirstElementByTagAndClassName('span', 'authIcons', 'instanceDiv' + outputArray[i]));
displayArray.push(myDiv.cloneNode(true));
}
function buttonOptions (id, length, i) {
// Make the buttons a row should have
var buttons = '';
if (length > 1) {
if (i + 1 != length) {
buttons += '<a class="btn btn-link text-midtone" href="" onclick="move_down(' + id + '); return false;"><span class="icon icon-long-arrow-down" role="presentation" aria-hidden="true"></span><span class="sr-only">' + get_string('moveitemdown') + '</span></a>'
}
else {
buttons += '<span class="emptybtnspace"></span>';
}
emptyThisNode(instanceListDiv);
if (i != 0) {
buttons += '<a class="btn btn-link text-midtone" href="" onclick="move_up(' + id + '); return false;"><span class="icon icon-long-arrow-up" role="presentation" aria-hidden="true"></span><span class="sr-only">' + get_string('moveitemup') + '</span></a>';
}
else {
for(i = 0; i < displayArray.length; i++) {
if(displayArray.length > 1) {
if (i + 1 != displayArray.length) {
getFirstElementByTagAndClassName('span', 'authIcons', displayArray[i]).innerHTML += '<a class="btn btn-link text-midtone" href="" onclick="move_down('+outputArray[i]+'); return false;"><span class="icon icon-long-arrow-down" role="presentation" aria-hidden="true"></span><span class="sr-only">'+get_string('moveitemdown')+'</span></a>'+"\n";
}
if(i != 0) {
getFirstElementByTagAndClassName('span', 'authIcons', displayArray[i]).innerHTML += '<a class="btn btn-link text-midtone" href="" onclick="move_up('+outputArray[i]+'); return false;"><span class="icon icon-long-arrow-up" role="presentation" aria-hidden="true"></span><span class="sr-only">'+get_string('moveitemup')+'</span></a>'+"\n";
}
buttons += '<span class="emptybtnspace"></span>';
}
}
buttons += '<a class="btn btn-default btn-sm" href="" onclick="removeConnection(' + id + '); return false;"><span class="icon icon-trash icon-lg text-danger" role="presentation" aria-hidden="true"></span><span class="sr-only">' + get_string('deleteitem') + '</span></a>' + "\n";
return buttons;
}
getFirstElementByTagAndClassName('span', 'authIcons', displayArray[i]).innerHTML += '<a class="btn btn-default btn-sm" href="" onclick="removeConnection('+outputArray[i]+'); return false;"><span class="icon icon-trash icon-lg text-danger" role="presentation" aria-hidden="true"></span><span class="sr-only">'+get_string('deleteitem')+'</span></a>'+"\n";
function rebuildInstanceList(outputArray) {
var displayArray = new Array();
var instanceList = jQuery('.authInstance');
instanceListDiv.appendChild(displayArray[i]);
// Take each connection row, remove its icons and add back new ones
for (i = 0; i < outputArray.length; i++) {
var row = jQuery('#instanceDiv' + outputArray[i]);
row.data('order', i);
row.find('.authIcons').html(buttonOptions(outputArray[i], outputArray.length, i));
}
// Now re-sort the rows
instanceList.sort(function(a, b) {
return jQuery(a).data('order') - jQuery(b).data('order');
});
jQuery("#instanceList").html(instanceList);
document.getElementById('instancePriority').value = outputArray.join(',');
}
......@@ -90,16 +100,10 @@
}
rebuildInstanceList(instanceArray);
document.getElementById('deleteList').value = deleteArray.join(',');
});
});
return false;
}
function emptyThisNode(node) {
while(node.hasChildNodes()) {
node.removeChild(node.childNodes[0]);
}
}
function addinstance() {
var selectedPlugin = document.getElementById('dummySelect').value;
var institution = '{{$institution}}';
......@@ -112,35 +116,22 @@
return;
}
function addConnection(id, name, connectionname) {
var newDiv = '<div class="authInstance" id="instanceDiv'+id+'"> '+
'<label class="authLabel"><a href="" onclick="editinstance('+id+',\''+connectionname+'\'); return false;">'+name+'</a></label> '+
'<span class="authIcons" id="arrows'+id+'"></span> </div>';
document.getElementById('instanceList').innerHTML += newDiv;
if(document.getElementById('instancePriority').value.length) {
instanceArray = document.getElementById('instancePriority').value.split(',');
} else {
instanceArray = new Array();
}
instanceArray.push(id);
rebuildInstanceList(instanceArray);
if (typeof formchangemanager !== 'undefined') {
var form = jQuery('div#instanceList').closest('form')[0];
formchangemanager.setFormState(form, FORM_CHANGED);
}
replaceChildNodes('messages');
}
</script>
{{*
IMPORTANT: do not introduce any new whitespace into the instanceList div.
*}}
{{if $instancelist}}
<div id="instanceList">
{{foreach $instancelist instance}}
<div class="authInstance" id="instanceDiv{{$instance->id}}">
<div class="authInstance" id="instanceDiv{{$instance->id}}" data-order="1">
<label class="authLabel">
{{if $instance->enable}}
<span class="icon icon-lg icon-check text-success" title="{{str tag='enabled'}}"></span>
{{else}}
<span class="icon icon-lg icon-times text-danger" title="{{str tag='disabled'}}"></span>
{{/if}}
<a href="" onclick="editinstance({{$instance->id}},'{{$instance->name}}'); return false;">
{{$instance->name}}</a>
</label>
......@@ -150,12 +141,16 @@ IMPORTANT: do not introduce any new whitespace into the instanceList div.
<span class="icon icon-long-arrow-down" role="presentation" aria-hidden="true"></span>
<span class="sr-only">{{str tag=moveitemdown}}</span>
</a>
{{else}}
<span class="emptybtnspace"></span>
{{/if}}
{{if $instance->index != 0 }}
<a class="btn btn-link text-midtone" href="" onclick="move_up({{$instance->id}}); return false;">
<span class="icon icon-long-arrow-up" role="presentation" aria-hidden="true"></span>
<span class="sr-only">{{str tag=moveitemup}}</span>
</a>
{{else}}
<span class="emptybtnspace"></span>
{{/if}}
<a href="" class="btn btn-default btn-sm" onclick="removeConnection({{$instance->id}}); return false;">
<span class="icon icon-trash icon-lg text-danger" role="presentation" aria-hidden="true"></span>
......@@ -165,6 +160,10 @@ IMPORTANT: do not introduce any new whitespace into the instanceList div.
</div>
{{/foreach}}
</div>
{{else}}
<div>{{str tag='instancelistempty' section='auth.webservice'}}</div>
{{/if}}
<div class="postlist">{{str tag='pcdescription' section='auth.webservice'}}</div>
<div class="select connections">
<span class="picker">
<select class="select form-control" name="dummy" id="dummySelect">
......
......@@ -441,3 +441,8 @@
.connections button {
margin-top: 10px;
}
.emptybtnspace {
display: inline-block;
width: 30px;
}
......@@ -77,6 +77,11 @@ if ($delete) {
exit();
}
function allocate_client_connection_cancel_submit(Pieform $form) {
$institution = $form->get_element('i');
redirect(get_config('wwwroot') . 'webservice/admin/connections.php?i=' . $institution['value']);
}
function allocate_client_connection_validate(Pieform $form, $values) {
global $SESSION;
......@@ -228,74 +233,74 @@ function allocate_client_connection() {
}
function update_auth_options() {
var current = $('allocate_client_connection_authtype').value;
var current = jQuery('#allocate_client_connection_authtype').val();
if ('token' == current || 'cert' == current) {
removeElementClass('allocate_client_connection_token_container', 'hidden');
removeElementClass('allocate_client_connection_useheader_container', 'hidden');
jQuery('#allocate_client_connection_token_container').removeClass('hidden');
jQuery('#allocate_client_connection_useheader_container').removeClass('hidden');
update_useheader_options();
}
else {
addElementClass('allocate_client_connection_token_container', 'hidden');
addElementClass('allocate_client_connection_useheader_container', 'hidden');
addElementClass('allocate_client_connection_header_container', 'hidden');
jQuery('#allocate_client_connection_token_container').addClass('hidden');
jQuery('#allocate_client_connection_useheader_container').addClass('hidden');
jQuery('#allocate_client_connection_header_container').addClass('hidden');
}
if ('oauth1' == current) {
removeElementClass('allocate_client_connection_consumer_container', 'hidden');
removeElementClass('allocate_client_connection_secret_container', 'hidden');
jQuery('#allocate_client_connection_consumer_container').removeClass('hidden');
jQuery('#allocate_client_connection_secret_container').removeClass('hidden');
}
else {
addElementClass('allocate_client_connection_consumer_container', 'hidden');
addElementClass('allocate_client_connection_secret_container', 'hidden');
jQuery('#allocate_client_connection_consumer_container').addClass('hidden');
jQuery('#allocate_client_connection_secret_container').addClass('hidden');
}
if ('user' == current || 'cert' == current || 'wsse' == current) {
removeElementClass('allocate_client_connection_username_container', 'hidden');
removeElementClass('allocate_client_connection_password_container', 'hidden');
jQuery('#allocate_client_connection_username_container').removeClass('hidden');
jQuery('#allocate_client_connection_password_container').removeClass('hidden');
}
else {
addElementClass('allocate_client_connection_username_container', 'hidden');
addElementClass('allocate_client_connection_password_container', 'hidden');
jQuery('#allocate_client_connection_username_container').addClass('hidden');
jQuery('#allocate_client_connection_password_container').addClass('hidden');
}
if ('cert' == current) {
removeElementClass('allocate_client_connection_certificate_container', 'hidden');
jQuery('#allocate_client_connection_certificate_container').removeClass('hidden');
}
else {
addElementClass('allocate_client_connection_certificate_container', 'hidden');
jQuery('#allocate_client_connection_certificate_container').addClass('hidden');
}
}
function update_type_options() {
var current = $('allocate_client_connection_type').value;
var current = jQuery('#allocate_client_connection_type').val();
if ('rest' == current || 'oauth1' == current) {
removeElementClass('allocate_client_connection_json_container', 'hidden');
jQuery('#allocate_client_connection_json_container').removeClass('hidden');
}
else {
addElementClass('allocate_client_connection_json_container', 'hidden');
jQuery('#allocate_client_connection_json_container').addClass('hidden');
}
}
function update_useheader_options() {
var checked = $('allocate_client_connection_useheader').checked;
var checked = jQuery('#allocate_client_connection_useheader:checked').length;
if (checked) {
removeElementClass('allocate_client_connection_header_container', 'hidden');
jQuery('#allocate_client_connection_header_container').removeClass('hidden');
}
else {
addElementClass('allocate_client_connection_header_container', 'hidden');
jQuery('#allocate_client_connection_header_container').addClass('hidden');
}
}
addLoadEvent(function() {
// new Pieform({"name":"allocate_client_connection","jsForm":true,"submitButtons":["submit"],"preSubmitCallback":"formStartProcessing","jsSuccessCallback":"formSuccess","jsErrorCallback":"formError","globalJsErrorCallback":"formGlobalError","postSubmitCallback":"formStopProcessing","newIframeOnSubmit":false,"checkDirtyChange":true});
jQuery(function() {
connect('allocate_client_connection_authtype', 'onchange', update_auth_options);
jQuery('#allocate_client_connection_authtype').on('change', update_auth_options);
update_auth_options();
connect('allocate_client_connection_type', 'onchange', update_type_options);
jQuery('#allocate_client_connection_type').on('change', update_type_options);
update_type_options();
connect('allocate_client_connection_useheader', 'onclick', update_useheader_options);
// update_useheader_options();
jQuery('#allocate_client_connection_useheader').on('click', update_useheader_options);
});
EOF;
......@@ -347,7 +352,7 @@ $connection_details['elements']['name'] = array(
$connection_details['elements']['enable'] = array(
'defaultvalue' => (($dbconnection->enable == 1) ? 'checked' : ''),
'type' => 'checkbox',
'type' => 'switchbox',
'disabled' => false,
'title' => get_string('enable', 'auth.webservice'),
);
......@@ -431,7 +436,7 @@ $connection_details['elements']['token'] = array(
$connection_details['elements']['useheader'] = array(
'title' => get_string('useheader', 'auth.webservice'),
'defaultvalue' => (($dbconnection->useheader == 1) ? 'checked' : ''),
'type' => 'checkbox',
'type' => 'switchbox',
'disabled' => false,
);
......@@ -464,14 +469,14 @@ $connection_details['elements']['certificate'] = array(
$connection_details['elements']['json'] = array(
'defaultvalue' => (($dbconnection->json == 1) ? 'checked' : ''),
'type' => 'checkbox',
'type' => 'switchbox',
'disabled' => false,
'title' => get_string('json', 'auth.webservice'),
);
$connection_details['elements']['isfatal'] = array(
'defaultvalue' => (($dbconnection->isfatal == 1) ? 'checked' : ''),
'type' => 'checkbox',
'type' => 'switchbox',
'disabled' => false,
'title' => get_string('isfatal', 'auth.webservice'),
);
......@@ -483,30 +488,6 @@ $connection_details['elements']['submit'] = array(
'goto' => 'addconnection.php?c=1',
);
// $elements = array(
// // fieldset for managing service function list
// 'connection_details' => array(
// 'type' => 'fieldset',
// 'legend' => ($add ? get_string('addconnection', 'auth.webservice') : get_string('editconnection', 'auth.webservice', $connectionid)),
// 'elements' => array(
// 'clist' => array(
// 'type' => 'html',
// 'value' => pieform($connection_details),
// )
// ),
// ),
// );
// $form = array(
// 'renderer' => 'div',
// 'id' => 'maintable',
// 'class' => 'form-group-nested',
// 'name' => 'connectionconfig',
// 'jsform' => true,
// 'successcallback' => 'allocate_client_connection_submit',
// 'validatecallback' => 'allocate_client_connection_validate',
// 'elements' => $elements,
// );
$form = pieform($connection_details);
$smarty = smarty();
if ($add) {
......
......@@ -24,6 +24,9 @@ define('INTERNAL', 1);
define('MENUITEM', 'webservices/connections');
define('INADMINMENU', 1);
define('ADMIN', 1);
define('SECTION_PLUGINTYPE', 'auth');
define('SECTION_PLUGINNAME', 'webservice');
define('SECTION_PAGE', 'connections');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(dirname(dirname(__FILE__)) . '/lib.php');
......@@ -62,15 +65,15 @@ if ($reorder && $json) {
$len = count(explode(',', $ids));
$ids = array_map("intval", explode(',', $ids));
if (count(array_unique($ids)) != $len) {
json_reply(true, 'Unique check failed for: '.var_export($ids, true));
json_reply(true, 'Unique check failed for: ' . var_export($ids, true));
}
$cons = array();
$idx = 0;
$idx = 1;
foreach ($ids as $id) {
$dbconnection = get_record('client_connections_institution', 'id', $id, 'institution', $institution);
if (empty($dbconnection)) {
json_reply(true, 'connection not found for: '.$id);
json_reply(true, 'connection not found for: ' . $id);
}
else {
$dbconnection->priority = $idx++;
......@@ -78,7 +81,7 @@ if ($reorder && $json) {
}
}
if (count($cons) != $len) {
json_reply(true, 'Not all connections found: '.var_export($ids, true));
json_reply(true, 'Not all connections found: ' . var_export($ids, true));
}
foreach ($cons as $c) {
......@@ -156,26 +159,24 @@ function webservice_connection_definitions() {
function webservice_client_connections($institution) {
$elements = array(
// fieldset for managing service function groups
'pluginconnections' => array(
'type' => 'fieldset',
'legend' => get_string('pluginconnections', 'auth.webservice'),
'elements' => array(
'sfgdescription' => array(
'value' => '<div><p>' . get_string('pcdescription', 'auth.webservice') . '</p></div>'
),
'webservicesservicecontainer' => array(
'type' => 'html',
'value' => webservice_connection_classes($institution),
)
),
'collapsible' => true,
'collapsed' => false,
'name' => 'plugin_connections',
),
// fieldset for managing service function groups
'pluginconnections' => array(
'type' => 'fieldset',
'legend' => get_string('pluginconnections', 'auth.webservice'),
'elements' => array(
'webservicesservicecontainer' => array(
'type' => 'html',
'value' => webservice_connection_classes($institution),
)
),
'collapsible' => true,
'collapsed' => false,
'name' => 'plugin_connections',
),
);
$form = array(
'name' => 'connectionform',
'renderer' => 'div',
'type' => 'div',
'elements' => $elements,
......@@ -299,6 +300,7 @@ $institutionselector = pieform(array(
// render the page
$form = webservice_client_connections($institution);
$smarty = smarty();
setpageicon($smarty, 'icon-plug');
safe_require('auth', 'webservice');
......
......@@ -93,12 +93,8 @@ $inlinejs = <<<JS
save_protos_switch('oauth');
});
if (!$('#needprotocols').length) {
$('#activate_connections_enabled_container').append('<span id="needprotocols" class="form-message-inline"></span>');
}
$('#activate_connections_enabled').on('change', function() {
// save master switch form
// save master connection switch form
$.post('index.php', $('#activate_connections').serialize());
});
});
......@@ -143,7 +139,7 @@ function activate_webservices_submit(Pieform $form, $values) {
}
exit;
}
redirect('/webservice/admin/index.php?open=activate_webservices');
redirect('/webservice/admin/index.php');
}
function activate_webservice_proto_submit(Pieform $form, $values) {
......@@ -1009,7 +1005,7 @@ function webservices_connections_master_switch_form() {
array(
'name' => 'activate_connections',
'elementclasses' => false,
'class' => 'form-switch',
'class' => 'form-switch form-group',
'successcallback' => 'activate_connections_submit',
'renderer' => 'div',
'jsform' => false,
......@@ -1038,7 +1034,7 @@ function activate_connections_submit(Pieform $form, $values) {
$enabled = $values['enabled'] ? 0 : 1;
set_config('webservice_connections_enabled', $enabled);
redirect('/webservice/admin/index.php?open=activate_connections');
redirect('/webservice/admin/index.php');
}
......@@ -1077,6 +1073,11 @@ function get_config_options_extended() {
'value' => '<h4>' . get_string('masterswitch', 'auth.webservice') . '</h4>',
),
'webservicesmasterswitchform' => webservices_master_switch_form(),
'masterswitchlabel2' => array(
'type' => 'html',
'value' => '<h4>' . get_string('connectionsmasterswitch', 'auth.webservice') . '</h4>',
),
'webservicesconnectionsswitchform' => webservices_connections_master_switch_form(),
'enablewebserviceprotos' => array(
'type' => 'html',
'value' => $protos->build(false),
......@@ -1087,22 +1088,6 @@ function get_config_options_extended() {
'name' => 'activate_webservices',
),
// fieldset of connections master switch
'webservicesconnections' => array(
'type' => 'fieldset',
'legend' => get_string('connectionsswitch', 'auth.webservice'),
'elements' => array(
'masterswitchlabel' => array(
'type' => 'html',
'value' => '<h4>' . get_string('connectionsmasterswitch', 'auth.webservice') . '</h4>',
),
'webservicesconnectionsswitchform' => webservices_connections_master_switch_form(),
),
'collapsible' => true,
'collapsed' => true,
'name' => 'activate_connections',
),
// System Certificates
'certificates' => array(
'type' => 'fieldset',
......
......@@ -79,9 +79,9 @@ class webservice_rest_server extends webservice_base_server {
execute_sql("delete from oauth_server_nonce");
// if we should have one - setup the OAuth server handler
$oauth_token = null;
if (webservice_protocol_is_enabled('oauth')) {
OAuthStore::instance('Mahara');
$oauth_token = null;
$this->oauth_server = new OAuthServer();
$headers = OAuthRequestLogger::getAllHeaders();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment