From de627313aa2e96ad4e506daae3574e57daf50fb7 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 7 Apr 2010 01:04:15 -0600 Subject: [PATCH] Convert fima to new preferences UI code --- fima/config/prefs.php.dist | 132 +++++++++++++--------------- fima/lib/Application.php | 48 +++++++--- fima/templates/prefs/closedperiodselect.inc | 6 -- fima/templates/prefs/ledgerselect.inc | 16 ---- 4 files changed, 97 insertions(+), 105 deletions(-) delete mode 100644 fima/templates/prefs/closedperiodselect.inc delete mode 100644 fima/templates/prefs/ledgerselect.inc diff --git a/fima/config/prefs.php.dist b/fima/config/prefs.php.dist index 16d382334..bc26a07ec 100644 --- a/fima/config/prefs.php.dist +++ b/fima/config/prefs.php.dist @@ -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:") ); diff --git a/fima/lib/Application.php b/fima/lib/Application.php index f9985712b..4d8136c98 100644 --- a/fima/lib/Application.php +++ b/fima/lib/Application.php @@ -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:") . + '
' . + Fima::buildDateWidget('closedperiod', (int)$GLOBALS['prefs']->getValue('closed_period'), '', _("None"), true) . + '

'; + } + + 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 index 65a745137..000000000 --- a/fima/templates/prefs/closedperiodselect.inc +++ /dev/null @@ -1,6 +0,0 @@ -isLocked('closed_period')): ?> -
-
-getValue('closed_period'), '', _("None"), true); ?> -

- \ No newline at end of file diff --git a/fima/templates/prefs/ledgerselect.inc b/fima/templates/prefs/ledgerselect.inc deleted file mode 100644 index 48bffc399..000000000 --- a/fima/templates/prefs/ledgerselect.inc +++ /dev/null @@ -1,16 +0,0 @@ -isLocked('activet_ledger')): - $ledgers = Fima::listLedgers(); - if (($active_ledger = $prefs->getValue('active_ledger')) == null || - !isset($ledgers[$active_ledger])) { - $active_ledger = Horde_Auth::getAuth(); - } -?> - -
-

- -- 2.11.0