From 57a664242e8363c7e2840be4f21456d9ec7f6d89 Mon Sep 17 00:00:00 2001
From: Bradley M. Froehle <brad.froehle@gmail.com>
Date: Sun, 17 Apr 2011 19:54:37 -0700
Subject: [PATCH] Issue #889396 by Dane Powell, bfroehle: Login form compatibility with Rubik (Open Atrium) and similar themes.

---
 cas.css    |   14 ++++++++------
 cas.js     |   30 ++++++++++++++++++++----------
 cas.module |   14 +++++++++-----
 3 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/cas.css b/cas.css
index ecb6c0b..e7c9b70 100644
--- a/cas.css
+++ b/cas.css
@@ -4,14 +4,16 @@
   background-repeat: no-repeat;
   padding-left: 20px;
 }
-html #user-login-form li.cas-link,
-html.js #user-login li.cas-link {
-  display: none;
-}
-html #user-login-form li.uncas-link,
-html #user-login li.uncas-link {
+
+#user-login-form li.cas-link,
+#user-login li.cas-link,
+#user-login-form li.uncas-link,
+#user-login li.uncas-link,
+#user-login-form .cas-login-redirection-message,
+#user-login .cas-login-redirection-message {
   display: none;
 }
+
 html.js #user-login-form li.cas-link,
 html.js #user-login li.cas-link {
   list-style: none;
diff --git a/cas.js b/cas.js
index a18ebf4..3eaafcd 100644
--- a/cas.js
+++ b/cas.js
@@ -1,9 +1,8 @@
 
 Drupal.behaviors.cas = function (context) {
-  var $loginElements = $("#edit-name-wrapper, #edit-pass-wrapper, #user-login-form li, #user-login li");
-  var $casElements = $("#edit-cas-identifier-wrapper, li.uncas-link");
-  $("#edit-cas-identifier").hide();
-  $("#edit-cas-identifier-wrapper label").hide();
+  var $loginElements = $("#edit-name-wrapper, #edit-pass-wrapper, li.cas-link, li.openid-link");
+  var $casElements = $("li.uncas-link, .cas-login-redirection-message");
+  $("#edit-cas-identifier-wrapper").hide();
   if($("#edit-cas-identifier").attr("checked")) {
     $loginElements.hide();
     // Use .css("display", "block") instead of .show() to be Konqueror friendly.
@@ -18,9 +17,9 @@ Drupal.behaviors.cas = function (context) {
 
   $("li.cas-link", context)
     .click( function() {
-       $loginElements.hide();
-       $casElements.css("display", "block");
-	   $("#edit-cas-identifier").attr("checked", true);
+      $loginElements.hide();
+      $casElements.css("display", "block");
+      $("#edit-cas-identifier").attr("checked", true);
       // Remove possible error message.
       $("#edit-name, #edit-pass").removeClass("error");
       $("div.messages.error").hide();
@@ -28,13 +27,24 @@ Drupal.behaviors.cas = function (context) {
     });
   $("li.uncas-link", context)
     .click(function() {
-       $loginElements.css("display", "block");
-       $casElements.hide();
-	   $("#edit-cas-identifier").attr("checked", false);
+      $loginElements.css("display", "block");
+      // Fix OpenID compatibility.
+      $('li.user-link').hide();
+      $casElements.hide();
+      $("#edit-cas-identifier").attr("checked", false);
       // Clear cas Identifier field and remove possible error message.
       $("div.messages.error").css("display", "block");
       // Set focus on username field.
       $("#edit-name")[0].focus();
       return false;
     });
+  // OpenID Compatibility
+  $("li.openid-link", context)
+    .click( function() {
+      $("li.cas-link").hide();
+    });
+  $("li.user-link", context)
+    .click( function() {
+      $("li.cas-link").css("display", "block");
+    });
 };
diff --git a/cas.module b/cas.module
index bad6537..799aef2 100644
--- a/cas.module
+++ b/cas.module
@@ -10,9 +10,9 @@
 define('CAS_NO_LINK', 0);
 define('CAS_ADD_LINK', 1);
 define('CAS_MAKE_DEFAULT', 2);
-define('CAS_LOGIN_INVITE_DEFAULT', 'Log in via single sign-on (CAS)');
-define('CAS_LOGIN_DRUPAL_INVITE_DEFAULT', 'Log in locally (no single sign-on)');
-define('CAS_LOGIN_REDIR_MESSAGE', 'You will be redirected to the secure cas login page');
+define('CAS_LOGIN_INVITE_DEFAULT', 'Log in using CAS');
+define('CAS_LOGIN_DRUPAL_INVITE_DEFAULT', 'Cancel CAS login');
+define('CAS_LOGIN_REDIR_MESSAGE', 'You will be redirected to the secure CAS login page.');
 define('CAS_EXCLUDE', 'services/*');
 
 /**
@@ -819,12 +819,16 @@ function cas_form_alter(&$form, &$form_state, $form_id) {
 
         $form['links']['#weight'] = 2;
 
+        $form['cas_description'] = array(
+          '#value' => "<div class='form-item cas-login-redirection-message'>" . t(variable_get('cas_login_redir_message', CAS_LOGIN_REDIR_MESSAGE)) . "</div>",
+          '#weight' => -1,
+        );
+
         $form['cas_identifier'] = array(
           '#type' => 'checkbox',
-          '#title' => t('Log in using CAS'),
+          '#title' => t(variable_get('cas_login_invite', CAS_LOGIN_INVITE_DEFAULT)) . ' (' . t(variable_get('cas_login_redir_message', CAS_LOGIN_REDIR_MESSAGE)) . ')',
           '#default_value' => variable_get('cas_login_form', CAS_NO_LINK) == CAS_MAKE_DEFAULT,
           '#weight' => -1,
-          '#description' => t(variable_get('cas_login_redir_message', CAS_LOGIN_REDIR_MESSAGE)),
         );
         $form['cas.return_to'] = array('#type' => 'hidden', '#value' => user_login_destination());
       }
-- 
1.7.4.1

