Skip to content

Commit

Permalink
Move flist select generation to view templates
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 5, 2014
1 parent 4c35a24 commit 9ba5c76
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 56 deletions.
2 changes: 1 addition & 1 deletion ingo/lib/Basic/Blacklist.php
Expand Up @@ -96,7 +96,7 @@ protected function _init()
if (!isset($blacklist_folder)) {
$blacklist_folder = $blacklist->getBlacklistFolder();
}
$folder_list = Ingo::flistSelect($blacklist_folder, 'actionvalue');
$folder_list = Ingo_Flist::select($blacklist_folder, 'actionvalue');

/* Get the blacklist rule. */
$bl_rule = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS)->findRule(Ingo_Storage::ACTION_BLACKLIST);
Expand Down
2 changes: 1 addition & 1 deletion ingo/lib/Basic/Rule.php
Expand Up @@ -324,7 +324,7 @@ protected function _init()
switch ($current_action->type) {
case 'folder':
$view->actionvaluelabel = _("Select target folder");
$view->actionvalue = Ingo::flistSelect($rule['action-value']);
$view->actionvalue = Ingo_Flist::select($rule['action-value']);
break;

case 'text':
Expand Down
4 changes: 2 additions & 2 deletions ingo/lib/Basic/Spam.php
Expand Up @@ -129,10 +129,10 @@ static public function url(array $opts = array())


/**
* Dummy class to hold the select box created by {@link Ingo::flistSelect()}.
* Dummy class to hold the select box created by {@link Ingo_Flist::select()}.
*
* @see Horde_Core_Ui_VarRenderer_Ingo
* @see Ingo::flistSelect()
* @see Ingo_Flist::select()
*/
class Horde_Form_Type_ingo_folders extends Horde_Form_Type {

Expand Down
67 changes: 67 additions & 0 deletions ingo/lib/Flist.php
@@ -0,0 +1,67 @@
<?php
/**
* Copyright 2002-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @category Horde
* @copyright 2002-2014 Horde LLC
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/

/**
* Generate folder lists for use in UI elements.
*
* @author Mike Cochrane <mike@graftonhall.co.nz>
* @author Jan Schneider <jan@horde.org>
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2002-2014 Horde LLC
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
class Ingo_Flist
{
/**
* Generates a folder widget.
*
* If an application is available that provides a mailboxList method
* then a &lt;select&gt; input is created. Otherwise a simple text field
* is returned.
*
* @param string $value The current value for the field.
* @param string $tagname The label for the select tag.
*
* @return string The HTML to render the field.
*/
static public function select($value = null, $tagname = 'actionvalue')
{
global $injector, $page_output, $registry;

$view = $injector->createInstance('Horde_View');
$view->addHelper('FormTag');
$view->addHelper('Tag');

$view->tagname = $tagname;
$view->val = $value;

if ($registry->hasMethod('mail/mailboxList')) {
try {
$view->create = $registry->hasMethod('mail/createMailbox');
$view->mboxes = $registry->call('mail/mailboxList');

$page_output->addScriptFile('new_folder.js');
$page_output->addInlineJsVars(array(
'IngoNewFolder.folderprompt' => _("Please enter the name of the new folder:")
));

return $view->render('flist/select');
} catch (Horde_Exception $e) {}
}

return $view->render('flist/input');
}

}
50 changes: 0 additions & 50 deletions ingo/lib/Ingo.php
Expand Up @@ -55,56 +55,6 @@ class Ingo
const RULE_FORWARD = 5;
const RULE_SPAM = 6;

/**
* Generates a folder widget.
*
* If an application is available that provides a mailboxList method
* then a &lt;select&gt; input is created. Otherwise a simple text field
* is returned.
*
* @param string $value The current value for the field.
* @param string $tagname The label for the select tag.
*
* @return string The HTML to render the field.
*/
static public function flistSelect($value = null, $tagname = 'actionvalue')
{
global $page_output, $registry;

if ($registry->hasMethod('mail/mailboxList')) {
try {
$mailboxes = $registry->call('mail/mailboxList');

$text = '<select class="flistSelect" id="' . $tagname . '" name="' . $tagname . '">' .
'<option value="">' . _("Select target folder:") . '</option>' .
'<option disabled="disabled">- - - - - - - - - -</option>';

if ($registry->hasMethod('mail/createMailbox')) {
$text .= '<option class="flistCreate" value="">' . _("Create new folder") . '</option>' .
'<option disabled="disabled">- - - - - - - - - -</option>';
}

foreach ($mailboxes as $val) {
$text .= sprintf(
"<option value=\"%s\"%s>%s</option>\n",
htmlspecialchars($val['ob']),
($val['ob'] == $value) ? ' selected="selected"' : '',
str_repeat('&nbsp;', $val['level'] * 2) . htmlspecialchars($val['label'])
);
}

$page_output->addScriptFile('new_folder.js');
$page_output->addInlineJsVars(array(
'IngoNewFolder.folderprompt' => _("Please enter the name of the new folder:")
));

return $text . '</select>';
} catch (Horde_Exception $e) {}
}

return '<input id="' . $tagname . '" name="' . $tagname . '" size="40" value="' . $value . '" />';
}

/**
* Validates an IMAP mailbox provided by user input.
*
Expand Down
2 changes: 1 addition & 1 deletion ingo/lib/Ui/VarRenderer/Ingo.php
Expand Up @@ -32,7 +32,7 @@ class_exists('Ingo_Form_Type_Longemail');

protected function _renderVarInput_ingo_folders(&$form, &$var, &$vars)
{
return Ingo::flistSelect($var->type->getFolder(), 'folder');
return Ingo_Flist::select($var->type->getFolder(), 'folder');
}

protected function _renderVarInput_ingo_form_type_longemail($form, &$var, &$vars)
Expand Down
10 changes: 9 additions & 1 deletion ingo/package.xml
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>yes</active>
</lead>
<date>2014-02-04</date>
<date>2014-02-05</date>
<version>
<release>3.2.0</release>
<api>3.2.0</api>
Expand Down Expand Up @@ -217,6 +217,7 @@
<file name="Api.php" role="horde" />
<file name="Application.php" role="horde" />
<file name="Exception.php" role="horde" />
<file name="Flist.php" role="horde" />
<file name="Ingo.php" role="horde" />
<file name="Session.php" role="horde" />
<file name="Smartmobile.php" role="horde" />
Expand Down Expand Up @@ -454,6 +455,10 @@
<file name="whitelist.html.php" role="horde" />
</dir> <!-- /templates/basic/whitelist -->
</dir> <!-- /templates/basic -->
<dir name="flist">
<file name="input.html.php" role="horde" />
<file name="select.html.php" role="horde" />
</dir> <!-- /templates/flist -->
<dir name="smartmobile">
<file name="rule.html.php" role="horde" />
<file name="rules.html.php" role="horde" />
Expand Down Expand Up @@ -662,6 +667,7 @@
<install as="ingo/lib/Api.php" name="lib/Api.php" />
<install as="ingo/lib/Application.php" name="lib/Application.php" />
<install as="ingo/lib/Exception.php" name="lib/Exception.php" />
<install as="ingo/lib/Flist.php" name="lib/Flist.php" />
<install as="ingo/lib/Ingo.php" name="lib/Ingo.php" />
<install as="ingo/lib/Session.php" name="lib/Session.php" />
<install as="ingo/lib/Smartmobile.php" name="lib/Smartmobile.php" />
Expand Down Expand Up @@ -846,6 +852,8 @@
<install as="ingo/templates/basic/script/script.html.php" name="templates/basic/script/script.html.php" />
<install as="ingo/templates/basic/script/_script.html.php" name="templates/basic/script/_script.html.php" />
<install as="ingo/templates/basic/whitelist/whitelist.html.php" name="templates/basic/whitelist/whitelist.html.php" />
<install as="ingo/templates/flist/input.html.php" name="templates/flist/input.html.php" />
<install as="ingo/templates/flist/select.html.php" name="templates/flist/select.html.php" />
<install as="ingo/templates/smartmobile/rule.html.php" name="templates/smartmobile/rule.html.php" />
<install as="ingo/templates/smartmobile/rules.html.php" name="templates/smartmobile/rules.html.php" />
<install as="Ingo/AllTests.php" name="test/Ingo/AllTests.php" />
Expand Down
1 change: 1 addition & 0 deletions ingo/templates/flist/input.html.php
@@ -0,0 +1 @@
<?php echo $this->textFieldTag($this->tagname, $this->escape($this->val), array('size' => 40)); ?>
14 changes: 14 additions & 0 deletions ingo/templates/flist/select.html.php
@@ -0,0 +1,14 @@
<?php
$o = $this->optionTag(null, _("Select target folder:")) .
$this->optionTag(null, '- - - - - - - - - -', false, array('disabled' => true));

if ($this->create) {
$o .= $this->optionTag(null, _("Create new folder"), false, array('class' => 'flistCreate')) .
$this->optionTag(null, '- - - - - - - - - -', false, array('disabled' => true));
}

foreach ($this->mboxes as $v) {
$o .= $this->optionTag($v['ob'], $this->escape(str_repeat(' ', $val['level'] * 2) . $val['label']), $val['ob'] == $this->val);
}

echo $this->selectTag($this->tagname, $o, array('class' => 'flistSelect'));

0 comments on commit 9ba5c76

Please sign in to comment.