Finish option CATEGORY_EDIT_IN_POPUP_NOT_IN_MENU

This commit is contained in:
Laurent Destailleur
2025-05-16 17:59:39 +02:00
parent d5a870869c
commit d540dd0ab7
7 changed files with 153 additions and 17 deletions

View File

@@ -22,7 +22,8 @@
/**
* \file htdocs/core/ajax/ajaxstatusprospect.php
* \brief File to return Ajax response on third parties request
* \brief File of service to update prospect status of a third party
* TODO Rename into updatestatusprospect.php
*/
if (!defined('NOTOKENRENEWAL')) {
@@ -87,7 +88,7 @@ if ($action === "updatestatusprospect" && $permisstiontoupdate) {
$response = '';
$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
$sql .= "fk_stcomm=".((int) $idstatus);
$sql .= "fk_stcomm = ".((int) $idstatus);
$sql .= " WHERE rowid = ".((int) $idprospect);
$resql = $db->query($sql);

View File

@@ -0,0 +1,107 @@
<?php
/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/ajax/fetchCategories.php
* \brief File to fetch categories
*/
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1'); // Disables token renewal
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
// Do not check anti CSRF attack test
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
// If we need access without being logged.
if (!empty($_GET['public'])) { // Keep $_GET here. GETPOST() is not yet defined so we use $_GET
if (!defined("NOLOGIN")) {
define("NOLOGIN", '1');
}
}
if (!defined('NOIPCHECK')) {
define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}
if (!defined('NOBROWSERNOTIF')) {
define('NOBROWSERNOTIF', '1');
}
include '../../main.inc.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
$action = GETPOST('action', 'aZ09');
$lang = GETPOST('lang', 'aZ09');
$type = GETPOST('type');
// Security check
if (!defined("NOLOGIN")) { // No need of restrictedArea if not logged: Later the select will filter on public articles only if not logged.
restrictedArea($user, 'knowledgemanagement', 0, 'knowledgemanagement_knowledgerecord', 'knowledgerecord');
}
/*
* Actions
*/
// None
/*
* View
*/
top_httphead('application/json');
if ($action == "getCategories") {
$response = '';
$sql = "SELECT c.rowid, c.label, c.color";
$sql .= " FROM ".MAIN_DB_PREFIX."categorie as c ";
$sql .= " WHERE c.type = '".$db->escape($type)."'";
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$response = array();
while ($i < $num) {
$obj = $db->fetch_object($resql);
$response[] = array('id' => $obj->rowid, 'label' => $obj->label, 'data-html' => 'TODO', 'color' => $obj->color);
$i++;
}
} else {
dol_print_error($db);
}
$response =json_encode($response);
echo $response;
}

View File

@@ -1,7 +1,6 @@
<?php
/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*/
/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
@@ -17,8 +16,8 @@
*/
/**
* \file /htdocs/core/ajax/fetchKnowledgeRecord.php
* \brief File to make Ajax action on Knowledge Management
* \file htdocs/core/ajax/fetchKnowledgeRecord.php
* \brief File to fetch km record
*/
if (!defined('NOTOKENRENEWAL')) {
@@ -85,7 +84,7 @@ top_httphead('application/json');
if ($action == "getKnowledgeRecord") {
$response = '';
$sql = "SELECT kr.rowid, kr.ref, kr.question, kr.answer,kr.url,ctc.code";
$sql = "SELECT kr.rowid, kr.ref, kr.question, kr.answer, kr.url, ctc.code";
$sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as kr ";
$sql .= " JOIN ".MAIN_DB_PREFIX."c_ticket_category as ctc ON ctc.rowid = kr.fk_c_ticket_category";
$sql .= " WHERE ctc.code = '".$db->escape($idticketgroup)."'";
@@ -109,6 +108,7 @@ if ($action == "getKnowledgeRecord") {
} else {
dol_print_error($db);
}
$response =json_encode($response);
echo $response;
}

View File

@@ -21,6 +21,7 @@
* \file htdocs/core/ajax/objectonoff.php
* \brief File to set status for an object. Called when ajax_object_onoff() is used.
* This Ajax service is often called when option MAIN_DIRECT_STATUS_UPDATE is set.
* TODO Rename into updatestatus.php
*/
if (!defined('NOTOKENRENEWAL')) {

View File

@@ -2827,7 +2827,7 @@ function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $di
console.log("open popup name='.$name.'");
},
close: function (event, ui) {
console.log("Popup is closed, run jsonclose='.$jsonclose.');
console.log("Popup is closed, run jsonclose = '.$jsonclose.'");
'.(empty($jsonclose) ? '' : $jsonclose.';').'
}
});

View File

@@ -2182,7 +2182,7 @@ function get_left_menu_bank($mainmenu, &$newmenu, $usemenuhider = 1, $leftmenu =
*/
function get_left_menu_products($mainmenu, &$newmenu, $usemenuhider = 1, $leftmenu = 'none', $type_user = 0)
{
global $user, $conf, $langs;
global $user, $langs;
if ($mainmenu == 'products') {
// Products
@@ -2358,7 +2358,7 @@ function get_left_menu_mrp($mainmenu, &$newmenu, $usemenuhider = 1, $leftmenu =
*/
function get_left_menu_projects($mainmenu, &$newmenu, $usemenuhider = 1, $leftmenu = 'none', $type_user = 0)
{
global $user, $conf, $langs;
global $user, $langs;
if ($mainmenu == 'project') {
if (isModEnabled('project')) {
@@ -2433,7 +2433,7 @@ function get_left_menu_projects($mainmenu, &$newmenu, $usemenuhider = 1, $leftme
*/
function get_left_menu_hrm($mainmenu, &$newmenu, $usemenuhider = 1, $leftmenu = 'none', $type_user = 0)
{
global $user, $conf, $langs;
global $user, $langs;
if ($mainmenu == 'hrm') {
// HRM module
@@ -2544,7 +2544,8 @@ function get_left_menu_tools($mainmenu, &$newmenu, $usemenuhider = 1, $leftmenu
global $user, $langs;
if ($mainmenu == 'tools') {
if (isModEnabled('category') && !getDolGlobalString('CATEGORY_EDIT_IN_POPUP_NOT_IN_MENU')) {
if (isModEnabled('category')) {
//if (isModEnabled('category') && getDolGlobalString('CATEGORY_EDIT_IN_POPUP_NOT_IN_MENU')) {
$titleindex = $langs->trans("Categories");
$newmenu->add("/categories/index.php?leftmenu=category", $titleindex, 0, $user->hasRight('category', 'read'), '', $mainmenu, 'category', 5, '', '', '', img_picto('', 'category', 'class="paddingright pictofixedwidth"'));
}

View File

@@ -2759,15 +2759,19 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayactio
$arrayselected[] = $cat->id;
}
print img_picto('', 'category', 'class="pictofixedwidth"');
$categtype = Categorie::TYPE_CUSTOMER;
$htmlname = 'custcats';
print $form->multiselectarray($htmlname, $cate_arbo, $arrayselected, 0, 0, 'minwidth100 widthcentpercentminusxx', 0, 0);
if (getDolGlobalString('CATEGORY_EDIT_IN_POPUP_NOT_IN_MENU')) {
// Add html code to add the edit button and go back
$jsonclose = 'doJsCodeAfterPopupClose'.$htmlname.'()';
$s = dolButtonToOpenUrlInDialogPopup($htmlname, $langs->transnoentitiesnoconv("Categories"), img_picto('', 'add', 'class="editfielda"'), '/categories/categorie_list.php?type='.Categorie::TYPE_CUSTOMER, '', '', '', $jsonclose);
$urltoopen = '/categories/categorie_list.php?type='.$categtype;
$s = dolButtonToOpenUrlInDialogPopup($htmlname, $langs->transnoentitiesnoconv("Categories"), img_picto('', 'add', 'class="editfielda"'), $urltoopen, '', '', '', $jsonclose);
print $s;
// Add js code to add the edit button and go back
print '<!-- Add js code to open the popup for category/edit/add -->'."\n";
print '<script>function doJsCodeAfterPopupClose'.$htmlname.'() {
console.log("doJsCodeAfterPopupClose'.$htmlname.' has been called, we refresh the combo content + refresh select2...");
@@ -2775,6 +2779,28 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayactio
// $("#'.dol_escape_js($htmlname).'").append(new Option("Option 4", "4"));
// Refresh select2 to take account of new values (enough for small change)
$.ajax({
url: \''.DOL_URL_ROOT.'/core/ajax/fetchCategories.php\',
data: {
action: \'getCategories\',
type: \''.dol_escape_htmltag($categtype).'\'
},
type: \'GET\',
dataType: \'json\',
success: function (data) {
var $select = $(\'#'.dol_escape_js($htmlname).'\');
$select.empty();
$.each(data, function (index, item) {
$select.append(\'<option value="\' + item.id + \'" data-html="aaa">\' + item.label + \'</option>\');
});
},
error: function (xhr, status, error) {
alert("Error when loading ajax page : " + error);
}
});
$("#'.dol_escape_js($htmlname).'").trigger("change");
// Alternative if change in select is complex
/*