move view designs setting to user design tab

This commit is contained in:
Evan Prodromou 2010-09-11 16:16:38 -04:00
parent 12eee30586
commit fca7ea664b
4 changed files with 94 additions and 26 deletions

View File

@ -134,10 +134,6 @@ class OthersettingsAction extends AccountSettingsAction
$this->arg('maxnoticelength') : User_urlshortener_prefs::maxNoticeLength($user), $this->arg('maxnoticelength') : User_urlshortener_prefs::maxNoticeLength($user),
_('URLs in notices longer than this will be shortened.')); _('URLs in notices longer than this will be shortened.'));
$this->elementEnd('li'); $this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('viewdesigns', _('View profile designs'),
- $user->viewdesigns, _('Show or hide profile designs.'));
$this->elementEnd('li');
$this->elementEnd('ul'); $this->elementEnd('ul');
$this->submit('save', _('Save')); $this->submit('save', _('Save'));
$this->elementEnd('fieldset'); $this->elementEnd('fieldset');
@ -170,8 +166,6 @@ class OthersettingsAction extends AccountSettingsAction
return; return;
} }
$viewdesigns = $this->boolean('viewdesigns');
$maxurllength = $this->trimmed('maxurllength'); $maxurllength = $this->trimmed('maxurllength');
if (!Validate::number($maxurllength, array('min' => 0))) { if (!Validate::number($maxurllength, array('min' => 0))) {
@ -193,7 +187,6 @@ class OthersettingsAction extends AccountSettingsAction
$original = clone($user); $original = clone($user);
$user->urlshorteningservice = $urlshorteningservice; $user->urlshorteningservice = $urlshorteningservice;
$user->viewdesigns = $viewdesigns;
$result = $user->update($original); $result = $user->update($original);

View File

@ -120,6 +120,20 @@ class UserDesignSettingsAction extends DesignSettingsAction
$this->showDesignForm($design); $this->showDesignForm($design);
} }
/**
* Shows the design settings form
*
* @param Design $design a working design to show
*
* @return nothing
*/
function showDesignForm($design)
{
$form = new UserDesignForm($this, $design, $this->submitaction);
$form->show();
}
/** /**
* Save or update the user's design settings * Save or update the user's design settings
* *
@ -128,6 +142,8 @@ class UserDesignSettingsAction extends DesignSettingsAction
function saveDesign() function saveDesign()
{ {
$this->saveDesignPreferences();
foreach ($this->args as $key => $val) { foreach ($this->args as $key => $val) {
if (preg_match('/(#ho|ho)Td.*g/i', $val)) { if (preg_match('/(#ho|ho)Td.*g/i', $val)) {
$this->sethd(); $this->sethd();
@ -164,7 +180,8 @@ class UserDesignSettingsAction extends DesignSettingsAction
$tile = true; $tile = true;
} }
$user = common_current_user(); $user = common_current_user();
$design = $user->getDesign(); $design = $user->getDesign();
if (!empty($design)) { if (!empty($design)) {
@ -282,4 +299,64 @@ class UserDesignSettingsAction extends DesignSettingsAction
$this->showForm(_('Enjoy your hotdog!'), true); $this->showForm(_('Enjoy your hotdog!'), true);
} }
function saveDesignPreferences()
{
$viewdesigns = $this->boolean('viewdesigns');
$user = common_current_user();
$original = clone($user);
$user->viewdesigns = $viewdesigns;
$result = $user->update($original);
if ($result === false) {
common_log_db_error($user, 'UPDATE', __FILE__);
throw new ServerException(_('Couldn\'t update user.'));
}
}
}
class UserDesignForm extends DesignForm
{
function __construct($out, $design, $actionurl)
{
parent::__construct($out, $design, $actionurl);
}
/**
* Legend of the Form
*
* @return void
*/
function formLegend()
{
$this->out->element('legend', null, _('Design settings'));
}
/**
* Data elements of the form
*
* @return void
*/
function formData()
{
$user = common_current_user();
$this->out->elementStart('ul', 'form_data');
$this->out->elementStart('li');
$this->out->checkbox('viewdesigns', _('View profile designs'),
- $user->viewdesigns, _('Show or hide profile designs.'));
$this->out->elementEnd('li');
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
$this->out->elementStart('fieldset');
$this->out->element('legend', null, _('Background file'));
parent::formData();
}
} }

View File

