| 1: | <?php |
| 2: | |
| 3: | namespace Zippy\Html\DataList; |
| 4: | |
| 5: | use Zippy\Html\HtmlComponent; |
| 6: | use Zippy\Interfaces\Paginable; |
| 7: | use Zippy\Interfaces\EventReceiver; |
| 8: | use Zippy\Event; |
| 9: | use Zippy\WebApplication; |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | class DataView extends AbstractList implements \Zippy\Interfaces\Requestable |
| 22: | { |
| 23: | private $rowevent = null; |
| 24: | private $selectedRow = null; |
| 25: | private $selectedclass = ""; |
| 26: | private $cellclickevent = null; |
| 27: | private $lastnumber = 0; |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | public function __construct($id, $DataSource, EventReceiver $receiver, $handler) { |
| 35: | AbstractList::__construct($id, $DataSource); |
| 36: | |
| 37: | $this->rowevent = new Event($receiver, $handler); |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public function Reload($resetpage = true) { |
| 44: | parent::Reload($resetpage); |
| 45: | |
| 46: | $this->components = array(); |
| 47: | |
| 48: | $list = $this->getItems(); |
| 49: | $this->lastnumber++; |
| 50: | |
| 51: | foreach ($list as $item) { |
| 52: | $datarow = new DataRow($this->id, $item, $this->lastnumber++); |
| 53: | $this->add($datarow); |
| 54: | if ($this->rowevent instanceof Event) { |
| 55: | $this->rowevent->onEvent($datarow); |
| 56: | } |
| 57: | $datarow->updateChildId(); |
| 58: | if ($this->selectedRow instanceof DataRow) { |
| 59: | if ($datarow->getNumber() == $this->selectedRow->getNumber() && $this->selectedclass != "") { |
| 60: | $datarow->setAttribute('class', $this->selectedclass); |
| 61: | } |
| 62: | } |
| 63: | |
| 64: | |
| 65: | } |
| 66: | } |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | final public function RenderImpl() { |
| 78: | |
| 79: | |
| 80: | |
| 81: | $rowtag = WebApplication::$dom->find('[zippy=' . $this->id . ']'); |
| 82: | |
| 83: | if ($rowtag->count() == 0) { |
| 84: | throw new \Zippy\Exception(sprintf(ERROR_MARKUP_NOTFOUND, $this->id)); |
| 85: | } |
| 86: | |
| 87: | $ids = array(); |
| 88: | $children = WebApplication::$dom->find('[zippy=' . $this->id . '] [zippy]'); |
| 89: | foreach ($children as $child) { |
| 90: | $ids[] = $child->attr("zippy"); |
| 91: | } |
| 92: | |
| 93: | $rows = $this->getDataRows(); |
| 94: | $rowtag= $rowtag->first() ; |
| 95: | $tn= $rowtag->tagName; |
| 96: | $attr=""; |
| 97: | foreach($rowtag->attributes as $a){ |
| 98: | $attr = $attr. " {$a->nodeName}=\"{$a->nodeValue}\" "; |
| 99: | }; |
| 100: | |
| 101: | $html_ = "<{$tn} {$attr} >". $rowtag->html() . "</{$tn}>"; |
| 102: | $html = ""; |
| 103: | foreach ($rows as $row) { |
| 104: | $i = $row->getNumber() ; |
| 105: | $id = $this->id .'_'.$i; |
| 106: | |
| 107: | $rep = "zippy=\"{$id}\" id=\"{$id}\" "; |
| 108: | $h = str_replace("zippy=\"{$this->id}\"", $rep, $html_) ; |
| 109: | $h = str_replace("zippy='{$this->id}'", $rep, $h) ; |
| 110: | |
| 111: | foreach($ids as $cid) { |
| 112: | $id = $cid .'_'.$i; |
| 113: | $rep = "zippy=\"{$id}\" id=\"{$id}\" "; |
| 114: | $h = str_replace("zippy=\"{$cid}\"", $rep, $h) ; |
| 115: | $h = str_replace("zippy='{$cid}'", $rep, $h) ; |
| 116: | |
| 117: | } |
| 118: | if ($this->cellclickevent instanceof \Zippy\Event) { |
| 119: | $url = $this->getURLNode() . ':' . ($i); |
| 120: | $onclick = "window.location='{$url}'"; |
| 121: | |
| 122: | $style = "cursor:pointer; "; |
| 123: | $h = str_replace("<tr", "<tr style=\"{$style}\" onclick=\"{$onclick}\" ", $h) ; |
| 124: | } |
| 125: | $html .= $h; |
| 126: | |
| 127: | } |
| 128: | |
| 129: | |
| 130: | $parent=$rowtag->parent(); |
| 131: | $rowtag->precede($html); |
| 132: | |
| 133: | $rowtag->destroy(); |
| 134: | |
| 135: | |
| 136: | $p = $this->getPageOwner() ; |
| 137: | if($p instanceof \Zippy\Html\WebPage) { |
| 138: | |
| 139: | |
| 140: | } |
| 141: | |
| 142: | foreach ($this->getChildComponents() as $component) { |
| 143: | |
| 144: | |
| 145: | $component->Render(); |
| 146: | } |
| 147: | |
| 148: | |
| 149: | } |
| 150: | |
| 151: | |
| 152: | |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: | public function setSelectedRow(DataRow $row = null) { |
| 159: | |
| 160: | $this->selectedRow = $row; |
| 161: | |
| 162: | } |
| 163: | |
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: | public function getSelectedRow() { |
| 169: | return $this->selectedRow; |
| 170: | } |
| 171: | |
| 172: | |
| 173: | |
| 174: | |
| 175: | |
| 176: | |
| 177: | public function setSelectedClass($selectedclass) { |
| 178: | $this->selectedclass = $selectedclass; |
| 179: | } |
| 180: | |
| 181: | final public function setCellClickEvent(\Zippy\Interfaces\EventReceiver $receiver, $handler) { |
| 182: | $this->cellclickevent = new \Zippy\Event($receiver, $handler); |
| 183: | } |
| 184: | |
| 185: | final public function RequestHandle() { |
| 186: | parent::RequestHandle(); |
| 187: | |
| 188: | $p = WebApplication::$app->getRequest()->request_params[$this->id]; |
| 189: | if ($this->cellclickevent instanceof \Zippy\Event) { |
| 190: | |
| 191: | |
| 192: | $srow = null; |
| 193: | foreach ($this->getDataRows() as $row) { |
| 194: | if ($row->getNumber() == $p[0]) { |
| 195: | $srow = $row; |
| 196: | } |
| 197: | } |
| 198: | |
| 199: | $this->cellclickevent->onEvent($srow); |
| 200: | |
| 201: | } |
| 202: | |
| 203: | } |
| 204: | } |
| 205: | |