Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DetailsViewFormLayout.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 
38  {
43  protected $tabsContent;
44 
50  protected $morePanelsLinkLabel;
51 
57  protected $lessPanelsLinkLabel;
58 
59  protected $labelsHaveOwnCells = true;
60 
61  public $alwaysShowErrorSummary = false;
62 
67  public function labelsHaveOwnCells($hasOwnCells)
68  {
69  assert('is_bool($hasOwnCells)');
70  $this->labelsHaveOwnCells = $hasOwnCells;
71  }
72 
80  public function render()
81  {
82  $content = '';
83  if ($this->alwaysShowErrorSummary || $this->shouldRenderTabbedPanels())
84  {
85  $content .= $this->errorSummaryContent;
86  }
87  $tabsContent = '';
88  foreach ($this->metadata['global']['panels'] as $panelNumber => $panel)
89  {
90  $content .= $this->renderDivTagByPanelNumber($panelNumber);
91  $content .= $this->renderPanelHeaderByPanelNumberAndPanel($panelNumber, $panel);
92  $content .= $this->resolveStartingTableTagAndColumnQuantityClass($panel);
93  $content .= TableUtil::getColGroupContent(static::getMaximumColumnCountForAllPanels($this->metadata), $this->labelsHaveOwnCells);
94  $content .= '<tbody>';
95 
96  foreach ($panel['rows'] as $row)
97  {
98  $cellsContent = null;
99  foreach ($row['cells'] as $cell)
100  {
101  if (is_array($cell['elements']))
102  {
103  foreach ($cell['elements'] as $renderedElement)
104  {
105  $cellsContent .= $renderedElement;
106  }
107  }
108  }
109  if (!empty($cellsContent))
110  {
111  $this->resolveRowWrapperTag($content, $cellsContent);
112  }
113  }
114  $content .= $this->renderLastPanelRowsByPanelNumber($panelNumber);
115  $content .= '</tbody>';
116  $content .= '</table>';
117  if ($this->shouldRenderTabbedPanels())
118  {
119  $content .= '</div>';
120  }
121  $content .= '</div>';
122  }
123  $this->renderScripts();
124  return $this->resolveFormLayoutContent($content);
125  }
126 
127  protected function resolveStartingTableTagAndColumnQuantityClass($panel)
128  {
129  assert('is_array($panel)');
130  if (static::getMaximumColumnCountForSpecificPanels($panel) == 2)
131  {
132  return '<table class="form-fields double-column">';
133  }
134  return '<table class="form-fields">';
135  }
136 
141  protected function resolveRowWrapperTag(& $content, $cellsContent)
142  {
143  assert('is_string($content) || $content == null');
144  assert('is_string($cellsContent)');
145  if (strpos($cellsContent, '<tr') === 0)
146  {
147  $content .= $cellsContent;
148  }
149  else
150  {
151  $content .= '<tr>';
152  $content .= $cellsContent;
153  $content .= '</tr>';
154  }
155  }
156 
157  protected function renderPanelHeaderByPanelNumberAndPanel($panelNumber, $panel)
158  {
159  if ($this->shouldRenderTabbedPanels())
160  {
161  $tabId = $this->uniqueId . '-panel-tab-' . $panelNumber;
162  $content = '<div id="' . $tabId . '">';
163  if (!empty($panel['title']))
164  {
165  $tabTitle = $panel['title'];
166  }
167  else
168  {
169  $tabTitle = Zurmo::t('Core', 'Tab'). ' ' . ($panelNumber + 1);
170  }
171  $this->addTabsContent('<li><a href="#' . $tabId . '">' . $tabTitle . '</a></li>');
172  return $content;
173  }
174  else
175  {
176  if (!empty($panel['title']))
177  {
178  return '<div class="panelTitle">' . $panel['title'] . '</div>';
179  }
180  }
181  }
182 
183  protected function renderDivTagByPanelNumber($panelNumber)
184  {
185  if ($panelNumber > 0 && $this->shouldHidePanelsAfterFirstPanel())
186  {
187  return '<div class="panel more-view-panel-' . $this->uniqueId . '" style="display:none;">';
188  }
189  else
190  {
191  return '<div class="panel">';
192  }
193  }
194 
195  protected function renderLastPanelRowsByPanelNumber($panelNumber)
196  {
197  $content = null;
198  if ($panelNumber == 0 && $this->shouldHidePanelsAfterFirstPanel())
199  {
200  $content .= '<tr>';
201  $content .= '<td colspan = "' . $this->maxCellsPerRow . '">';
202  $content .= ZurmoHtml::link($this->getMorePanelsLinkLabel(),
203  '#', array('class' => 'more-panels-link', 'id' => 'show-more-panels-link-' . $this->uniqueId . '',
204  'data-unique' => $this->uniqueId, 'data-label' => $this->getLessPanelsLinkLabel()));
205  $content .= '</td>';
206  $content .= '</tr>';
207  }
208  return $content;
209  }
210 
211  protected function renderScripts()
212  {
213  if ($this->shouldHidePanelsAfterFirstPanel())
214  {
215  Yii::app()->clientScript->registerScript('showMorePanels',
216  "
217  $('.more-panels-link').click(
218  function()
219  {
220  var uniqueId = $(this).data('unique');
221  var label = $(this).data('label');
222  var oldLabel = $(this).html();
223  $('.more-view-panel-' + uniqueId).toggle();
224  $(this).html(label);
225  $(this).data('label', oldLabel);
226  return false;
227  }
228  );
229  ");
230  }
231  }
232 
233  protected function resolveFormLayoutContent($content)
234  {
235  if ($this->shouldRenderTabbedPanels())
236  {
237  $content = '<div id="' . $this->uniqueId . '-panel-tabs"><ul>' . $this->getTabsContent() . '</ul>' . $content . '</div>';
238  // Begin Not Coding Standard
239  Yii::app()->clientScript->registerScript('initializeTabs' . $this->uniqueId, "
240  $(function() {
241  $( '#" . $this->uniqueId . "-panel-tabs' ).tabs({selected: 0});
242  });");
243  // End Not Coding Standard
244  }
245  return $content;
246  }
247 
248  protected function shouldHidePanelsAfterFirstPanel()
249  {
250  if (isset($this->metadata['global']['panelsDisplayType']) &&
251  $this->metadata['global']['panelsDisplayType'] == FormLayout::PANELS_DISPLAY_TYPE_FIRST)
252  {
253  return true;
254  }
255  return false;
256  }
257 
258  protected function shouldRenderTabbedPanels()
259  {
260  if (isset($this->metadata['global']['panelsDisplayType']) &&
261  $this->metadata['global']['panelsDisplayType'] == FormLayout::PANELS_DISPLAY_TYPE_TABBED &&
262  count($this->metadata['global']['panels']) > 1)
263  {
264  return true;
265  }
266  return false;
267  }
268 
269  protected function addTabsContent($content)
270  {
271  $this->tabsContent .= $content;
272  }
273 
274  protected function getTabsContent()
275  {
276  return $this->tabsContent;
277  }
278 
279  public function setMorePanelsLinkLabel($label)
280  {
281  $this->morePanelsLinkLabel = $label;
282  }
283 
284  public function setLessPanelsLinkLabel($label)
285  {
286  $this->lessPanelsLinkLabel = $label;
287  }
288 
289  protected function getMorePanelsLinkLabel()
290  {
291  if ($this->morePanelsLinkLabel == null)
292  {
293  Zurmo::t('Core', 'More Options');
294  }
295  else
296  {
297  return $this->morePanelsLinkLabel;
298  }
299  }
300 
301  protected function getLessPanelsLinkLabel()
302  {
303  if ($this->lessPanelsLinkLabel == null)
304  {
305  Zurmo::t('Core', 'Fewer Options');
306  }
307  else
308  {
309  return $this->lessPanelsLinkLabel;
310  }
311  }
312  }
313 ?>
resolveRowWrapperTag(&$content, $cellsContent)
Generated on Tue Jul 7 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.