@ -160,13 +160,13 @@ class DesignForm extends Form
'value' => ImageFile::maxFileSizeInt())); 'value' => ImageFile::maxFileSizeInt()));
$this->out->elementEnd('li'); $this->out->elementEnd('li');
if (!empty($design->backgroundimage)) { if (!empty($this->design->backgroundimage)) {
$this->out->elementStart('li', array('id' => $this->out->elementStart('li', array('id' =>
'design_background-image_onoff')); 'design_background-image_onoff'));
$this->out->element('img', array('src' => $this->out->element('img', array('src' =>
Design::url($design->backgroundimage))); Design::url($this->design->backgroundimage)));
$attrs = array('name' => 'design_background-image_onoff', $attrs = array('name' => 'design_background-image_onoff',
'type' => 'radio', 'type' => 'radio',
@ -174,7 +174,7 @@ class DesignForm extends Form
'class' => 'radio', 'class' => 'radio',
'value' => 'on'); 'value' => 'on');
if ($design->disposition & BACKGROUND_ON) { if ($this->design->disposition & BACKGROUND_ON) {
$attrs['checked'] = 'checked'; $attrs['checked'] = 'checked';
} }
@ -190,7 +190,7 @@ class DesignForm extends Form
'class' => 'radio', 'class' => 'radio',
'value' => 'off'); 'value' => 'off');
if ($design->disposition & BACKGROUND_OFF) { if ($this->design->disposition & BACKGROUND_OFF) {
$attrs['checked'] = 'checked'; $attrs['checked'] = 'checked';
} }
@ -205,7 +205,7 @@ class DesignForm extends Form
$this->out->elementStart('li'); $this->out->elementStart('li');
$this->out->checkbox('design_background-image_repeat', $this->out->checkbox('design_background-image_repeat',
_('Tile background image'), _('Tile background image'),
($design->disposition & BACKGROUND_TILE) ? true : false); ($this->design->disposition & BACKGROUND_TILE) ? true : false);
$this->out->elementEnd('li'); $this->out->elementEnd('li');
} }
@ -218,7 +218,7 @@ class DesignForm extends Form
try { try {
$bgcolor = new WebColor($design->backgroundcolor); $bgcolor = new WebColor($this->design->backgroundcolor);
$this->out->elementStart('li'); $this->out->elementStart('li');
$this->out->element('label', array('for' => 'swatch-1'), _('Background')); $this->out->element('label', array('for' => 'swatch-1'), _('Background'));
@ -231,7 +231,7 @@ class DesignForm extends Form
'value' => '')); 'value' => ''));
$this->out->elementEnd('li'); $this->out->elementEnd('li');
$ccolor = new WebColor($design->contentcolor); $ccolor = new WebColor($this->design->contentcolor);
$this->out->elementStart('li'); $this->out->elementStart('li');
$this->out->element('label', array('for' => 'swatch-2'), _('Content')); $this->out->element('label', array('for' => 'swatch-2'), _('Content'));
@ -244,7 +244,7 @@ class DesignForm extends Form
'value' => '')); 'value' => ''));
$this->out->elementEnd('li'); $this->out->elementEnd('li');
$sbcolor = new WebColor($design->sidebarcolor); $sbcolor = new WebColor($this->design->sidebarcolor);
$this->out->elementStart('li'); $this->out->elementStart('li');
$this->out->element('label', array('for' => 'swatch-3'), _('Sidebar')); $this->out->element('label', array('for' => 'swatch-3'), _('Sidebar'));
@ -257,7 +257,7 @@ class DesignForm extends Form
'value' => '')); 'value' => ''));
$this->out->elementEnd('li'); $this->out->elementEnd('li');
$tcolor = new WebColor($design->textcolor); $tcolor = new WebColor($this->design->textcolor);
$this->out->elementStart('li'); $this->out->elementStart('li');
$this->out->element('label', array('for' => 'swatch-4'), _('Text')); $this->out->element('label', array('for' => 'swatch-4'), _('Text'));
@ -270,7 +270,7 @@ class DesignForm extends Form
'value' => '')); 'value' => ''));
$this->out->elementEnd('li'); $this->out->elementEnd('li');
$lcolor = new WebColor($design->linkcolor); $lcolor = new WebColor($this->design->linkcolor);
$this->out->elementStart('li'); $this->out->elementStart('li');
$this->out->element('label', array('for' => 'swatch-5'), _('Links')); $this->out->element('label', array('for' => 'swatch-5'), _('Links'));
@ -284,7 +284,7 @@ class DesignForm extends Form
$this->out->elementEnd('li'); $this->out->elementEnd('li');
} catch (WebColorException $e) { } catch (WebColorException $e) {
common_log(LOG_ERR, 'Bad color values in design ID: ' .$design->id); common_log(LOG_ERR, 'Bad color values in design ID: ' .$this->design->id);
} }
$this->out->elementEnd('ul'); $this->out->elementEnd('ul');

View File

@ -174,28 +174,26 @@ class DesignSettingsAction extends AccountSettingsAction
function saveBackgroundImage($design) function saveBackgroundImage($design)
{ {
// Now that we have a Design ID we can add a file to the design. // Now that we have a Design ID we can add a file to the design.
// XXX: This is an additional DB hit, but figured having the image // XXX: This is an additional DB hit, but figured having the image
// associated with the Design rather than the User was worth // associated with the Design rather than the User was worth
// it. -- Zach // it. -- Zach
if ($_FILES['design_background-image_file']['error'] == if (array_key_exists('design_background-image_file', $_FILES) &&
UPLOAD_ERR_OK) { $_FILES['design_background-image_file']['error'] == UPLOAD_ERR_OK) {
$filepath = null; $filepath = null;
try { try {
$imagefile = $imagefile = ImageFile::fromUpload('design_background-image_file');
ImageFile::fromUpload('design_background-image_file');
} catch (Exception $e) { } catch (Exception $e) {
$this->showForm($e->getMessage()); $this->showForm($e->getMessage());
return; return;
} }
$filename = Design::filename($design->id, $filename = Design::filename($design->id,
image_type_to_extension($imagefile->type), image_type_to_extension($imagefile->type),
common_timestamp()); common_timestamp());
$filepath = Design::path($filename); $filepath = Design::path($filename);