36 abstract protected function _createController($controllerName,$variables=[],$ctrlTemplate=
'controller.tpl',$hasView=
false);
40 abstract public function showSimpleMessage($content, $type, $icon=
"info", $timeout=NULL, $staticName=null);
44 $this->
_createController($_POST[
"name"],[],
'controller.tpl',isset($_POST[
"lbl-ck-div-name"]));
51 $action=$_POST[
"action"];
52 $controller=$_POST[
"controller"];
53 $controllerFullname=$_POST[
"controllerFullname"];
54 $viewName=$controller .
"/" . $action .
".html";
56 if (\file_exists(ROOT . DS .
"views" . DS . $viewName)) {
57 $this->jquery->exec(
'$("#msgControllers").transition("show");$("#msgControllers .content").transition("show").append("<br><b>' . $viewName .
'</b> created !");',
true);
59 $r=new \ReflectionMethod($controllerFullname, $action);
60 $lines=file($r->getFileName());
61 $views=$this->
_getAdminViewer()->getActionViews($controllerFullname, $controller, $action, $r, $lines);
62 foreach ( $views as $view ) {
63 echo $view->compile($this->jquery);
66 echo $this->jquery->compile($this->view);
71 $viewName=$controller .
"/" . $action .
".html";
81 $controller=$_POST[
"controller"];
82 $modal=$this->jquery->semantic()->htmlModal(
"modalNewAction",
"Creating a new action in controller");
83 $modal->setInverted();
84 $frm=$this->jquery->semantic()->htmlForm(
"frmNewAction");
85 $dd=$frm->addDropdown(
'controller', \array_combine($controllers, $controllers),
"Controller", $controller);
86 $dd->getField()->setShowOnFocus(
false);
87 $fields=$frm->addFields([
"action",
"parameters" ],
"Action & parameters");
88 $fields->getItem(0)->addRules([
"empty",[
"checkAction",
"Action {value} already exists!" ] ]);
89 $frm->addTextarea(
"content",
"Implementation")->addRule([
"checkContent",
"Errors parsing action content!" ]);
91 $frm->addCheckbox(
"ck-view",
"Create associated view");
92 $frm->addCheckbox(
"ck-add-route",
"Add route...");
94 $frm->addContent(
"<div id='div-new-route' style='display: none;'>");
96 $fields=$frm->addFields();
97 $fields->addInput(
"path",
"",
"text",
"")->addRule([
"checkRoute",
"Route {value} already exists!" ]);
99 $duration=$fields->addInput(
"duration",
"",
"number");
100 $ck=$duration->labeledCheckbox(
"left", null);
101 $ck->getField()->setProperty(
"name",
"ck-Cache");
102 $frm->addContent(
"</div>");
104 $frm->setValidationParams([
"on" =>
"blur",
"inline" =>
true ]);
105 $frm->setSubmitParams($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_newAction",
"#messages");
106 $modal->setContent($frm);
107 $modal->addAction(
"Validate");
108 $this->jquery->click(
"#action-modalNewAction-0",
"$('#frmNewAction').form('submit');",
false,
false);
109 $modal->addAction(
"Close");
110 $this->jquery->exec(
"$('.dimmer.modals.page').html('');$('#modalNewAction').modal('show');",
true);
111 $this->jquery->jsonOn(
"change",
"#ck-add-route", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_addRouteWithNewAction",
"post", [
"context" =>
"$('#frmNewAction')",
"params" =>
"$('#frmNewAction').serialize()",
"jsCondition" =>
"$('#ck-add-route').is(':checked')" ]);
112 $this->jquery->exec(Rule::ajax($this->jquery,
"checkAction", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_methodExists",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewAction" ]),
true);
113 $this->jquery->exec(Rule::ajax($this->jquery,
"checkContent", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_checkContent",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewAction" ]),
true);
114 $this->jquery->exec(Rule::ajax($this->jquery,
"checkRoute", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_checkRoute",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewAction" ]),
true);
115 $this->jquery->change(
"#ck-add-route",
"$('#div-new-route').toggle($(this).is(':checked'));");
117 echo $this->jquery->compile($this->view);
124 header(
'Content-type: application/json');
125 $controller=$_POST[
"controller"];
126 $action=$_POST[
"action"];
127 if (\method_exists($controller, $action)) {
128 $result[
"result"]=
false;
130 $result[
"result"]=
true;
132 echo json_encode($result);
139 header(
'Content-type: application/json');
140 $content=$_POST[
"content"];
142 echo json_encode($result);
149 header(
'Content-type: application/json');
150 $path=$_POST[
"path"];
153 echo json_encode($result);
160 header(
'Content-type: application/json');
162 $controller=$_POST[
"controller"];
163 $action=$_POST[
"action"];
164 $parameters=$_POST[
"parameters"];
168 $urlParts=\array_diff(\array_merge([ $controller,$action ], $parameters), [
"",
"{}" ]);
169 $result[
"path"]=\implode(
'/', $urlParts);
170 echo json_encode($result);
178 $controller=$_POST[
"controller"];
179 $r=new \ReflectionClass($controller);
180 $ctrlFilename=$r->getFileName();
181 $action=$_POST[
"action"];
182 $parameters=$_POST[
"parameters"];
183 $content=$_POST[
"content"];
185 $createView=isset($_POST[
"ck-view"]);
186 $createRoute=isset($_POST[
"ck-add-route"]);
188 $fileContent=\trim($fileContent);
189 $posLast=\strrpos($fileContent,
"}");
190 if ($posLast !==
false) {
193 $content.=
"\n\t\t\$this->loadView('" . $viewname .
"');\n";
194 $msgContent.=
"<br>Created view : <b>" . $viewname .
"</b>";
199 $path=$_POST[
"path"];
200 $routeProperties=[
'"' . $path .
'"' ];
201 $methods=$_POST[
"methods"];
203 $routeProperties[]=
'"methods"=>' . $this->
getMethods($methods);
205 if (isset($_POST[
"ck-Cache"])) {
206 $routeProperties[]=
'"cache"=>true';
207 if (isset($_POST[
"duration"])) {
208 $duration=$_POST[
"duration"];
209 if (\ctype_digit($duration)) {
210 $routeProperties[]=
'"duration"=>' . $duration;
214 $routeProperties=\implode(
",", $routeProperties);
220 $actionContent=
UFileSystem::openReplaceInTemplateFile($frameworkDir .
"/admin/templates/action.tpl", [
"%route%" =>
"\n" . $routeAnnotation,
"%actionName%" => $action,
"%parameters%" => $parameters,
"%content%" => $content ]);
221 $fileContent=\substr_replace($fileContent,
"\n%content%", $posLast - 1, 0);
223 echo $this->
showSimpleMessage(
"Errors parsing action content!",
"warning",
"warning circle", null,
"msgControllers");
224 echo $this->jquery->compile($this->view);
228 $msgContent=
"The action <b>{$action}</b> is created in controller <b>{$controller}</b>" . $msgContent;
229 echo $this->
showSimpleMessage($msgContent,
"info",
"info circle", null,
"msgControllers");
234 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_refreshControllers/refresh",
"#dtControllers", [
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false,
"dataType" =>
"html" ]);
235 echo $this->jquery->compile($this->view);
242 $message=\ob_get_clean();
244 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_refreshControllers/refresh",
"#dtControllers", [
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false,
"dataType" =>
"html" ]);
245 echo $this->jquery->compile($this->view);
249 $methods=\explode(
",", $strMethods);
251 foreach ( $methods as $method ) {
252 $result[]=
'"' . $method .
'"';
254 return "[" . \implode(
",", $result) .
"]";
static isPost()
Returns true if the request is sent by the POST method.
_createController($controllerName, $variables=[], $ctrlTemplate='controller.tpl', $hasView=false)
static getClassCode($classname)
_refreshCacheControllers()
static getRouteInfo($path)
static indent($code, $count=2)
_addMessageForRouteCreation($path)
static isValidCode($code)
static openReplaceWriteFromTemplateFile($source, $destination, $keyAndValues)
_createViewOp($controller, $action)
createController($force=null)
static openReplaceInTemplateFile($source, $keyAndValues)
showSimpleMessage($content, $type, $icon="info", $timeout=NULL, $staticName=null)
static cleanParameters($parameters)
static replaceWriteFromContent($content, $destination, $keyAndValues)
static getParametersForRoute($parameters)
static initCache(&$config, $type="all", $silent=false)
static getClassSimpleName($classnameWithNamespace)