[pLog-svn] r3434 - in plog/trunk: . class/summary/action class/summary/view js/ui locale templates/summary templates/summary/xml

mark at devel.lifetype.net mark at devel.lifetype.net
Thu May 18 15:53:18 GMT 2006


Author: mark
Date: 2006-05-18 15:53:18 +0000 (Thu, 18 May 2006)
New Revision: 3434

Added:
   plog/trunk/class/summary/action/checkusernameajaxaction.class.php
   plog/trunk/class/summary/view/summaryxmlview.class.php
   plog/trunk/js/ui/summary.js
   plog/trunk/templates/summary/xml/
   plog/trunk/templates/summary/xml/response.template
Modified:
   plog/trunk/class/summary/view/summaryusercreationview.class.php
   plog/trunk/class/summary/view/summaryview.class.php
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/locale/locale_zh_TW.php
   plog/trunk/summary.php
   plog/trunk/templates/summary/registerstep1.template
Log:
Add support for user name check ajax.

Now user can check the name does exist or not before process the registration process.

For doing this:

1. I change the summaryview. Add a template folder parameter

2. Add a new summaryxmlview

3. Add the checkUserName ajax stuff..

It is only check the name exsit or not. And did not do any user name validation stuff ..

Added: plog/trunk/class/summary/action/checkusernameajaxaction.class.php
===================================================================
--- plog/trunk/class/summary/action/checkusernameajaxaction.class.php	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/class/summary/action/checkusernameajaxaction.class.php	2006-05-18 15:53:18 UTC (rev 3434)
@@ -0,0 +1,57 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/summary/action/registeraction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+	include_once( PLOG_CLASS_PATH."class/summary/view/summaryxmlview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+     * Action that adds a new article category to the database.
+     */
+    class CheckUserNameAjaxAction extends RegisterAction 
+	{
+
+    	var $_userName;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function CheckUserNameAjaxAction( $actionInfo, $request )
+        {
+        	$this->RegisterAction( $actionInfo, $request );
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+			$this->_userName = Textfilter::filterAllHTML($this->_request->getValue( "userName" ));
+			
+            // once we have built the object, we can add it to the database
+            $this->_view = new SummaryXmlView( "response" );				
+            $this->_view->setValue( "method", "checkUserNameAjax" );
+            
+			// create the object...
+            $users = new Users();
+            $userInfo = $users->getUserInfoFromUsername( $this->_userName );
+            if( !$userInfo )
+            {
+            	$this->_view->setValue( "success", "1" );
+            	$this->_view->setValue( "message", $this->_locale->tr("check_username_ok") );   
+            }
+            else
+            {
+            	$this->_view->setValue( "success", "0" );
+            	$this->_view->setValue( "message", $this->_locale->tr("error_username_exist") );  
+            }
+                
+            return true;	
+        }
+    }
+?>
\ No newline at end of file

Modified: plog/trunk/class/summary/view/summaryusercreationview.class.php
===================================================================
--- plog/trunk/class/summary/view/summaryusercreationview.class.php	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/class/summary/view/summaryusercreationview.class.php	2006-05-18 15:53:18 UTC (rev 3434)
@@ -25,6 +25,7 @@
     		else {
     			$this->setValue( "useCaptchaAuth", false );	    		
     		}
+    		$this->setValue( "summaryBaseUrl", $config->getValue( "base_url" )."/summary.php" );
     		
 			parent::render();    		
 		}

