Author: sevein
Date: Tue Jan  3 15:09:09 2012
New Revision: 10546

Log:
Add job scheduling settings section/form

Added:
   trunk/lib/form/SettingsJobSchedulingForm.class.php   (contents, props 
changed)
Modified:
   trunk/apps/qubit/modules/settings/actions/listAction.class.php
   trunk/apps/qubit/modules/settings/templates/listSuccess.php

Modified: trunk/apps/qubit/modules/settings/actions/listAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/settings/actions/listAction.class.php      Tue Jan 
 3 15:08:38 2012        (r10545)
+++ trunk/apps/qubit/modules/settings/actions/listAction.class.php      Tue Jan 
 3 15:09:09 2012        (r10546)
@@ -64,6 +64,7 @@
     $this->uiLabelForm = new SettingsGenericForm(array(), array(
       'settings' => QubitSetting::getByScope('ui_label'), 'scope'=>'ui_label', 
'fieldsRequired' => false));
     $this->oaiRepositoryForm = new SettingsOaiRepositoryForm;
+    $this->jobSchedulingForm = new SettingsJobSchedulingForm;
     $this->initializeDefaultPageElementsForm();
 
     // Handle POST data (form submit)
@@ -138,6 +139,18 @@
         }
       }
 
+      // Handle job scheduling form submission
+      if (null !== $request->job_scheduling)
+      {
+        $this->jobSchedulingForm->bind($request->job_scheduling);
+        if ($this->jobSchedulingForm->isValid())
+        {
+          // Do update and redirect to avoid repeat submit wackiness
+          $this->updateJobSchedulingSettings($this->jobSchedulingForm);
+          $this->redirect('settings/list');
+        }
+      }
+
       if (null !== $languageCode = $request->languageCode)
       {
         try
@@ -168,6 +181,7 @@
     $this->populateDefaultTemplateForm($this->defaultTemplateForm);
     $this->populateUiLabelForm($this->uiLabelForm);
     $this->populateOaiRepositoryForm($this->oaiRepositoryForm);
+    $this->populateJobSchedulingForm($this->jobSchedulingForm);
 
     // Last symfony 1.0 forms holdout
     $this->i18nLanguages = QubitSetting::getByScope('i18n_languages');
@@ -581,6 +595,39 @@
 
     return $this;
   }
+  /**
+   * Populate the Job scheduling form
+   */
+  protected function populateJobSchedulingForm()
+  {
+    // Get OAI Repository settings
+    $useJobScheduler = QubitSetting::getSettingByName('use_job_scheduler');
+
+    // Set defaults for global form
+    $this->oaiRepositoryForm->setDefaults(array(
+      'use_job_scheduler' => (isset($useJobScheduler)) ? 
intval($useJobScheduler->getValue(array('sourceCulture' => true))) : 1
+    ));
+  }
+
+  /**
+   * Update the Job scheduling settings
+   */
+  protected function updateJobSchedulingSettings()
+  {
+    $thisForm = $this->jobSchedulingForm;
+
+    // Job scheduler radio button
+    if (null !== $useJobSchedulerValue = 
$thisForm->getValue('use_job_scheduler'))
+    {
+      $setting = QubitSetting::getSettingByName('use_job_scheduler');
+
+      // Force sourceCulture update to prevent discrepency in settings between 
cultures
+      $setting->setValue($useJobSchedulerValue, array('sourceCulture' => 
true));
+      $setting->save();
+    }
+
+    return $this;
+  }
 
   protected function initializeDefaultPageElementsForm()
   {

Modified: trunk/apps/qubit/modules/settings/templates/listSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/settings/templates/listSuccess.php Tue Jan  3 
15:08:38 2012        (r10545)
+++ trunk/apps/qubit/modules/settings/templates/listSuccess.php Tue Jan  3 
15:09:09 2012        (r10546)
@@ -259,3 +259,29 @@
   </table>
   </form>
 </fieldset>
+
+<!-- Job scheduling settings -->
+<fieldset class="collapsible collapsed">
+  <legend><?php echo __('Job scheduling') ?></legend>
+  <form action="<?php echo url_for('settings/list') ?>" method="post">
+  <table class="list">
+  <thead>
+    <tr>
+      <th width="30%"><?php echo __('Name')?></th>
+      <th><?php echo __('Value')?></th>
+    </tr>
+  </thead>
+  <tbody>
+    <?php echo $jobSchedulingForm ?>
+    <tr>
+      <td>&nbsp;</td>
+      <td>
+        <div style="float: right; margin: 3px 8px 0 0;">
+          <input class="form-submit" type="submit" value="<?php echo 
__('Save') ?>"/>
+        </div>
+      </td>
+    </tr>
+  </tbody>
+  </table>
+  </form>
+</fieldset>

Added: trunk/lib/form/SettingsJobSchedulingForm.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/lib/form/SettingsJobSchedulingForm.class.php  Tue Jan  3 15:09:09 
2012        (r10546)
@@ -0,0 +1,58 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ProjectConfiguration::getActive()->loadHelpers('I18N');
+
+/**
+ * Global form definition for settings module - with validation.
+ *
+ * @package    qubit
+ * @subpackage settings
+ * @version    svn: $Id$
+ */
+class SettingsJobSchedulingForm extends sfForm
+{
+  public function configure()
+  {
+    // Build widgets
+    $this->setWidgets(array(
+      'use_job_scheduler' => new sfWidgetFormSelectRadio(array('choices' => 
array(1 => 'yes', 0 => 'no')), array('class' => 'radio'))
+    ));
+
+    // Add labels
+    $this->widgetSchema->setLabels(array(
+      'use_job_scheduler' => __('Enable job scheduler')
+    ));
+
+    // Add helper text
+    $this->widgetSchema->setHelps(array(
+      'use_job_scheduler' => __('')
+    ));
+
+    $this->validatorSchema['use_job_scheduler'] = new 
sfValidatorInteger(array('required' => false));
+
+    // Set decorator
+    $decorator = new QubitWidgetFormSchemaFormatterList($this->widgetSchema);
+    $this->widgetSchema->addFormFormatter('list', $decorator);
+    $this->widgetSchema->setFormFormatterName('list');
+
+    // Set wrapper text for OAI Harvesting form settings
+    $this->widgetSchema->setNameFormat('job_scheduling[%s]');
+  }
+}

-- 
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.com/group/qubit-commits?hl=en.

Reply via email to