From ae7839ffaada72c522ffcd9b3f4f1cc04027a720 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Nov 2008 06:23:09 +0000 Subject: Revise the user login code. * Remove user registration link and popup from the theme; this shouldn't be done in a popup. Use ajaxform to simplify the way that we load the login popup. * Create form.html.php, this is a template for Forge based forms. * Move user validation rules into User_Model and let forms populate the rules into their forms as useful. * Undo r18688's changes regarding the REST code. We should never accept a null resource, this breaks the REST abstraction. * Change login and user controllers to use Forge which lets us delete login.html.php and user.html.php since those now are generated by the theme-owned form template --- themes/default/css/screen.css | 84 ++++++++++++++++++------------------ themes/default/js/user.js | 79 +++++++++------------------------ themes/default/views/form.html.php | 54 +++++++++++++++++++++++ themes/default/views/header.html.php | 40 ++++++++--------- themes/default/views/page.html.php | 3 +- 5 files changed, 136 insertions(+), 124 deletions(-) create mode 100644 themes/default/views/form.html.php (limited to 'themes/default') diff --git a/themes/default/css/screen.css b/themes/default/css/screen.css index 5261706a..eeb4eeb9 100644 --- a/themes/default/css/screen.css +++ b/themes/default/css/screen.css @@ -576,7 +576,7 @@ table.gMetadata td.toggle { /** ** ******************************************************************* - * 8) Forms (general and specific) + * 8) Forms (general and specific) ** ******************************************************************* */ @@ -596,15 +596,15 @@ label { cursor: help; } -input[type="text"], +input[type="text"], input[type="password"], -textarea, -select { +textarea, +select { } -input[type="text"], -input[type="password"], -textarea, +input[type="text"], +input[type="password"], +textarea, .gValidationRule { width: 40%; } @@ -645,7 +645,7 @@ optgroup { select { } -textarea { +textarea { width: 99%; height: 12em; } @@ -655,16 +655,16 @@ button { /* ~~~~~~~~~ Form layout ~~~~~~~~~~ */ -form ul, form li { - list-style: none !important; +form ul, form li { + list-style: none !important; } -form ul { - margin: 0; +form ul { + margin: 0; padding: 0; } -form li { - margin-top: .5em; +form li { + margin-top: .5em; padding: .3em 1.5em .3em 1em; } @@ -676,16 +676,16 @@ form ul ul li { float: left; } -input, +input, textarea { - display: block; + display: block; clear: both; } /* ~~~~~~~~~ Inline fieldsets ~~~~~~~~~~ */ .gInline li { - float: left; + float: left; margin: 0; padding: .3em .5em .4em; text-align: left; @@ -694,7 +694,7 @@ textarea { .gInline input { } -.gInline input[type="Submit"] { +.gInline input[type="Submit"] { margin-top: 1em; } @@ -702,16 +702,16 @@ textarea { margin-top: 0; } -.gInline input[type="text"], -.gInline input[type="password"], -.gInline textarea, -.gInline .gValidationRule { +.gInline input[type="text"], +.gInline input[type="password"], +.gInline textarea, +.gInline .gValidationRule { width: 10em; } -input:focus, -textarea:focus, -option:focus { +input:focus, +textarea:focus, +option:focus { background-color: #ffc; } @@ -720,13 +720,13 @@ option:focus { .gRequired { } -ul.gError, -li.gError { +ul.gError, +li.gError { background-color: #ffdcdc; } -.gError label, -.gValidationRule { +.gError label, +.gValidationRule { color: red; } @@ -735,24 +735,24 @@ li.gError { margin-top: .5em; } -form.gError input[type="text"], -li.gError input[type="text"], -form.gError input[type="password"], -li.gError input[type="password"], -form.gError input[type="checkbox"], -li.gError input[type="checkbox"], -form.gError input[type="radio"], -li.gError input[type="radio"], -form.gError textarea, -li.gError textarea, -form.gError select, -li.gError select { +form.gError input[type="text"], +li.gError input[type="text"], +form.gError input[type="password"], +li.gError input[type="password"], +form.gError input[type="checkbox"], +li.gError input[type="checkbox"], +form.gError input[type="radio"], +li.gError input[type="radio"], +form.gError textarea, +li.gError textarea, +form.gError select, +li.gError select { border: 2px solid red; } /* ~~~~~~~~ form font size ~~~~~~ */ -#gHeader form, #gSidebar form { +#gHeader form, #gSidebar form { font-size: .9em; } diff --git a/themes/default/js/user.js b/themes/default/js/user.js index b389a67e..42ab1aa7 100644 --- a/themes/default/js/user.js +++ b/themes/default/js/user.js @@ -1,66 +1,29 @@ -$(document).ready(function() { - $("#gLoginForm").submit(function() { - process_login(); - return false; - }); - $("#gLogoutLink").click(function() { - process_logout(); - return false; - }); -}); - -function show_form(formName) { - $(formName + "Link").css({display: "none"}); - $(formName + "Text").css({display: "inline"}); - $(formName + "Close").css({display: "inline"}); - var url = $(formName + "Form").attr("formSrc"); - $.get(url, null, function(data, textStatus) { - $(formName + "Form").html(data); - $(formName + "Form").css({display: "block"}); +function show_login(url) { + $("#gLoginLink").hide(); + $("#gLoginClose").show(); + $.get(url, function(data) { + $("#gLoginFormContainer").html(data); + ajaxify_login_form(); }); } -function hide_form(formName) { - $(formName + "Link").css({display: "inline"}); - $(formName + "Form").css({display: "none"}); - $(formName + "Form").html(""); - $(formName + "Text").css({display: "none"}); - $(formName + "Close").css({display: "none"}); -} - -function process_login() { - $.ajax({ - url: $("#gLogin").attr("action"), - type: "POST", - data: $("#gLogin").serialize(), - dataType: "json", - error: function(XMLHttpRequest, textStatus, errorThrown) { - alert("textStatus: " + textStatus + "\nerrorThrown: " + errorThrown); - }, - success: function(data, textStatus) { - if (data.error_message != "") { - $("#gLoginMessage").html(data.error_message); - $("#gLoginMessage").css({display: "block"}); - $("#gLogin").addClass("gError"); - } else { +function ajaxify_login_form() { + $("form#gLogin").ajaxForm({ + target: "#gLoginFormContainer", + success: function(responseText, statusText) { + if (!responseText) { window.location.reload(); + } else { + ajaxify_login_form(); } - } + }, }); } -function process_logout() { - $.ajax({ - url: $("#gLogoutLink").attr("href"), - type: "GET", - dataType: "json", - error: function(XMLHttpRequest, textStatus, errorThrown) { - alert("textStatus: " + textStatus + "\nerrorThrown: " + errorThrown); - }, - success: function(data, textStatus) { - if (data.logout) { - window.location.reload(); - } - } - }); -} \ No newline at end of file +function close_login() { + $("#gLogin").remove(); + $("#gLoginClose").hide(); + $("#gLoginLink").show(); + $("input#gUsername").val(""); + $("input#gPassword").val(""); +} diff --git a/themes/default/views/form.html.php b/themes/default/views/form.html.php new file mode 100644 index 00000000..bc8d1339 --- /dev/null +++ b/themes/default/views/form.html.php @@ -0,0 +1,54 @@ +"; +} +if ($title) { + print ""; +} + +function DrawForm($inputs, $level=1) { + $error_messages = array(); + $prefix = str_repeat(" ", $level); + + foreach ($inputs as $input) { + if ($input->type == 'group') { + print "$prefix
\n"; + print "$prefix $input->name\n"; + print "$prefix \n"; + print "$prefix
\n"; + } else { + if ($input->error_messages()) { + $error_messages = array_merge($error_messages, $input->error_messages()); + print "$prefix
  • \n"; + } else { + print "$prefix
  • \n"; + } + if ($input->label()) { + print $prefix . " " . $input->label() . "\n"; + } + print $prefix . " " . $input->render() . "\n"; + print "$prefix
  • \n"; + if ($input->message()) { + print "$prefix
  • \n"; + print $prefix . " " . $input->message() . "\n"; + print "$prefix
  • \n"; + } + } + } + if ($error_messages) { + print "$prefix
    \n"; + foreach ($error_messages as $message) { + print "

    $message

    "; + } + print "$prefix

    \n"; + } +} +DrawForm($inputs); + +print($close); +?> diff --git a/themes/default/views/header.html.php b/themes/default/views/header.html.php index 24dd9331..8cba82ba 100644 --- a/themes/default/views/header.html.php +++ b/themes/default/views/header.html.php @@ -2,31 +2,25 @@ " src="url("images/logo.png") ?>" />

    title_edit ?>

    -
    +
    + +