Commit a5988cdf authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review
Browse files

Merge changes I2982be3a,I525f692d,If26ebd58,I71d46a08

* changes:
  Add button class around external login links
  Add a label to the extra login links
  Add divs around login form
  Add support for a generic pieform container
parents df442b6f 24765025
......@@ -220,7 +220,7 @@ class PluginAuthBrowserid extends PluginAuth {
public static function login_form_elements() {
return array(
'loginbrowserid' => array(
'value' => '<div class="login-externallink"><a href="javascript:window.browserid_login()">' . get_string('login', 'auth.browserid') . '</a></div>'
'value' => '<div class="login-externallink"><a class="btn" href="javascript:window.browserid_login()">' . get_string('login', 'auth.browserid') . '</a></div>'
)
);
}
......
......@@ -1041,6 +1041,7 @@ function auth_get_login_form() {
'value' => get_string('login')
),
'register' => array(
'type' => 'markup',
'value' => '<div id="login-helplinks">' . '<a href="' . get_config('wwwroot') . 'forgotpass.php" tabindex="2">' . get_string('lostusernamepassword') . '</a></div>'
),
'login_submitted' => array(
......@@ -1048,6 +1049,12 @@ function auth_get_login_form() {
'value' => 1
),
);
$elements = array(
'login' => array(
'type' => 'container',
'elements' => $elements
)
);
// Get any extra elements from the enabled auth plugins
......@@ -1064,6 +1071,20 @@ function auth_get_login_form() {
$showbasicform = true;
}
}
if (!empty($extraelements) && $showbasicform) {
$loginlabel = array(
'type' => 'markup',
'value' => '<label>'.get_string('orloginvia') . '</label>'
);
$extraelements = array_merge(array('label' => $loginlabel), $extraelements);
}
$extraelements = array(
'login_extra' => array(
'type' => 'container',
'class' => 'login_extra',
'elements' => $extraelements
)
);
// Replace or supplement the standard login form elements
if ($showbasicform) {
......@@ -1747,10 +1768,19 @@ function auth_generate_login_form() {
'value' => get_string('login')
),
'register' => array(
'type' => 'markup',
'value' => '<div id="login-helplinks">' . $registerlink
. '<a href="' . get_config('wwwroot') . 'forgotpass.php" tabindex="2">' . get_string('lostusernamepassword') . '</a></div>'
),
);
$elements = array(
'login' => array(
'type' => 'container',
'class' => 'login',
'elements' => $elements
)
);
// Get any extra elements from the enabled auth plugins
$extraelements = array();
......@@ -1766,6 +1796,20 @@ function auth_generate_login_form() {
$showbasicform = true;
}
}
if (!empty($extraelements) && $showbasicform) {
$loginlabel = array(
'type' => 'markup',
'value' => '<label>'.get_string('orloginvia') . '</label>'
);
$extraelements = array_merge(array('label' => $loginlabel), $extraelements);
}
$extraelements = array(
'login_extra' => array(
'type' => 'container',
'class' => 'login_extra',
'elements' => $extraelements
)
);
// Replace or supplement the standard login form elements
if ($showbasicform) {
......
......@@ -596,7 +596,7 @@ class PluginAuthSaml extends PluginAuth {
public static function login_form_elements() {
$elements = array(
'loginsaml' => array(
'value' => '<div class="login-externallink"><a href="' . get_config('wwwroot') . 'auth/saml/">' . get_string('login', 'auth.saml') . '</a></div>'
'value' => '<div class="login-externallink"><a class="btn" href="' . get_config('wwwroot') . 'auth/saml/">' . get_string('login', 'auth.saml') . '</a></div>'
)
);
return $elements;
......
......@@ -335,6 +335,7 @@ $string['loggedoutok'] = 'You have been logged out successfully';
$string['login'] = 'Login';
$string['loginfailed'] = 'You have not provided the correct credentials to log in. Please check your username and password are correct.';
$string['loginto'] = 'Log in to %s';
$string['orloginvia'] = 'Or login via:';
$string['newpassword'] = 'New password';
$string['nosessionreload'] = 'Reload the page to log in';
$string['oldpassword'] = 'Current password';
......
......@@ -115,7 +115,7 @@ class Pieform {/*{{{*/
/**
* A hash of references to the elements of the form, not including
* fieldsets (although including all elements inside any fieldsets. Used
* fieldsets/containers (although including all elements inside any fieldsets/containers. Used
* internally for simplifying looping over elements
*
* @var array
......@@ -315,7 +315,7 @@ class Pieform {/*{{{*/
$this->spamerror = false;
}
// Get references to all the elements in the form, excluding fieldsets
// Get references to all the elements in the form, excluding fieldsets/containers
foreach ($this->data['elements'] as $name => &$element) {
// The name can be in the element itself. This is compatibility for
// the perl version
......@@ -323,11 +323,11 @@ class Pieform {/*{{{*/
$name = $element['name'];
}
if (isset($element['type']) && $element['type'] == 'fieldset') {
// Load the fieldset plugin as we know this form has one now
$this->include_plugin('element', 'fieldset');
if (isset($element['type']) && ($element['type'] == 'fieldset' || $element['type'] == 'container')) {
// Load the fieldset/container plugin as we know this form has one now
$this->include_plugin('element', $element['type']);
if ($this->get_property('template')) {
self::info("Your form '$this->name' has a fieldset, but is using a template. Fieldsets make no sense when using templates");
self::info("Your form '$this->name' has a " . $element['type'] . ", but is using a template. Fieldsets/containers make no sense when using templates");
}
foreach ($element['elements'] as $subname => &$subelement) {
......@@ -360,7 +360,7 @@ class Pieform {/*{{{*/
// This can't be done using $this->elementrefs, because you can't unset
// an entry in there and have it unset the entry in $this->data['elements']
foreach ($this->data['elements'] as $name => $element) {
if (isset($element['type']) && $element['type'] == 'fieldset') {
if (isset($element['type']) && ($element['type'] == 'fieldset' || $element['type'] == 'container')) {
foreach ($element['elements'] as $subname => $subelement) {
if (!empty($subelement['ignore'])) {
unset ($this->data['elements'][$name]['elements'][$subname]);
......@@ -647,7 +647,7 @@ class Pieform {/*{{{*/
// Builds the HTML each element (see the build_element_html method for
// more information)
foreach ($this->data['elements'] as &$element) {
if ($element['type'] == 'fieldset') {
if ($element['type'] == 'fieldset' || $element['type'] == 'container') {
foreach ($element['elements'] as &$subelement) {
$this->build_element_html($subelement);
}
......@@ -818,14 +818,14 @@ class Pieform {/*{{{*/
/**
* Retrieves a list of elements in the form.
*
* This flattens fieldsets, and ignores the actual fieldset elements
* This flattens fieldsets/containers, and ignores the actual fieldset/container elements
*
* @return array The elements of the form
*/
public function get_elements() {/*{{{*/
$elements = array();
foreach ($this->data['elements'] as $name => $element) {
if ($element['type'] == 'fieldset') {
if ($element['type'] == 'fieldset' || $element['type'] == 'container') {
foreach ($element['elements'] as $subelement) {
$elements[] = $subelement;
}
......@@ -841,7 +841,7 @@ class Pieform {/*{{{*/
* Returns the element with the given name. Throws a PieformException if the
* element cannot be found.
*
* Fieldset elements are ignored. This might change if a valid case for
* Fieldset and container elements are ignored. This might change if a valid case for
* needing them is found.
*
* @param string $name The name of the element to find
......@@ -950,7 +950,7 @@ EOF;
return;
}
foreach ($this->data['elements'] as $key => &$element) {
if ($element['type'] == 'fieldset') {
if ($element['type'] == 'fieldset' || $element['type'] == 'container') {
foreach ($element['elements'] as &$subelement) {
if ($subelement['name'] == $name) {
$subelement['error'] = $message;
......@@ -1231,7 +1231,7 @@ EOF;
* for example if they were check boxes that were not checked upon
* submission.
*
* A value is returned for every element (except fieldsets of course). If
* A value is returned for every element (except fieldsets/containers of course). If
* an element was not set, the value set is <kbd>null</kbd>.
*
* @return array The submitted values
......@@ -1329,7 +1329,7 @@ EOF;
*/
private function auto_focus_first_error() {/*{{{*/
foreach ($this->data['elements'] as &$element) {
if ($element['type'] == 'fieldset') {
if ($element['type'] == 'fieldset' || $element['type'] == 'container') {
foreach ($element['elements'] as &$subelement) {
if (isset($subelement['error'])) {
$subelement['autofocus'] = true;
......@@ -1580,7 +1580,7 @@ EOF;
* PieformException.
*
* {@internal This is separate so that child element types can nest other
* elements inside them (like the fieldset element does for example).}}
* elements inside them (like the fieldset and container elements do for example).}}
*
* NOTE: This function is SCHEDULED FOR REMOVAL. Nicer ways of getting built
* elements are available
......@@ -1612,6 +1612,11 @@ function pieform_render_element(Pieform $form, $element) {/*{{{*/
$element['html'] = pieform_element_fieldset($form, $element);
}
// Render containers now
if ($element['type'] == 'container') {
$element['html'] = pieform_element_container($form, $element);
}
return $rendererfunction($form, $element);
}/*}}}*/
......
<?php
/**
* Pieforms: Advanced web forms made easy
* Copyright (C) 2012 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package pieforms
* @subpackage element
* @author Hugh Davenport <hugh@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2012 Catalyst IT Ltd http://catalyst.net.nz
*
*/
/**
* Renders a container. Containers contain other elements, and do not count as a
* "true" element, in that they do not have a value and cannot be validated.
*
* Similar to a fieldset, except with no wrapper, apart from the div produced by
* the pieform
*
* @param Pieform $form The form to render the element for
* @param array $element The element to render
* @return string The HTML for the element
*/
function pieform_element_container(Pieform $form, $element) {/*{{{*/
$result = "";
foreach ($element['elements'] as $subname => $subelement) {
$result .= "\t" . pieform_render_element($form, $subelement);
}
return $result;
}/*}}}*/
......@@ -59,8 +59,8 @@ class FormRendererMultiColumnTable {/*{{{*/
private $form;
function add_element($builtelement, $rawelement) {
if ($rawelement['type'] == 'fieldset') {
throw new PieformException('The multicolumntable renderer does not support fieldsets');
if ($rawelement['type'] == 'fieldset' || $rawelement['type'] == 'container') {
throw new PieformException('The multicolumntable renderer does not support fieldsets or containers');
}
if (!isset($rawelement['key'])) {
......
......@@ -33,6 +33,9 @@
*/
function pieform_renderer_table(Pieform $form, $element) {/*{{{*/
$formname = $form->get_name();
if ($element['type'] == 'container') {
throw new PieformException('The table renderer does not support containers');
}
if ($element['type'] == 'fieldset') {
// Add table tags to the build element, to preserve HTML compliance
$builtelement = $element['html'];
......
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