function render() { if (!$this->iterator) { $this->addOutputCode('<p>' . $this->getAttribute('emptySearchLabel') . '</p>'); return; } // legge le colonne da visualizzare dai figli // NOTA: le colonne sono gi� state lette sul process // ma vengono rilette perch� pu� essere variata la visibilit� $this->_columns = array(); for ($i = 0; $i < count($this->childComponents); $i++) { $this->_columns[] = $this->childComponents[$i]->getProperties(); } $addJsCode = false; $output = ''; if ($this->_totalRecord > 0) { $class = $this->getAttribute('tableCssClass') != '' ? ' class="' . $this->getAttribute('tableCssClass') . '"' : ''; $output .= '<table id="' . $this->getId() . '"' . $class . '>'; if ($this->getAttribute('label') != '') { $output .= '<caption>' . $this->getAttribute('label') . '</caption>'; } if ($this->getAttribute('drawHeader')) { // disegna le colonne $output .= '<thead>'; $output .= '<tr>'; //foreach ($this->_columns as $v) for ($i = 0; $i < count($this->_columns); $i++) { $v = $this->_columns[$i]; if ($v['visible'] === true) { $cssClass = !empty($v['cssClass']) ? ' class="' . $v['cssClass'] . '"' : ''; $id = !empty($v['id']) ? ' id="' . $v['id'] . '"' : ''; $width = !empty($v['width']) ? ' style="width: ' . $v['width'] . 'px;"' : ''; if (!empty($v['renderCell'])) { $renderCell =& org_glizy_ObjectFactory::createObject($v['renderCell'], $this->_application); if (method_exists($renderCell, 'getHeader')) { $v['headerText'] = $renderCell->getHeader($v['headerText']); } unset($renderCell); } if (!empty($v['command'])) { $output .= '<th' . $id . $cssClass . $width . '>'; if ($v['command'] == 'publish') { $output .= '<input name="publishAll" value="" type="checkbox" class="js-selectall" />'; } $output .= '</th>'; } else { if (!$this->getAttribute('skipOrder') && $v['orderable']) { $addJsCode = true; $headerId = 'orderBy_' . $i; $headerClass = 'DataGridHeader'; $headerImage = ''; if ($i == $this->_orderBy) { $headerId .= '_' . ($this->_orderDirection == 'ASC' ? 'DESC' : 'ASC'); $headerImage = $this->_orderDirection == 'ASC' ? '<span class="ui-icon ui-icon-triangle-1-s"></span>' : '<span class="ui-icon ui-icon-triangle-1-n"></span>'; } else { $headerId .= '_' . $this->_orderDirection; } $output .= '<th' . $id . $cssClass . $width . '><a href="#" id="' . $headerId . '" class="' . $headerClass . '">' . $v['headerText'] . '</a>' . $headerImage . '</th>'; } else { $output .= '<th' . $cssClass . $width . '>' . $v['headerText'] . '</th>'; } } } } $output .= '</tr>'; $output .= '</thead>'; } if (!$this->getAttribute('hideTotals')) { $output .= '<tfoot>'; $output .= '<tr><td style="text-align: right;" colspan="' . count($this->_columns) . '">' . __T('GLZ_TOTAL_RECORDS') . ' ' . $this->_totalRecord . '</td></tr>'; $output .= '</tfoot>'; } $output .= '<tbody>'; $key = 0; $tempCssClass = $this->_cssClass; $rowCellClass = $this->getAttribute('renderRow'); if (!empty($rowCellClass)) { $rowCellClass =& org_glizy_ObjectFactory::createObject($rowCellClass, $this->_application); } foreach ($this->iterator as $ar) { $v = $ar->getValuesAsArray(true); $rowOutput = ''; foreach ($this->_columns as $vv) { if ($vv['key']) { $key = $v[$vv['columnName']]; } if ($vv['visible'] === false) { continue; } $tempOutput = ''; $cssClass = ''; if (!empty($vv['renderCell'])) { $renderCell =& org_glizy_ObjectFactory::createObject($vv['renderCell'], $this->_application); if (is_object($renderCell)) { $tempOutput .= $renderCell->renderCell($key, isset($v[$vv['columnName']]) ? $v[$vv['columnName']] : '', $ar, $vv['columnName']); $cssClass = !empty($vv['cssClass']) ? $vv['cssClass'] : ''; if (method_exists($renderCell, 'getCssClass')) { $cssClass = $renderCell->getCssClass($key, isset($v[$vv['columnName']]) ? $v[$vv['columnName']] : '', $v); } } } else { if (!empty($vv['command'])) { $addJsCode = true; if (strtolower($this->_application->getPageId()) == 'usergroups') { if ($vv['command'] == 'delete' && $v['usergroup_backEndAccess']) { continue; } } switch ($vv['command']) { case 'edit': if ($this->_user->acl($vv['aclService'], $vv['command'])) { if (!is_null($this->_versionFieldName)) { if ($this->_user->acl($vv['aclService'], $vv['command'])) { $icon = org_glizy_Assets::get('ICON_EDIT'); $ar =& $this->_dataProvider->getNewObject(); $joinFields = $ar->getJoinFields(); $result = $ar->find(array($joinFields['detailTable'] => $key, $this->_versionFieldName => 'PUBLISHED')); //$result = $ar->find(array($joinFields['detailTable'] => $key, $this->_versionFieldName => 'PUBLISHED', $this->_languageFieldName => $this->_application->getEditingLanguageId())); } else { $icon = org_glizy_Assets::get('ICON_EDITDRAFT'); $result = true; } if ($result) { $tempOutput .= '<img title="' . org_glizy_locale_Locale::get('GLZ_RECORD_EDIT') . '" id="edit_' . $key . '" class="DataGridCommand" src="' . $icon . '" width="16" height="16" border="0" />'; } else { $tempOutput .= '<img id="" class="DataGridCommand" src="' . org_glizy_Assets::get('ICON_EDIT_OFF') . '" width="16" height="16" border="0" />'; } } else { $tempOutput .= '<img title="' . org_glizy_locale_Locale::get('GLZ_RECORD_EDIT') . '" id="edit_' . $key . '" class="DataGridCommand" src="' . org_glizy_Assets::get('ICON_EDIT') . '" width="16" height="16" border="0" />'; } } break; case 'editDraft': if (!is_null($this->_versionFieldName) && $this->_user->acl($vv['aclService'], $vv['command'])) { $ar =& $this->_dataProvider->getNewObject(); $joinFields = $ar->getJoinFields(); $result = $ar->find(array($joinFields['detailTable'] => $key, $this->_versionFieldName => 'DRAFT')); //$result = $ar->find(array($joinFields['detailTable'] => $key, $this->_versionFieldName => 'DRAFT', $this->_languageFieldName => $this->_application->getEditingLanguageId())); if ($result) { $tempOutput .= '<img title="' . org_glizy_locale_Locale::get('GLZ_RECORD_EDIT') . '" id="editDraft_' . $key . '" class="DataGridCommand" src="' . org_glizy_Assets::get('ICON_EDITDRAFT') . '" width="16" height="16" border="0" />'; } else { $tempOutput .= '<img id="" class="DataGridCommand" src="' . org_glizy_Assets::get('ICON_EDITDRAFT_OFF') . '" width="16" height="16" border="0" />'; } } break; case 'preview': $tempOutput .= '<img title="' . org_glizy_locale_Locale::get('GLZ_RECORD_PREVIEW') . '" id="preview_' . $key . '" class="DataGridCommand" src="' . org_glizy_Assets::get('ICON_PREVIEW') . '" width="16" height="16" border="0" />'; break; case 'delete': if ($this->_user->acl($vv['aclService'], $vv['command'])) { $tempOutput .= '<img title="' . org_glizy_locale_Locale::get('GLZ_RECORD_DELETE') . '" id="delete_' . $key . '" class="DataGridCommand" src="' . org_glizy_Assets::get('ICON_DELETE') . '" width="16" height="16" border="0" />'; } break; case 'publish': if ($this->_user->acl($vv['aclService'], $vv['command'])) { $tempOutput .= '<input name="publish[]" value="' . $key . '" type="checkbox">'; } break; } } else { if (!is_null($this->_languageFieldName) && $v[$this->_languageFieldName] != $this->_application->getEditingLanguageId()) { $tempOutput .= '<em>' . $v[$vv['columnName']] . '</em>'; } else { $tempOutput .= $v[$vv['columnName']]; } } } $cssClass = !empty($cssClass) ? ' class="' . $cssClass . '"' : ''; $rowOutput .= '<td style="text-align: ' . $vv['align'] . ';"' . $cssClass . '>' . $tempOutput . '</td>'; } if (!count($tempCssClass)) { $tempCssClass = $this->_cssClass; } $cssClass = array_shift($tempCssClass); if (!empty($rowCellClass)) { $output .= $rowCellClass->renderRow($v, $cssClass); } else { $output .= '<tr class="' . $cssClass . '" id="row_' . $key . '">'; } $output .= $rowOutput . '</tr>'; } $output .= '</tbody>'; $output .= '</table>'; } else { $emptyLabel = $this->getAttribute('emptyLabel'); if (!empty($emptyLabel)) { $output .= '<p class="datagridEmpty">' . $emptyLabel . '</p>'; } } $this->addOutputCode($output); if (!$addJsCode) { return; } $jsId = $this->getId(); $jsMessage = org_glizy_locale_Locale::get('GLZ_RECORD_MSG_DELETE'); // TODO // controllare che il valore di controller sia settato $controllerClass =& $this->getAttribute('controller'); if (is_object($controllerClass)) { $jsStateUrl = $controllerClass->changeStateUrl(); $jsStateUrl = str_replace(__Link::makeUrl('link', array('pageId' => $this->_application->getPageId())) . '?', '', $jsStateUrl); $jsStateUrl = __Link::removeParams(array($controllerClass->getId() . '_recordId'), $jsStateUrl); $jsCurrentStateUrl = $controllerClass->changeStateUrl($controllerClass->getState()); $controllerId = $controllerClass->getid(); } else { $jsStateUrl = __Link::removeParams(array($jsId . '_orderBy', $jsId . '_orderDirection')); $jsCurrentStateUrl = $jsStateUrl; $controllerId = ''; } $output = ''; $output = <<<EOD <script language="JavaScript" type="text/JavaScript"> jQuery(document).ready(function() { jQuery('#{$jsId} input.js-selectall').change(function(){ var checked = this.checked; \$(this).closest('table').find("input[name='publish[]']").each(function(i, el){ el.checked = checked; }) }); jQuery(['#{$jsId} .DataGridCommand', '#{$jsId} .DataGridHeader']).each(function(index,element) { jQuery( element ).css( {cursor: 'pointer'} ); jQuery( element ).click( function() { var command = this.id.split('_'); var loc = "{$jsStateUrl}"+command[0]+"&{$controllerId}_recordId="+command[1]; switch (command[0]) { case 'delete': this.parentNode.parentNode.oldClass2 = this.parentNode.parentNode.oldClass; this.parentNode.parentNode.className2 = this.parentNode.parentNode.className; this.parentNode.parentNode.className = "ruled"; this.parentNode.parentNode.oldClass = "ruled"; if (confirm("{$jsMessage}")) { location.href = loc; } this.parentNode.parentNode.oldClass = this.parentNode.parentNode.oldClass2; this.parentNode.parentNode.className = this.parentNode.parentNode.oldClass2; break; case 'orderBy': loc = "{$jsCurrentStateUrl}&{$jsId}_orderBy="+command[1]+"&{$jsId}_orderDirection="+command[2]; location.href = loc; default: location.href = loc; break; } }); }); }); </script> EOD; if (!empty($output)) { $this->addOutputCode($output); } }