toHtml() which // generates the look and feel of the original Cobalt products. // // applicability: // NOTE: This implementation and style are scheduled for removal. global $isClassicListDefined; if($isClassicListDefined) return; $isClassicListDefined = true; // description: turn the object into HTML form // param: scrollList: the ScrollList object // param: style: the style to show in (optional) // returns: HTML that represents the object or // "" if pageIndex is out of range function toClassicListHtml($scrollList, $style = "") { $this = $scrollList; $widgetid = $this->widgetid; if($style == null || $style->getPropertyNumber() == 0) { $page = $this->getPage(); $style = $this->getDefaultStyle($page->getStylist()); } // find out style properties $borderColor = $style->getProperty("borderColor"); $borderThickness = $style->getProperty("borderThickness"); $controlAlign = $style->getProperty("controlAlign"); $controlStyleStr = $style->toBackgroundStyle("controlCell"); $controlLabelStyleStr = $style->toTextStyle("controlLabel"); $formFieldStyleStr = $style->toBackgroundStyle("entryCell").$style->toTextStyle("entryCell"); $labelStyleStr = $style->toBackgroundStyle("labelCell"); $sortAscendingIcon = $style->getProperty("sortAscendingIcon"); $sortDescendingIcon = $style->getProperty("sortDescendingIcon"); $sortedAscendingIcon = $style->getProperty("sortedAscendingIcon"); $sortedDescendingIcon = $style->getProperty("sortedDescendingIcon"); $titleAlign = $style->getProperty("titleAlign"); $titleStyleStr = $style->toBackgroundStyle("titleCell"); $width = $this->width; if (!$width) { $width = $style->getProperty("width"); } if (!$width) { $width = 550; } $entries = $this->getEntries(); $entryIds = $this->entryIds; $entriesSelected = $this->entriesSelected; $entryNum = count($entries); $sortedIndex = $this->getSortedIndex(); $sortOrder = $this->getSortOrder(); // sort the entries if($sortedIndex != -1) $this->sortEntries($entries); /* // prepare a hash for sorting $sortHash = array(); for($i = 0; $i < $entryNum; $i++) { $entry = $entries[$i]; $sortHash[$entry[$sortedIndex]->getValue()] = $entry; } // sort if($sortOrder == "ascending") ksort($sortHash); else krsort($sortHash); // save result $entries = array_values($sortHash); */ $desiredLength = $this->getLength(); $length = $desiredLength; // out of range? $pageIndex = $this->getPageIndex(); if($pageIndex < 0 || $pageIndex > $entryNum/$length) return ""; // find out from where to start listing $from = $pageIndex*$length; // find out length if($from+$length > $entryNum) $length = $entryNum-$from; $id = $this->getId(); $page = $this->getPage(); $i18n = $page->getI18n(); $form = $page->getForm(); $formId = $form->getId(); $entryLabelObjs = $this->getEntryLabels(); $entryLabelNum = count($entryLabelObjs); // find out if any entries can be selected $hasSelectColumn = false; for($i = 0; $i < $entryNum; $i++) if($entryIds[$i] != "") { $hasSelectColumn = true; break; } // find out number of columns $columnNum = $hasSelectColumn ? $entryLabelNum+1 : $entryLabelNum; $builder = new FormFieldBuilder(); // make entry count $messageTag = ($entryNum == 1) ? $this->entryCountTagSingular : $this->entryCountTagPlural; $entryCount = "".$i18n->interpolate($messageTag, array("count" => $entryNum)).""; // make page selection widget if($entryNum <= $length) $pageSelect = ""; else { // make button for selection $pageIndexId = "_ScrollList_pageIndex_$widgetid"; $multiButton = new MultiButton($page); $pageIndexCount = 0; for($i = 0; $i < $entryNum; $i += $desiredLength) { // find the range $fromEntry = $desiredLength*$pageIndexCount+1; $toEntry = $desiredLength*($pageIndexCount+1); $toEntry = ($toEntry <= $entryNum) ? $toEntry : $entryNum; // add action $multiButton->addAction("javascript: document.$formId.$pageIndexId.value = $pageIndexCount; document.$formId.submit()", $i18n->get("entryRange", "palette", array("from" => $fromEntry, "to" => $toEntry))); // next page $pageIndexCount++; } $multiButton->setSelectedIndex($pageIndex); // make hidden field to store page index $result .= $builder->makeHiddenField($pageIndexId, $pageIndex); $pageSelect .= "".$multiButton->toHtml().""; } // make buttons $buttons = $this->getButtons(); $allButtons = ""; if(count($buttons) > 0) { $allButtons .= ""; for($i = 0; $i < count($buttons); $i++) { if($i > 0) $allButtons .= ""; $allButtons .= ""; } $allButtons .= "
 ".$buttons[$i]->toHtml()."
