Commit dc933f02 authored by Donal McMullan's avatar Donal McMullan
Browse files

First cut at new Pieforms element for auth instances

parent 7579e6e9
......@@ -90,6 +90,7 @@ if ($institution || $add) {
if (!$add) {
$data = get_record('institution', 'name', $institution);
$lockedprofilefields = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
$authinstances = auth_get_auth_instances_for_institution($institution);
}
else {
$data = new StdClass;
......@@ -136,9 +137,9 @@ if ($institution || $add) {
'help' => true,
),
'authplugin' => array(
'type' => 'select',
'type' => 'authlist',
'title' => get_string('authplugin', 'admin'),
'options' => get_records_menu('auth_installed', '', '', 'name', 'name, name'),
'options' => $authinstances,
'help' => true,
),
'registerallowed' => array(
......@@ -188,6 +189,8 @@ if ($institution || $add) {
'value' => array(get_string('submit'), get_string('cancel'))
);
$smarty->assign('authinstances_count', count($authinstances));
$smarty->assign('institution_form', pieform(array(
'name' => 'institution',
'renderer' => 'table',
......
<?php
/**
* This program is part of Mahara
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form-element
* @author Martyn Smith <martyn@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
/**
* Provides an email list, with verification to enable addresses
*
* @param array $element The element to render
* @param Pieform $form The form to render the element for
* @return string The HTML for the element
*/
function pieform_element_authlist(Pieform $form, $element) {
$smarty = smarty();
$smarty->left_delimiter = '{{';
$smarty->right_delimiter = '}}';
$value = $form->get_value($element);
if (!is_array($value) && isset($element['defaultvalue']) && is_array($element['defaultvalue'])) {
$value = $element['defaultvalue'];
}
if (!isset($value['default'])) {
$value['default'] = '';
}
//var_dump($value['instancelist']);exit;
if (is_array($value) && count($value)) {
$smarty->assign('instancelist', $value['instancelist']);
$smarty->assign('default', $value['default']);
}
$smarty->assign('name', $element['name']);
return $smarty->fetch('form/authlist.tpl');
}
function pieform_element_authlist_get_value(Pieform $form, $element) {
$name = $element['name'];
$global = ($form->get_property('method') == 'get') ? $_GET : $_POST;
//if (!isset($global[$name . '_valid']) || !is_array($global[$name . '_valid'])) {
// return null;
//}
$value = array();
$value['instancelist'] = $element['options'];
//$value['default'] = $global[$name . '_selected'];
//$value['validated'] = $global[$name . '_valid'];
//if (isset($global[$name . '_invalid']) && is_array($global[$name . '_invalid'])) {
// $value['unvalidated'] = $global[$name . '_invalid'];
//}
//$value['options'] = array();
return $value;
}
?>
<script type="text/javascript">
var {{$name}}_newrefinput = null;
var {{$name}}_newref = null;
addLoadEvent(function() {
connect('{{$name}}_list', 'onkeypress', function (k) {
if (k.key().code == 13 && {{$name}}_newref) {
{{$name}}_addedemail();
k.stop();
}
// cancel (esc)
if (k.key().code == 27 && {{$name}}_newref ) {
removeElement({{$name}}_newrefinput);
removeElement({{$name}}_newref);
{{$name}}_newrefinput = null;
{{$name}}_newref = null;
k.stop();
}
});
});
function {{$name}}_addedemail() {
removeElement({{$name}}_newrefinput);
removeElement({{$name}}_newref);
var newEmail = {{$name}}_newrefinput.value;
if (typeof(newEmail) == 'string' && newEmail.length > 0) {
appendChildNodes('{{$name}}_list', DIV({'class': 'unvalidated'},
INPUT({'type': 'hidden', 'name': '{{$name}}_invalid[]' , 'value': {{$name}}_newrefinput.value}),
' ',
{{$name}}_newrefinput.value,
A({'href': '', 'onclick': '{{$name}}_remove(this); return false'}, '[x]'),
' a validation email will be sent when you save your profile'
));
}
{{$name}}_newrefinput = null;
{{$name}}_newref = null;
}
function {{$name}}_new() {
if ( {{$name}}_newref ) {
return false;
}
{{$name}}_newrefinput = INPUT({'type': 'text'});
{{$name}}_newref = DIV(null,{{$name}}_newrefinput);
appendChildNodes('{{$name}}_list', {{$name}}_newref);
{{$name}}_newrefinput.focus();
connect({{$name}}_newrefinput, 'onblur', function(k) {
{{$name}}_addedemail();
k.stop();
});
}
function {{$name}}_remove(x) {
var div = x.parentNode;
var radio = filter(
function(elem) { return getNodeAttribute(elem, 'type') == 'radio'; },
getElementsByTagAndClassName('input', null, div)
);
if (radio[0] && radio[0].checked) {
alert(get_string('cantremovedefaultemail'));
return;
}
removeElement(x.parentNode);
}
function {{$name}}_validated(email) {
var email = filter(
function(elem) { return getNodeAttribute(elem, 'type') == 'hidden' && elem.value == email ; },
getElementsByTagAndClassName('input', null, '{{$name}}_list')
)[0];
if (!email) {
return;
}
var div = email.parentNode;
email = email.value;
swapDOM(
div,
DIV(
{'class': 'validated'},
LABEL(null,
INPUT({'type': 'radio', 'name': '{{$name}}_selected', 'value': email}),
INPUT({'type': 'hidden', 'name': '{{$name}}_valid[]' , 'value': email}),
' ' + email
),
' ',
A({'href': '', 'onclick': '{{$name}}_remove(this); return false'}, '[x]')
)
);
}
function {{$name}}_cookie_check() {
var cookie = getCookie('validated_email');
if (cookie) {
{{$name}}_validated(cookie);
clearCookie('validated_email');
}
callLater(1, {{$name}}_cookie_check);
}
addLoadEvent({{$name}}_cookie_check);
</script>
<!-- TODO: shouldn't have css inline -->
<style type="text/css">
.unvalidated { color: gray; }
</style>
<div id="{{$name}}_list">
{{section name=mysec loop=$instancelist}}
<div class="validated">
<label>
<input type="hidden" name="authinstance[]" value="{{$instance->id}}">
<a href="" onclick="{{$name}}_edit({{$instance->id}}); return false;">{{$instancelist[mysec]->instancename}}</a></label>&nbsp;&nbsp;
{{ if $mysec + 1 < $authinstances_count }}
<a href="" onclick="{{$name}}_down({{$instance->id}}); return false;">[&darr;]</a>
{{ /if }}
{{ if $mysec != 0 }}
<a href="" onclick="{{$name}}_up({{$instance->id}}); return false;">[&uarr;]</a>
{{ /if }}
{{ if $authinstances_count > 0 }}
<a href="" onclick="{{$name}}_remove({{$instance->id}}); return false;">[x]</a>
{{ else }}
<a href="" title="Please configure another plugin before disabling this one." onclick="{{$name}}_cannot_remove({{$instance->id}}); return false;">[x]</a>
{{ /if }}
</div>
{{/section}}
</div>
<a href="" onclick="{{$name}}_new(); return false;">{{str tag="addemail"}}</a>
Markdown is supported
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