[pLog-svn] r4903 - in plog/trunk: class/action/admin js/ui templates/admin
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Thu Mar 1 09:25:25 EST 2007
Author: oscar
Date: 2007-03-01 09:25:25 -0500 (Thu, 01 Mar 2007)
New Revision: 4903
Modified:
plog/trunk/class/action/admin/adminaddarticlecategoryajaxaction.class.php
plog/trunk/js/ui/plogui.js
plog/trunk/templates/admin/editpost.template
plog/trunk/templates/admin/header.template
plog/trunk/templates/admin/newpost.template
Log:
moved the new category via ajax to the new ajax classes, ana moved the javascript code to the Lifetype.UI.Pages namespace.
Modified: plog/trunk/class/action/admin/adminaddarticlecategoryajaxaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminaddarticlecategoryajaxaction.class.php 2007-03-01 13:50:09 UTC (rev 4902)
+++ plog/trunk/class/action/admin/adminaddarticlecategoryajaxaction.class.php 2007-03-01 14:25:25 UTC (rev 4903)
@@ -1,9 +1,10 @@
<?php
- lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/action/admin/ajax/adminajaxaction.class.php" );
lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
- lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
- lt_include( PLOG_CLASS_PATH."class/view/admin/adminxmlview.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/view/admin/ajax/adminajaxview.class.php" );
/**
* \ingroup Action
@@ -11,13 +12,10 @@
*
* Action that adds a new article category to the database.
*/
- class AdminAddArticleCategoryAjaxAction extends AdminAction
+ class AdminAddArticleCategoryAjaxAction extends AdminAjaxAction
{
var $_categoryName;
- var $_categoryUrl;
- var $_properties;
- var $_categoryDescription;
/**
* Constructor. If nothing else, it also has to call the constructor of the parent
@@ -25,26 +23,10 @@
*/
function AdminAddArticleCategoryAjaxAction( $actionInfo, $request )
{
- $this->AdminAction( $actionInfo, $request );
- }
- function validate()
- {
- // fetch the data, we already know it's valid and that we can trust it!
- $this->_categoryName = Textfilter::filterAllHTML($this->_request->getValue( "categoryName" ));
- $this->_categoryUrl = "";
- $this->_categoryInMainPage = 1;
- $this->_categoryDescription = $this->_categoryName;
- $this->_properties = "";
+ $this->AdminAjaxAction( $actionInfo, $request );
- // check if there's any file to upload
- if( empty($this->_categoryName) || $this->_categoryName == "" ) {
- $this->_view = new AdminXmlView( $this->_blogInfo, "response" );
- $this->_view->setValue( "method", "addCategoryAjax" );
- $this->_view->setValue( "success", "0" );
- $this->_view->setValue( "message", $this->_locale->tr("error_adding_article_category") );
- return false;
- }
- return true;
+ $this->registerFieldValidator( "categoryName", new StringValidator());
+ $this->setValidationErrorView( $this->getErrorView( $this->_locale->tr("error_adding_article_category" )));
}
/**
@@ -52,36 +34,36 @@
*/
function perform()
{
+ // get the category name, it will be the only parameter
+ $this->_categoryName = Textfilter::filterAllHTML($this->_request->getValue( "categoryName" ));
+ if( empty($this->_categoryName) || $this->_categoryName == "" ) {
+ $this->_view = $this->getErrorView( $this->_locale->tr("error_adding_article_category"));
+ return false;
+ }
+
// create the object...
$categories = new ArticleCategories();
$category = new ArticleCategory( $this->_categoryName,
- $this->_categoryUrl,
+ "", // category URL, not used
$this->_blogInfo->getId(),
- $this->_categoryInMainPage,
- $this->_categoryDescription,
+ 1, // show the category in the main page
+ $this->_categoryName, // category description, same as name
0,
- $this->_properties );
+ "" );
// fire the pre event...
$this->notifyEvent( EVENT_PRE_CATEGORY_ADD, Array( "category" => &$category ));
- $this->_view = new AdminXmlView( $this->_blogInfo, "response" );
- $this->_view->setValue( "method", "addCategoryAjax" );
+ $this->_view = new AdminAjaxView( $this->_blogInfo, "addCategoryAjax" );
// once we have built the object, we can add it to the database!
$catId = $categories->addArticleCategory( $category );
// once we have built the object, we can add it to the database
- $this->_view = new AdminXmlView( $this->_blogInfo, "response" );
- $this->_view->setValue( "method", "addCategoryAjax" );
- if( $catId )
- {
- $this->_view->setValue( "success", "1" );
- $this->_view->setValue( "message", $this->_locale->pr("category_added_ok", $this->_categoryName) );
-
- $result = '<id>'.$catId.'</id>';
- $result .= '<name>'.$this->_categoryName.'</name>';
- $this->_view->setValue( "result", $result );
+ if( $catId ) {
+ $this->_view->setSuccess( true );
+ $this->_view->setMessage( $this->_locale->pr("category_added_ok", $this->_categoryName ));
+ $this->_view->setResult( $category );
// fire the post event
$this->notifyEvent( EVENT_POST_CATEGORY_ADD, Array( "category" => &$category ));
@@ -89,10 +71,9 @@
// clear the cache if everything went fine
CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );
}
- else
- {
- $this->_view->setValue( "success", "0" );
- $this->_view->setValue( "message", $this->_locale->tr("error_adding_article_category") );
+ else {
+ $this->_view->setSuccess( false );
+ $this->_view->setMessage( $this->_locale->tr("error_adding_article_category") );
}
return true;
Modified: plog/trunk/js/ui/plogui.js
===================================================================
--- plog/trunk/js/ui/plogui.js 2007-03-01 13:50:09 UTC (rev 4902)
+++ plog/trunk/js/ui/plogui.js 2007-03-01 14:25:25 UTC (rev 4903)
@@ -60,56 +60,6 @@
}
/**
- * The following functions are called when clicking the "add category" button
- */
-function addArticleCategoryAjax()
-{
- var categoryName = $F('newArticleCategory');
- if (categoryName != '')
- {
- var url = plogAdminBaseUrl;
- var params = 'op=addArticleCategoryAjax' + '&categoryName=' + encodeURIComponent(categoryName);
- var myAjax = new Ajax.Request(
- url,
- {method: 'get', parameters: params, onComplete: addArticleCategoryOption, onLoading: showArticleCategorySavingStatus }
- );
- }
-}
-
-function addArticleCategoryOption(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;
- if (!success) {
- window.alert(message);
- }
- else
- {
- var catId = xmldoc.getElementsByTagName('id')[0].firstChild.nodeValue;
- var catName = xmldoc.getElementsByTagName('name')[0].firstChild.nodeValue;
- for(i=$( 'postCategories' ).length; i>0; i--)
- {
- tmpText = $( 'postCategories' ).options[i-1].text;
- tmpValue = $( 'postCategories' ).options[i-1].value;
- tmpSelected = $( 'postCategories' ).options[i-1].selected;
- $( 'postCategories' ).options[i] = new Option( tmpText, tmpValue );
- $( 'postCategories' ).options[i].selected = tmpSelected;
- }
- $( 'postCategories' ).options[0] = new Option( catName, catId );
- $( 'postCategories' ).options[0].selected = true;
- $( 'newArticleCategory' ).value = '';
- $( 'addArticleCategory' ).disabled = 0;
- }
-}
-
-function showArticleCategorySavingStatus(originalRequest) {
- $( 'newArticleCategory' ).value = msgSaving;
- $( 'addArticleCategory' ).disabled = 1;
-}
-
-/**
* this function is the one called when clicking the "add category" button
*/
function switchOptionPanel()
@@ -288,4 +238,56 @@
iframe.src = url;
return( true );
+}
+
+/*****
+ * Code to add categories via Ajax
+ *****/
+Lifetype.UI.Pages.NewPost = function() {}
+
+/**
+ * The following functions are called when clicking the "add category" button
+ */
+Lifetype.UI.Pages.NewPost.addArticleCategoryAjax = function()
+{
+ var categoryName = $F('newArticleCategory');
+ if (categoryName != '') {
+ var params = 'op=addArticleCategoryAjax' + '&categoryName=' + encodeURIComponent(categoryName);
+
+ // build the full URL
+ var url = plogAdminBaseUrl + "?" + params;
+
+ var transaction = YAHOO.util.Connect.asyncRequest( 'GET', url, { success:Lifetype.UI.Pages.NewPost.addArticleCategoryOption, failure:Lifetype.UI.Pages.NewPost.addArticleCategoryOption } );
+
+ // show the "loading" message
+ $( 'newArticleCategory' ).value = msgSaving;
+ $( 'addArticleCategory' ).disabled = 1;
+ }
+}
+
+Lifetype.UI.Pages.NewPost.addArticleCategoryOption = function(originalRequest)
+{
+ //put returned XML in the textarea
+ var msg = Lifetype.JSon.decode( originalRequest.responseText );
+ var success = msg.success;
+ var message = msg.message;
+ if (!success) {
+ window.alert(message);
+ }
+ else {
+ var catId = msg.result._id;
+ var catName = msg.result._name;
+ for(i=$( 'postCategories' ).length; i>0; i--)
+ {
+ tmpText = $( 'postCategories' ).options[i-1].text;
+ tmpValue = $( 'postCategories' ).options[i-1].value;
+ tmpSelected = $( 'postCategories' ).options[i-1].selected;
+ $( 'postCategories' ).options[i] = new Option( tmpText, tmpValue );
+ $( 'postCategories' ).options[i].selected = tmpSelected;
+ }
+ $( 'postCategories' ).options[0] = new Option( catName, catId );
+ $( 'postCategories' ).options[0].selected = true;
+ $( 'newArticleCategory' ).value = '';
+ $( 'addArticleCategory' ).disabled = 0;
+ }
}
\ No newline at end of file
Modified: plog/trunk/templates/admin/editpost.template
===================================================================
--- plog/trunk/templates/admin/editpost.template 2007-03-01 13:50:09 UTC (rev 4902)
+++ plog/trunk/templates/admin/editpost.template 2007-03-01 14:25:25 UTC (rev 4903)
@@ -131,7 +131,7 @@
{/foreach}
</select>
<input type="text" name="newArticleCategory" id="newArticleCategory" style="width:100px; margin-top:3px;" size="16" value="" />
- <input type="button" name="addArticleCategory" id="addArticleCategory" style="width:35px; margin-top:3px;" value="{$locale->tr("add")}" onclick="javascript:addArticleCategoryAjax()" />
+ <input type="button" name="addArticleCategory" id="addArticleCategory" style="width:35px; margin-top:3px;" value="{$locale->tr("add")}" onclick="Lifetype.UI.Pages.NewPost.addArticleCategoryAjax()" />
{include file="$admintemplatepath/validate.template" field=postCategories message=$locale->tr("error_no_categories")}
</div>
Modified: plog/trunk/templates/admin/header.template
===================================================================
--- plog/trunk/templates/admin/header.template 2007-03-01 13:50:09 UTC (rev 4902)
+++ plog/trunk/templates/admin/header.template 2007-03-01 14:25:25 UTC (rev 4903)
@@ -28,6 +28,11 @@
<script type="text/javascript" src="js/cookie/cookie.js"></script>
<script type="text/javascript" src="js/prototype/prototype.js"></script>
<script type="text/javascript" src="js/rico/rico.js"></script>
+<!-- Yahoo UI Library -->
+<script type="text/javascript" src="js/yui/yahoo/yahoo-min.js"></script>
+<script type="text/javascript" src="js/yui/dom/dom-min.js"></script>
+<script type="text/javascript" src="js/yui/event/event-min.js"></script>
+<script type="text/javascript" src="js/yui/connection/connection-min.js"></script>
<!-- LifeType UI Library -->
<script type="text/javascript" src="js/ui/default.js"></script>
<script type="text/javascript" src="js/ui/common.js"></script>
@@ -36,10 +41,6 @@
<script type="text/javascript" src="js/ui/plogui.js"></script>
<script type="text/javascript" src="js/ui/tableeffects.js"></script>
<script type="text/javascript" src="js/ui/overlay.js"></script>
-<!-- Yahoo UI Library -->
-<script type="text/javascript" src="js/yui/yahoo/yahoo-min.js"></script>
-<script type="text/javascript" src="js/yui/dom/dom-min.js"></script>
-<script type="text/javascript" src="js/yui/event/event-min.js"></script>
{if $location_data_enabled}
<!-- Location libraries -->
<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key={$google_maps_api_key}"></script>
Modified: plog/trunk/templates/admin/newpost.template
===================================================================
--- plog/trunk/templates/admin/newpost.template 2007-03-01 13:50:09 UTC (rev 4902)
+++ plog/trunk/templates/admin/newpost.template 2007-03-01 14:25:25 UTC (rev 4903)
@@ -155,7 +155,7 @@
{/foreach}
</select>
<input type="text" name="newArticleCategory" id="newArticleCategory" style="width:100px; margin-top:3px;" size="16" value="" />
- <input type="button" name="addArticleCategory" id="addArticleCategory" style="width:35px; margin-top:3px;" value="{$locale->tr("add")}" onclick="javascript:addArticleCategoryAjax()" />
+ <input type="button" name="addArticleCategory" id="addArticleCategory" style="width:35px; margin-top:3px;" value="{$locale->tr("add")}" onclick="Lifetype.UI.Pages.NewPost.addArticleCategoryAjax()" />
{include file="$admintemplatepath/validate.template" field=postCategories message=$locale->tr("error_no_category_selected")}
</div>
More information about the pLog-svn
mailing list