Skip to content

Commit

Permalink
Merge pull request #441 from evarisk-theo/fix_task_attribution_js
Browse files Browse the repository at this point in the history
#285 [Task] fix: submitting form JS
  • Loading branch information
nicolas-eoxia authored Jul 24, 2023
2 parents 73514c4 + 3120963 commit aea41cb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
2 changes: 1 addition & 1 deletion js/dolisirh.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions js/modules/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ window.dolisirh.task.event = function() {
$(document).on('click', '.show-only-tasks-with-timespent', window.dolisirh.task.showOnlyTasksWithTimeSpent);
$(document).on('click', '.timespent-create', window.dolisirh.task.createTimeSpent);
$(document).on('click', '.toggleTaskFavorite', window.dolisirh.task.toggleTaskFavorite);
$(document).on('submit', '#addtimeform', window.dolisirh.task.searchForm );
};

/**
Expand Down Expand Up @@ -286,6 +287,16 @@ window.dolisirh.task.toggleTaskFavorite = function() {
});
};

/**
* Add more open modal data.
*
* @memberof DoliSIRH_Task
*
* @since 1.4.0
* @version 1.4.0
*
* @return {void}
*/
window.saturne.modal.addMoreOpenModalData = function(modalToOpen, elementFrom) {
let cell = elementFrom.find('.timespent');

Expand All @@ -299,3 +310,40 @@ window.saturne.modal.addMoreOpenModalData = function(modalToOpen, elementFrom) {
$('.timespent-create').attr('value', taskID);
$('.timespent-date').html(date);
};

/**
* Submit form dynamically to avoid 406 errors.
*
* @memberof DoliSIRH_Task
*
* @since 1.4.0
* @version 1.4.0
*
* @return {void}
*/
window.dolisirh.task.searchForm = function(event) {
event.preventDefault()

var addTimeForm = document.getElementById('addtimeform');
var formData = new FormData(addTimeForm);
let newFormData = new FormData();

for (const pair of formData.entries()) {
if (pair[1] != '') {
newFormData.append(pair[0], pair[1])
}
}
window.saturne.loader.display($('#addtimeform'));

$.ajax({
url: document.URL,
type: "POST",
data: newFormData,
processData: false,
contentType: false,
success: function (resp) {
$('.wpeo-loader').removeClass('wpeo-loader');
$('#addtimeform').html($(resp).find('#addtimeform').children())
},
});
}
15 changes: 4 additions & 11 deletions view/timespent_range.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,12 @@
$action = '';
}

if ($action == 'add_time' && $permissiontoRead && GETPOST('assigntask')) {
if ($action == 'add_time' && $permissiontoRead && GETPOST('assigned_task_id') > 0) {
$action = 'assign_task';
$error = 0;

if ($taskID > 0) {
$result = $task->fetch($taskID);
if ($result < 0) {
$error++;
}
} else {
setEventMessages($langs->transnoentitiesnoconv('ErrorFieldRequired', $langs->transnoentitiesnoconv('Task')), [], 'errors');
$error++;
}
$task->fetch(GETPOST('assigned_task_id'));

if (!GETPOST('type')) {
setEventMessages($langs->transnoentitiesnoconv('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), [], 'errors');
$error++;
Expand Down Expand Up @@ -462,7 +455,7 @@
}
print '<div class="taskiddiv inline-block">';
print img_picto('', 'projecttask', 'class="pictofixedwidth"');
$formProject->selectTasks(-1, $taskID, 'task_id', 32, 0, '-- ' . $langs->trans('ChooseANotYetAssignedTask') . ' --', 1, 0, 0, '', '', 'all', $userTmp);
$formProject->selectTasks(-1, $taskID, 'assigned_task_id', 32, 0, '-- ' . $langs->trans('ChooseANotYetAssignedTask') . ' --', 1, 0, 0, '', '', 'all', $userTmp);
print '</div>';
print ' ' . $formCompany->selectTypeContact($task, 46, 'type', 'internal', 'rowid', 0, 'maxwidth150onsmartphone');
print '<input type="submit" class="button valignmiddle smallonsmartphone" name="assigntask" value="' . dol_escape_htmltag($titleAssignTask) . '">';
Expand Down

0 comments on commit aea41cb

Please sign in to comment.