Added StyleEditForm and implemented preview image uploads
authorAlexander Ebert <ebert@woltlab.com>
Wed, 10 Oct 2012 15:38:40 +0000 (17:38 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 10 Oct 2012 15:38:40 +0000 (17:38 +0200)
acptemplates/styleAdd.tpl
files/lib/acp/form/StyleAddForm.class.php
files/lib/acp/form/StyleEditForm.class.php [new file with mode: 0644]
language/de.xml

index d2bbf4ed7d04a1d5d963d0d34330228bad411ebe..3377126966313ab0b6ad4f59e33be5b6a275d484 100644 (file)
@@ -1,5 +1,6 @@
 {include file='header'}
 
+<script type="text/javascript" src="{@$__wcf->getPath()}acp/js/WCF.ACP.StyleEditor.js"></script>
 <script type="text/javascript" src="{@$__wcf->getPath()}js/WCF.ColorPicker.js"></script>
 <script type="text/javascript">
        //<![CDATA[
@@ -22,6 +23,8 @@
                }
                $useFluidLayout.change(useFluidLayout);
                useFluidLayout();
+               
+               new WCF.ACP.StyleEditor.Upload(0, '{$tmpHash}');
        });
        //]]>
 </script>
                                
                                <dl{if $errorField == 'image'} class="formError"{/if}>
                                        <dt><label for="image">{lang}wcf.acp.style.image{/lang}</label></dt>
-                                       <dd>
-                                               <input type="hidden" name="image" value="{$image}" readonly="readonly" class="long" /> TODO: Add upload here!
+                                       <dd class="framed">
+                                               <img src="{if $action == 'add'}{@$__wcf->getPath()}images/stylePreview.png{else}{@$style->getPreviewImage()}{/if}" alt="" id="styleImage" />
+                                               <div id="uploadImage" class="marginTop"></div>
+                                               {*<input type="hidden" name="image" value="{$image}" readonly="readonly" class="long" /> TODO: Add upload here!*}
                                                {if $errorField == 'image'}
                                                        <small class="innerError">
                                                                {if $errorType == 'empty'}
        
        <div class="formSubmit">
                <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s" />
+               <input type="hidden" name="tmpHash" value="{$tmpHash}" />
                {if $styleID|isset}<input type="hidden" name="id" value="{@$styleID}" />{/if}
        </div>
 </form>