"; } if (!$this->entryCountHidden) { $controlRow = " $pageSelect $entryCount
$allButtons
"; } else { $controlRow = ""; } $labelObj = $this->getLabel(); $label = $labelObj->toHtml($style->getSubstyle("titleLabel")); $result .= " $controlRow "; if($length == 0) { $emptyList = ($this->emptyMsg == "") ? $i18n->get("emptyList", "palette") : $i18n->interpolate($this->emptyMsg); $result .= " "; } else { // entry labels $sortedIndexId = "_ScrollList_sortedIndex_$widgetid"; $sortOrderId = "_ScrollList_sortOrder_$widgetid"; $sortables = $this->getSortables(); // make hidden fields $result .= $builder->makeHiddenField($sortedIndexId, $sortedIndex); $result .= $builder->makeHiddenField($sortOrderId, $sortOrder); if (!$this->headerRowHidden) { $result .= "\n"; // put in place holder for select column if($hasSelectColumn) { $result .= " \n"; } } for($i = 0; $i < $entryLabelNum; $i++) { if (!$this->headerRowHidden) { $label = is_object($entryLabelObjs[$i]) ? $entryLabelObjs[$i]->toHtml($style->getSubstyle("labelLabel")) : " "; $mouseOver = $entryLabelObjs[$i]->getDescription(); $mouseOver = $i18n->interpolateJs($mouseOver); $entryLabelObjs[$i]->setDescription(""); $label = $entryLabelObjs[$i]->toHtml( $style->getSubstyle("labelLabel") ); $entryLabelObjs[$i]->setDescription( $mouseOver ); $label = " $label "; } // get sorted widget $sortWidget = ""; if(in_array($i, $sortables)) { // use the correct order // use the correct icon if($sortedIndex == $i && $sortOrder == "ascending") { $order = "descending"; $icon = $sortedAscendingIcon; } else if($sortedIndex == $i && $sortOrder == "descending") { $order = "ascending"; $icon = $sortedDescendingIcon; } else if($sortedIndex != $i && $sortOrder == "ascending") { $order = "ascending"; $icon = $sortAscendingIcon; } else if($sortedIndex != $i && $sortOrder == "descending") { $order = "descending"; $icon = $sortDescendingIcon; } $sortWidget = ""; } // get the width for this column $columnWidths = $this->getColumnWidths(); $width = (is_array($columnWidths) && $columnWidths[$i] != "") ? "WIDTH=\"$columnWidths[$i]\"" : ""; if (!$this->headerRowHidden) { $result .= " \n"; } } if (!$this->headerRowHidden) { $result .= "\n"; } } // get alignments $alignments = $this->getAlignments(); // entries for($i = $from; $i < $from+$length; $i++) { $result .= ""; // add select column if necessary if($hasSelectColumn) $result .= ""; $entry = $entries[$i]; for($j = 0; $j < $entryLabelNum; $j++) { // always show something. Otherwise, no background will be drawn $html = " "; if ($entry[$j]) $html = $entry[$j]->toHtml(); if($html == "") $html = " "; // find out alignment // Note: alignment can be empty $alignment = is_array($alignments) ? $alignments[$j] : ""; // make padding $padding = ""; $leftPadding = ($alignment == "" || $alignment == "left") ? $padding : ""; $rightPadding = ($alignment == "right") ? $padding : ""; if($leftPadding == "" && $rightPadding == "") $result .= ""; else $result .= ""; } $result .= "\n"; } // duplicate control row if length is greater than the limit $duplicateLimit = $this->getDuplicateLimit(); if($length > $duplicateLimit) $result .= $controlRow; $result .= "
$label
$emptyList
"; if ($this->isSelectAll()) { $result .= ""; } else { $result .= " "; } $result .= "
$label$sortWidget
".$builder->makeCheckboxField($entryIds[$i], "true", "rw", $entriesSelected[$i])."$html$leftPadding$rightPadding
$html
"; return $result; }