Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ComponentWithTreeForReportWizardView.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 
41  {
45  abstract protected function getItemsCount();
46 
51  abstract protected function getItemsContent(& $rowCount);
52 
57  public static function getTreeType()
58  {
59  throw new NotImplementedException();
60  }
61 
65  public static function getTreeDivId()
66  {
67  return static::getTreeType() . 'TreeArea';
68  }
69 
73  protected function renderFormContent()
74  {
75  $content = $this->renderAttributesAndRelationsTreeContent();
76  $content .= ZurmoHtml::tag('div', array('class' => 'dynamic-droppable-area'), $this->renderRightSideContent());
77  return $content;
78  }
79 
83  protected function renderRightSideContent()
84  {
85  $rowCount = 0;
86  $items = $this->getItemsContent($rowCount);
87  if ($this->isListContentSortable())
88  {
89  $itemsContent = $this->getSortableListContent($items);
90  }
91  else
92  {
93  $itemsContent = $this->getNonSortableListContent($items);
94  }
95  $idInputHtmlOptions = array('id' => static::resolveRowCounterInputId(static::getTreeType()));
96  $hiddenInputName = static::getTreeType() . 'RowCounter';
97  $dropZone = $this->renderRightSideDropZoneContent();
98  $droppableAttributesContent = ZurmoHtml::tag('div', array('class' => 'dynamic-rows'), $itemsContent);
99  $droppableAttributesContent .= $this->renderExtraDroppableAttributesContent();
100  $content = ZurmoHtml::hiddenField($hiddenInputName, $rowCount, $idInputHtmlOptions);
101  $content .= ZurmoHtml::tag('div', array('class' => 'droppable-dynamic-rows-container ' .
102  static::getTreeType()), $droppableAttributesContent . $dropZone);
103  $content .= ZurmoHtml::tag('div', array('class' => 'zero-components-view ' .
104  static::getTreeType()), $this->getZeroComponentsContent());
105  return $content;
106  }
107 
111  protected function renderRightSideDropZoneContent()
112  {
113  return ZurmoHtml::tag('div', array('class' => 'drop-zone'), ZurmoHtml::tag('div', array(), Zurmo::t('Core', 'Drop Here')));
114  }
115 
120  {
121  }
122 
129  protected function renderItems(& $rowCount, $componentData, $trackableStructurePosition = false)
130  {
131  assert('is_int($rowCount)');
132  assert('is_array($componentData)');
133  assert('is_bool($trackableStructurePosition)');
134  $items = array();
135  $wizardFormClassName = get_class($this->model);
136  foreach ($componentData as $component)
137  {
138  $nodeIdWithoutTreeType = $component->attributeIndexOrDerivedType;
140  resolveInputPrefixData($wizardFormClassName,
141  $this->getTreeType(), $rowCount);
142  $adapter = new ReportAttributeToElementAdapter($inputPrefixData, $component,
143  $this->form, $this->getTreeType());
144  $view = new AttributeRowForReportComponentView($adapter,
145  $rowCount, $inputPrefixData,
147  resolveAttributeByNodeId($nodeIdWithoutTreeType),
148  (bool)$trackableStructurePosition, true, static::getTreeType());
149  $view->addWrapper = false;
150  $items[] = array('content' => $view->render());
151  $rowCount++;
152  }
153  return $items;
154  }
155 
160  protected function getNonSortableListContent(Array $items)
161  {
162  $content = null;
163  foreach ($items as $item)
164  {
165  $content .= ZurmoHtml::tag('li', array(), $item['content']);
166  }
167  return ZurmoHtml::tag('ul', array(), $content);
168  }
169 
174  protected function getSortableListContent(Array $items)
175  {
176  $cClipWidget = new CClipWidget();
177  $cClipWidget->beginClip(static::getTreeType() . 'ReportComponentSortable');
178  $cClipWidget->widget('application.core.widgets.JuiSortable', array(
179  'items' => $items,
180  'itemTemplate' => '<li>content</li>',
181  'htmlOptions' =>
182  array(
183  'id' => static::getTreeType() . 'attributeRowsUl',
184  'class' => 'sortable',
185  ),
186  'options' => array(
187  'placeholder' => 'ui-state-highlight',
188  ),
189  'showEmptyList' => false
190  ));
191  $cClipWidget->endClip();
192  return $cClipWidget->getController()->clips[static::getTreeType() . 'ReportComponentSortable'];
193  }
194 
195  protected function registerScripts()
196  {
197  parent::registerScripts();
198  $script = '
199  $(".droppable-dynamic-rows-container.' . static::getTreeType() . '").live("drop", function(event, ui)
200  {
201  ' . $this->getAjaxForDroppedAttribute() . '
202  });
203  $(".item-to-place", "#' . static::getTreeType() . 'TreeArea").live("dblclick", function(event)
204  {
205  ' . $this->getAjaxForDoubleClickedAttribute() . '
206  });
207  $(".remove-dynamic-row-link.' . static::getTreeType() . '").live("click", function()
208  {
209  var size = $("#' . get_class($this) . ' .dynamic-rows > ul > li").length;
210  $(this).parent().parent().remove(); //removes the <li>
211  if (size < 2)
212  {
213  $(".' . static::getZeroComponentsClassName() . '").fadeIn(400);
214  }
216  return false;
217  });
218  ';
219  Yii::app()->getClientScript()->registerScript(static::getTreeType() . 'ReportComponentForTreeScript', $script);
220  }
221 
225  protected function getAddAttributeUrl()
226  {
227  return Yii::app()->createUrl('reports/default/addAttributeFromTree',
228  array_merge($_GET, array('type' => $this->model->type,
229  'treeType' => static::getTreeType())));
230  }
231 
235  protected function getAjaxForDroppedAttribute()
236  {
237  $rowCounterInputId = static::resolveRowCounterInputId(static::getTreeType());
238  return ZurmoHtml::ajax(array(
239  'type' => 'POST',
240  'data' => 'js:$("#' . $this->form->getId() . '").serialize()',
241  'url' => 'js:$.param.querystring("' .
242  $this->getAddAttributeUrl() .
243  '", "nodeId=" + ui.helper.attr("id") + "&rowNumber=" + $(\'#' . $rowCounterInputId . '\').val())',
244  'beforeSend' => 'js:function()
245  {
246  $(".ui-overlay-block").fadeIn(50);
247  $(this).makeLargeLoadingSpinner(true, ".ui-overlay-block"); //- add spinner to block anything else
248  }',
249  'success' => 'js:function(data)
250  {
251  var ul = $(".droppable-dynamic-rows-container.' . static::getTreeType() . '").parent().find(".dynamic-rows").find("ul:first");
252  $(\'#' . $rowCounterInputId . '\').val(parseInt($(\'#' . $rowCounterInputId . '\').val()) + 1);
253  ul.append(data);
254  ' . $this->getReportAttributeRowAddOrRemoveExtraScript() . '
255  $(".' . static::getZeroComponentsClassName() . '").fadeOut(150);
256  $(this).makeLargeLoadingSpinner(false, ".ui-overlay-block");
257  $(".ui-overlay-block").fadeOut(50);
258  window.scrollTo(0, ul.find("li:last-child > div").offset().top);
259  ul.find("li:last-child > div").addClass("glow").animate({backgroundColor:"#f0f0f0"}, 2000);
260  }'
261  ));
262  }
263 
267  protected function getAjaxForDoubleClickedAttribute()
268  {
269  $rowCounterInputId = static::resolveRowCounterInputId(static::getTreeType());
270  return ZurmoHtml::ajax(array(
271  'type' => 'POST',
272  'data' => 'js:$("#' . $this->form->getId() . '").serialize()',
273  'url' => 'js:$.param.querystring("' . $this->getAddAttributeUrl() . '",
274  "nodeId=" + event.currentTarget.id + "&rowNumber=" + $(\'#' . $rowCounterInputId . '\').val())',
275  'beforeSend' => 'js:function()
276  {
277  $(".ui-overlay-block").fadeIn(50);
278  $(this).makeLargeLoadingSpinner(true, ".ui-overlay-block"); //- add spinner to block anything else
279  }',
280  'success' => 'js:function(data)
281  {
282  var ul = $(".droppable-dynamic-rows-container.' . static::getTreeType() . '").parent().find(".dynamic-rows").find("ul:first");
283  $(\'#' . $rowCounterInputId . '\').val(parseInt($(\'#' . $rowCounterInputId . '\').val()) + 1);
284  ul.append(data);
285  ' . $this->getReportAttributeRowAddOrRemoveExtraScript() . '
286  $(".' . static::getZeroComponentsClassName() . '").hide();
287  $(this).makeLargeLoadingSpinner(false, ".ui-overlay-block");
288  $(".ui-overlay-block").fadeOut(50);
289  window.scrollTo(0, ul.find("li:last-child > div").offset().top);
290  ul.find("li:last-child > div").addClass("glow").animate({backgroundColor:"#f0f0f0"}, 2000);
291  }'
292  ));
293  }
294 
298  protected function getReportAttributeRowAddOrRemoveExtraScript()
299  {
300  }
301 
305  protected function isListContentSortable()
306  {
307  return false;
308  }
309  }
310 ?>
static resolveInputPrefixData($formModelClassName, $treeType, $rowNumber)
renderItems(&$rowCount, $componentData, $trackableStructurePosition=false)
Generated on Sat Nov 28 2020 07:10:46
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.