Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DividedMenu.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  // manually import the class
38  // on non-ajax requests we load MbMenu and that loads it but for ajax requests this isn't imported
39  Yii::import('zii.widgets.CMenu');
40 
41  class DividedMenu extends CMenu
42  {
43  public $submenuHtmlOptions = array('class' => 'button-actions');
44 
45  protected $renderIconTrigger = true;
46 
47  public function init()
48  {
49  if (!isset($this->htmlOptions['id']))
50  {
51  $this->htmlOptions['id'] = $this->getId();
52  }
53  else
54  {
55  $this->setId($this->htmlOptions['id']);
56  }
57  $route = $this->getController()->getRoute();
58  $this->items = $this->normalizeItems($this->items, $route, $hasActiveChild);
59  }
60 
61  protected function renderMenu($items)
62  {
63  if (count($items))
64  {
65  if (count($items) > 1)
66  {
67  throw new NotSupportedException;
68  }
69  if (isset($this->htmlOptions['class']) && $this->htmlOptions['class'] == 'clickable-dividedmenu')
70  {
71  $this->renderIconTrigger = false;
72  }
73  if ($this->isButtonDivided($items[0]))
74  {
75  $class = 'split-button';
76  }
77  else
78  {
79  $class = 'default-button';
80  }
81  if (empty($this->htmlOptions['class']))
82  {
83  $this->htmlOptions['class'] = $class;
84  }
85  else
86  {
87  $this->htmlOptions['class'] .= ' ' . $class;
88  }
89  echo ZurmoHtml::openTag('div', $this->htmlOptions)."\n";
90  $this->renderMenuRecursive($items);
91  echo ZurmoHtml::closeTag('div');
92  }
93  }
94 
95  protected function renderMenuRecursive($items)
96  {
97  $item = $items[0];
98  $options = isset($item['itemOptions']) ? $item['itemOptions'] : array();
99  $class = array();
100  if ($item['active'] && $this->activeCssClass!='')
101  {
102  $class[] = $this->activeCssClass;
103  }
104  if ($class !== array())
105  {
106  if (empty($options['class']))
107  {
108  $options['class'] = implode(' ', $class);
109  }
110  else
111  {
112  $options['class'].=' '.implode(' ', $class);
113  }
114  }
115 
116  if (isset($item['itemOptions']['iconClass']))
117  {
118  $icon = ZurmoHtml::tag('i', array('class' => $item['itemOptions']['iconClass']), null);
119  }
120  else
121  {
122  $icon = null;
123  }
124 
125  if (!isset($item['dynamicLabel']))
126  {
127  $item['dynamicLabel'] = null;
128  }
129 
130  if (isset($item['url']))
131  {
132  $label = $this->linkLabelWrapper === null ? $item['label'] : CHtml::tag($this->linkLabelWrapper, $this->linkLabelWrapperHtmlOptions, $item['label']);
133  $label = ZurmoHtml::tag('span', array('class' => 'button-label'), $label);
134  echo CHtml::link($icon . $label . $item['dynamicLabel'], $item['url'], array('class' => 'button-action'));
135  $spanForTrigger = null;
136  }
137  else
138  {
139  $item['linkOptions']['class'] = 'button-label';
140  $spanForTrigger = $icon;
141  $spanForTrigger .= CHtml::tag('span',isset($item['linkOptions']) ? $item['linkOptions'] : array(), $item['label']); // Not Coding Standard
142  $spanForTrigger .= $item['dynamicLabel'];
143  }
144 
145  if (isset($item['items']) && count($item['items']) || isset($item['dynamicContent']))
146  {
147  $label = null;
148  if ($this->renderIconTrigger)
149  {
150  $label = ZurmoHtml::tag('i', array('class' => 'icon-trigger'), null);
151  }
152  if (isset($spanForTrigger))
153  {
154  echo ZurmoHtml::link($spanForTrigger . $label, null, array('class' => 'button-action-trigger'));
155  }
156  else
157  {
158  echo ZurmoHtml::link($label, null, array('class' => 'button-trigger'));
159  }
160  echo ZurmoHtml::openTag('ul', isset($item['submenuOptions']) ? $item['submenuOptions'] : $this->submenuHtmlOptions);
161  if (isset($item['dynamicContent']))
162  {
163  echo ZurmoHtml::openTag('li');
164  echo $item['dynamicContent'];
165  echo ZurmoHtml::closeTag('li');
166  }
167  if (isset($item['items']) && count($item['items']))
168  {
169  foreach ($item['items'] as $item)
170  {
171  $options = isset($item['itemOptions']) ? $item['itemOptions'] : array();
172  $class = array();
173  if ($item['active'] && $this->activeCssClass!='')
174  {
175  $class[] = $this->activeCssClass;
176  }
177  if ($class !== array())
178  {
179  if (empty($options['class']))
180  {
181  $options['class'] = implode(' ', $class);
182  }
183  else
184  {
185  $options['class'].=' '.implode(' ', $class);
186  }
187  }
188  echo ZurmoHtml::openTag('li', $options);
189  echo $this->renderMenuItem($item);
190  echo ZurmoHtml::closeTag('li');
191  }
192  }
193  echo ZurmoHtml::closeTag('ul');
194  }
195  }
196 
197  public function run()
198  {
199  $this->renderMenu($this->items);
200  }
201 
202  protected function isButtonDivided($item)
203  {
204  if (count($item['items']) && isset($item['url']))
205  {
206  return true;
207  }
208  return false;
209  }
210 
211  protected function renderMenuItem($item)
212  {
213  if ((isset($item['ajaxLinkOptions'])))
214  {
215  if ($this->linkLabelWrapper === null)
216  {
217  $label = $item['label'];
218  }
219  else
220  {
221  $label = ZurmoHtml::tag($this->linkLabelWrapper, $this->linkLabelWrapperHtmlOptions, $item['label']);
222  }
223  return ZurmoHtml::ajaxLink($label, $item['url'], $item['ajaxLinkOptions'], $this->resolveHtmlOptions($item));
224  }
225  else
226  {
227  return parent::renderMenuItem($item);
228  }
229  }
230 
231  protected function resolveHtmlOptions(array $item)
232  {
233  $htmlOptions = array();
234  if (isset($item['linkOptions']))
235  {
236  $htmlOptions = $item['linkOptions'];
237  }
238  return $htmlOptions;
239  }
240  }
241 ?>
static ajaxLink($text, $url, $ajaxOptions=array(), $htmlOptions=array())
Definition: ZurmoHtml.php:328
Generated on Sat Jul 4 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.