Modified: plog/trunk/class/summary/view/summaryview.class.php
===================================================================
--- plog/trunk/class/summary/view/summaryview.class.php	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/class/summary/view/summaryview.class.php	2006-05-18 15:53:18 UTC (rev 3434)
@@ -9,11 +9,13 @@
 	{
 
         var $_templateName;
+        var $_templateFolder;
 
-        function SummaryView( $templateName )
+        function SummaryView( $templateName, $templateFolder = "summary" )
         {
             $this->View();
-            $this->_templateName = $templateName;            
+            $this->_templateName = $templateName;
+            $this->_templateFolder = $templateFolder;
         }
         
         /**
@@ -41,7 +43,7 @@
 			parent::render();
 		
             $templateService = new TemplateService();
-            $template = $templateService->customTemplate( $this->_templateName, "summary" );
+            $template = $templateService->customTemplate( $this->_templateName, $this->_templateFolder );
 
             $this->_params->setValue( "version", new Version());
             $this->_params->setValue( "locale", $this->_locale );

Added: plog/trunk/class/summary/view/summaryxmlview.class.php
===================================================================
--- plog/trunk/class/summary/view/summaryxmlview.class.php	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/class/summary/view/summaryxmlview.class.php	2006-05-18 15:53:18 UTC (rev 3434)
@@ -0,0 +1,17 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/summary/view/summaryview.class.php" );
+	
+    /**
+     * \ingroup View
+     * @private
+     */	
+	class SummaryXmlView extends SummaryView
+	{
+        function SummaryXmlView( $templateName )
+        {
+            $this->SummaryView( $templateName, "summary/xml" );
+			$this->setContentType( TEXT_XML_CONTENT_TYPE );
+        }
+	}
+?>
\ No newline at end of file

Added: plog/trunk/js/ui/summary.js
===================================================================
--- plog/trunk/js/ui/summary.js	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/js/ui/summary.js	2006-05-18 15:53:18 UTC (rev 3434)
@@ -0,0 +1,37 @@
+function checkUserNameAjax()
+{
+	var userName = $F('userName');
+	if (userName != '')
+	{
+		var url = plogSummaryBaseUrl;
+		var params = 'op=checkUserNameAjax' + '&userName=' + encodeURIComponent(userName);
+		var myAjax = new Ajax.Request(
+						url,
+						{method: 'get', parameters: params, onComplete: showCheckUserNameResult }
+						);
+	}
+	else
+	{
+		alert("Username can not be empty");
+	}
+}
+
+function showCheckUserNameResult(originalRequest) {
+	//put returned XML in the textarea
+	var xmldoc = originalRequest.responseXML;
+	var success = xmldoc.getElementsByTagName('success')[0].firstChild.nodeValue;
+	var message = xmldoc.getElementsByTagName('message')[0].firstChild.nodeValue;
+	var successIcon = '<span style="background:green;color:white;font-weight:bold">&nbsp;!&nbsp;</span>&nbsp;&nbsp;';
+	var errorIcon = '<span style="background:red;color:white;font-weight:bold">&nbsp;!&nbsp;</span>&nbsp;&nbsp;';
+	Element.show($('checkResult'));
+	if( success == 1 )
+	{
+		$( 'checkResult' ).className  = 'fieldValidationSuccess';
+		$( 'checkResult' ).innerHTML = successIcon + message;
+	}
+	else
+	{
+		$( 'checkResult' ).className  = 'fieldValidationError';
+		$( 'checkResult' ).innerHTML = errorIcon + message;
+	}
+}
\ No newline at end of file

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/locale/locale_en_UK.php	2006-05-18 15:53:18 UTC (rev 3434)
@@ -1028,4 +1028,8 @@
 
 $messages['before_unload_message'] = 'It seems you have unsaved post, are you sure you want to leave?\n (If you don\'t press the "Ok" button in restart-seconds seconds, the auto save mechanisim will restart again.)';
 
+$messages['check_username'] = 'Check User Name';
+$messages['check_username_ok'] = 'Congradulations! The user name is available!';
+$messages['error_username_exist'] = 'Sorry! The user name is not available, please try others.';
+
 ?>
\ No newline at end of file

Modified: plog/trunk/locale/locale_zh_TW.php
===================================================================
--- plog/trunk/locale/locale_zh_TW.php	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/locale/locale_zh_TW.php	2006-05-18 15:53:18 UTC (rev 3434)
@@ -1028,4 +1028,8 @@
 
 $messages['before_unload_message'] = '你有尚未儲存的變更,你確定要離開嗎?\n如果你未於 restart-seconds 秒內按下『確定』,自動備份機制將重新啟動。';
 
+$messages['check_username'] = '檢查使用者名稱';
+$messages['check_username_ok'] = '恭喜!這個使用者名稱還沒有任何人使用。';
+$messages['error_username_exist'] = '抱歉!這個使用者名稱已經被別人用了,試試其他的吧!';
+
 ?>
\ No newline at end of file

Modified: plog/trunk/summary.php
===================================================================
--- plog/trunk/summary.php	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/summary.php	2006-05-18 15:53:18 UTC (rev 3434)
@@ -67,6 +67,7 @@
 		$_actionMap["RegisterStep3"] = "doBlogRegistration";
 		$_actionMap["RegisterStep4"] = "ChooseBlogTemplateAction";    
 		$_actionMap["RegisterStep5"] = "doFinishRegister";
+		$_actionMap["checkUserNameAjax"] = "checkUserNameAjaxAction";
 	}
 	else {
 		$_actionMap["RegisterStep0"] = "SummaryRegistrationDisabledAction";
@@ -74,7 +75,8 @@
 		$_actionMap["RegisterStep2"] = "SummaryRegistrationDisabledAction";
 		$_actionMap["RegisterStep3"] = "SummaryRegistrationDisabledAction";
 		$_actionMap["RegisterStep4"] = "SummaryRegistrationDisabledAction";    
-		$_actionMap["RegisterStep5"] = "SummaryRegistrationDisabledAction";	
+		$_actionMap["RegisterStep5"] = "SummaryRegistrationDisabledAction";
+		$_actionMap["checkUserNameAjax"] = "SummaryRegistrationDisabledAction";	
 	}
 	$_actionMap["resetPasswordForm"] = "SummaryShowResetPasswordForm";
 	$_actionMap["sendResetEmail"] = "SummarySendResetEmail";

