From 985828da3a29eb90943cfe3dc05faeda1b588e3b Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 28 Oct 2018 10:11:45 +0100 Subject: [PATCH] responsive account table --- lam/lib/lists.inc | 206 ++--------------------------------- lam/lib/types/group.inc | 16 +-- lam/lib/types/user.inc | 46 ++++---- lam/templates/lib/500_lam.js | 17 --- 4 files changed, 37 insertions(+), 248 deletions(-) diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index 82aaf494..aa1fc07d 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -201,13 +201,7 @@ class lamList { // navigation bar $this->listDrawNavigationBar(sizeof($this->entries)); echo ("
\n"); - echo "
"; $this->printAccountTable($this->entries); - // account table head - $this->listPrintTableHeader(); - // account table body - $this->listPrintTableBody($this->entries); - echo "
"; } else { // buttons @@ -218,8 +212,6 @@ class lamList { echo ("
\n"); $accounts = array(); $this->printAccountTable($accounts); - // account table head - $this->listPrintTableHeader(); echo "
\n"; } $this->printFooter(); @@ -474,7 +466,7 @@ class lamList { $actionElement->addElement($clearFilterButton); } - $filterElements = array($actionElement); + $filterElements = array(new htmlDiv(null, $actionElement, array('nowrap'))); $clearFilter = isset($_POST['clear_filter']); foreach ($this->attrArray as $attributeName) { $attributeName = strtolower($attributeName); @@ -483,7 +475,7 @@ class lamList { if (!$clearFilter && isset($this->filters[$attributeName])) { $value = $this->filters[$attributeName]; } - $filterInput = new htmlInputField('filter' . $attributeName, $value); + $filterInput = new htmlInputField('filter' . $attributeName, $value, null); $filterInput->setCSSClasses(array($this->type->getScope() . '-bright')); $filterInput->setOnKeyPress("SubmitForm('apply_filter', event);"); $filterElements[] = $filterInput; @@ -531,11 +523,10 @@ class lamList { $onClickEvents[$i + 2] = "list_click('" . $rowID . "');"; $onDoubleClickEvents[$i + 2] = "top.location.href='../account/edit.php?type=" . $this->type->getId() . "&DN=" . rawurlencode($info[$index]['dn']) . "';"; $this->addToolLinks($info[$index], $rowID, $actionElement); - $row[] = $actionElement; + $row[] = new htmlDiv(null, $actionElement, array('nowrap')); foreach ($this->attrArray as $attributeName) { $attributeName = strtolower($attributeName); - $row[] = new htmlOutputText($attributeName); // TODO - //$this->listPrintTableCellContent($info[$index], $attributeName); + $row[] = $this->getTableCellContent($info[$index], $attributeName); } $data[] = $row; } @@ -577,84 +568,6 @@ class lamList { } } - /** - * Prints the attribute and filter row at the account table head - * @deprecated - */ - protected function listPrintTableHeader() { - $filter = $this->getFilterAsTextForURL(); - // print table header - echo "type->getScope() . "-border collapse accountlist ui-corner-all\" width=\"100%\">\n"; - echo "type->getScope() . "-dark\">\n"; - echo "\n"; - echo "\n"; - // table header - for ($k = 0; $k < sizeof($this->descArray); $k++) { - if (strtolower($this->attrArray[$k]) == $this->sortColumn) { - $sortImage = "sort_asc.png"; - if ($this->sortDirection < 0) { - $sortImage = "sort_desc.png"; - } - echo "\n"; - } - else echo "\n"; - } - echo "\n"; - - // print filter row - echo "type->getScope() . "-bright\">\n"; - echo "\n"; - echo "\n"; - // print input boxes for filters - for ($k = 0; $k < sizeof($this->descArray); $k++) { - echo "\n"; - } - echo "\n"; - } - - /** - * Prints the content of a single attribute filter area. - * - * @param String $attrName attribute name - * @param boolean $clearFilter true if filter value should be cleared - * @deprecated - */ - protected function printFilterArea($attrName, $clearFilter) { - $value = ""; - if (!$clearFilter) { - if (isset($this->filters[strtolower($attrName)])) { - $value = $this->filters[strtolower($attrName)]; - } - } - $filterInput = new htmlInputField('filter' . strtolower($attrName), $value); - $filterInput->setCSSClasses(array($this->type->getScope() . '-dark')); - $filterInput->setFieldSize('15'); - $filterInput->setOnKeyPress("SubmitForm('apply_filter', event);"); - parseHtml(null, $filterInput, array(), false, $this->tabindex, $this->type->getScope()); - } - /** * Returns if the given attribute can be filtered. * If filtering is not possible then no filter box will be displayed. @@ -668,123 +581,27 @@ class lamList { } /** - * Prints the entry list - * - * @param array $info entries - * @deprecated - */ - protected function listPrintTableBody(&$info) { - echo "\n"; - // calculate which rows to show - $table_begin = ($this->page - 1) * $this->maxPageEntries; - if (($this->page * $this->maxPageEntries) > sizeof($info)) $table_end = sizeof($info); - else $table_end = ($this->page * $this->maxPageEntries); - // get sort mapping - $sortMapping = &$this->sortMapping; - if (empty($sortMapping)) { - $sortMapping = array(); - $infoSize = sizeof($info); - for ($i = 0; $i < $infoSize; $i++) { - $sortMapping[$i] = $i; - } - } - // print account list - for ($i = $table_begin; $i < $table_end; $i++) { - $index = $sortMapping[$i]; - $rowID = base64_encode($info[$index]['dn']); - if ((($i - $table_begin) % 2) == 1) { - $classes = ' ' . $this->type->getScope() . '-bright'; - } - else { - $classes = ' ' . $this->type->getScope() . '-dark'; - } - echo("type->getId() . "&DN=" . rawurlencode($info[$index]['dn']) . "'\">\n"); - echo " \n"; - $this->listPrintToolLinks($info[$index], $rowID); - for ($k = 0; $k < sizeof($this->attrArray); $k++) { - echo ("\n"); - } - echo("\n"); - } - // display select all link - $colspan = sizeof($this->attrArray) + 1; - echo "type->getScope() . "-bright\">\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "
\"select " . - "" . _("Select all") . "type->getId() . "&". - "sort=" . strtolower($this->attrArray[$k]) . $filter . "&norefresh=y" . "\">" . $this->descArray[$k] . - " \"sorttype->getId() . "&". - "sort=" . strtolower($this->attrArray[$k]) . $filter . "&norefresh=y" . "\">" . $this->descArray[$k] . "
"; - printHelpLink(getHelp('', '250'), '250'); - echo ""; - $filterGroup = new htmlGroup(); - $filterButton = new htmlButton('apply_filter', 'filter.png', true); - $filterButton->setTitle(_("Filter")); - $filterGroup->addElement($filterButton); - if (sizeof($this->filters) > 0) { - $filterGroup->addElement(new htmlSpacer('1px', null)); - $clearFilterButton = new htmlButton('clear_filter', 'clearFilter.png', true); - $clearFilterButton->setTitle(_('Clear filter')); - $filterGroup->addElement($clearFilterButton); - } - parseHtml(null, $filterGroup, array(), false, $this->tabindex, $this->type->getScope()); - echo ""; - if ($this->canBeFiltered($this->attrArray[$k])) { - $this->printFilterArea($this->attrArray[$k], isset($_POST['clear_filter'])); - } - echo "
"); - $attrName = strtolower($this->attrArray[$k]); - $this->listPrintTableCellContent($info[$index], $attrName); - echo ("
\"select " . - "" . _("Select all") . "
\n"; - } - - /** - * Prints the tool image links (e.g. edit and delete) for each account. - * - * @param array $account LDAP attributes - * @param String $id account ID - * @deprecated - */ - private function listPrintToolLinks($account, $id) { - $toolCount = 0; - $group = new htmlGroup(); - // edit link - $editLink = new htmlLink('', "../account/edit.php?type=" . $this->type->getId() . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/edit.png'); - $editLink->setTitle(_("Edit")); - $group->addElement($editLink); - $toolCount++; - // delete link - if (checkIfWriteAccessIsAllowed($this->type->getId()) && checkIfDeleteEntriesIsAllowed($this->type->getId())) { - $deleteLink = new htmlLink('', "deletelink.php?type=" . $this->type->getId() . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/delete.png'); - $deleteLink->setTitle(_("Delete")); - $group->addElement($deleteLink); - $toolCount++; - } - // PDF button - $pdfButton = new htmlButton("createPDF_" . $id, 'pdf.png', true); - $pdfButton->setTitle(_('Create PDF file')); - $group->addElement($pdfButton); - $toolCount++; - // additional tools - $tools = $this->getAdditionalTools(); - for ($i = 0; $i < sizeof($tools); $i++) { - $toolLink = new htmlLink('', $tools[$i]->getLinkTarget() . "?type=" . $this->type->getId() . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/' . $tools[$i]->getImage()); - $toolLink->setTitle($tools[$i]->getName()); - $group->addElement($toolLink); - $toolCount++; - } - $width = ($toolCount * 20) + 20; - echo ""; - parseHtml(null, $group, array(), false, $this->tabindex, $this->type->getScope()); - echo "\n"; - } - - /** - * Prints the content of a cell in the account list for a given LDAP entry and attribute. + * Returns the content of a cell in the account list for a given LDAP entry and attribute. * * @param array $entry LDAP attributes * @param string $attribute attribute name + * @return htmlElement content */ - protected function listPrintTableCellContent(&$entry, &$attribute) { + protected function getTableCellContent(&$entry, &$attribute) { // print all attribute entries seperated by "; " if (isset($entry[$attribute]) && sizeof($entry[$attribute]) > 0) { if (is_array($entry[$attribute])) { if (($attribute == 'entryexpiretimestamp') && !empty($entry[$attribute][0])) { - echo formatLDAPTimestamp($entry[$attribute][0]); + return new htmlOutputText(formatLDAPTimestamp($entry[$attribute][0])); } else { // sort array sort($entry[$attribute]); - echo htmlspecialchars(implode("; ", $entry[$attribute]), ENT_QUOTES, "UTF-8"); + return new htmlOutputText(implode("; ", $entry[$attribute])); } } else { - echo htmlspecialchars($entry[$attribute], ENT_QUOTES, "UTF-8"); + return new htmlOutputText($entry[$attribute]); } } } @@ -1110,9 +927,6 @@ class lamList { jQuery(document).ready(function() { jQuery('#tab_type->getId(); ?>').addClass('ui-tabs-active'); jQuery('#tab_type->getId(); ?>').addClass('ui-state-active'); - window.onload = listResizeITabContentDiv; - window.onresize = listResizeITabContentDiv; - jQuery('#filterButton').button(); }); '; $values = $entry[$attribute]; if (!empty($values)) { usort($values, 'compareDN'); @@ -375,12 +372,11 @@ class lamGroupList extends lamList { $values[$i] = getAbstractDN($values[$i]); } } - echo implode('
', $values); - echo ''; + return new htmlDiv(null, new htmlOutputText(implode('
', $values), false), array('rightToLeftText')); } // print all other attributes else { - parent::listPrintTableCellContent($entry, $attribute); + return parent::getTableCellContent($entry, $attribute); } } diff --git a/lam/lib/types/user.inc b/lam/lib/types/user.inc index 3079c86e..28aad542 100644 --- a/lam/lib/types/user.inc +++ b/lam/lib/types/user.inc @@ -717,24 +717,21 @@ class lamUserList extends lamList { } /** - * Prints the content of a cell in the account list for a given LDAP entry and attribute. - * - * @param array $entry LDAP attributes - * @param string $attribute attribute name + * {@inheritDoc} + * @see lamList::getTableCellContent() */ - protected function listPrintTableCellContent(&$entry, &$attribute) { + protected function getTableCellContent(&$entry, &$attribute) { // check if there is something to display at all if (($attribute != self::ATTR_ACCOUNT_STATUS) && (!isset($entry[$attribute]) || !is_array($entry[$attribute]) || (sizeof($entry[$attribute]) < 1))) { - parent::listPrintTableCellContent($entry, $attribute); - return; + return parent::getTableCellContent($entry, $attribute); } // translate GID to group name if (($attribute == "gidnumber") && ($this->trans_primary == "on")) { if (isset($this->trans_primary_hash[$entry[$attribute][0]])) { - echo $this->trans_primary_hash[$entry[$attribute][0]]; + return new htmlOutputText($this->trans_primary_hash[$entry[$attribute][0]]); } else { - parent::listPrintTableCellContent($entry, $attribute); + return parent::getTableCellContent($entry, $attribute); } } // show user photos @@ -764,47 +761,45 @@ class lamUserList extends lamList { if ($imgHeight < 64) { $minSize = $imgHeight; } - $imgTitle = _('Click to switch between thumbnail and original size.'); - echo "\"""; - echo ''; + return new htmlImage($photoFile, null, $minSize, _('Photo')); } elseif (($attribute == 'mail') || ($attribute == 'rfc822Mailbox')) { + $group = new htmlGroup(); if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) { for ($i = 0; $i < sizeof($entry[$attribute]); $i++) { if ($i > 0) { - echo ", "; + $group->addElement(new htmlOutputText(", ")); } - echo "" . $entry[$attribute][$i] . "\n"; + $group->addElement(new htmlLink($entry[$attribute][$i], "mailto:" . $entry[$attribute][$i])); } } + return $group; } // expire dates elseif ($attribute == 'shadowexpire') { if (!empty($entry[$attribute][0])) { $time = new DateTime('@' . $entry[$attribute][0] * 24 * 3600, getTimeZone()); - echo $time->format('d.m.Y'); + return new htmlOutputText($time->format('d.m.Y')); } } elseif ($attribute == 'sambakickofftime') { if (!empty($entry[$attribute][0])) { if ($entry[$attribute][0] > 2147483648) { - echo "∞"; + return new htmlOutputText("∞"); } else { $date = new DateTime('@' . $entry[$attribute][0], new DateTimeZone('UTC')); - echo $date->format('d.m.Y'); + return new htmlOutputText($date->format('d.m.Y')); } } } // account status elseif ($attribute == self::ATTR_ACCOUNT_STATUS) { - $this->printAccountStatus($entry); + return $this->getAccountStatus($entry); } // print all other attributes else { - parent::listPrintTableCellContent($entry, $attribute); + return parent::getTableCellContent($entry, $attribute); } } @@ -1040,11 +1035,12 @@ class lamUserList extends lamList { } /** - * Prints the account status. + * Returns the account status. * * @param array $attrs LDAP attributes + * @return htmlElement content */ - private function printAccountStatus(&$attrs) { + private function getAccountStatus(&$attrs) { // check status $unixAvailable = self::isUnixAvailable($attrs); $sambaAvailable = self::isSambaAvailable($attrs); @@ -1144,10 +1140,10 @@ class lamUserList extends lamList { $tipContent .= '' . _('Password expired') . '  '; } $tipContent .= ''; - echo 'status'; + return new htmlOutputText('status', false); } else { - echo 'status'; + return new htmlImage('../../graphics/' . $icon, 16, 16, 'status'); } } diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index d6ac8351..3996aef1 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -62,23 +62,6 @@ function listPageNumberKeyPress(url, e) { return true; } -/** - * Resizes the content area of the account lists to fit the window size. - * This prevents that the whole page is scrolled in the browser. Only the account table has scroll bars. - */ -function listResizeITabContentDiv() { - var myDiv = document.getElementById("listTabContentArea"); - var height = document.documentElement.clientHeight; - height -= myDiv.offsetTop; - height -= 105; - myDiv.style.height = height +"px"; - - var myDivScroll = document.getElementById("listScrollArea"); - var top = myDivScroll.offsetTop; - var scrollHeight = height - (top - myDiv.offsetTop); - myDivScroll.style.height = scrollHeight + "px"; -}; - /** * Shows the dialog to change the list settings. *