FIX refresh of tasks combo must use an ajax page not a full html page

This commit is contained in:
Laurent Destailleur 2020-10-17 21:14:19 +02:00
parent 53eef48596
commit 547b3602cc
3 changed files with 24 additions and 22 deletions

View File

@ -389,7 +389,7 @@ if (empty($reshook) && $action == 'add')
$moreparam = '';
if ($user->id != $object->userownerid) $moreparam = "filtert=-1"; // We force to remove filter so created record is visible when going back to per user view.
//Create reminders
// Create reminders
if ($addreminder == 'on'){
$actionCommReminder = new ActionCommReminder($db);
@ -1166,10 +1166,11 @@ if ($action == 'create')
print "\n".'<script type="text/javascript">';
print '$(document).ready(function () {
$("#projectid").change(function () {
var url = "'.$url.'&projectid="+$("#projectid").val();
var url = "'.DOL_URL_ROOT.'/projet/ajax/projects.php?mode=gettasks&socid="+$("#projectid").val()+"&projectid="+$("#projectid").val();
console.log("Call url to get new list of tasks: "+url);
$.get(url, function(data) {
console.log($( data ).find("#taskid").html());
if (data) $("#taskid").html( $( data ).find("#taskid").html() ).select2();
console.log(data);
if (data) $("#taskid").html(data).select2();
})
});
})';
@ -1345,7 +1346,7 @@ if ($id > 0)
$object->contact_id = GETPOST("contactid", 'int');
$object->fk_project = GETPOST("projectid", 'int');
$object_private = GETPOST("note", 'restricthtml');
$object->note_private = GETPOST("note", 'restricthtml');
}
if ($result2 < 0 || $result3 < 0 || $result4 < 0 || $result5 < 0)

View File

@ -349,7 +349,7 @@ class FormProjets
if ($resql)
{
// Use select2 selector
if (!empty($conf->use_javascript_ajax))
if (empty($option_only) && !empty($conf->use_javascript_ajax))
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);

View File

@ -33,10 +33,8 @@ if (empty($_GET['keysearch']) && !defined('NOREQUIREHTML')) define('NOREQUIREHT
require '../../main.inc.php';
$htmlname = GETPOST('htmlname', 'alpha');
$htmlname = GETPOST('htmlname', 'aZ09');
$socid = GETPOST('socid', 'int');
$action = GETPOST('action', 'aZ09');
$id = GETPOST('id', 'int');
$discard_closed = GETPOST('discardclosed', 'int');
@ -44,28 +42,31 @@ $discard_closed = GETPOST('discardclosed', 'int');
* View
*/
dol_syslog(join(',', $_GET));
dol_syslog("Call ajax projet/ajax/projects.php");
//dol_syslog(join(',', $_GET));
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
// Load translation files required by the page
$langs->load("main");
top_httphead();
if (empty($htmlname)) return;
if (empty($htmlname) && !GETPOST('mode', 'aZ09')) return;
$match = preg_grep('/('.$htmlname.'[0-9]+)/', array_keys($_GET));
sort($match);
$idprod = (!empty($match[0]) ? $match[0] : '');
// Mode to get list of projects
if (!GETPOST('mode', 'aZ09') || GETPOST('mode', 'aZ09') != 'gettasks') {
// When used from jQuery, the search term is added as GET param "term".
$searchkey = (GETPOSTISSET($htmlname) ? GETPOST($htmlname, 'aZ09') : '');
if (!GETPOST($htmlname) && !GETPOST($idprod)) return;
$formproject = new FormProjets($db);
$arrayresult = $formproject->select_projects_list($socid, '', $htmlname, 0, 0, 1, $discard_closed, 0, 0, 1, $searchkey);
}
// When used from jQuery, the search term is added as GET param "term".
$searchkey = ((!empty($idprod) && GETPOST($idprod)) ?GETPOST($idprod) : (GETPOST($htmlname) ?GETPOST($htmlname) : ''));
// Mode to get list of tasks
if (GETPOST('mode', 'aZ09') == 'gettasks') {
$formproject = new FormProjets($db);
$formproject->selectTasks((!empty($$socid) ? $socid : -1), 0, 'taskid', 24, 1, '1', 1, 0, 0, 'maxwidth500', GETPOST('projectid', 'int'), '');
return;
}
$form = new FormProjets($db);
$arrayresult = $form->select_projects_list($socid, '', $htmlname, 0, 0, 1, $discard_closed, 0, 0, 1, $searchkey);
$db->close();