42 protected $gridIdSuffix;
44 protected $hideAllSearchPanelsToStart;
46 protected $showAdvancedSearch =
true;
55 $hideAllSearchPanelsToStart =
false
58 assert(
'$model != null');
59 assert(
'is_string($listModelClassName)');
60 assert(
'is_bool($hideAllSearchPanelsToStart)');
61 $this->model = $model;
62 $this->listModelClassName = $listModelClassName;
63 $this->gridIdSuffix = $gridIdSuffix;
64 $this->gridId =
'list-view';
65 $this->hideAllSearchPanelsToStart = $hideAllSearchPanelsToStart;
77 $content =
'<div class="wide form">';
79 list($form, $formStart) = $clipWidget->renderBeginWidget(
80 'NoRequiredsActiveForm',
81 array(
'id' => $this->getSearchFormId(),
82 'action' => $this->getFormActionUrl(),
83 'enableAjaxValidation' => $this->getEnableAjaxValidationValue(),
84 'clientOptions' => $this->getClientOptions(),
88 $content .= $formStart;
90 $content .= $this->renderAfterFormLayout($form);
91 $formEnd = $clipWidget->renderEndWidget();
93 $content .= $this->renderModalContainer();
98 protected function getEnableAjaxValidationValue()
103 protected function getClientOptions()
108 protected function getFormActionUrl()
113 protected function renderAfterFormLayout($form)
115 $this->registerScripts();
126 $moreSearchOptionsLink = $this->resolveMoreSearchOptionsLinkContent();
127 $selectListAttributesLink = $this->getSelectListAttributesLinkContent();
129 $clearSearchLabelPrefix = $this->getClearSearchLabelPrefixContent();
130 $clearSearchLabel = $this->getClearSearchLabelContent();
131 $clearSearchLinkStartingStyle = $this->getClearSearchLinkStartingStyle();
132 $clearSearchLink = ZurmoHtml::link($clearSearchLabelPrefix . $clearSearchLabel,
'#',
133 array(
'id' =>
'clear-search-link' . $this->gridIdSuffix,
134 'style' => $clearSearchLinkStartingStyle));
135 $startingDivStyle = null;
136 if ($this->hideAllSearchPanelsToStart)
138 $startingDivStyle =
"style='display:none;'";
140 $content =
'<div class="search-form-tools">';
141 $content .= $moreSearchOptionsLink;
142 $content .= $selectListAttributesLink;
143 $content .= $kanbanBoardOptionsLink;
144 $content .= $clearSearchLink;
146 $content .= $this->renderClearingSearchInputContent();
147 $content .=
'</div>';
151 protected function resolveMoreSearchOptionsLinkContent()
153 if ($this->showAdvancedSearch)
155 return ZurmoHtml::link(Zurmo::t(
'Core',
'Advanced'),
'#', array(
'id' =>
'more-search-link' . $this->gridIdSuffix));
159 protected function getClearSearchLabelPrefixContent()
163 protected function getClearSearchLabelContent()
165 return Zurmo::t(
'Core',
'Clear');
168 protected function getClearSearchLinkStartingStyle()
170 if ($this->model->anyMixedAttributes == null)
172 return "display:none;";
176 protected function getExtraRenderForClearSearchLinkScript()
180 protected function renderClearingSearchInputContent()
182 $idInputHtmlOptions = array(
'id' => $this->getClearingSearchInputId());
183 $hiddenInputName =
'clearingSearch';
184 return ZurmoHtml::hiddenField($hiddenInputName, null, $idInputHtmlOptions);
187 protected function getClearingSearchInputId()
189 return 'clearingSearch-' . $this->getSearchFormId();
192 protected function registerScripts()
194 DropDownUtil::registerScripts();
196 Yii::app()->clientScript->registerScript(
'search' . $this->getSearchFormId(),
"
197 $('#clear-search-link" . $this->gridIdSuffix .
"').removeAttr('clearForm');
198 $('#clear-search-link" . $this->gridIdSuffix .
"').clearform({
199 form: '#" . $this->getSearchFormId() .
"'
202 $('#clear-search-link" . $this->gridIdSuffix .
"').unbind('click.clear');
203 $('#clear-search-link" . $this->gridIdSuffix .
"').bind('click.clear', function(){
204 $('#" . $this->getClearingSearchInputId() .
"').val('1');
205 $('#clear-search-link" . $this->gridIdSuffix .
"').hide();
206 " . $this->getExtraRenderForClearSearchLinkScript() .
"
207 $(this).closest('form').submit();
208 $('#" . $this->getClearingSearchInputId() .
"').val('');
212 $('#more-search-link" . $this->gridIdSuffix .
"').unbind('click.more');
213 $('#more-search-link" . $this->gridIdSuffix .
"').bind('click.more', function(event){
214 $('.select-list-attributes-view').hide();
215 $('.kanban-board-options-view').hide();
216 $(this).closest('form').find('.search-view-1').toggle();
220 $('#cancel-advanced-search').unbind('click');
221 $('#cancel-advanced-search').live('click', function(event){
222 $(this).closest('form').find('.search-view-1').hide();
225 $this->renderAdvancedSearchScripts();
229 protected function renderAdvancedSearchScripts()
231 Yii::app()->clientScript->registerScript(
'advancedSearch' . $this->getSearchFormId(),
"
232 $('#" . $this->getSearchFormId() .
"').unbind('submit');
233 $('#" . $this->getSearchFormId() .
"').bind('submit', function(event)
235 $(this).closest('form').find('.search-view-1').hide();
237 $('.select-list-attributes-view').hide();
238 $('.kanban-board-options-view').hide();
239 $('#" . $this->gridId . $this->gridIdSuffix .
"-selectedIds').val(null);
240 $.fn.yiiGridView.update('" . $this->gridId . $this->gridIdSuffix .
"',
242 data: $(this).serialize() + '&" . $this->listModelClassName .
"_page=&" .
243 $this->listModelClassName .
"_sort=" .
260 var empty = $('#" . $this->getSearchFormId().
"').find('.anyMixedAttributes-input').val() == '';
261 $(this).closest('form').find('.search-view-1').find(':input').each(function()
263 if ($(this).val() != '')
270 $('#clear-search-link" . $this->gridIdSuffix .
"').show();
274 $('#clear-search-link" . $this->gridIdSuffix .
"').hide();
302 $('#" . $this->getSearchFormId().
"').find('.anyMixedAttributes-input').unbind('input.clear propertychange.clear keyup.clear');
303 $('#" . $this->getSearchFormId().
"').find('.anyMixedAttributes-input').bind('input.clear propertychange.clear keyup.clear', function(event)
305 $('#clear-search-link" . $this->gridIdSuffix .
"').show();
318 $metadata = self::getMetadata();
319 $maxCellsPerRow = $this->getMaxCellsPerRow();
321 $content .= $this->renderSummaryCloneContent();
322 assert(
'count($metadata["global"]["panels"]) == 2 || count($metadata["global"]["panels"]) == 1');
323 foreach ($metadata[
'global'][
'panels'] as $key => $panel)
325 $startingDivStyle =
"";
326 if ($key == 1 || $this->hideAllSearchPanelsToStart)
328 $startingDivStyle =
"style='display:none;'";
330 $content .=
'<div class="search-view-' . $key .
'" ' . $startingDivStyle .
'>';
333 $content .= $this->renderAdvancedSearchForFormLayout($panel, $maxCellsPerRow, $form);
337 $content .= $this->renderStaticSearchRows($panel, $maxCellsPerRow, $form);
342 $content .= $this->renderViewToolBarContainerForAdvancedSearch($form);
344 $content .=
'</div>';
346 $content .= $this->renderListAttributesSelectionContent($form);
354 protected function renderSummaryCloneContent()
356 return ZurmoHtml::tag(
'div',
358 'id' => $this->getListViewId() .
'-summary-clone',
359 'class' => ExtendedGridView::CLONE_SUMMARY_CLASS,
364 protected function getSelectListAttributesLinkContent()
366 if ($this->model->getListAttributesSelector() != null &&
367 ($this->model->getKanbanBoard() == null || !$this->model->getKanbanBoard()->getIsActive()))
369 return ZurmoHtml::link(Zurmo::t(
'Core',
'Columns'),
'#', array(
'id' =>
'select-list-attributes-link' . $this->gridIdSuffix));
373 protected function renderListAttributesSelectionContent(
ZurmoActiveForm $form)
375 if ($this->model->getListAttributesSelector() == null)
379 Yii::app()->clientScript->registerScript(
'listAttributes' . $this->getSearchFormId(),
"
380 $('#select-list-attributes-link" . $this->gridIdSuffix .
"').unbind('click.more');
381 $('#select-list-attributes-link" . $this->gridIdSuffix .
"').bind('click.more', function(event)
383 $(this).closest('form').find('.search-view-1').hide();
384 $(this).closest('form').find('.kanban-board-options-view').hide();
385 $('.select-list-attributes-view').toggle();
389 $('#list-attributes-reset').unbind('click.close');
390 $('#list-attributes-reset').bind('click.close', function()
392 $('.select-list-attributes-view').hide();
395 $('#list-attributes-apply').unbind('click.close');
396 $('#list-attributes-apply').bind('click.close', function()
398 $('.select-list-attributes-view').hide();
403 $element->editableTemplate =
'{content}';
404 $content = $element->render();
405 return ZurmoHtml::tag(
'div', array(
'class' =>
'select-list-attributes-view',
406 'style' =>
'display:none'), $content);
414 if ($this->model->getKanbanBoard() != null && $this->model->getKanbanBoard()->getIsActive())
416 return ZurmoHtml::link(Zurmo::t(
'Core',
'Options'),
'#', array(
'id' =>
'kanban-board-options-link' . $this->gridIdSuffix));
426 if ($this->model->getKanbanBoard() == null || !$this->model->getKanbanBoard()->getIsActive())
430 Yii::app()->clientScript->registerScript(
'kanbanBoardOptions' . $this->getSearchFormId(),
"
431 $('#kanban-board-options-link" . $this->gridIdSuffix .
"').unbind('click.more');
432 $('#kanban-board-options-link" . $this->gridIdSuffix .
"').bind('click.more', function(event)
434 $(this).closest('form').find('.search-view-1').hide();
435 $('.select-list-attributes-view').hide();
436 $('.kanban-board-options-view').toggle();
440 $('#kanban-board-options-reset').unbind('click.close');
441 $('#kanban-board-options-reset').bind('click.close', function()
443 $('.kanban-board-options-view').hide();
446 $('#kanban-board-options-apply').unbind('click.close');
447 $('#kanban-board-options-apply').bind('click.close', function()
449 $('.kanban-board-options-view').hide();
454 $element->editableTemplate =
'{content}';
455 $content = $element->render();
456 return ZurmoHtml::tag(
'div', array(
'class' =>
'kanban-board-options-view',
'style' =>
'display:none'), $content);
459 protected function renderViewToolBarContainerForAdvancedSearch($form)
461 $content =
'<div class="view-toolbar-container clearfix">';
462 $content .=
'<div class="form-toolbar">';
463 $content .= $this->renderViewToolBarLinksForAdvancedSearch($form);
464 $content .=
'</div></div>';
468 protected function renderViewToolBarLinksForAdvancedSearch($form)
471 $params[
'label'] = Zurmo::t(
'Core',
'Search');
472 $params[
'htmlOptions'] = array(
'id' =>
'search-advanced-search',
'onclick' =>
'js:$(this).addClass("attachLoadingTarget");');
474 $content = $searchElement->render();
476 '#', array(
'id' =>
'cancel-advanced-search',
'class' =>
'cancel-button'));
477 return $content . $closeButton;
480 protected function renderSaveInputAndSaveButtonContentForAdvancedSearch($form)
484 protected function renderAdvancedSearchForFormLayout($panel, $maxCellsPerRow, $form)
486 return $this->renderStaticSearchRows($panel, $maxCellsPerRow, $form);
489 protected function renderStaticSearchRows($panel, $maxCellsPerRow, $form = null)
492 foreach ($panel[
'rows'] as $row)
494 $innerContent = null;
495 foreach ($row[
'cells'] as $cell)
497 if (!empty($cell[
'elements']))
499 foreach ($cell[
'elements'] as $elementInformation)
501 if (count($row[
'cells']) == 1 && count($row[
'cells']) < $maxCellsPerRow)
503 $elementInformation[
'wide'] =
true;
505 $elementclassname = $elementInformation[
'type'] .
'Element';
506 $element =
new $elementclassname($this->model, $elementInformation[
'attributeName'], $form, array_slice($elementInformation, 2));
507 $innerContent .= $element->render();
510 $content .= ZurmoHtml::tag(
'tr', array(), $innerContent);
513 return ZurmoHtml::tag(
'table', array(), $content);
589 protected function getColumnCount($metadata)
592 foreach ($metadata[
'panels'] as $panel)
594 foreach ($panel[
'rows'] as $row)
597 foreach ($row[
'cells'] as $cell)
601 if ($tempCount > $columnCount)
603 $columnCount = $tempCount;
610 public static function getDesignerRulesType()
615 protected function getSearchFormId()
617 return 'search-form' . $this->gridIdSuffix;
620 protected function getListViewId()
622 return $this->gridId . $this->gridIdSuffix;
625 protected function getMaxCellsPerRow()
627 $designerRulesType = static::getDesignerRulesType();
628 $designerRulesClassName = $designerRulesType .
'DesignerRules';
629 $designerRules =
new $designerRulesClassName();
630 return $designerRules->maxCellsPerRow();
633 protected function renderModalContainer()
635 return ZurmoHtml::tag(
'div', array(
636 'id' => ModelElement::MODAL_CONTAINER_PREFIX .
'-' . $this->getSearchFormId()
648 if (StarredUtil::modelHasStarredInterface($this->model->getModel()))
650 $content .= $form->hiddenField($this->model,
'filterByStarred',
651 array(
'class' => $form->id .
'_filterByStarred'));
static wrapLabel($label, $class= 'z-label')
renderFormLayout(ZurmoActiveForm $form)
static getDefaultMetadata()
renderStarredFilterHidenField($form)
__construct($model, $listModelClassName, $gridIdSuffix=null, $hideAllSearchPanelsToStart=false)
getExtraQueryPartForSearchFormScriptSubmitFunction()
renderFiltersContent($form)
getHideOrShowClearSearchLinkScript()
getKanbanBoardOptionsLinkContent()
renderFormBottomPanelExtraLinks()
renderKanbanBoardOptionsContent(ZurmoActiveForm $form)
getExtraRenderFormBottomPanelScriptPart()