37 abstract protected function showSimpleMessage($content, $type, $title=null,$icon=
"info", $timeout=NULL, $staticName=null):HtmlMessage;
40 $model=$this->
getModelsNS() .
"\\" . ucfirst($table);
44 $bt=$this->jquery->semantic()->htmlButton(
"btYuml",
"Class diagram");
45 $bt->postOnClick($adminRoute.
"/_showDiagram/",
"{model:'" . \str_replace(
"\\",
"|", $model) .
"'}",
"#modal", [
"attr" =>
"" ]);
46 $this->jquery->exec(
'$("#models-tab .item").tab();',
true);
47 $this->jquery->getOnClick (
"#btAddNew", $adminRoute .
"/newModel/" . $this->formModal,
"#frm-add-update",[
"hasLoader"=>
"internal"] );
48 $this->jquery->compile($this->view);
49 $this->loadView($this->
_getAdminFiles()->getViewShowTable(), [
"classname" => $model ]);
53 $model=$_SESSION[
"model"];
55 $this->jquery->execAtLast(
'$("#table-details").html("");');
56 $this->jquery->renderView(
"@framework/Admin/main/component.html",[
"compo"=>$compo]);
60 $array=\explode(
".", $tableAndId);
61 if (\is_array($array)) {
64 $this->jquery->exec(
"$('#menuDbs .active').removeClass('active');$('.ui.label.left.pointing.teal').removeClass('left pointing teal active');$(\"[data-ajax='" . $table .
"']\").addClass('active');$(\"[data-ajax='" . $table .
"']\").find('.ui.label').addClass('left pointing teal');",
true);
66 $this->jquery->execAtLast(
"$(\"tr[data-ajax='" . $id .
"']\").click();");
67 echo $this->jquery->compile();
72 $_SESSION[
"model"]=$model;
74 $this->formModal=($this->
_getModelViewer()->isModal($datas,$model))?
"modal" :
"no";
75 return $this->
_getModelViewer()->getModelDataTable($datas, $model,$this->activePage);
79 $this->activePage=$page;
81 if(is_numeric($recordsPerPage)){
84 $this->activePage=Pagination::getPageOfRow($rownum,$recordsPerPage);
86 return DAO::paginate($model,$this->activePage,$recordsPerPage);
91 protected function search($model,$search){
97 $model=$_POST[
"_model"];
98 if(isset($_POST[
"s"])){
99 $instances=$this->
search($model, $_POST[
"s"]);
104 if(isset($recordsPerPage)){
107 print_r($responseFormatter->getJSONDatas($instances));
109 $this->formModal=($this->
_getModelViewer()->isModal($instances,$model))?
"modal" :
"no";
110 $compo= $this->
_getModelViewer()->getModelDataTable($instances, $model)->refresh([
"tbody"]);
111 $this->jquery->execAtLast(
'$("#search-query-content").html("'.$_POST[
"s"].
'");$("#search-query").show();$("#table-details").html("");');
112 $this->jquery->renderView(
"@framework/Admin/main/component.html",[
"compo"=>$compo]);
116 protected function _edit($instance, $modal=
"no") {
117 $_SESSION[
"instance"]=$instance;
118 $modal=($modal ==
"modal");
120 $this->jquery->click(
"#action-modal-frmEdit-0",
"$('#frmEdit').form('submit');",
false);
122 $this->jquery->click(
"#bt-cancel",
"$('#form-container').transition('drop');");
123 $this->jquery->compile($this->view);
124 $this->loadView($this->
_getAdminFiles()->getViewEditTable(), [
"modal" => $modal ]);
126 $this->jquery->exec(
"$('#modal-frmEdit').modal('show');",
true);
127 $form=$form->asModal(\get_class($instance));
128 $form->setActions([
"Okay",
"Cancel" ]);
129 $btOkay=$form->getAction(0);
130 $btOkay->addClass(
"green")->setValue(
"Validate modifications");
131 $form->onHidden(
"$('#modal-frmEdit').remove();");
132 echo $form->compile($this->jquery, $this->view);
133 echo $this->jquery->compile($this->view);
137 public function edit($modal=
"no", $ids=
"") {
139 $instance->_new=
false;
140 $this->
_edit($instance, $modal);
144 $model=$_SESSION[
"model"];
145 $instance=
new $model();
146 $instance->_new=
true;
147 $this->
_edit($instance, $modal);
151 $message=
new CRUDMessage(
"Modifications were successfully saved",
"Updating");
152 $instance=@$_SESSION[
"instance"];
153 $isNew=$instance->_new;
157 $message->setType(
"success")->setIcon(
"check circle outline");
159 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/refreshTable/".$pk,
"#lv", [
"jqueryDone" =>
"replaceWith" ]);
164 $message->setMessage(
"An error has occurred. Can not save changes.")->setType(
"error")->setIcon(
"warning circle");
166 echo $this->_showSimpleMessage($message,
"updateMsg");
167 echo $this->jquery->compile($this->view);
171 $model=$_SESSION[
'model'];
172 $ids=\explode(
"_", $ids);
174 if(isset($instance)){
177 echo $this->
showSimpleMessage(
"This object does not exist!",
"warning",
"Get object",
"warning circle");
178 echo $this->jquery->compile($this->view);
182 public function delete($ids) {
184 if (method_exists($instance,
"__toString"))
185 $instanceString=$instance .
"";
187 $instanceString=get_class($instance);
188 if (
sizeof($_POST) > 0) {
190 $message=$this->
showSimpleMessage(
"Deletion of `<b>" . $instanceString .
"</b>`",
"info",
"Deletion",
"info", 4000);
191 $this->jquery->exec(
"$('tr[data-ajax={$ids}]').remove();",
true);
193 $message=$this->
showSimpleMessage(
"Can not delete `" . $instanceString .
"`",
"warning",
"Error",
"warning");
196 $message=$this->showConfMessage(
"Do you confirm the deletion of `<b>" . $instanceString .
"</b>`?",
"error",
"Remove confirmation", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/delete/{$ids}",
"#table-messages", $ids);
199 echo $this->jquery->compile($this->view);
203 $reflection=new \ReflectionClass($model);
204 $publicMethods=$reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
206 foreach ( $publicMethods as $method ) {
207 $methodName=$method->getName();
208 if (JString::startswith($methodName,
"get")) {
209 $attributeName=lcfirst(JString::replaceAtFirst($methodName,
"get",
""));
210 if (!property_exists($model, $attributeName))
211 $result[]=$methodName;
221 $model=$_SESSION[
'model'];
223 $semantic=$this->jquery->semantic();
224 $grid=$semantic->htmlGrid(
"detail");
225 if (
sizeof($fkInstances) > 0) {
226 $wide=intval(16 /
sizeof($fkInstances));
229 foreach ( $fkInstances as $member=>$fkInstanceArray ) {
230 $element=$viewer->getFkMemberElementDetails($member,$fkInstanceArray[
"objectFK"],$fkInstanceArray[
"fkClass"],$fkInstanceArray[
"fkTable"]);
231 if (isset($element)) {
232 $grid->addCol($wide)->setContent($element);
238 $this->jquery->getOnClick(
".showTable", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/showTableClick",
"#divTable", [
"attr" =>
"data-ajax",
"ajaxTransition" =>
"random" ]);
239 echo $this->jquery->compile($this->view);
250 foreach ( $array as $dataAjax => $caption ) {
251 $result[]=$this->
_getCk($caption, $dataAjax);
256 private function _getCk($caption, $dataAjax) {
257 $ck=
new HtmlCheckbox(
"ck-" . $dataAjax, $caption,
"1");
258 $ck->setProperty(
"name",
"ck[]");
259 $ck->setProperty(
"data-ajax", $dataAjax);
static asJSON()
Sets the response content-type to application/json.
static getRownum($className, $ids)
static getOne($className, $keyValues, $loadManyToOne=true, $loadOneToMany=false, $useCache=NULL)
Returns an instance of $className from the database, from $keyvalues values of the primary key...
showTableClick($tableAndId)
edit($modal="no", $ids="")
static paginate($className, $page=1, $rowsPerPage=20, $condition=null)
showSimpleMessage($content, $type, $title=null, $icon="info", $timeout=NULL, $staticName=null)
static post($key, $default=NULL)
Returns the value of the $key variable passed by the post method or $default if the $key variable doe...
static getFirstKeyValue($instance)
static getAll($className, $condition='', $loadManyToOne=true, $loadOneToMany=false, $useCache=NULL)
Returns an array of $className objects from the database.
static objectAsJSON($instance)
_getCk($caption, $dataAjax)
showTable($table, $id=null)
static count($className, $condition='')
Returns the number of objects of $className from the database respecting the condition possibly passe...
_edit($instance, $modal="no")
static getModelMetadata($className)
static getFKIntances($instance, $model)
getInstances($model, $page=1, $id=null)
static search($model, $search, $fields, $initialCondition="1=1")
_showModel($model, $id=null)
static remove($instance)
Deletes the object $instance from the database.
static update($instance, $values, $updateManyToOneInForm=true, $updateManyToManyInForm=false)