Framework  3.9
DraggableList Class Reference

DraggableList provides a simple user interface for sorting a list of items. More...

Public Member Functions

 __construct ($items, $id="draggable_list", $format=null, $handler=null)
 
 enableDragReorder ($handler)
 
 writeScript ()
 
 drawList ()
 

Public Attributes

 $items
 
 $id
 
 $format
 
 $listTag = "ul"
 The HTML list tag type. More...
 
 $CSSclass = null
 CSS class(es) to be applied to the list. More...
 
 $styles = null
 Specific CSS styles to be applied to the list. More...
 
 $emptyList = "No items in the list"
 Message to display when the list is empty. More...
 
 $reorderHandler = null
 Handler script that implements reordering records. More...
 
 $dragText = ""
 Optional text to display above reorderable table. More...
 

Detailed Description

DraggableList provides a simple user interface for sorting a list of items.

Users can click and drag items within the list. Sorting is updated on the server via a sort handler that must be able to parse pairs of primary keys and sort order values.

Author
andy

Definition at line 46 of file draggable_list.inc.

Constructor & Destructor Documentation

◆ __construct()

DraggableList::__construct (   $items,
  $id = "draggable_list",
  $format = null,
  $handler = null 
)

Definition at line 59 of file draggable_list.inc.

60  {
61  $this->items = $items;
62  $this->id = $id;
63  $this->format = $format;
64  $this->reorderHandler = $handler;
65  }

Member Function Documentation

◆ drawList()

DraggableList::drawList ( )

Definition at line 88 of file draggable_list.inc.

89  {
90  if (!count($this->items))
91  {
92  echo "<p>{$this->emptyList}</p>";
93  return;
94  }
95 
96  $attrs = "";
97  if ($this->CSSclass)
98  {
99  $attrs .= " class='draggable {$this->CSSclass}'";
100  }
101  else
102  {
103  $attrs .= " class='draggable'";
104  }
105 
106  if ($this->styles) $attrs .= " style='{$this->styles}'";
107 ?>
108 
109  <? echo $this->dragText;?>
110  <<?echo $this->listTag?> id="<?echo $this->id?>"<?echo $attrs?>>
111 <?
112  foreach($this->items as $item)
113  {
114  $pkTag = " data-pk='".$item->getPrimaryKeyValue()."'";
115 
116  echo "<li{$pkTag}>";
117 
118  if (is_callable($this->format))
119  {
120  echo call_user_func($this->format, $item);
121  }
122  else echo $item->format($this->format);
123 
124  echo "</li>\n";
125  }
126  echo "</{$this->listTag}>\n";
127  }
$dragText
Optional text to display above reorderable table.

◆ enableDragReorder()

DraggableList::enableDragReorder (   $handler)

Definition at line 67 of file draggable_list.inc.

68  {
69  $this->reorderHandler = $handler;
70  }

◆ writeScript()

DraggableList::writeScript ( )

Definition at line 72 of file draggable_list.inc.

73  {
74  if (!count($this->items)) return;
75  $pk = $this->items[0]->getPrimaryKey();
76 
77  $script = <<<ENDSCRIPT
78 <script type='text/javascript'>
79 window.addEvent('domready', function()
80 {
81  new DraggableList('{$this->id}', '{$this->reorderHandler}', '{$pk}');
82 });
83 </script>
84 ENDSCRIPT;
85  return $script;
86  }
DraggableList provides a simple user interface for sorting a list of items.

Member Data Documentation

◆ $CSSclass

DraggableList::$CSSclass = null

CSS class(es) to be applied to the list.

Definition at line 52 of file draggable_list.inc.

◆ $dragText

DraggableList::$dragText = ""

Optional text to display above reorderable table.

Definition at line 57 of file draggable_list.inc.

◆ $emptyList

DraggableList::$emptyList = "No items in the list"

Message to display when the list is empty.

Definition at line 54 of file draggable_list.inc.

◆ $format

DraggableList::$format

Definition at line 50 of file draggable_list.inc.

◆ $id

DraggableList::$id

Definition at line 49 of file draggable_list.inc.

◆ $items

DraggableList::$items

Definition at line 48 of file draggable_list.inc.

◆ $listTag

DraggableList::$listTag = "ul"

The HTML list tag type.

Definition at line 51 of file draggable_list.inc.

◆ $reorderHandler

DraggableList::$reorderHandler = null

Handler script that implements reordering records.

Definition at line 56 of file draggable_list.inc.

◆ $styles

DraggableList::$styles = null

Specific CSS styles to be applied to the list.

Definition at line 53 of file draggable_list.inc.


The documentation for this class was generated from the following file: