Convert fima to new preferences UI code
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Apr 2010 07:04:15 +0000 (01:04 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Apr 2010 07:04:15 +0000 (01:04 -0600)
fima/config/prefs.php.dist
fima/lib/Application.php
fima/templates/prefs/closedperiodselect.inc [deleted file]
fima/templates/prefs/ledgerselect.inc [deleted file]

index 16d3823..bc26a07 100644 (file)
@@ -3,72 +3,64 @@
  * See horde/config/prefs.php for documentation on the structure of this file.
  */
 
-// Make sure that constants are defined.
-@define('FIMA_BASE', '/usr/share/horde/fima');
-require_once FIMA_BASE . '/lib/Fima.php';
-
 $prefGroups['share'] = array(
     'column' => _("General Options"),
     'label' => _("Active Configuration"),
     'desc' => _("Choose your active Ledger and Posting Type."),
-    'members' => array('ledgerselect', 'active_postingtype', 'closedperiodselect')
+    'members' => array(
+        'active_ledger', 'active_postingtype', 'closedperiodselect'
+    )
 );
 
 $prefGroups['display'] = array(
     'column' => _("General Options"),
     'label' => _("Interface Options"),
     'desc' => _("Change the display and input options."),
-    'members' => array('max_postings', 'startpage', 'sortby', 'altsortby', 'sortdir', 'wildcard_format', 'amount_format', 'expenses_sign', 'delete_opt', 'report_graphsize')
+    'members' => array(
+        'max_postings', 'startpage', 'sortby', 'altsortby', 'sortdir',
+        'wildcard_format', 'amount_format', 'expenses_sign', 'delete_opt',
+        'report_graphsize'
+    )
 );
 
-// active ledger selection widget
-$_prefs['ledgerselect'] = array('type' => 'special');
-
 // active ledger
 // Set locked to true if you don't want users to have multiple ledgers.
 $_prefs['active_ledger'] = array(
-    'value' => Horde_Auth::getAuth() ? Horde_Auth::getAuth() : 0,
-    'locked' => false,
-    'shared' => true,
-    'type' => 'implicit'
+    'value' => Horde_Auth::getAuth() ? Horde_Auth::getAuth() : 0
+    'type' => 'enum',
+    'shared' => true
 );
 
 // store the ledgers to diplay
 $_prefs['display_ledgers'] = array(
-    'value' => 'a:0:{}',
-    'locked' => false,
-    'shared' => false,
-    'type' => 'implicit'
+    'value' => 'a:0:{}'
 );
 
 // active posting type
 $_prefs['active_postingtype'] = array(
     'value' => FIMA_POSTINGTYPE_ACTUAL,
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array(FIMA_POSTINGTYPE_ACTUAL => _("Actual"),
-                    FIMA_POSTINGTYPE_FORECAST => _("Forecast"),
-                    FIMA_POSTINGTYPE_BUDGET => _("Budget")),
+    'enum' => array(
+        FIMA_POSTINGTYPE_ACTUAL => _("Actual"),
+        FIMA_POSTINGTYPE_FORECAST => _("Forecast"),
+        FIMA_POSTINGTYPE_BUDGET => _("Budget")
+    ),
     'desc' => _("Your active posting type:")
 );
 
 // closed period selection widget
-$_prefs['closedperiodselect'] = array('type' => 'special');
+$_prefs['closedperiodselect'] = array(
+    'type' => 'special'
+);
 
 // closed period
 $_prefs['closed_period'] = array(
-    'value' => 0,
-    'locked' => false,
-    'shared' => false,
-    'type' => 'implicit'
+    'value' => 0
 );
 
 // postings per page
 $_prefs['max_postings'] = array(
     'value' => 20,
-    'locked' => false,
-    'shared' => false,
     'type' => 'number',
     'desc' => _("Postings per page in the list view.")
 );
@@ -76,83 +68,81 @@ $_prefs['max_postings'] = array(
 // start page
 $_prefs['startpage'] = array(
     'value' => -1,
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array(1 => _("First Page"),
-                    -1 => _("Last Page")),
+    'enum' => array(
+        1 => _("First Page"),
+        -1 => _("Last Page")
+    ),
     'desc' => _("When displaying the postings, which page do you want to start on?")
 );
 
 // user preferred sorting column
 $_prefs['sortby'] = array(
     'value' => FIMA_SORT_DATE,
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array(FIMA_SORT_DATE => _("Date"),
-                    FIMA_SORT_ASSET => _("Asset Account"),
-                    FIMA_SORT_ACCOUNT => _("Posting Account"),
-                    FIMA_SORT_AMOUNT => _("Amount"),
-                    FIMA_SORT_DESC => _("Description")),
+    'enum' => array(
+        FIMA_SORT_DATE => _("Date"),
+        FIMA_SORT_ASSET => _("Asset Account"),
+        FIMA_SORT_ACCOUNT => _("Posting Account"),
+        FIMA_SORT_AMOUNT => _("Amount"),
+        FIMA_SORT_DESC => _("Description")
+    ),
     'desc' => _("Sort postings by:")
 );
 
 // alternate sort column
 $_prefs['altsortby'] = array(
     'value' => FIMA_SORT_ACCOUNT,
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array(FIMA_SORT_DATE => _("Date"),
-                    FIMA_SORT_ASSET => _("Asset Account"),
-                    FIMA_SORT_ACCOUNT => _("Posting Account"),
-                    FIMA_SORT_AMOUNT => _("Amount"),
-                    FIMA_SORT_DESC => _("Description")),
+    'enum' => array(
+        FIMA_SORT_DATE => _("Date"),
+        FIMA_SORT_ASSET => _("Asset Account"),
+        FIMA_SORT_ACCOUNT => _("Posting Account"),
+        FIMA_SORT_AMOUNT => _("Amount"),
+        FIMA_SORT_DESC => _("Description")
+    ),
     'desc' => _("Then:")
 );
 
 // user preferred sorting direction
 $_prefs['sortdir'] = array(
     'value' => FIMA_SORT_ASCEND,
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array(FIMA_SORT_ASCEND => _("Ascending"),
-                    FIMA_SORT_DESCEND => _("Descending")),
+    'enum' => array(
+        FIMA_SORT_ASCEND => _("Ascending"),
+        FIMA_SORT_DESCEND => _("Descending")
+    ),
     'desc' => _("Sort direction:")
 );
 
 // format for wildcards
 $_prefs['wildcard_format'] = array(
     'value' => 'dos',
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array('dos' => _("DOS (* and ?)"),
-                    'sql' => _("SQL (% and _)"),
-                    'none' => _("none")),
+    'enum' => array(
+        'dos' => _("DOS (* and ?)"),
+        'sql' => _("SQL (% and _)"),
+        'none' => _("none")
+    ),
     'desc' => _("Select the format for wildcards for text search:")
 );
 
 // format for amounts
 $_prefs['amount_format'] = array(
     'value' => '.,',
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array('.,' => _("-12.345.678,90"),
-                    ',.' => _("-12,345,678.90"),
-                    ' ,' => _("-12 345 678,90"),
-                    '\'.' => _("-12'345'678.90")),
+    'enum' => array(
+        '.,' => _("-12.345.678,90"),
+        ',.' => _("-12,345,678.90"),
+        ' ,' => _("-12 345 678,90"),
+        '\'.' => _("-12'345'678.90")
+    ),
     'desc' => _("Select the format for amounts:")
 );
 
 // sign for expenses
 $_prefs['expenses_sign'] = array(
     'value' => 0,
-    'locked' => false,
-    'shared' => false,
     'type' => 'checkbox',
     'desc' => _("Enter expenses with negative sign?")
 );
@@ -160,8 +150,6 @@ $_prefs['expenses_sign'] = array(
 // preference for delete confirmation dialog.
 $_prefs['delete_opt'] = array(
     'value' => 1,
-    'locked' => false,
-    'shared' => false,
     'type' => 'checkbox',
     'desc' => _("Do you want to confirm deleting postings?")
 );
@@ -169,12 +157,12 @@ $_prefs['delete_opt'] = array(
 // report graph size
 $_prefs['report_graphsize'] = array(
     'value' => '800x600',
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array('400x300'  => _("400 x 300 Pixel"),
-                    '800x600'  => _("800 x 600 Pixel"),
-                    '1024x768' => _("1024 x 768 Pixel"),
-                    '1600x1200' => _("1600 x 1200 Pixel")),
+    'enum' => array(
+        '400x300'  => _("400 x 300 Pixel"),
+        '800x600'  => _("800 x 600 Pixel"),
+        '1024x768' => _("1024 x 768 Pixel"),
+        '1600x1200' => _("1600 x 1200 Pixel")
+    ),
     'desc' => _("Select the canvas size for chart reports:")
 );
index f998571..4d8136c 100644 (file)
@@ -4,6 +4,43 @@ class Fima_Application extends Horde_Regsitry_Application
     public $version = '1.0.1';
 
     /**
+     * Code to run on init when viewing prefs for this application.
+     *
+     * @param Horde_Core_Prefs_Ui $ui  The UI object.
+     */
+    public function prefsInit($ui)
+    {
+        switch ($ui->group) {
+        case 'share':
+            if (!$GLOBALS['prefs']->isLocked('active_ledger')) {
+                $ui->override['active_ledger'] = Fima::listLedgers();
+            }
+            break;
+        }
+    }
+
+    /**
+     * Generate code used to display a special preference.
+     *
+     * @param Horde_Core_Prefs_Ui $ui  The UI object.
+     * @param string $item             The preference name.
+     *
+     * @return string  The HTML code to display on the options page.
+     */
+    public function prefsSpecial($ui, $item)
+    {
+        switch ($item) {
+        case 'closedperiodselect':
+            return _("Closed by period:") .
+                '<br />' .
+                Fima::buildDateWidget('closedperiod', (int)$GLOBALS['prefs']->getValue('closed_period'), '', _("None"), true) .
+                '</select><br /><br />';
+        }
+
+        return '';
+    }
+
+    /**
      * Special preferences handling on update.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
@@ -14,17 +51,6 @@ class Fima_Application extends Horde_Regsitry_Application
     public function prefsSpecialUpdate($ui, $item)
     {
         switch ($item) {
-        case 'ledgerselect':
-            if (isset($ui->vars->active_ledger)) {
-                $ledgers = Fima::listLedgers();
-                if (is_array($ledgers) &&
-                    array_key_exists($ui->vars->active_ledger, $ledgers)) {
-                    $GLOBALS['prefs']->setValue('active_ledger', $ui->vars->active_ledger);
-                    return true;
-                }
-            }
-            break;
-
         case 'closedperiodselect':
             $period = $ui->vars->closedperiod;
             $period = ((int)$period['year'] > 0 && (int)$period['month'] > 0)
diff --git a/fima/templates/prefs/closedperiodselect.inc b/fima/templates/prefs/closedperiodselect.inc
deleted file mode 100644 (file)
index 65a7451..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php if (!$prefs->isLocked('closed_period')): ?>
-<br />
-<?php echo _("Closed by period:") ?><br />
-<?php echo Fima::buildDateWidget('closedperiod', (int)$prefs->getValue('closed_period'), '', _("None"), true); ?>
-</select><br /><br />
-<?php endif; ?>
\ No newline at end of file
diff --git a/fima/templates/prefs/ledgerselect.inc b/fima/templates/prefs/ledgerselect.inc
deleted file mode 100644 (file)
index 48bffc3..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-if (!$prefs->isLocked('activet_ledger')):
-    $ledgers = Fima::listLedgers();
-    if (($active_ledger = $prefs->getValue('active_ledger')) == null ||
-        !isset($ledgers[$active_ledger])) {
-        $active_ledger = Horde_Auth::getAuth();
-    }
-?>
-
-<?php echo _("Your active ledger:") ?><br />
-<select name="active_ledger">
-<?php foreach ($ledgers as $id => $ledger): ?>
-    <option value="<?php echo htmlspecialchars($id) ?>"<?php if ($id == $active_ledger) echo ' selected="selected"' ?>><?php echo htmlspecialchars($ledger->get('name')) ?></option>
-<?php endforeach; ?>
-</select><br /><br />
-<?php endif; ?>