5use Ajax\semantic\html\elements\HtmlButton;
6use Ajax\semantic\html\elements\HtmlHeader;
7use Ajax\semantic\html\elements\HtmlLabel;
8use Ajax\semantic\widgets\datatable\DataTable;
9use Ajax\semantic\widgets\datatable\PositionInTable;
10use Ajax\service\JString;
46 if ($this->style ===
'inverted') {
47 $elm->setInverted (
true );
48 if ($elm instanceof DataTable) {
49 $elm->setActiveRowSelector (
'black' );
64 public function getModelDataElement($instance, $model, $modal): \Ajax\semantic\widgets\dataelement\DataElement {
65 $semantic = $this->jquery->semantic ();
66 $fields = $this->controller->_getAdminData ()->getElementFieldNames ( $model );
68 $dataElement = $semantic->dataElement (
"de", $instance );
69 $pk = OrmUtils::getFirstKeyValue ( $instance );
70 $dataElement->getInstanceViewer ()->setIdentifierFunction (
function () use ($pk) {
73 $dataElement->setFields ( $fields );
74 $dataElement->setCaptions ( $this->
getElementCaptions ( $fields, $model, $instance ) );
77 foreach ( $fkInstances as $member => $fkInstanceArray ) {
78 if (array_search ( $member, $fields ) !==
false) {
79 $dataElement->setValueFunction ( $member,
function () use ($fkInstanceArray, $member) {
80 return $this->
getFkMemberElement ( $member, $fkInstanceArray [
"objectFK"], $fkInstanceArray [
"fkClass"], $fkInstanceArray [
"fkTable"] );
85 return $dataElement->addClass ( $this->style );
96 return \array_map (
'ucfirst', $captions );
107 $adminRoute = $this->controller->_getBaseRoute ();
108 $files = $this->controller->_getFiles ();
109 $dataTable = $this->getDataTableInstance ( $instances, $model, $totalCount, $page );
110 $attributes = $this->controller->_getAdminData ()->getFieldNames ( $model );
111 $this->setDataTableAttributes ( $dataTable, $attributes, $model, $instances );
112 $dataTable->setCaptions ( $this->getCaptions ( $attributes, $model ) );
113 $dataTable->setFocusable(
true);
114 $dataTable->addClass (
'small very compact' );
115 $lbl =
new HtmlLabel (
'search-query',
"<span id='search-query-content'></span>" );
116 $icon = $lbl->addIcon (
'delete',
false );
117 $lbl->wrap (
"<span>",
"</span>" );
118 $lbl->setProperty (
"style",
"display: none;" );
119 $icon->getOnClick ( $adminRoute . $files->getRouteRefreshTable (),
'#' . $this->getDataTableId (), [
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
"internal" ] );
121 $dataTable->addItemInToolbar ( $lbl );
122 $dataTable->addSearchInToolbar ();
123 $dataTable->setToolbarPosition ( PositionInTable::FOOTER );
124 $dataTable->getToolbar ()->setSecondary ();
125 $this->setStyle ( $dataTable );
130 $modal = ($this->isModal ( $instances, $model ) ?
'modal' :
'no');
132 $adminRoute = $this->controller->_getBaseRoute ();
133 $files = $this->controller->_getFiles ();
134 $dataTable->setButtons ( $this->getDataTableRowButtons () );
135 $dataTable->setFields ( $attributes );
136 if (\array_search (
'password', $attributes ) !==
false) {
137 $dataTable->setValueFunction (
'password',
function ($v) {
138 return UString::mask ( $v );
141 $dataTable->setIdentifierFunction ( CRUDHelper::getIdentifierFunction ( $model ) );
143 if (! isset ( $selector )) {
144 if (\count ( $instances ) > 0 && $this->showDetailsOnDataTableClick ()) {
145 $dataTable->getOnRow (
'click', $adminRoute . $files->getRouteDetails (),
"#table-details", [
"selector" => $selector,
"attr" =>
"data-ajax",
"hasLoader" =>
false,
"jsCallback" =>
"return false;" ] );
146 $dataTable->setActiveRowSelector (
'active' );
149 $dataTable->setUrls ( [
'refresh' => $adminRoute . $files->getRouteRefresh (),
'delete' => $adminRoute . $files->getRouteDelete (),
'edit' => $adminRoute . $files->getRouteEdit () .
"/" . $modal,
'display' => $adminRoute . $files->getRouteDisplay () .
"/" . $modal ] );
150 $dataTable->setTargetSelector ( [
'delete' =>
'#table-messages',
'edit' =>
'#frm-add-update',
'display' =>
'#table-details' ] );
151 $this->addEditMemberFonctionality (
'dataTable' );
153 $this->addAllButtons ( $dataTable, $attributes );
157 if (($editMemberParams = $this->getEditMemberParams ()) !==
false) {
158 if (isset ( $editMemberParams [$part] )) {
159 $params = $editMemberParams [$part];
160 $params->compile ( $this->controller->_getBaseRoute (), $this->jquery, $part );
172 if ($totalCount > 6) {
195 $dtId = $this->getDataTableId ();
196 $semantic = $this->jquery->semantic ();
197 $recordsPerPage = $this->recordsPerPage ( $model, $totalCount );
198 if (\is_numeric ( $recordsPerPage )) {
199 $grpByFields = $this->getGroupByFields ();
200 if (\is_array ( $grpByFields )) {
201 $dataTable = $semantic->dataTable ( $dtId, $model, $instances );
202 $dataTable->setGroupByFields ( $grpByFields );
204 $dataTable = $semantic->jsonDataTable ( $dtId, $model, $instances );
206 $dataTable->paginate ( $page, $totalCount, $recordsPerPage, 5 );
207 $dataTable->onSearchTerminate (
'$("#search-query-content").html(data);$("#search-query").show();$("#table-details").html("");' );
209 $dataTable = $semantic->dataTable ( $dtId, $model, $instances );
211 $dataTable->setLibraryId (
'lv' );
221 return [
'edit',
'delete' ];
225 $transition = $this->getTransition ();
226 $dataTable->onPreCompile (
function () use (&$dataTable) {
227 $dataTable->getHtmlComponent ()->colRightFromRight ( 0 );
228 $tb = $dataTable->getPaginationToolbar ();
230 $tb->addClass ( $this->style );
233 $dataTable->addAllButtons (
false, [
'ajaxTransition' => $transition,
'hasLoader' =>
'internal' ],
function ($bt) {
234 $bt->addClass (
'circular ' . $this->style );
235 $this->onDataTableRowButton ( $bt ,
'display');
237 $bt->addClass (
'circular ' . $this->style );
238 $this->onDataTableRowButton ( $bt ,
'edit');
240 $bt->addClass (
'circular ' . $this->style );
241 $this->onDataTableRowButton ( $bt ,
'delete');
243 $buttons=\array_diff($this->getDataTableRowButtons(),[
'edit',
'display',
'delete']);
244 foreach ($buttons as $bt){
245 $attr=JString::cleanIdentifier($bt);
246 $dataTable->insertDefaultButtonIn($dataTable->getButtonsColumn(),$bt,
"_$attr circular basic",
false,
function($b) use($attr){
247 $b->addClass ( $this->style );
248 $this->onDataTableRowButton ( $b,$attr );
251 $dataTable->setDisplayBehavior ( [
'jsCallback' =>
'$("#dataTable").hide();',
'ajaxTransition' => $transition,
'hasLoader' =>
'internal' ] );
292 return \array_map (
'ucfirst', $captions );
304 $res =
new HtmlHeader (
'', 4, $member,
'content' );
305 return $res->addClass ( $this->style );
317 $res =
new HtmlHeader (
'', 4, $member .
' (' . \count ( $list ) .
')',
'content' );
318 return $res->addClass ( $this->style );
330 $res = $this->jquery->semantic ()->htmlLabel (
'element-' . $className .
'.' . $member, $object .
'' );
331 return $res->addClass ( $this->style );
343 $element = $this->jquery->semantic ()->htmlList (
'list-' . $className .
'.' . $member );
344 $element->setMaxVisible ( 15 );
346 return $element->addClass (
'animated divided celled ' . $this->style );
359 $_fkClass = str_replace (
"\\",
".", $fkClass );
360 $header =
new HtmlHeader (
"", 4, $memberFK,
"content" );
361 if (is_array ( $objectFK ) || $objectFK instanceof \Traversable) {
362 $header = $this->getFkHeaderListDetails ( $memberFK, $fkClass, $objectFK );
363 $element = $this->getFkListDetails ( $memberFK, $fkClass, $objectFK );
364 foreach ( $objectFK as $oItem ) {
365 if (method_exists ( $oItem,
"__toString" )) {
366 $id = (CRUDHelper::getIdentifierFunction ( $fkClass )) ( 0, $oItem );
367 $item = $element->addItem ( $oItem .
"" );
368 $item->setProperty (
"data-ajax", $_fkClass .
"||" . $id );
369 $item->addClass (
"showTable" );
370 $this->onDisplayFkElementListDetails ( $item, $memberFK, $fkClass, $oItem );
374 if (method_exists ( $objectFK,
"__toString" )) {
375 $header = $this->getFkHeaderElementDetails ( $memberFK, $fkClass, $objectFK );
376 $id = (CRUDHelper::getIdentifierFunction ( $fkClass )) ( 0, $objectFK );
377 $element = $this->getFkElementDetails ( $memberFK, $fkClass, $objectFK );
378 $element->setProperty (
"data-ajax", $_fkClass .
"||" . $id )->addClass (
"showTable" );
381 if (isset ( $element )) {
382 return [ $header,$element ];
409 $_fkClass = str_replace (
"\\",
".", $fkClass );
410 if (is_array ( $objectFK ) || $objectFK instanceof \Traversable) {
411 $element = $this->getFkList ( $memberFK, $objectFK );
412 foreach ( $objectFK as $oItem ) {
413 if (\method_exists ( $oItem,
'__toString' )) {
414 $id = (CRUDHelper::getIdentifierFunction ( $fkClass )) ( 0, $oItem );
415 $item = $element->addItem ( $oItem .
'' );
416 $item->setProperty (
'data-ajax', $_fkClass .
'||' . $id );
417 $item->addClass (
'showTable' );
418 $this->displayFkElementList ( $item, $memberFK, $fkClass, $oItem );
422 if (method_exists ( $objectFK,
'__toString' )) {
423 $id = (CRUDHelper::getIdentifierFunction ( $fkClass )) ( 0, $objectFK );
424 $element = $this->getFkElement ( $memberFK, $fkClass, $objectFK );
425 $element->setProperty (
'data-ajax', $_fkClass .
'||' . $id )->addClass (
'showTable' );
440 $element = $this->jquery->semantic ()->htmlList (
'list-' . $member );
441 $element->setMaxVisible ( 10 );
442 return $element->addClass (
'animated' );
465 $res = $this->jquery->semantic ()->htmlLabel (
'element-' . $className .
'.' . $member, $object .
'' );
466 return $res->addClass ( $this->style );
Ubiquity\controllers\crud$CRUDHelper This class is part of Ubiquity.
static getFKIntances($instance, $model, $included=false)
Associated with a CRUDController class Responsible of the display.
recordsPerPage($model, $totalCount=0)
getFkMemberElement($memberFK, $objectFK, $fkClass, $fkTable)
Returns a component for displaying a foreign object (from DataElement)
addAllButtons(DataTable $dataTable, $attributes)
getFkListDetails($member, $className, $list)
Returns a list component for displaying a collection of foreign objects (*ToMany relations),...
getFkHeaderElementDetails($member, $className, $object)
Returns the header for a single foreign object (element is an instance, issue from ManyToOne),...
getDataTableInstance($instances, $model, $totalCount, $page=1)
Returns the dataTable instance for dispaying a list of object.
onDisplayFkElementListDetails($element, $member, $className, $object)
To modify for displaying an element in a list component of foreign objects (from DataTable)
setDataTableAttributes(DataTable $dataTable, $attributes, $model, $instances, $selector=null)
getGroupByFields()
Returns the fields on which a grouping is performed.
getFkList($member, $list)
Returns a list component for displaying a collection of foreign objects (*ToMany relations),...
getDataTableRowButtons()
Returns an array of buttons ["display","edit","delete"] to display for each row in dataTable.
__construct(HasModelViewerInterface $controller, $style=null)
showDetailsOnDataTableClick()
To override to make sure that the detail of a clicked object is displayed or not.
getModelDataTable($instances, $model, $totalCount, $page=1)
Returns the dataTable responsible for displaying instances of the model.
displayFkElementList($element, $member, $className, $object)
To modify for displaying an element in a list component of foreign objects, (from DataElement)
onDataTableRowButton(HtmlButton $bt,?string $name=null)
To override for modifying the dataTable row buttons.
getElementCaptions($captions, $className, $instance)
Returns the captions for DataElement fields in display route.
getCaptions($captions, $className)
Returns the captions for list fields in showTable action.
onConfirmButtons(HtmlButton $confirmBtn, HtmlButton $cancelBtn)
To override for modifying the showConfMessage dialog buttons.
getFkHeaderListDetails($member, $className, $list)
Returns the header for a list of foreign objects (issue from oneToMany or ManyToMany),...
getFkElement($member, $className, $object)
Returns a component for displaying a single foreign object (manyToOne relation), (from DataElement)
getTransition()
The default transition for display, edit and delete behaviors.
getFkMemberElementDetails($memberFK, $objectFK, $fkClass, $fkTable)
Returns a component for displaying a foreign object (from DataTable)
getFkElementDetails($member, $className, $object)
Returns a component for displaying a single foreign object (manyToOne relation), (from DataTable)
getModelDataElement($instance, $model, $modal)
Returns a DataElement object for displaying the instance Used in the display method of the CrudContro...
addEditMemberFonctionality($part)
Object/relational mapping utilities.