Commit 19f99baf authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

FIX(actionHelper): update for add software button

parent d12c3e83
Pipeline #9941 passed with stage
in 3 minutes and 35 seconds
......@@ -28,25 +28,27 @@ class ActionHelper extends Helper
/**
* Create form with one button
*
* @param string $formMethod
* @param string $controller
* @param string $action
* @param int $id
* @param string $btnText
* @param string $btnClass
* @param string $formUrl
* @param string $btnExtraClass
* @param $formMethod
* @param $controller
* @param $action
* @param $id
* @param $btnTxt
* @param $btnClass
* @param $formUrl
* @param string $btnExtraClass default = ''
* @param bool $bypassCheckId default = false
* @return string|null
*/
private function communButton(
private function communBtn(
$formMethod,
$controller,
$action,
$id,
$btnText,
$btnTxt,
$btnClass,
$formUrl,
$btnExtraClass = ''
$btnExtraClass = '',
$bypassCheckId = false
) {
$userType = $this->request->session()->read('Auth.User.user_type');
if ($userType === null) {
......@@ -54,7 +56,8 @@ class ActionHelper extends Helper
}
$htmlId = "$controller-$action-$id";
if (!is_null($id) && $this->hasAccess($userType, $controller, $action)) {
$hasAccess = $this->hasAccess($userType, $controller, $action);
if ((!is_null($id) || $bypassCheckId) && $hasAccess) {
$btnCssClass = $btnClass . ' ' . $btnExtraClass;
$formOptions = [
"url" => $formUrl,
......@@ -64,7 +67,7 @@ class ActionHelper extends Helper
];
$html = '';
$html .= $this->Form->create(null, $formOptions);
$html .= $this->Form->button($btnText, ["class" => $btnCssClass, "id" => "btn_$htmlId",]);
$html .= $this->Form->button($btnTxt, ["class" => $btnCssClass, "id" => "btn_$htmlId",]);
$html .= $this->Form->end();
return $html;
} else {
......@@ -81,7 +84,7 @@ class ActionHelper extends Helper
*/
public function edit(array $options)
{
$btnText = isset($options["text"]) ? $options["text"] : "Edit";
$btnTxt = isset($options["text"]) ? $options["text"] : "Edit";
$btnClass = isset($options["class"]) ? $options['class'] : "btn btn-default addmore btn-edit";
$formMethod = isset($options["method"]) ? $options["method"] : "post"; // default post method
$controller = isset($options["controller"]) ? $options["controller"] : $this->request->controller;
......@@ -92,7 +95,7 @@ class ActionHelper extends Helper
} else {
$formUrl = ['prefix' => false, 'controller' => $controller, 'action' => $action, $id];
}
return $this->communButton($formMethod, $controller, $action, $id, $btnText, $btnClass, $formUrl);
return $this->communBtn($formMethod, $controller, $action, $id, $btnTxt, $btnClass, $formUrl);
}
/**
......@@ -101,7 +104,7 @@ class ActionHelper extends Helper
*/
public function fallBack(array $options)
{
$btnText = isset($options["text"]) ? $options["text"] : "Delete";
$btnTxt = isset($options["text"]) ? $options["text"] : "Delete";
$btnClass = isset($options["class"]) ? $options['class'] : "btn btn-default removeOne";
$formMethod = isset($options["method"]) ? $options["method"] : "delete"; // default post method
$controller = isset($options["controller"]) ? $options["controller"] : $this->request->controller;
......@@ -112,7 +115,7 @@ class ActionHelper extends Helper
} else {
$formUrl = ['prefix' => false, 'controller' => $controller, 'action' => $action, $id];
}
return $this->communButton($formMethod, $controller, $action, $id, $btnText, $btnClass, $formUrl);
return $this->communBtn($formMethod, $controller, $action, $id, $btnTxt, $btnClass, $formUrl);
}
/**
......@@ -122,24 +125,29 @@ class ActionHelper extends Helper
*/
public function participate(array $options)
{
$btnText = isset($options["text"]) ? $options["text"] : null;
$btnTxt = isset($options["text"]) ? $options["text"] : null;
$btnClass = isset($options["class"]) ? $options['class'] : "btn btn-default addmore";
$btnExtraClass = isset($options["extraCssClass"]) ? $options["extraCssClass"] : "";
$formMethod = isset($options["method"]) ? $options["method"] : "post"; // default post method
$controller = isset($options["controller"]) ? $options["controller"] : $this->request->controller;
$ctrl = isset($options["controller"]) ? $options["controller"] : $this->request->controller;
$action = isset($options["action"]) ? $options["action"] : "add";
$id = isset($options["id"]) ? $options["id"] : null;
if (isset($options["url"])) {
$formUrl = $options["url"];
} else {
$formUrl = ['prefix' => false, 'controller' => $controller, 'action' => $action, $id];
$formUrl = ['prefix' => false, 'controller' => $ctrl, 'action' => $action, $id];
}
$html = $this->communButton($formMethod, $controller, $action, $id, $btnText, $btnClass, $formUrl);
if (is_null($html) && !is_null($btnText)) {
$htmlId = "$controller-$action-$id";
$bypassTestId = false;
if ($ctrl === 'Softwares' && $action === 'add') {
// prevent test on ID (null equals) performed into communBtn() for this case
$bypassTestId = true;
}
$html = $this->communBtn($formMethod, $ctrl, $action, $id, $btnTxt, $btnClass, $formUrl, '', $bypassTestId);
if (is_null($html) && !is_null($btnTxt)) {
$htmlId = "$ctrl-$action-$id";
$html = $this->Form->button(
$btnText,
$btnTxt,
[
"class" => "btn btn-default inactive-button " . $btnExtraClass,
"disabled" => "disabled",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment