[pLog-svn] r3362 - in plog/trunk: class/action/admin class/controller js/ui templates/admin

mark at devel.lifetype.net mark at devel.lifetype.net
Mon May 8 06:15:31 GMT 2006


Author: mark
Date: 2006-05-08 06:15:29 +0000 (Mon, 08 May 2006)
New Revision: 3362

Added:
   plog/trunk/class/action/admin/adminchangelinkscategoryaction.class.php
Modified:
   plog/trunk/class/controller/admincontrollermap.properties.php
   plog/trunk/js/ui/plogui.js
   plog/trunk/templates/admin/editlinks.template
Log:
Add massive links category function. Now, user can change links to different category massively. 

Added: plog/trunk/class/action/admin/adminchangelinkscategoryaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangelinkscategoryaction.class.php	2006-05-08 05:11:01 UTC (rev 3361)
+++ plog/trunk/class/action/admin/adminchangelinkscategoryaction.class.php	2006-05-08 06:15:29 UTC (rev 3362)
@@ -0,0 +1,96 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminlinkslistview.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+     * Action that shows a form to change the settings of the current blog.
+     */
+    class AdminChangeLinksCategoryAction extends AdminAction 
+	{
+
+        var $_linkIds;
+		var $_linkCategoryId;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminChangeLinksCategoryAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+			
+			$this->registerFieldValidator( "linkIds", new ArrayValidator());
+			$this->registerFieldValidator( "linkCategoryId", new IntegerValidator());
+			$view = new AdminLinksListView( $this->_blogInfo );	
+			$view->setErrorMessage( $this->_locale->tr("error_no_links_selected"));
+			$this->setValidationErrorView( $view );
+        }
+		
+		function perform()
+		{
+			$this->_linkIds = $this->_request->getValue( "linkIds" );
+			$this->_linkCategoryId = $this->_request->getValue( "linkCategoryId" );
+				
+			$this->_changeLinks();
+		}
+
+        /**
+         * Carries out the specified action
+		 * @private
+         */
+        function _changeLinks()
+        {
+            $errorMessage = "";
+			$successMessage = "";
+			$numOk = 0;
+
+        	// update the link
+            $links = new MyLinks();
+
+            foreach( $this->_linkIds as $linkId ) {
+            	// load the link
+                $link = $links->getMyLink( $linkId, $this->_blogInfo->getId());
+				
+				if( $link ) {
+					// fire the event
+					$this->notifyEvent( EVENT_PRE_LINK_UPDATE, Array( "link" => &$link ));
+
+					// update the link category
+					$link->setCategoryId( $this->_linkCategoryId );
+					$result = $links->updateMyLink( $link );
+					
+					if( !$result )
+						$errorMessage .= $this->_locale->pr("error_updating_link", $link->getName())."<br/>";
+					else {
+						$numOk++;
+						if( $numOk > 1 )
+							$successMessage = $this->_locale->pr("links_updated_ok", $numOk );
+						else
+							$successMessage = $this->_locale->pr("link_updated_ok", $link->getName());
+					}
+				}
+				else {
+					$errorMessage .= $this->_locale->pr("error_updating_link2", $linkId)."<br/>";
+				}
+            }
+
+            $this->_view = new AdminLinksListView( $this->_blogInfo );
+            if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
+			if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage );
+            $this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );
+
+            // better to return true if everything fine
+            return true;
+        }
+    }
+?>

Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php	2006-05-08 05:11:01 UTC (rev 3361)
+++ plog/trunk/class/controller/admincontrollermap.properties.php	2006-05-08 06:15:29 UTC (rev 3362)
@@ -68,6 +68,8 @@
     // deletes a link from the database
     $actions["deleteLink"] = "AdminDeleteLinkAction";
     $actions["deleteLinks"] = "AdminDeleteLinkAction";
+	// massive change links category
+	$actions["changeLinksCategory"] = "AdminChangeLinksCategoryAction";	
     // shows the list of link categories
     $actions["editLinkCategories"] = "AdminEditLinkCategoriesAction";
     // deletes a link category

Modified: plog/trunk/js/ui/plogui.js
===================================================================
--- plog/trunk/js/ui/plogui.js	2006-05-08 05:11:01 UTC (rev 3361)
+++ plog/trunk/js/ui/plogui.js	2006-05-08 06:15:29 UTC (rev 3362)
@@ -199,6 +199,12 @@
 	document.getElementById("Resources").submit();
 }
 
+function submitLinksList(op)
+{
+	document.getElementById("links").op.value = op;
+	document.getElementById("links").submit();
+}
+
 function switchMassiveOption()
 {
 	if ( $('massiveChangeOption').style.display == 'none' )

Modified: plog/trunk/templates/admin/editlinks.template
===================================================================
--- plog/trunk/templates/admin/editlinks.template	2006-05-08 05:11:01 UTC (rev 3361)
+++ plog/trunk/templates/admin/editlinks.template	2006-05-08 06:15:29 UTC (rev 3362)
@@ -1,7 +1,12 @@
 {include file="$admintemplatepath/header.template"}
 {include file="$admintemplatepath/navigation.template" showOpt=editLinks title=$locale->tr("editLinks")}
-        <div id="list_nav_bar">
-            <div id="list_nav_select">
+  <script type="text/javascript" src="js/ui/plogui.js"></script>
+  <script type="text/javascript">
+    var showMassiveChangeOption = '{$locale->tr("show_massive_change_option")}';
+    var hideMassiveChangeOption = '{$locale->tr("hide_massive_change_option")}';
+  </script>
+<div id="list_nav_bar">
+<div id="list_nav_select">
 <form id="viewLinks" action="admin.php" method="post">
  <fieldset>
   <legend>{$locale->tr("show_by")}</legend>
@@ -34,6 +39,9 @@
  </div>
 
 <form id="links" action="admin.php" method="post">
+<div class="optionIcon">
+  <a id="optionIconLink" href="#" title="{$locale->tr("show_massive_change_option")}" onclick="switchMassiveOption()">{$locale->tr("show_massive_change_option")}</a>
+</div>
 <div id="list">
   {include file="$admintemplatepath/successmessage.template"}
   {include file="$admintemplatepath/errormessage.template"}
@@ -81,6 +89,18 @@
   {include file="$admintemplatepath/adminpager.template" style=list}
   <input type="hidden" name="op" value="deleteLinks"/>
   <input type="submit" name="Delete selected" value="{$locale->tr("delete")}"/>
+  <div id="massiveChangeOption" style="display: none">
+    <fieldset>
+      <legend>{$locale->tr("messave_change_option")}</legend>
+	  <label for="linkCategoryId">{$locale->tr("category")}</label>
+	  <select name="linkCategoryId" id="linkCategoryId">
+        {foreach from=$linkscategories item=category}
+          <option value="{$category->getId()}">{$category->getName()}</option>
+        {/foreach}
+      </select>
+	  <input type="button" name="changeLinksCategory" value="{$locale->tr("change_category")}" class="submit" onClick="javascript:submitLinksList('changeLinksCategory');" />
+    </fieldset>
+  </div>  
  </div>
 </form>
 



More information about the pLog-svn mailing list