From 98b5fa0545d147a28c2085cb238184b374d22153 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 10 Oct 2012 17:38:40 +0200 Subject: [PATCH] Added StyleEditForm and implemented preview image uploads --- acptemplates/styleAdd.tpl | 10 +- files/lib/acp/form/StyleAddForm.class.php | 29 ++--- files/lib/acp/form/StyleEditForm.class.php | 119 +++++++++++++++++++++ language/de.xml | 1 + 4 files changed, 145 insertions(+), 14 deletions(-) create mode 100644 files/lib/acp/form/StyleEditForm.class.php diff --git a/acptemplates/styleAdd.tpl b/acptemplates/styleAdd.tpl index d2bbf4ed7d..3377126966 100644 --- a/acptemplates/styleAdd.tpl +++ b/acptemplates/styleAdd.tpl @@ -1,5 +1,6 @@ {include file='header'} + @@ -189,8 +192,10 @@
-
- TODO: Add upload here! +
+ +
+ {* TODO: Add upload here!*} {if $errorField == 'image'} {if $errorType == 'empty'} @@ -422,6 +427,7 @@
+ {if $styleID|isset}{/if}
diff --git a/files/lib/acp/form/StyleAddForm.class.php b/files/lib/acp/form/StyleAddForm.class.php index e714bfeddc..c2cbef40e1 100644 --- a/files/lib/acp/form/StyleAddForm.class.php +++ b/files/lib/acp/form/StyleAddForm.class.php @@ -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 index 0000000000..d715c688c2 --- /dev/null +++ b/files/lib/acp/form/StyleEditForm.class.php @@ -0,0 +1,119 @@ + + * @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 + )); + } +} diff --git a/language/de.xml b/language/de.xml index a5faa13720..dc939d6481 100644 --- a/language/de.xml +++ b/language/de.xml @@ -45,6 +45,7 @@ + -- 2.20.1