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

oscar at devel.lifetype.net oscar at devel.lifetype.net
Tue Aug 14 17:08:25 EDT 2007


Author: oscar
Date: 2007-08-14 17:08:25 -0400 (Tue, 14 Aug 2007)
New Revision: 5825

Added:
   plog/trunk/class/action/admin/adminaddtemplatefolderaction.class.php
Modified:
   plog/trunk/class/controller/admincontrollermap.properties.php
   plog/trunk/js/ui/forms.js
   plog/trunk/js/ui/pages/templateeditor.js
   plog/trunk/js/ui/ui.js
   plog/trunk/templates/admin/edittemplate.template
   plog/trunk/templates/admin/edittemplate_table.template
Log:
Added support for creating new template folders in the template editor


Added: plog/trunk/class/action/admin/adminaddtemplatefolderaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminaddtemplatefolderaction.class.php	                        (rev 0)
+++ plog/trunk/class/action/admin/adminaddtemplatefolderaction.class.php	2007-08-14 21:08:25 UTC (rev 5825)
@@ -0,0 +1,79 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminnewtemplatefolderview.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );		
+	lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );		
+	lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/template/editor/templatetools.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminsitetemplateslistview.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminerrordialogview.class.php" );
+	
+	class AdminAddTemplateFolderAction extends AdminAction
+	{
+		function __construct( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+			
+			$this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
+			$this->registerFieldValidator( "path", new StringValidator(), true );
+			$this->registerFieldValidator( "folderName", new StringValidator(), true );
+			$view = new AdminSiteTemplatesListView( $this->_blogInfo );
+			$view->setErrorMessage( $this->_locale->tr( "error_loading_template" ));
+			$this->setValidationErrorView( $view );
+
+			$this->requireAdminPermission( "edit_global_templates" );
+		}
+		
+		function validate()
+		{
+			if( !parent::validate()) 
+				return false;
+
+			// check that the template really exists
+			$this->_templateId = $this->_request->getFilteredValue( "templateId", new RegexpFilter( "/[^A-Za-z0-9_]/" ));
+			if( !TemplateSets::isTemplate( $this->_templateId )) {
+				$this->_form->setFieldValidationStatus( "templateId", false );
+				$this->validationErrorProcessing();
+				return( false );
+			}
+
+			// if the template exists, check that the path exists too
+			$this->_path = $this->_request->getFilteredValue( "path", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
+			if( !TemplateTools::isValidTemplatePath( $this->_templateId, $this->_path )) {
+				$this->_form->setFieldValidationStatus( "path", false );
+				$this->validationErrorProcessing();
+				return( false );				
+			}
+
+			// otherwise everything is peachy
+			return( true );
+		}
+		
+		function createFolder()
+		{
+			$folderName = $this->_request->getFilteredValue( "folderName", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
+			$folder = TemplateSetStorage::getTemplateFolder( $this->_templateId) . "/" . $this->_path . "/" . $folderName;
+			
+			return( File::createDir( $folder, File::FILE_DEFAULT_DIRECTORY_CREATION_MODE, false ));
+		}	
+		
+		function performAjax()
+		{
+			$result = $this->createFolder();
+			
+			lt_include( PLOG_CLASS_PATH."class/view/admin/ajax/adminajaxview.class.php" );
+			$this->_view = new AdminAjaxView( $this->_blogInfo );
+			
+			$this->_view->setSuccess( $result );
+			if( $result )
+				$this->_view->setSuccessMessage( $this->_locale->tr( "template_folder_created_ok" ));
+			else
+				$this->_view->setErrorMessage( $this->_locale->tr( "error_creating_template_folder" ));			
+			
+			return( true );
+		}
+	}
+	
+?>
\ No newline at end of file

Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php	2007-08-14 21:03:37 UTC (rev 5824)
+++ plog/trunk/class/controller/admincontrollermap.properties.php	2007-08-14 21:08:25 UTC (rev 5825)
@@ -360,4 +360,6 @@
 	$actions["editTemplateFile"] = "AdminEditTemplateFileAction";	
 	$actions["updateTemplateFile"] = "AdminUpdateTemplateFileAction";
 	$actions["deleteTemplateFile"] = "AdminDeleteTemplateFileAction";
+	$actions["newTemplateFolder"] = "AdminNewTemplateFolderAction";	
+	$actions["addTemplateFolder"] = "AdminAddTemplateFolderAction";		
 ?>
\ No newline at end of file

Modified: plog/trunk/js/ui/forms.js
===================================================================
--- plog/trunk/js/ui/forms.js	2007-08-14 21:03:37 UTC (rev 5824)
+++ plog/trunk/js/ui/forms.js	2007-08-14 21:08:25 UTC (rev 5825)
@@ -10,6 +10,8 @@
 
 Lifetype.Forms.List = function() {}
 
+Lifetype.Forms.Element = function() {}
+
 /**
  * @static
  * Removes the selected items from the list
@@ -320,6 +322,15 @@
  */
 Lifetype.Forms.Events.performRequestFailureEvent = new YAHOO.util.CustomEvent('performRequestFailureEvent');
 
+Lifetype.Forms.performUrl = function( url )
+{
+	var a = document.createElement( 'a' );
+	a.href = url;
+	a.style.display = 'none';
+	document.body.appendChild( a );
+	Lifetype.Forms.performRequest( a );
+}
+
 /**
  * This method can be used to execute a form or an anchor tag via XmlHttpRequest. Its output
  * is processed and placed in the page according to certain tags: ViewInfo and ViewInfoMessage for

Modified: plog/trunk/js/ui/pages/templateeditor.js
===================================================================
--- plog/trunk/js/ui/pages/templateeditor.js	2007-08-14 21:03:37 UTC (rev 5824)
+++ plog/trunk/js/ui/pages/templateeditor.js	2007-08-14 21:08:25 UTC (rev 5825)
@@ -12,6 +12,19 @@
 	Lifetype.UI.Pages.TemplateEditor.currentUrl = url;
 }
 
+Lifetype.UI.Pages.TemplateEditor.newFolderButtonHandler = function( a )
+{
+	var v = Lifetype.UI.Prompt.OkCancelPrompt.show( tr('enter_template_folder_name'), {handleOk:Lifetype.UI.Pages.TemplateEditor.handleNewFolderOk} );
+}
+
+Lifetype.UI.Pages.TemplateEditor.handleNewFolderOk = function( value )
+{
+	if( value != "" ) {
+		var url = '?op=addTemplateFolder&templateId=' + Lifetype.Dom.$( 'templateId' ).value + '&path=' + Lifetype.Dom.$( 'currentPath' ).value + '&folderName=' + value;
+		Lifetype.Forms.performUrl( url );
+	}
+}
+
 YAHOO.util.Event.addListener( window, "load", function() {
 	var t = new Lifetype.Effects.Table( "templateFiles" );
 	t.stripe();

Modified: plog/trunk/js/ui/ui.js
===================================================================
--- plog/trunk/js/ui/ui.js	2007-08-14 21:03:37 UTC (rev 5824)
+++ plog/trunk/js/ui/ui.js	2007-08-14 21:08:25 UTC (rev 5825)
@@ -41,6 +41,32 @@
 }
 
 /**
+ * Jumps to the first page in the ajax pager.
+ * @static
+ */
+Lifetype.UI.AjaxPager.firstPage = function()
+{
+	el = Lifetype.Dom.$( 'Pager' );
+	el.selectedIndex = 0;
+	Lifetype.UI.AjaxPager.onChangeEvent( el );	
+
+	return( false );
+}
+
+/**
+ * Jumps to the last page in the ajax pager.
+ * @static
+ */
+Lifetype.UI.AjaxPager.lastPage = function()
+{
+	el = Lifetype.Dom.$( 'Pager' );
+	el.selectedIndex = el.options.length - 1;
+	Lifetype.UI.AjaxPager.onChangeEvent( el );	
+
+	return( false );
+}
+
+/**
  * Jumps to the next page in the ajax pager.
  * @static
  */
@@ -160,3 +186,92 @@
 {	
   return( str.replace(/<\/?[^>]+>/gi, ''));
 }
+
+/**
+ * Namespace for prompt windows
+ */
+Lifetype.UI.Prompt = function() {}
+
+/**********
+ * Displays a very simple prompt with an input text box, an "Ok" button
+ * and a "Cancel" button
+ **********/
+
+/**
+ * Diplays a new prompt with the "Ok" and "Cancel" buttons
+ *
+ * @param str The string message to show
+ * @param props An object that may contain the following properties:
+ *   okCallback: the function to call when the 'ok' button is clicked
+ *   cancelCallback: the function to call then the 'cancel' button is clicked
+ *   defaultValue: the default value to show in the prompt, if any
+ */
+Lifetype.UI.Prompt.OkCancelPrompt = function( str, props )
+{
+	Lifetype.UI.Prompt.OkCancelPrompt.superclass.constructor.call( this, YAHOO.util.Dom.generateId(), {
+		fixedcenter:true,
+		constraintoviewport:true,
+		visible:false, 
+		close: true,
+		draggable: false,
+		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration: 0.25},
+		underlay:"shadow",
+		modal:true,
+		buttons : [ { text:tr("ok"), handler:this.handleOk, isDefault:true }, 
+		            { text:tr("cancel"), handler:this.handleCancel } ]		
+	});
+	
+	if( props != undefined ) {
+		this.okCallback = props.handleOk;
+		this.cancelCallback = props.handleCancel;
+		this.defaultValue = props.defaultValue;
+	}
+
+	var dlgBody  = "<div class='promptBody'>" + str + "<br/>" +
+		          "<input type='text' name='dlgPromptText' id='dlgPromptText' class='dlgPromptText' size='50' value='";
+	if( this.defaultValue )
+		dlgBody += this.defaultValue;
+	dlgBody     +=  "' /></div>";
+	this.setBody( dlgBody );
+	this.render( document.body );
+}
+
+YAHOO.extend( Lifetype.UI.Prompt.OkCancelPrompt, YAHOO.widget.Dialog );
+
+/**
+ * Handler for the Ok button. You should not reimplement this one,
+ * as it takes care of fetching the value that was typed in the field 
+ * and passing it to the okCallback function
+ * @private
+ */
+Lifetype.UI.Prompt.OkCancelPrompt.prototype.handleOk = function()
+{
+	if( this.okCallback != undefined ) {
+		var value = Lifetype.Dom.$( 'dlgPromptText' ).value;
+		this.okCallback( value );
+		this.handleCancel();
+	}
+	else {
+		this.handleCancel();
+	}
+}
+
+/**
+ * Handler for Cancel button. You should not reimplement this one either
+ * @private
+ */
+Lifetype.UI.Prompt.OkCancelPrompt.prototype.handleCancel = function()
+{
+	this.hide();
+	this.setBody( '' );
+}
+
+/**
+ * Static method that can be called to use the Lifetype.UI.Prompt.OkCancelPrompt class
+ * @static
+ */
+Lifetype.UI.Prompt.OkCancelPrompt.show = function( txt, props )
+{
+	var p = new Lifetype.UI.Prompt.OkCancelPrompt( txt, props );
+	p.show();
+}
\ No newline at end of file

Modified: plog/trunk/templates/admin/edittemplate.template
===================================================================
--- plog/trunk/templates/admin/edittemplate.template	2007-08-14 21:03:37 UTC (rev 5824)
+++ plog/trunk/templates/admin/edittemplate.template	2007-08-14 21:08:25 UTC (rev 5825)
@@ -6,7 +6,8 @@
 {check_perms adminperm=add_template}
 <div class="extraFunctions">
 	<div class="left">		
-		<a id="newFolderButton" href="?op=newTemplateFolder" rel="overlay">{$locale->tr("new_folder")}</a>&nbsp;|
+		<a id="newFolderButton" href="#"
+		   onClick="Lifetype.UI.Pages.TemplateEditor.newFolderButtonHandler(this);return(false);">{$locale->tr("new_folder")}</a>&nbsp;|
 		<a id="uploadFileButton" href="?op=newTemplateFile" rel="overlay">{$locale->tr("upload_file")}</a>
 	</div>
 	<div class="right">
@@ -22,11 +23,12 @@
  {include file="$admintemplatepath/edittemplate_table.template"}
  </div>
  <div id="list_action_bar">
-   <input type="hidden" name="templateId" value="{$template}" />
+   <input type="hidden" name="templateId" id="templateId" value="{$template}" />
    <input type="hidden" name="path" value="{$path}" />
    <input type="hidden" name="op" value="deleteTemplateFile" class="submit" />
    <input type="submit" name="{$locale->tr("delete")}" value="{$locale->tr("delete")}"/>
  </div>
 </form>
+
 {include file="$blogtemplate/footernavigation.template"}
 {include file="$blogtemplate/footer.template"}
\ No newline at end of file

Modified: plog/trunk/templates/admin/edittemplate_table.template
===================================================================
--- plog/trunk/templates/admin/edittemplate_table.template	2007-08-14 21:03:37 UTC (rev 5824)
+++ plog/trunk/templates/admin/edittemplate_table.template	2007-08-14 21:08:25 UTC (rev 5825)
@@ -91,4 +91,5 @@
   </tr>
  {/foreach}
  </tbody>
-</table>
\ No newline at end of file
+</table>
+<input type="hidden" id="currentPath" value="{$path}" />
\ No newline at end of file



More information about the pLog-svn mailing list