30 $modal=($this->
_getModelViewer()->isModal($objects,$this->model))?
"modal":
"no";
32 $this->jquery->getOnClick (
"#btAddNew", $this->
_getBaseRoute() .
"/newModel/" . $modal,
"#frm-add-update",[
"hasLoader"=>
"internal"] );
37 $this->activePage=$page;
41 if(is_numeric($recordsPerPage)){
44 $this->activePage=Pagination::getPageOfRow($rownum,$recordsPerPage);
63 if(isset($_POST[
"s"])){
69 if(isset($recordsPerPage)){
72 print_r($responseFormatter->getJSONDatas($instances));
76 $this->jquery->execAtLast(
'$("#search-query-content").html("'.$_POST[
"s"].
'");$("#search-query").show();$("#table-details").html("");');
77 $this->jquery->renderView(
"@framework/main/component.html",[
"compo"=>$compo]);
86 public function edit($modal=
"no", $ids=
"") {
89 $instance->_new=
false;
90 $this->
_edit($instance, $modal);
92 $this->jquery->execAtLast(
"$('._edit[data-ajax={$ids}]').trigger('click');");
104 $instance->_new=
true;
105 $this->
_edit($instance, $modal);
107 $this->jquery->execAtLast(
"$('.ui.button._new').trigger('click');");
121 $this->jquery->execOn(
"click",
"._close",
'$("#table-details").html("");$("#dataTable").show();');
122 $this->jquery->getOnClick(
"._edit", $this->
_getBaseRoute().
"/edit/".$modal.
"/".$key,
"#frm-add-update");
123 $this->jquery->getOnClick(
"._delete", $this->
_getBaseRoute().
"/delete/".$key,
"#table-messages");
125 $this->
_getModelViewer()->getModelDataElement($instance, $this->model,$modal);
126 $this->jquery->renderView($this->
_getFiles()->getViewDisplay(), [
"classname" => $this->model,
"instance"=>$instance,
"pk"=>$key ]);
128 $this->jquery->execAtLast(
"$('._display[data-ajax={$ids}]').trigger('click');");
133 protected function _edit($instance, $modal=
"no") {
134 $_SESSION[
"instance"]=$instance;
135 $modal=($modal ==
"modal");
137 $this->jquery->click(
"#action-modal-frmEdit-0",
"$('#frmEdit').form('submit');",
false);
139 $this->jquery->click(
"#bt-cancel",
"$('#form-container').transition('drop');");
140 $this->jquery->compile($this->view);
143 $this->jquery->exec(
"$('#modal-frmEdit').modal('show');",
true);
144 $form=$form->asModal(\get_class($instance));
145 $form->setActions([
"Okay",
"Cancel" ]);
146 $btOkay=$form->getAction(0);
147 $btOkay->addClass(
"green")->setValue(
"Validate modifications");
148 $form->onHidden(
"$('#modal-frmEdit').remove();");
149 echo $form->compile($this->jquery, $this->view);
150 echo $this->jquery->compile($this->view);
165 public function delete($ids) {
168 if (method_exists($instance,
"__toString"))
169 $instanceString=$instance .
"";
171 $instanceString=get_class($instance);
172 if (
sizeof($_POST) > 0) {
175 $message=
new CRUDMessage(
"Deletion of `<b>" . $instanceString .
"</b>`",
"Deletion",
"info",
"info circle",4000);
176 $message=$this->
_getEvents()->onSuccessDeleteMessage($message);
177 $this->jquery->exec(
"$('._element[data-ajax={$ids}]').remove();",
true);
179 $message=
new CRUDMessage(
"Can not delete `" . $instanceString .
"`",
"Deletion",
"warning",
"warning circle");
180 $message=$this->
_getEvents()->onErrorDeleteMessage($message);
182 }
catch (\Exception $e){
183 $message=
new CRUDMessage(
"Exception : can not delete `" . $instanceString .
"`",
"Exception",
"warning",
"warning");
184 $message=$this->
_getEvents()->onErrorDeleteMessage($message);
188 $message=
new CRUDMessage(
"Do you confirm the deletion of `<b>" . $instanceString .
"</b>`?",
"Remove confirmation",
"error");
189 $this->
_getEvents()->onConfDeleteMessage($message);
193 echo $this->jquery->compile($this->view);
195 $this->jquery->execAtLast(
"$('._delete[data-ajax={$ids}]').trigger('click');");
204 $this->jquery->execAtLast(
'$("#table-details").html("");');
205 $this->jquery->renderView(
"@framework/main/component.html",[
"compo"=>$compo]);
212 $message=
new CRUDMessage(
"Modifications were successfully saved",
"Updating");
213 $instance=@$_SESSION[
"instance"];
214 $isNew=$instance->_new;
218 $message->setType(
"success")->setIcon(
"check circle outline");
219 $message=$this->
_getEvents()->onSuccessUpdateMessage($message);
222 $message->setMessage(
"An error has occurred. Can not save changes.")->setType(
"error")->setIcon(
"warning circle");
223 $message=$this->
_getEvents()->onErrorUpdateMessage($message);
225 }
catch(\Exception $e){
226 if (method_exists($instance,
"__toString"))
227 $instanceString=$instance .
"";
229 $instanceString=get_class($instance);
230 $message=
new CRUDMessage(
"Exception : can not update `" . $instanceString .
"`",
"Exception",
"warning",
"warning");
231 $message=$this->
_getEvents()->onErrorUpdateMessage($message);
234 echo $this->jquery->compile($this->view);
238 if($this->
_getAdminData()->refreshPartialInstance() && !$isNew){
242 $this->jquery->get($this->
_getBaseRoute() .
"/refreshTable/".$pk,
"#lv", [
"jqueryDone" =>
"replaceWith" ]);
257 $semantic=$this->jquery->semantic();
258 $grid=$semantic->htmlGrid(
"detail");
259 if (
sizeof($fkInstances) > 0) {
260 $wide=intval(16 /
sizeof($fkInstances));
263 foreach ( $fkInstances as $member=>$fkInstanceArray ) {
264 $element=$viewer->getFkMemberElementDetails($member,$fkInstanceArray[
"objectFK"],$fkInstanceArray[
"fkClass"],$fkInstanceArray[
"fkTable"]);
265 if (isset($element)) {
266 $grid->addCol($wide)->setContent($element);
272 $url=$this->
_getEvents()->onDetailClickURL($this->model);
276 echo $this->jquery->compile($this->view);
279 $this->jquery->execAtLast(
"$('tr[data-ajax={$ids}]').trigger('click');");
286 $this->jquery->postOnClick(
".showTable", $this->
_getBaseRoute() .
"/".$url,
"{}",
"#divTable", [
"attr" =>
"data-ajax",
"ajaxTransition" =>
"random" ]);
290 $ids=\explode(
"_", $ids);
292 if(isset($instance)){
295 $message=
new CRUDMessage(
"This object does not exist!",
"Get object",
"warning",
"warning circle");
296 $message=$this->
_getEvents()->onNotFoundMessage($message);
298 echo $this->jquery->compile($this->view);
311 return $this->
getSingleton($this->modelViewer,
"getAdminData");
323 return $this->
getSingleton($this->modelViewer,
"getModelViewer");
335 return $this->
getSingleton($this->crudFiles,
"getFiles");
351 if (! isset ( $value )) {
352 $value = $this->$method ();
358 $this->
_getEvents()->beforeLoadView($viewName,$vars);
361 $mainTemplate=$files->getBaseTemplate();
362 if(isset($mainTemplate)){
363 $vars[
"_viewname"]=$viewName;
364 $vars[
"_base"]=$mainTemplate;
365 $this->jquery->renderView($files->getViewBaseTemplate(),$vars);
367 $vars[
"hasScript"]=
true;
368 $this->jquery->renderView($viewName,$vars);
371 $vars[
"hasScript"]=
true;
372 $this->jquery->renderView($viewName,$vars);
update()
Updates an instance from the data posted in a form.
The base class for displaying datas in CRUD controllers.
static asJSON()
Sets the response content-type to application/json.
static getRownum($className, $ids)
getModelViewer()
To override for defining a new ModelViewer.
getAdminData()
To override for defining a new adminData.
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...
getFiles()
To override for changing view files.
static paginate($className, $page=1, $rowsPerPage=20, $condition=null)
_edit($instance, $modal="no")
static post($key, $default=NULL)
Returns the value of the $key variable passed by the post method or $default if the $key variable doe...
_showSimpleMessage(CRUDMessage $message, $staticName=null)
crudLoadView($viewName, $vars=[])
static getFirstKeyValue($instance)
loadView($viewName, $pData=NULL, $asString=false)
Loads the view $viewName possibly passing the variables $pdata.
static getAll($className, $condition='', $loadManyToOne=true, $loadOneToMany=false, $useCache=NULL)
Returns an array of $className objects from the database.
static objectAsJSON($instance)
showDetail($ids)
Shows associated members with foreign keys.
_showConfMessage(CRUDMessage $message, $url, $responseElement, $data, $attributes=NULL)
display($modal="no", $ids="")
Displays an instance.
static isAjax()
Returns true if the request is an Ajax request.
static count($className, $condition='')
Returns the number of objects of $className from the database respecting the condition possibly passe...
getInstances($page=1, $id=null)
static getFKIntances($instance, $model)
getEvents()
To override for changing events.
static search($model, $search, $fields, $initialCondition="1=1")
edit($modal="no", $ids="")
Edits an instance.
index()
Default page : list all objects.
getSingleton($value, $method)
static remove($instance)
Deletes the object $instance from the database.
static update($instance, $values, $updateManyToOneInForm=true, $updateManyToManyInForm=false)
refreshInstance($instance, $isNew)
_getInstancesFilter($model)
newModel($modal="no")
Adds a new instance and edits it.