Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
JuiPortlets.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  Yii::import('zii.widgets.jui.CJuiWidget');
38 
76  class JuiPortlets extends CJuiWidget
77  {
82  public $items = array();
83 
88  public $uniqueLayoutId;
89 
90  public $moduleId;
91 
92  public $saveUrl;
93 
102  public $layoutType;
103 
104  public $cssFile = null;
105 
110  public $collapsible = true;
111 
116  public $movable = true;
117 
122 
123  public function init()
124  {
125  assert('!empty($this->layoutType)');
126  assert('!empty($this->uniqueLayoutId)');
127  assert('!empty($this->moduleId)');
128  assert('!empty($this->saveUrl)');
129  assert('is_bool($this->collapsible)');
130  assert('is_bool($this->movable)');
131  assert('in_array($this->layoutType, array("100", "50,50", "75,25"))'); // Not Coding Standard
132  $this->themeUrl = Yii::app()->themeManager->baseUrl;
133  $this->theme = Yii::app()->theme->name;
135  parent::init();
136  }
137 
148  public static function renderPortlet($item, $uniqueLayoutId, $moduleId, $renderOnClickEvent = true)
149  {
150  $content = "<div class=\"juiportlet-widget-head\">\n";
151  $content .= "<h3>" . $item['title'] . "</h3>";
152  $content .= "<div class=\"portlet-actions-container\">" .
153  static::renderOptionsMenu($item, $uniqueLayoutId, $moduleId, $renderOnClickEvent, $item['portletParams']);
154  $content .= $item['headContent'] . "</div>\n";
155  if (isset($item['collapsed']) && $item['collapsed'])
156  {
157  $widgetContentStyle = "style=\"display:none;\"";
158  }
159  else
160  {
161  $widgetContentStyle = '';
162  }
163  $content .= "</div>\n";
164  $content .= "<div class=\"juiportlet-widget-content\" $widgetContentStyle >\n";
165  $content .= $item['content'] . "\n";
166  $content .= "</div>\n";
167  return $content;
168  }
169 
178  protected static function renderOptionsMenu(array $item, $uniqueLayoutId, $moduleId, $renderOnClickEvent = true, $portletParams = array())
179  {
180  $menuItems = array('label' => null, 'items' => array());
181 
182  if (isset($item['editable']) && $item['editable'] == true)
183  {
184  $menuItems['items'][] = static::makeEditMenuItem($item['id'], $uniqueLayoutId, $moduleId, $renderOnClickEvent, $portletParams);
185  }
186  if (isset($item['removable']) && $item['removable'] == true)
187  {
188  $menuItems['items'][] = array('label' => Zurmo::t('Core', 'Remove Portlet'), 'url' => '#',
189  'linkOptions' => array('class' => 'remove-portlet'));
190  }
191  if (isset($item['additionalOptionMenuItems']) && !empty($item['additionalOptionMenuItems']) )
192  {
193  foreach ($item['additionalOptionMenuItems'] as $additionalOptionMenuItem)
194  {
195  $menuItems['items'][] = array('label' => $additionalOptionMenuItem['label'],
196  'url' => $additionalOptionMenuItem['url']);
197  }
198  }
199  if (count($menuItems['items']) > 0)
200  {
201  $cClipWidget = new CClipWidget();
202  $cClipWidget->beginClip("PortletOptionMenu" . $uniqueLayoutId);
203  $cClipWidget->widget('application.core.widgets.MbMenu', array(
204  'htmlOptions' => array('class' => 'options-menu edit-portlet-menu'),
205  'items' => array($menuItems),
206  ));
207  $cClipWidget->endClip();
208  return $cClipWidget->getController()->clips['PortletOptionMenu' . $uniqueLayoutId];
209  }
210  }
211 
212  protected static function makeEditMenuItem($portletId, $uniqueLayoutId, $moduleId, $renderOnClickEvent = true, $portletParams = array())
213  {
214  $htmlOptions = array(
215  'class' => 'edit',
216  'id' => $uniqueLayoutId. '_' . $portletId . '_EditLink'
217  );
218  if (!$renderOnClickEvent)
219  {
220  return array('label' => Zurmo::t('Core', 'Configure Portlet'), 'url' => '#',
221  'linkOptions' => $htmlOptions);
222  }
223  else
224  {
225  $url = null;
226  }
227  $url = Yii::app()->createUrl($moduleId .'/defaultPortlet/ModalConfigEdit/', array(
228  'uniqueLayoutId' => $uniqueLayoutId,
229  'portletId' => $portletId,
230  'portletParams' => $portletParams,
231  ));
232  return array('label' => Zurmo::t('Core', 'Configure Portlet'), 'url' => $url,
233  'linkOptions' => $htmlOptions, 'ajaxLinkOptions' => static::resolveAjaxOptionsForEditLink());
234  }
235 
236  protected static function resolveAjaxOptionsForEditLink()
237  {
238  $title = Zurmo::t('Core', 'Edit Portlet');
239  return ModalView::getAjaxOptionsForModalLink($title);
240  }
241 
246  public function run()
247  {
248  assert('!empty($this->uniqueLayoutId)');
249  $id = $this->getId();
250  $this->htmlOptions['id'] = $id;
251  $columnsClass = '.juiportlet-columns-' . $this->uniqueLayoutId;
252  $script = "juiPortlets.init('" . $this->uniqueLayoutId . "',"; // Not Coding Standard
253  $script .= "'" . $this->moduleId . "', '" . $this->saveUrl . "', ";
254  if (Yii::app()->request->enableCsrfValidation)
255  {
256  $script .= "'" . Yii::app()->request->csrfTokenName . "', '" . Yii::app()->request->csrfToken . "', ";
257  }
258  else
259  {
260  $script .= "null, null, ";
261  }
262  $script .= "'" . $columnsClass . "', '" . $this->collapsible . "', '" . $this->movable . "', ";
263  $script .= "'" . Zurmo::t('Core', 'This portlet will be removed, ok?') . "');";
264  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $script);
265  $content = "";
266  $content .= "<div class=\"juiportlet-columns\"> \n";
267  if (!empty($this->items))
268  {
269  if ($this->layoutType == '100')
270  {
271  $totalColumns = 1;
272  $columnStyle[1] = 'juiportlet-column-no-split';
273  }
274  if ($this->layoutType == '50,50') // Not Coding Standard
275  {
276  $totalColumns = 2;
277  $columnStyle[1] = 'juiportlet-column-split-even-2';
278  $columnStyle[2] = 'juiportlet-column-split-even-2';
279  }
280  if ($this->layoutType == '75,25') // Not Coding Standard
281  {
282  $totalColumns = 2;
283  $columnStyle[1] = 'juiportlet-column-split-left-75';
284  $columnStyle[2] = 'juiportlet-column-split-right-25';
285  }
286  if (count($this->items) < $totalColumns)
287  {
288  $keys = array_keys($this->items);
289  if ($keys[0] == $totalColumns)
290  {
291  //TODO: when we expand to 3 or 4 columns, need to fill blank columns when appropriate and it might
292  //be more than just one occurance. We will need some sort of for loop.
293  $this->items = array(1 => array(array('blankColumn' => true))) + $this->items;
294  }
295  else
296  {
297  $this->items[] = array(array('blankColumn' => true));
298  }
299  }
300  foreach ($this->items as $column => $columnPortlets)
301  {
302  $classString = "juiportlet-columns-" . $this->uniqueLayoutId . " ";
303  $classString .= "juiportlet-widget-column" . $column . " ";
304  $classString .= "juiportlet-column " . $columnStyle[$column];
305  $content .= "<ul class=\"". $classString . "\">\n";
306  foreach ($columnPortlets as $position => $item)
307  {
308  if (isset($item['blankColumn']) && $item['blankColumn'])
309  {
310  $content .= "<li>&#160;\n";
311  $content .= "</li>\n";
312  }
313  else
314  {
315  $content .= "<li class=\"juiportlet-widget " . $item['uniqueClass'] .
316  "\" id=\"" . $item['uniqueId'] . "\">\n";
317  $content .= JuiPortlets::renderPortlet($item, $this->uniqueLayoutId, $this->moduleId);
318  $content .= "</li>\n";
319  }
320  }
321  $content .= "</ul>\n";
322  }
323  }
324  $content .= "</div>";
325  echo $content;
326  }
327 
331  protected function registerJuiPortletsScripts()
332  {
333  if ($this->baseJuiPortletsScriptUrl === null)
334  {
335  $this->baseJuiPortletsScriptUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.core.widgets.assets'));
336  }
337  $cs = Yii::app()->getClientScript();
338  $cs->registerScriptFile($this->baseJuiPortletsScriptUrl . '/juiportlets/JuiPortlets.js', CClientScript::POS_END);
339  }
340  }
341 ?>
registerJuiPortletsScripts()
static renderPortlet($item, $uniqueLayoutId, $moduleId, $renderOnClickEvent=true)
static renderOptionsMenu(array $item, $uniqueLayoutId, $moduleId, $renderOnClickEvent=true, $portletParams=array())
Generated on Sun Jul 12 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.