Skip to content

Commit 331007f

Browse files
committed
Add col alignment from right
1 parent 489ec7e commit 331007f

File tree

3 files changed

+95
-5
lines changed

3 files changed

+95
-5
lines changed

Ajax/common/html/BaseHtml.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ protected function compile_once(JsUtils $js=NULL, &$view=NULL) {
197197
$beforeCompile($this,$js,$view);
198198
}
199199
}
200-
if(\is_callable($this->_preCompile)){
201-
$pc=$this->_preCompile;
202-
$pc($this);
203-
}
200+
$this->callCallback($this->_preCompile);
204201
unset($this->properties["jsCallback"]);
205202
$this->_compiled=true;
206203
}
@@ -279,6 +276,28 @@ public function onPostCompile($callback){
279276
}
280277

281278
public function onPreCompile($callback){
282-
$this->_preCompile=$callback;
279+
$this->_preCompile=$this->addCallback($this->_preCompile, $callback);
280+
}
281+
282+
private function addCallback($originalValue,$callback){
283+
if(isset($originalValue)){
284+
if(!is_array($originalValue)){
285+
$result=[$originalValue];
286+
}
287+
$result[]=$callback;
288+
return $result;
289+
}
290+
return $callback;
291+
}
292+
293+
private function callCallback($callable){
294+
if(\is_callable($callable)){
295+
return $callable($this);
296+
}
297+
if(is_array($callable)){
298+
foreach ($callable as $call){
299+
$this->callCallback($call);
300+
}
301+
}
283302
}
284303
}

Ajax/semantic/html/collections/table/HtmlTable.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,33 @@ public function colRight($colIndex) {
231231
public function colLeft($colIndex) {
232232
return $this->colAlign($colIndex, "colLeft");
233233
}
234+
235+
/**
236+
* Sets the col alignment to center
237+
* @param int $colIndex
238+
* @return HtmlTable
239+
*/
240+
public function colCenterFromRight($colIndex) {
241+
return $this->colAlign($colIndex, "colCenterFromRight");
242+
}
243+
244+
/**
245+
* Sets the col alignment to right
246+
* @param int $colIndex
247+
* @return HtmlTable
248+
*/
249+
public function colRightFromRight($colIndex) {
250+
return $this->colAlign($colIndex, "colRightFromRight");
251+
}
252+
253+
/**
254+
* Sets col alignment to left
255+
* @param int $colIndex
256+
* @return HtmlTable
257+
*/
258+
public function colLeftFromRight($colIndex) {
259+
return $this->colAlign($colIndex, "colLeftFromRight");
260+
}
234261

235262
public function setColAlignment($colIndex,$alignment){
236263
switch ($alignment){
@@ -252,6 +279,27 @@ public function setColAlignment($colIndex,$alignment){
252279
$this->colAlign($colIndex, $function);
253280
return $this;
254281
}
282+
283+
public function setColAlignmentFromRight($colIndex,$alignment){
284+
switch ($alignment){
285+
case TextAlignment::LEFT:
286+
$function="colLeftFromRight";
287+
break;
288+
289+
case TextAlignment::RIGHT:
290+
$function="colRightFromRight";
291+
break;
292+
293+
case TextAlignment::CENTER:
294+
$function="colCenterFromRight";
295+
break;
296+
297+
default:
298+
$function="colLeftFromRight";
299+
}
300+
$this->colAlign($colIndex, $function);
301+
return $this;
302+
}
255303

256304
private function colAlign($colIndex, $function) {
257305
if (\is_array($colIndex)) {

Ajax/semantic/html/content/table/HtmlTableContent.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@ private function colAlign($colIndex, $function) {
213213
}
214214
return $this;
215215
}
216+
217+
private function colAlignFromRight($colIndex, $function) {
218+
$count=$this->count();
219+
for($i=0; $i < $count; $i++) {
220+
$maxRow=$this->content[$i]->count();
221+
$index=$maxRow-$colIndex-1;
222+
if (($cell=$this->getCell($i, $index))!== NULL)
223+
$cell->$function();
224+
}
225+
return $this;
226+
}
216227

217228
public function colCenter($colIndex) {
218229
return $this->colAlign($colIndex, "textCenterAligned");
@@ -225,6 +236,18 @@ public function colRight($colIndex) {
225236
public function colLeft($colIndex) {
226237
return $this->colAlign($colIndex, "textLeftAligned");
227238
}
239+
240+
public function colCenterFromRight($colIndex) {
241+
return $this->colAlignFromRight($colIndex, "textCenterAligned");
242+
}
243+
244+
public function colRightFromRight($colIndex) {
245+
return $this->colAlignFromRight($colIndex, "textRightAligned");
246+
}
247+
248+
public function colLeftFromRight($colIndex) {
249+
return $this->colAlignFromRight($colIndex, "textLeftAligned");
250+
}
228251

229252
/**
230253
* Returns the number of rows (TR)

0 commit comments

Comments
 (0)