1: <?php
 2: /**
 3:  * Copyright 2013-2014 Horde LLC (http://www.horde.org/)
 4:  *
 5:  * See the enclosed file COPYING for license information (GPL). If you
 6:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 7:  *
 8:  * @category  Horde
 9:  * @copyright 2013-2014 Horde LLC
10:  * @license   http://www.horde.org/licenses/gpl GPL
11:  * @package   IMP
12:  */
13: 
14: /**
15:  * Defines AJAX actions used to toggle expand/collapse state of mailboxes.
16:  *
17:  * @author    Michael Slusarz <slusarz@horde.org>
18:  * @category  Horde
19:  * @copyright 2013-2014 Horde LLC
20:  * @license   http://www.horde.org/licenses/gpl GPL
21:  * @package   IMP
22:  */
23: class IMP_Ajax_Application_Handler_Mboxtoggle
24: extends Horde_Core_Ajax_Application_Handler
25: {
26:     /**
27:      * AJAX action: Expand mailboxes (saves expanded state in prefs).
28:      *
29:      * Variables used:
30:      *   - action: (string) [REQUIRED] Either 'collapse' or 'expand'.
31:      *   - all: (integer) 1 to toggle all mailboxes (mailbox information
32:      *          will not be returned).
33:      *   - mboxes: (string) The list of mailboxes to process (JSON encoded
34:      *             array; mailboxes are base64url encoded); required if 'all'
35:      *             is 0.
36:      *
37:      * @return boolean  True.
38:      */
39:     public function toggleMailboxes()
40:     {
41:         $ftree = $GLOBALS['injector']->getInstance('IMP_Ftree');
42: 
43:         if ($this->vars->all) {
44:             $old_track = $ftree->eltdiff->track;
45:             $ftree->eltdiff->track = false;
46: 
47:             switch ($this->vars->action) {
48:             case 'collapse':
49:                 $ftree->collapseAll();
50:                 break;
51: 
52:             case 'expand':
53:                 $ftree->expandAll();
54:                 break;
55:             }
56: 
57:             $ftree->eltdiff->track = $old_track;
58:         } elseif (!empty($this->vars->mboxes)) {
59:             $mboxes = IMP_Mailbox::formFrom(json_decode($this->vars->mboxes));
60: 
61:             switch ($this->vars->action) {
62:             case 'collapse':
63:                 $ftree->collapse($mboxes);
64:                 break;
65: 
66:             case 'expand':
67:                 $ftree->expand($mboxes);
68:                 break;
69:             }
70:         }
71: 
72:         return true;
73:     }
74: 
75: }
76: