35 abstract protected function _createController($controllerName,$variables=[],$ctrlTemplate=
'controller.tpl',$hasView=
false,$jsCallback=
"");
39 abstract public function showSimpleMessage($content, $type, $icon=
"info", $timeout=NULL, $staticName=null);
43 $this->
_createController($_POST[
"name"],[],
'controller.tpl',isset($_POST[
"lbl-ck-div-name"]));
50 $action=$_POST[
"action"];
51 $controller=$_POST[
"controller"];
52 $controllerFullname=$_POST[
"controllerFullname"];
53 $viewName=$controller .
"/" . $action .
".html";
55 if (\file_exists(ROOT . DS .
"views" . DS . $viewName)) {
56 $this->jquery->exec(
'$("#msgControllers").transition("show");$("#msgControllers .content").transition("show").append("<br><b>' . $viewName .
'</b> created !");',
true);
58 $r=new \ReflectionMethod($controllerFullname, $action);
59 $lines=file($r->getFileName());
60 $views=$this->
_getAdminViewer()->getActionViews($controllerFullname, $controller, $action, $r, $lines);
61 foreach ( $views as $view ) {
62 echo $view->compile($this->jquery);
65 echo $this->jquery->compile($this->view);
70 $viewName=$controller .
"/" . $action .
".html";
80 $controller=$_POST[
"controller"];
81 $modal=$this->jquery->semantic()->htmlModal(
"modalNewAction",
"Creating a new action in controller");
82 $modal->setInverted();
83 $frm=$this->jquery->semantic()->htmlForm(
"frmNewAction");
84 $dd=$frm->addDropdown(
'controller', \array_combine($controllers, $controllers),
"Controller", $controller);
85 $dd->getField()->setShowOnFocus(
false);
86 $fields=$frm->addFields([
"action",
"parameters" ],
"Action & parameters");
87 $fields->getItem(0)->addRules([
"empty",[
"checkAction",
"Action {value} already exists!" ] ]);
88 $frm->addTextarea(
"content",
"Implementation")->addRule([
"checkContent",
"Errors parsing action content!" ]);
90 $frm->addCheckbox(
"ck-view",
"Create associated view");
91 $frm->addCheckbox(
"ck-add-route",
"Add route...");
93 $frm->addContent(
"<div id='div-new-route' style='display: none;'>");
95 $fields=$frm->addFields();
96 $fields->addInput(
"path",
"",
"text",
"")->addRule([
"checkRoute",
"Route {value} already exists!" ]);
98 $duration=$fields->addInput(
"duration",
"",
"number");
99 $ck=$duration->labeledCheckbox(
"left", null);
100 $ck->getField()->setProperty(
"name",
"ck-Cache");
101 $frm->addContent(
"</div>");
103 $frm->setValidationParams([
"on" =>
"blur",
"inline" =>
true ]);
104 $frm->setSubmitParams($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_newAction",
"#messages");
105 $modal->setContent($frm);
106 $modal->addAction(
"Validate");
107 $this->jquery->click(
"#action-modalNewAction-0",
"$('#frmNewAction').form('submit');",
false,
false);
108 $modal->addAction(
"Close");
109 $this->jquery->exec(
"$('.dimmer.modals.page').html('');$('#modalNewAction').modal('show');",
true);
110 $this->jquery->jsonOn(
"change",
"#ck-add-route", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_addRouteWithNewAction",
"post", [
"context" =>
"$('#frmNewAction')",
"params" =>
"$('#frmNewAction').serialize()",
"jsCondition" =>
"$('#ck-add-route').is(':checked')" ]);
111 $this->jquery->exec(Rule::ajax($this->jquery,
"checkAction", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_methodExists",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewAction" ]),
true);
112 $this->jquery->exec(Rule::ajax($this->jquery,
"checkContent", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_checkContent",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewAction" ]),
true);
113 $this->jquery->exec(Rule::ajax($this->jquery,
"checkRoute", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_checkRoute",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewAction" ]),
true);
114 $this->jquery->change(
"#ck-add-route",
"$('#div-new-route').toggle($(this).is(':checked'));");
116 echo $this->jquery->compile($this->view);
123 header(
'Content-type: application/json');
124 $controller=$_POST[
"controller"];
125 $action=$_POST[
"action"];
126 if (\method_exists($controller, $action)) {
127 $result[
"result"]=
false;
129 $result[
"result"]=
true;
131 echo json_encode($result);
138 header(
'Content-type: application/json');
139 $content=$_POST[
"content"];
141 echo json_encode($result);
148 header(
'Content-type: application/json');
149 $path=$_POST[
"path"];
152 echo json_encode($result);
159 header(
'Content-type: application/json');
161 $controller=$_POST[
"controller"];
162 $action=$_POST[
"action"];
163 $parameters=$_POST[
"parameters"];
167 $urlParts=\array_diff(\array_merge([ $controller,$action ], $parameters), [
"",
"{}" ]);
168 $result[
"path"]=\implode(
'/', $urlParts);
169 echo json_encode($result);
177 $controller=$_POST[
"controller"];
178 $r=new \ReflectionClass($controller);
179 $ctrlFilename=$r->getFileName();
180 $action=$_POST[
"action"];
181 $parameters=$_POST[
"parameters"];
182 $content=$_POST[
"content"];
184 $createView=isset($_POST[
"ck-view"]);
185 $createRoute=isset($_POST[
"ck-add-route"]);
187 $fileContent=\trim($fileContent);
188 $posLast=\strrpos($fileContent,
"}");
189 if ($posLast !==
false) {
192 $content.=
"\n\t\t\$this->loadView('" . $viewname .
"');\n";
193 $msgContent.=
"<br>Created view : <b>" . $viewname .
"</b>";
198 $path=$_POST[
"path"];
199 $routeProperties=[
'"' . $path .
'"' ];
200 $methods=$_POST[
"methods"];
202 $routeProperties[]=
'"methods"=>' . $this->
getMethods($methods);
204 if (isset($_POST[
"ck-Cache"])) {
205 $routeProperties[]=
'"cache"=>true';
206 if (isset($_POST[
"duration"])) {
207 $duration=$_POST[
"duration"];
208 if (\ctype_digit($duration)) {
209 $routeProperties[]=
'"duration"=>' . $duration;
213 $routeProperties=\implode(
",", $routeProperties);
219 $actionContent=
UFileSystem::openReplaceInTemplateFile($frameworkDir .
"/admin/templates/action.tpl", [
"%route%" =>
"\n" . $routeAnnotation,
"%actionName%" => $action,
"%parameters%" => $parameters,
"%content%" => $content ]);
220 $fileContent=\substr_replace($fileContent,
"\n%content%", $posLast - 1, 0);
222 echo $this->
showSimpleMessage(
"Errors parsing action content!",
"warning",
"warning circle", null,
"msgControllers");
223 echo $this->jquery->compile($this->view);
227 $msgContent=
"The action <b>{$action}</b> is created in controller <b>{$controller}</b>" . $msgContent;
228 echo $this->
showSimpleMessage($msgContent,
"info",
"info circle", null,
"msgControllers");
233 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_refreshControllers/refresh",
"#dtControllers", [
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false,
"dataType" =>
"html" ]);
234 echo $this->jquery->compile($this->view);
241 $message=\ob_get_clean();
243 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_refreshControllers/refresh",
"#dtControllers", [
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false,
"dataType" =>
"html" ]);
244 echo $this->jquery->compile($this->view);
248 $methods=\explode(
",", $strMethods);
250 foreach ( $methods as $method ) {
251 $result[]=
'"' . $method .
'"';
253 return "[" . \implode(
",", $result) .
"]";
static isPost()
Returns true if the request is sent by the POST method.
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)
_createController($controllerName, $variables=[], $ctrlTemplate='controller.tpl', $hasView=false, $jsCallback="")
static getParametersForRoute($parameters)
static initCache(&$config, $type="all", $silent=false)
static getClassSimpleName($classnameWithNamespace)