index e714bfeddc996898e445659c22ce1d39da278397..c2cbef40e103c77a3f8152b3604668d06cf60f6d 100644 (file)
@@ -103,12 +103,6 @@ class StyleAddForm extends ACPForm {
         */
        public $iconPath = 'icon/';
        
-       /**
-        * path to preview image 
-        * @var string
-        */
-       public $image = '';
-       
        /**
         * image path
         * @var string
@@ -151,6 +145,12 @@ class StyleAddForm extends ACPForm {
         */
        public $templateGroupID = 0;
        
+       /**
+        * temporary image hash
+        * @var string
+        */
+       public $tmpHash = '';
+       
        /**
         * fluid or fixed layout
         * @var boolean
@@ -177,6 +177,13 @@ class StyleAddForm extends ACPForm {
                $templateGroupList->sqlOrderBy = "template_group.templateGroupName ASC";
                $templateGroupList->readObjects();
                $this->availableTemplateGroups = $templateGroupList->getObjects();
+               
+               if (isset($_REQUEST['tmpHash'])) {
+                       $this->tmpHash = StringUtil::trim($_REQUEST['tmpHash']);
+               }
+               if (empty($this->tmpHash)) {
+                       $this->tmpHash = StringUtil::getRandomID();
+               }
        }
        
        /**
@@ -209,7 +216,6 @@ class StyleAddForm extends ACPForm {
                if (isset($_POST['authorURL'])) $this->authorURL = StringUtil::trim($_POST['authorURL']);
                if (isset($_POST['copyright'])) $this->copyright = StringUtil::trim($_POST['copyright']);
                if (isset($_POST['iconPath'])) $this->iconPath = StringUtil::trim($_POST['iconPath']);
-               if (isset($_POST['image'])) $this->image = StringUtil::trim($_POST['image']);
                if (isset($_POST['imagePath'])) $this->imagePath = StringUtil::trim($_POST['imagePath']);
                if (isset($_POST['license'])) $this->license = StringUtil::trim($_POST['license']);
                if (isset($_POST['styleDate'])) $this->styleDate = StringUtil::trim($_POST['styleDate']);
@@ -381,7 +387,6 @@ class StyleAddForm extends ACPForm {
                                'styleDescription' => ($this->styleDescription ? $this->styleDescription : null),
                                'styleVersion' => $this->styleVersion,
                                'styleDate' => $this->styleDate,
-                               'image' => $this->image,
                                'imagePath' => $this->imagePath,
                                'copyright' => $this->copyright,
                                'license' => $this->license,
@@ -389,6 +394,7 @@ class StyleAddForm extends ACPForm {
                                'authorURL' => $this->authorURL,
                                'iconPath' => $this->iconPath
                        ),
+                       'tmpHash' => $this->tmpHash,
                        'variables' => $this->variables
                ));
                $this->objectAction->executeAction();
@@ -397,9 +403,8 @@ class StyleAddForm extends ACPForm {
                $this->saved();
                
                // reset variables
-               $this->authorName = $this->authorURL = $this->copyright = $this->fontFamily = '';
-               $this->image = $this->license = $this->styleDate = $this->styleDescription = '';
-               $this->styleName = $this->styleVersion = 0;
+               $this->authorName = $this->authorURL = $this->copyright = $this->fontFamily = $this->image = '';
+               $this->license = $this->styleDate = $this->styleDescription = $this->styleName = $this->styleVersion = '';
                
                $this->iconPath = 'icon/';
                $this->imagePath = 'images/';
@@ -428,7 +433,6 @@ class StyleAddForm extends ACPForm {
                        'copyright' => $this->copyright,
                        'fontFamily' => $this->fontFamily,
                        'iconPath' => $this->iconPath,
-                       'image' => $this->image,
                        'imagePath' => $this->imagePath,
                        'license' => $this->license,
                        'styleDate' => $this->styleDate,
@@ -436,6 +440,7 @@ class StyleAddForm extends ACPForm {
                        'styleName' => $this->styleName,
                        'styleVersion' => $this->styleVersion,
                        'templateGroupID' => $this->templateGroupID,
+                       'tmpHash' => $this->tmpHash,
                        'useFluidLayout' => $this->useFluidLayout,
                        'variables' => $this->variables
                ));
diff --git a/files/lib/acp/form/StyleEditForm.class.php b/files/lib/acp/form/StyleEditForm.class.php
new file mode 100644 (file)
index 0000000..d715c68
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+namespace wcf\acp\form;
+use wcf\data\style\Style;
+use wcf\data\style\StyleAction;
+use wcf\form\AbstractForm;
+use wcf\system\exception\IllegalLinkException;
+use wcf\system\WCF;
+
+/**
+ * Shows the style edit form.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.acp.style
+ * @subpackage acp.form
+ * @category   Community Framework
+ */
+class StyleEditForm extends StyleAddForm {
+       /**
+        * style object
+        * @var wcf\data\style\Style
+        */
+       public $style = null;
+       
+       /**
+        * style id
+        * @var integer
+        */
+       public $styleID = 0;
+       
+       /**
+        * @see wcf\page\IPage::readParameters()
+        */
+       public function readParameters() {
+               if (isset($_REQUEST['id'])) $this->styleID = intval($_REQUEST['id']);
+               $this->style = new Style($this->styleID);
+               if (!$this->style->styleID) {
+                       throw new IllegalLinkException();
+               }
+               
+               parent::readParameters();
+       }
+       
+       /**
+        * @see wcf\acp\form\StyleAddForm::readStyleVariables()
+        */
+       protected function readStyleVariables() {
+               $this->variables = $this->style->getVariables();
+       }
+       
+       /**
+        * @see wcf\page\IPage::readData()
+        */
+       public function readData() {
+               parent::readData();
+               
+               if (empty($_POST)) {
+                       $this->authorName = $this->style->authorName;
+                       $this->authorURL = $this->style->authorURL;
+                       $this->copyright = $this->style->copyright;
+                       $this->iconPath = $this->style->iconPath;
+                       $this->imagePath = $this->style->imagePath;
+                       $this->license = $this->style->license;
+                       $this->styleDate = $this->style->styleDate;
+                       $this->styleDescription = $this->style->styleDescription;
+                       $this->styleName = $this->style->styleName;
+                       $this->styleVersion = $this->style->styleVersion;
+                       $this->templateGroupID = $this->style->templateGroupID;
+               }
+       }
+       
+       /**
+        * @see wcf\form\IForm::save()
+        */
+       public function save() {
+               AbstractForm::saved();
+               
+               $this->objectAction = new StyleAction(array($this->style), 'update', array(
+                       'data' => array(
+                               'styleName' => $this->styleName,
+                               'templateGroupID' => $this->templateGroupID,
+                               'styleDescription' => ($this->styleDescription ? $this->styleDescription : null),
+                               'styleVersion' => $this->styleVersion,
+                               'styleDate' => $this->styleDate,
+                               'imagePath' => $this->imagePath,
+                               'copyright' => $this->copyright,
+                               'license' => $this->license,
+                               'authorName' => $this->authorName,
+                               'authorURL' => $this->authorURL,
+                               'iconPath' => $this->iconPath
+                       ),
+                       'tmpHash' => $this->tmpHash,
+                       'variables' => $this->variables
+               ));
+               $this->objectAction->executeAction();
+               
+               // call saved event
+               $this->saved();
+               
+               // reload style object to update preview image
+               $this->style = new Style($this->style->styleID);
+               
+               WCF::getTPL()->assign('success', true);
+       }
+       
+       /**
+        * @see wcf\page\IPage::assignVariables()
+        */
+       public function assignVariables() {
+               parent::assignVariables();
+               
+               WCF::getTPL()->assign(array(
+                       'action' => 'edit',
+                       'style' => $this->style,
+                       'styleID' => $this->styleID
+               ));
+       }
+}
index a5faa1372049bc104dbd4f74e0a5da7ebaf49cf0..dc939d64813cbdc7723facfcb2c6f94bf53c0ad7 100644 (file)
@@ -45,6 +45,7 @@
                <item name="wcf.acp.style.iconPath"><![CDATA[Icon-Pfad]]></item>
                <item name="wcf.acp.style.iconPath.description"><![CDATA[Wenn Ihr Stil eigene Icons benötigt, sollten diese in einem Unterordner des Ordners &laquo;icons&raquo; ablegen. Geben Sie hier den Pfad zu diesem Ordner an.]]></item>
                <item name="wcf.acp.style.image"><![CDATA[Vorschaubild]]></item>
+               <item name="wcf.acp.style.image.description"><![CDATA[Laden Sie hier ein Vorschaubild dieses Stiles hoch, als Bildformate sind JPG und PNG zulässig. Es wird empfohlen Vorschaubilder immer mit der Größe 225px x 140px anzulegen, größere Grafiken werden automatisch skaliert.]]></item>
                <item name="wcf.acp.style.imagePath"><![CDATA[Bilder-Pfad]]></item>
                <item name="wcf.acp.style.imagePath.description"><![CDATA[Wenn Ihr Stil eigene Grafiken benötigt, sollten diese in einem Unterordner des Ordners &laquo;images&raquo; ablegen. Geben Sie hier den Pfad zu diesem Ordner an.]]></item>
                <item name="wcf.acp.style.license"><![CDATA[Lizenz]]></item>