Author: david
Date: 2008-10-23 16:24:09 -0700 (Thu, 23 Oct 2008)
New Revision: 1496
Removed:
trunk/qubit/apps/qubit/modules/settings/actions/updateAction.class.php
Modified:
trunk/qubit/apps/qubit/modules/settings/actions/deleteAction.class.php
trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
trunk/qubit/apps/qubit/modules/settings/templates/listSuccess.php
trunk/qubit/lib/form/SettingsGenericForm.class.php
trunk/qubit/lib/form/SettingsGlobalForm.class.php
trunk/qubit/lib/form/SettingsSiteInformationForm.class.php
trunk/qubit/web/vendor/drupal/misc/collapse.js
Log:
- Keep divs open on form submit on settings/list page. (Issue #472)
- Delete settings/actions/updateAction and move last of the update code into
settings/actions/listAction
Modified: trunk/qubit/apps/qubit/modules/settings/actions/deleteAction.class.php
===================================================================
--- trunk/qubit/apps/qubit/modules/settings/actions/deleteAction.class.php
2008-10-23 22:24:47 UTC (rev 1495)
+++ trunk/qubit/apps/qubit/modules/settings/actions/deleteAction.class.php
2008-10-23 23:24:09 UTC (rev 1496)
@@ -35,7 +35,7 @@
// TODO: else populate an error?
$this->refreshSettings();
- return $this->redirect('settings/list');
+ return
$this->redirect('settings/list?i18n_languages_cs='.$request->getParameter('i18n_languages_cs',
1));
}
private function refreshSettings()
Modified: trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
===================================================================
--- trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
2008-10-23 22:24:47 UTC (rev 1495)
+++ trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
2008-10-23 23:24:09 UTC (rev 1496)
@@ -83,7 +83,7 @@
{
// Do update and redirect to avoid repeat submit wackiness
$this->updateGlobalSettings();
- $this->redirect('settings/list');
+
$this->redirect('settings/list?global_cs='.$request->getParameter('global_settings[collapse_state]',
0));
}
}
@@ -95,7 +95,7 @@
{
// Do update and redirect to avoid repeat submit wackiness
$this->updateSiteInformationSettings();
- $this->redirect('settings/list');
+
$this->redirect('settings/list?site_information_cs='.$request->getParameter('site_information[collapse_state]',0));
}
}
@@ -107,7 +107,7 @@
{
// Do update and redirect to avoid repeat submit wackiness
$this->updateDefaultTemplateSettings($this->defaultTemplateForm);
- $this->redirect('settings/list');
+
$this->redirect('settings/list?default_template_cs='.$request->getParameter('default_template[collapse_state]',
0));
}
}
@@ -119,19 +119,27 @@
{
// Do update and redirect to avoid repeat submit wackiness
$this->updateUiLabelSettings($this->uiLabelForm);
- $this->redirect('settings/list');
+
$this->redirect('settings/list?ui_label_cs='.$request->getParameter('ui_label[collapse_state]',
0));
}
}
+
+ if (null !==$request->getParameter('language_code'))
+ {
+ // Do update and redirect to avoid repeat submit wackiness
+ $this->updateI18nLanguagesSettings($request);
+
$this->redirect('settings/list?i18n_languages_cs='.$request->getParameter('i18n_languages[collapse_state]',
0));
+ }
}
// Populate forms
- $this->populateGlobalForm();
- $this->populateSiteInformationForm();
- $this->populateDefaultTemplateForm($this->defaultTemplateForm);
- $this->populateUiLabelForm($this->uiLabelForm);
+ $this->populateGlobalForm($request);
+ $this->populateSiteInformationForm($request);
+ $this->populateDefaultTemplateForm($request, $this->defaultTemplateForm);
+ $this->populateUiLabelForm($request, $this->uiLabelForm);
- // Last symfony 1.0 forms holdout
+ // Populate i18n form - the last symfony 1.0 form holdout
$this->i18nLanguages = QubitSetting::getByScope('i18n_languages');
+ $this->i18nLanguagesCollapseState =
($request->getParameter('i18n_languages[collapse_state]',0) ||
$request->getParameter('i18n_languages_cs',0)) ? 1 : 0;
// make vars available to template
$this->availableLanguages = self::$availableLanguges;
@@ -140,7 +148,7 @@
/**
* Populate the Global form with database values (non-localized)
*/
- protected function populateGlobalForm()
+ protected function populateGlobalForm($request)
{
// Get global settings
$version = QubitSetting::getSettingByName('version');
@@ -148,9 +156,11 @@
$refImageMaxWidth =
QubitSetting::getSettingByName('reference_image_maxwidth');
$hitsPerPage = QubitSetting::getSettingByName('hits_per_page');
$multiRepository = QubitSetting::getSettingByName('multi_repository');
+ $collapseState =
($request->getParameter('global_settings[collapse_state]',0) ||
$request->getParameter('global_cs',0)) ? 1 : 0;
// Set defaults for global form
$this->globalForm->setDefaults(array(
+ 'collapse_state' => $collapseState,
'version' => (isset($version)) ?
$version->getValue(array('sourceCulture'=>true)) : null,
'upload_dir' => (isset($uploadDir)) ?
$uploadDir->getValue(array('sourceCulture'=>true)) : null,
'reference_image_maxwidth' => (isset($refImageMaxWidth)) ?
$refImageMaxWidth->getValue(array('sourceCulture'=>true)) : null,
@@ -213,14 +223,17 @@
/**
* Populate the site information settings from the database (localized)
*/
- protected function populateSiteInformationForm()
+ protected function populateSiteInformationForm($request)
{
// Get site information settings
$this->siteTitle = (null !== $siteTitle =
QubitSetting::getSettingByName('site_title')) ? $siteTitle : new QubitSetting;
$this->siteDescription = (null !== $siteDescription =
QubitSetting::getSettingByName('site_description')) ? $siteDescription : new
QubitSetting;
+
+ $collapseState =
($request->getParameter('site_information[collapse_state]',0) ||
$request->getParameter('site_information_cs',0)) ? 1 : 0;
// Set defaults values
$this->siteInformationForm->setDefaults(array(
+ 'collapse_state' => $collapseState,
'site_title' => $this->siteTitle->getValue(array('culture' =>
$this->culture)),
'site_description' => $this->siteDescription->getValue(array('culture'
=> $this->culture))
));
@@ -268,8 +281,10 @@
/**
* Populate the default template settings from the database (non-localized)
*/
- protected function populateDefaultTemplateForm($form)
- {
+ protected function populateDefaultTemplateForm($request, $form)
+ {
+ $collapseState =
($request->getParameter('default_template[collapse_state]',0) ||
$request->getParameter('default_template_cs',0)) ? 1 : 0;
+ $form->setDefault('collapse_state', $collapseState);
foreach ($form->getSettings() as $setting)
{
$form->setDefault($setting->getName(),
$setting->getValue(array('sourceCulture' => true)));
@@ -304,8 +319,10 @@
/**
* Populate the ui_label form with database values (localized)
*/
- protected function populateUiLabelForm($form)
+ protected function populateUiLabelForm($request, $form)
{
+ $collapseState = ($request->getParameter('ui_label[collapse_state]',0) ||
$request->getParameter('ui_label_cs',0)) ? 1 : 0;
+ $form->setDefault('collapse_state', $collapseState);
foreach ($form->getSettings() as $setting)
{
$form->setDefault($setting->getName(), $setting->getValue());
@@ -337,4 +354,35 @@
return $this;
}
-} // End class
\ No newline at end of file
+ /**
+ * Update ui_label db values with form values (localized)
+ *
+ * @return $this
+ */
+ protected function updateI18nLanguagesSettings($request)
+ {
+ // we are adding a new language
+ sfLoader::loadHelpers(array('I18N'));
+
+ $setting = new QubitSetting;
+ $setting->setName($request->getParameter('language_code'));
+ $setting->setScope('i18n_languages');
+ $setting->setEditable(true);
+ $setting->setDeleteable(true);
+
$setting->setValue(format_language($request->getParameter('language_code'),
$request->getParameter('language_code')));
+
$setting->getCurrentSettingI18n()->setCulture($request->getParameter('language_code'));
+
+ $setting->save();
+
+ $this->refreshSettings();
+ return $this;
+ }
+
+ protected function refreshSettings()
+ {
+ // clear the file cache containing the settings
+ $fileCache = new sfFileCache(array('cache_dir' =>
sfConfig::get('sf_app_cache_dir').'/settings'));
+ $fileCache->clean();
+ }
+} // End class
+
Deleted: trunk/qubit/apps/qubit/modules/settings/actions/updateAction.class.php
===================================================================
--- trunk/qubit/apps/qubit/modules/settings/actions/updateAction.class.php
2008-10-23 22:24:47 UTC (rev 1495)
+++ trunk/qubit/apps/qubit/modules/settings/actions/updateAction.class.php
2008-10-23 23:24:09 UTC (rev 1496)
@@ -1,96 +0,0 @@
-<?php
-
-/*
- * This file is part of the Qubit Toolkit.
- * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/**
- * Settings update controller.
- *
- * @package qubit
- * @subpackage settings
- * @version svn: $Id$
- * @author David Juhasz <[EMAIL PROTECTED]>
- */
-class SettingsUpdateAction extends sfAction
-{
- public function execute($request)
- {
- // determine what we are updating based on the request vars
- if ($this->getRequestParameter('new_setting_name') &&
$this->getRequestParameter('new_setting_value'))
- {
- // we are adding a new setting
- $setting = new QubitSetting;
- $setting->setName($this->getRequestParameter('new_setting_name'));
- $setting->setScope($this->getRequestParameter('fieldset'));
- $setting->setEditable(true);
- $setting->setDeleteable(true);
- $setting->setValue($this->getRequestParameter('new_setting_value'));
-
- $setting->save();
- }
- else if ($this->getRequestParameter('language_code'))
- {
- // we are adding a new language
- sfLoader::loadHelpers(array('I18N'));
-
- $setting = new QubitSetting;
- $setting->setName($this->getRequestParameter('language_code'));
- $setting->setScope('i18n_languages');
- $setting->setEditable(true);
- $setting->setDeleteable(true);
-
$setting->setValue(format_language($this->getRequestParameter('language_code'),
$this->getRequestParameter('language_code')));
-
$setting->getCurrentSettingI18n()->setCulture($this->getRequestParameter('language_code'));
-
- $setting->save();
-
- // go directly back, do not update anything else
- $this->refreshSettings();
- return $this->redirect('settings/list');
- }
-
- // update any existing values
- $parameters = $this->getRequest()->getParameterHolder()->getAll();
-
- foreach ($parameters as $parameter => $value)
- {
- if (is_numeric($parameter))
- {
- $setting = QubitSetting::getById($parameter);
- $this->forward404Unless($setting);
-
- if ($setting->isEditable())
- {
- $setting->setValue($value);
- $setting->save();
- }
- }
- }
-
- $this->refreshSettings();
- return $this->redirect('settings/list');
- }
-
- private function refreshSettings()
- {
- // clear the file cache containing the settings
- $fileCache = new sfFileCache(array('cache_dir' =>
sfConfig::get('sf_app_cache_dir').'/settings'));
- $fileCache->clean();
- }
-
-}
\ No newline at end of file
Modified: trunk/qubit/apps/qubit/modules/settings/templates/listSuccess.php
===================================================================
--- trunk/qubit/apps/qubit/modules/settings/templates/listSuccess.php
2008-10-23 22:24:47 UTC (rev 1495)
+++ trunk/qubit/apps/qubit/modules/settings/templates/listSuccess.php
2008-10-23 23:24:09 UTC (rev 1496)
@@ -3,8 +3,8 @@
<!-- Global settings table -->
<div class="tableHeader" style="margin-bottom: 10px;"><?php echo __('global')
?></div>
<fieldset class="collapsible collapsed">
- <legend><?php echo __('global') ?></legend>
- <form action="<?php echo url_for('settings/list') ?>" method="POST">
+<legend><?php echo __('global') ?></legend>
+<form action="<?php echo url_for('settings/list') ?>" method="POST">
<table class="list">
<thead>
<tr>
@@ -24,14 +24,16 @@
</tr>
</tbody>
</table>
- </form>
+</form>
</fieldset>
<!-- Site information form -->
<div class="tableHeader" style="margin-bottom: 10px;"><?php echo __('site
information') ?></div>
<fieldset class="collapsible collapsed">
- <legend><?php echo __('site information') ?></legend>
- <form action="<?php echo url_for('settings/list') ?>" method="POST">
+<legend><?php echo __('site information') ?></legend>
+<form action="<?php echo url_for('settings/list') ?>" method="POST">
+ <?php echo $siteInformationForm->renderGlobalErrors() ?>
+ <?php echo $siteInformationForm['collapse_state'] ?>
<table class="list">
<thead>
<tr>
@@ -74,14 +76,14 @@
</tr>
</tbody>
</table>
- </form>
+</form>
</fieldset>
<!-- Default template form -->
<div class="tableHeader" style="margin-bottom: 10px;"><?php echo __('default
template') ?></div>
<fieldset class="collapsible collapsed">
- <legend><?php echo __('default template') ?></legend>
- <form action="<?php echo url_for('settings/list') ?>" method="POST">
+<legend><?php echo __('default template') ?></legend>
+<form action="<?php echo url_for('settings/list') ?>" method="POST">
<table class="list">
<thead>
<tr>
@@ -103,14 +105,16 @@
</tr>
</tbody>
</table>
- </form>
+</form>
</fieldset>
<!-- UI Label Form -->
<div class="tableHeader" style="margin-bottom: 10px;"><?php echo __('user
interface label') ?></div>
<fieldset class="collapsible collapsed">
- <legend><?php echo __('user interface label') ?></legend>
- <form action="<?php echo url_for('settings/list') ?>" method="POST">
+<legend><?php echo __('user interface label') ?></legend>
+<form action="<?php echo url_for('settings/list') ?>" method="POST">
+ <?php echo $siteInformationForm->renderGlobalErrors() ?>
+ <?php echo $uiLabelForm['collapse_state'] ?>
<table class="list">
<thead>
<tr>
@@ -151,16 +155,16 @@
</tr>
</tbody>
</table>
- </form>
+</form>
</fieldset>
<!-- I18n Languages Form -->
<div class="tableHeader" style="margin-bottom: 10px;"><?php echo __('i18n
languages') ?></div>
<fieldset class="collapsible collapsed">
- <legend><?php echo __('i18n languages') ?></legend>
- <form action="<?php echo url_for('settings/update') ?>" method="POST">
-
+<legend><?php echo __('i18n languages') ?></legend>
+<form action="<?php echo url_for('settings/list') ?>" method="POST">
+ <input type="hidden" class="collapse_state"
name="i18n_languages[collapse_state]" value="<?php echo
$i18nLanguagesCollapseState ?>"/>
<table class="list">
<thead>
<tr>
@@ -169,7 +173,7 @@
<th/>
</tr>
</thead>
-
+
<tbody>
<?php foreach ($i18nLanguages as $setting): ?>
<tr>
@@ -181,7 +185,8 @@
</td>
<td>
<?php if ($setting->isDeleteable()): ?>
- <?php echo link_to(image_tag('delete', 'valign=top'),
'settings/delete?id='.$setting->getId(), array('post' => 'true', 'confirm' =>
__('are you sure?'))) ?>
+ <?php $urlString =
'settings/delete?id='.$setting->getId().'&i18n_languages_cs=1' ?>
+ <?php echo link_to(image_tag('delete', 'valign=top'), $urlString,
array('post' => 'true', 'confirm' => __('are you sure?'))) ?>
<?php endif; ?>
</td>
</tr>
@@ -199,5 +204,5 @@
</tr>
</tbody>
</table>
- </form>
+</form>
</fieldset>
\ No newline at end of file
Modified: trunk/qubit/lib/form/SettingsGenericForm.class.php
===================================================================
--- trunk/qubit/lib/form/SettingsGenericForm.class.php 2008-10-23 22:24:47 UTC
(rev 1495)
+++ trunk/qubit/lib/form/SettingsGenericForm.class.php 2008-10-23 23:24:09 UTC
(rev 1496)
@@ -31,13 +31,16 @@
{
public function configure()
{
+ $widgets['collapse_state'] = new sfWidgetFormInputHidden(array(),
array('class'=>'collapse_state'));
+ $validators['collapse_state'] = new
sfValidatorNumber(array('required'=>false));
+
// Build widgets and validators
foreach($this->getSettings() as $setting) {
$widgets[$setting->getName()] = new sfWidgetFormInput;
$validators[$setting->getName()] = new
sfValidatorString(array('required'=>$this->areFieldsRequired()));
}
- // Set them
+ // Add widgets and validators
$this->setWidgets($widgets);
$this->setValidators($validators);
Modified: trunk/qubit/lib/form/SettingsGlobalForm.class.php
===================================================================
--- trunk/qubit/lib/form/SettingsGlobalForm.class.php 2008-10-23 22:24:47 UTC
(rev 1495)
+++ trunk/qubit/lib/form/SettingsGlobalForm.class.php 2008-10-23 23:24:09 UTC
(rev 1496)
@@ -39,6 +39,7 @@
{
// Build widgets
$this->setWidgets(array(
+ 'collapse_state' => new sfWidgetFormInputHidden(array(),
array('class'=>'collapse_state')),
'version' => new sfWidgetFormInput(array(), array('class'=>'disabled',
'disabled'=>true)),
'upload_dir' => new sfWidgetFormInput(array(),
array('class'=>'disabled', 'disabled'=>true)),
'reference_image_maxwidth' => new sfWidgetFormInput,
@@ -95,6 +96,7 @@
$this->validatorSchema['version'] = new sfValidatorString(array('required'
=> false));
$this->validatorSchema['upload_dir'] = new
sfValidatorString(array('required' => false));
$this->validatorSchema['multi_repository'] = new
sfValidatorNumber(array('required' => false));
+ $this->validatorSchema['collapse_state'] = new
sfValidatorNumber(array('required' => false));
// Set decorator
$decorator = new QubitWidgetFormSchemaFormatterList($this->widgetSchema);
Modified: trunk/qubit/lib/form/SettingsSiteInformationForm.class.php
===================================================================
--- trunk/qubit/lib/form/SettingsSiteInformationForm.class.php 2008-10-23
22:24:47 UTC (rev 1495)
+++ trunk/qubit/lib/form/SettingsSiteInformationForm.class.php 2008-10-23
23:24:09 UTC (rev 1496)
@@ -33,6 +33,7 @@
{
// Build widgets
$this->setWidgets(array(
+ 'collapse_state' => new sfWidgetFormInputHidden(array(),
array('class'=>'collapse_state')),
'site_title' => new sfWidgetFormInput,
'site_description' => new sfWidgetFormInput
));
@@ -51,6 +52,7 @@
// $this->widgetSchema->setHelps();
// Validators
+ $this->validatorSchema['collapse_state'] = new
sfValidatorNumber(array('required'=>false));
$this->validatorSchema['site_title'] = new
sfValidatorString(array('required'=>false));
$this->validatorSchema['site_description'] = new
sfValidatorString(array('required'=>false));
Modified: trunk/qubit/web/vendor/drupal/misc/collapse.js
===================================================================
--- trunk/qubit/web/vendor/drupal/misc/collapse.js 2008-10-23 22:24:47 UTC
(rev 1495)
+++ trunk/qubit/web/vendor/drupal/misc/collapse.js 2008-10-23 23:24:09 UTC
(rev 1496)
@@ -1,3 +1,4 @@
+// Requires jQuery library http://docs.jquery.com/Downloading_jQuery
// $Id$
/**
@@ -23,6 +24,7 @@
Drupal.collapseScrollIntoView(this.parentNode);
}
});
+ $("input.collapse_state", fieldset).each(function() {this.value = 1});
}
else {
$('div.action', fieldset).hide();
@@ -30,6 +32,7 @@
$(this.parentNode).addClass('collapsed');
this.parentNode.animating = false;
});
+ $("input.collapse_state", fieldset).each(function() {this.value = 0});
}
};
@@ -53,25 +56,35 @@
Drupal.behaviors.collapse = function (context) {
$('fieldset.collapsible > legend:not(.collapse-processed)',
context).each(function() {
var fieldset = $(this.parentNode);
+
+ // Get initial state of div from "collapse_state" form field
+ var initState = $("input.collapse_state", fieldset).attr("value");
+
// Expand if there are errors inside
- if ($('input.error, textarea.error, select.error', fieldset).size() > 0) {
+ if (initState == 1 || $('input.error, textarea.error, select.error,
.validation_error, .form_error', fieldset).size() > 0) {
fieldset.removeClass('collapsed');
}
// Turn the legend into a clickable link and wrap the contents of the
fieldset
// in a div for easier animation
var text = this.innerHTML;
- $(this).empty().append($('<a href="#">'+ text +'</a>').click(function() {
- var fieldset = $(this).parents('fieldset:first')[0];
- // Don't animate multiple times
- if (!fieldset.animating) {
- fieldset.animating = true;
- Drupal.toggleFieldset(fieldset);
- }
- return false;
- }))
- .after($('<div class="fieldset-wrapper"></div>')
- .append(fieldset.children(':not(legend):not(.action)')))
- .addClass('collapse-processed');
+ $(this).empty().append($('<a href="#">'+ text +'</a>').click(function() {
+ var fieldset = $(this).parents('fieldset:first')[0];
+ // Don't animate multiple times
+ if (!fieldset.animating) {
+ fieldset.animating = true;
+ Drupal.toggleFieldset(fieldset);
+ }
+ return false;
+ }))
+ .after($('<div class="fieldset-wrapper"></div>')
+ .append(fieldset.children(':not(legend):not(.action)')))
+ .addClass('collapse-processed');
+
+ // Mark div collapsed
+
+ if (fieldset.hasClass('collapsed')) {
+ $("input.collapse_state", fieldset).each(function() {this.value = 0});
+ }
});
};
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---