Modified: plog/trunk/templates/summary/registerstep1.template
===================================================================
--- plog/trunk/templates/summary/registerstep1.template	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/templates/summary/registerstep1.template	2006-05-18 15:53:18 UTC (rev 3434)
@@ -1,4 +1,11 @@
 {include file="summary/header.template" section=$locale->tr("register_step1_title")}
+  <script type="text/javascript" src="js/prototype/prototype.js"></script>
+  <script type="text/javascript" src="js/ui/summary.js"></script>
+  <script type="text/javascript">
+  	var plogSummaryBaseUrl = "{$summaryBaseUrl}/summary.php";
+  	var successCheckUserNameMessage = "{$locale->tr("check_username_ok")}";
+  	var errorCheckUserNameMessage = "{$locale->tr("error_username_exist")}";
+  </script>
   <form name="newUser" action="summary.php" method="post">
     <fieldset class="inputField">
         <legend>{$locale->tr("step1")}</legend>
@@ -10,7 +17,9 @@
             <label for="userName">{$locale->tr("username")}</label>
 			<span class="required">*</span>
 			<div class="formHelp">{$locale->tr("username_help")}</div>
-            <input type="text" name="userName" value="{$userName}" id="userName" />
+            <input type="text" name="userName" value="{$userName}" id="userName" style="width: 73%;"/>
+            <input type="button" name="checkUserName" value="{$locale->tr("check_username")}" style="width: 25%;" onclick="javascript:checkUserNameAjax();">
+            <div id="checkResult" style="display: none"></div>
             {include file="summary/validate.template" field=userName message=$locale->tr("error_incorrect_username")}
         </div>
         <div class="field">

Added: plog/trunk/templates/summary/xml/response.template
===================================================================
--- plog/trunk/templates/summary/xml/response.template	2006-05-18 10:46:03 UTC (rev 3433)
+++ plog/trunk/templates/summary/xml/response.template	2006-05-18 15:53:18 UTC (rev 3434)
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<response>
+ <method>{$method}</method>
+ <success>{$success}</success>
+ <message><![CDATA[{$message}]]></message>
+ <result>{$result}</result>
+</response>
\ No newline at end of file



More information about the pLog-svn mailing list