diff --git a/js/dolisirh.min.js b/js/dolisirh.min.js index 45625dd..f4b47bd 100644 --- a/js/dolisirh.min.js +++ b/js/dolisirh.min.js @@ -1 +1 @@ -"use strict";window.dolisirh||(window.dolisirh={},window.dolisirh.scriptsLoaded=!1),window.dolisirh.scriptsLoaded||(window.dolisirh.init=function(){window.dolisirh.load_list_script()},window.dolisirh.load_list_script=function(){if(!window.dolisirh.scriptsLoaded){let t=void 0,i=void 0;for(t in window.dolisirh)for(i in window.dolisirh[t].init&&window.dolisirh[t].init(),window.dolisirh[t])window.dolisirh[t]&&window.dolisirh[t][i]&&window.dolisirh[t][i].init&&window.dolisirh[t][i].init();window.dolisirh.scriptsLoaded=!0}},window.dolisirh.refresh=function(){let t=void 0,i=void 0;for(t in window.dolisirh)for(i in window.dolisirh[t].refresh&&window.dolisirh[t].refresh(),window.dolisirh[t])window.dolisirh[t]&&window.dolisirh[t][i]&&window.dolisirh[t][i].refresh&&window.dolisirh[t][i].refresh()},$(document).ready(window.dolisirh.init)),window.dolisirh.certificate={},window.dolisirh.certificate.init=function(){window.dolisirh.certificate.event()},window.dolisirh.certificate.event=function(){$(document).on("change","#element_type",window.dolisirh.certificate.reloadField)},window.dolisirh.certificate.reloadField=function(){var t=$(this).val(),i=window.saturne.toolbox.getToken(),e=window.saturne.toolbox.getQuerySeparator(document.URL);$.ajax({url:document.URL+e+"element_type="+t+"&token="+i,type:"POST",processData:!1,contentType:!1,success:function(t){$(".field_element_type").replaceWith($(t).find(".field_element_type")),$(".field_fk_element").replaceWith($(t).find(".field_fk_element"))},error:function(){}})},window.dolisirh.task={},window.dolisirh.task.init=function(){window.dolisirh.task.event()},window.dolisirh.task.event=function(){$(document).on("click",".auto-fill-timespent",window.dolisirh.task.addTimeSpent),$(document).on("click",".auto-fill-timespent-project",window.dolisirh.task.divideTimeSpent),$(document).on("click",".show-only-favorite-tasks",window.dolisirh.task.showOnlyFavoriteTasks),$(document).on("click",".show-only-tasks-with-timespent",window.dolisirh.task.showOnlyTasksWithTimeSpent),$(document).on("click",".select-logic-operators-mode",window.dolisirh.task.selectLogicOperatorsMode),$(document).on("click",".show-closed-projects",window.dolisirh.task.showClosedProjects),$(document).on("click",".show-sticky-total-timespent-info",window.dolisirh.task.showStickyTotalTimeSpentInfo),$(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)},window.dolisirh.task.addTimeSpent=function(){var t=$(".non-consumed-time-minute").val(),i=$(".non-consumed-time-hour").val();$(".inputhour").val(""),$(".inputminute").val(""),$(this).closest(".duration").find(".inputhour").val(i),$(this).closest(".duration").find(".inputminute").val(t)},window.dolisirh.task.divideTimeSpent=function(){var t=$(this).closest(".project-line").attr("id");let i,e;var o=+$(".non-consumed-time-minute").val()+60*+$(".non-consumed-time-hour").val(),n=$("."+t).length;let s=parseInt(o/n);$(".inputhour").val(""),$(".inputminute").val(""),$("."+t).each(function(){e=parseInt(s/60),i=s%60,$(this).find(".inputhour").val(e),$(this).find(".inputminute").val(i)})},window.dolisirh.task.showOnlyFavoriteTasks=function(){var t=$(".id-container").find('input[name="token"]').val();let i="?";document.URL.match(/\?/)&&(i="&");let e;e=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=show_only_favorite_tasks&token="+t,type:"POST",processData:!1,data:JSON.stringify({showOnlyFavoriteTasks:e}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.showOnlyTasksWithTimeSpent=function(){var t=$(".id-container").find('input[name="token"]').val();let i="?";document.URL.match(/\?/)&&(i="&");let e;e=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=show_only_tasks_with_timespent&token="+t,type:"POST",processData:!1,data:JSON.stringify({showOnlyTasksWithTimeSpent:e}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.selectLogicOperatorsMode=function(){var t=window.saturne.toolbox.getToken(),i=window.saturne.toolbox.getQuerySeparator(document.URL);let e;e=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=select_logic_operators_mode&token="+t,type:"POST",processData:!1,data:JSON.stringify({selectLogicOperatorsMode:e}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.showClosedProjects=function(){var t=window.saturne.toolbox.getToken(),i=window.saturne.toolbox.getQuerySeparator(document.URL);let e;e=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=show_closed_projects&token="+t,type:"POST",processData:!1,data:JSON.stringify({showClosedProjects:e}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.showStickyTotalTimeSpentInfo=function(){var t=window.saturne.toolbox.getToken(),i=window.saturne.toolbox.getQuerySeparator(document.URL);let e;e=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=show_sticky_total_timespent_info&token="+t,type:"POST",processData:!1,data:JSON.stringify({showStickyTotalTimeSpentInfo:e}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.createTimeSpent=function(){var t=$(this).attr("value"),i=$(this).closest(".timespent-add-modal").find(".timespent-container"),e=i.find(".timespent-timestamp").val(),o=i.find(".timespent-datehour").val(),n=i.find(".timespent-datemin").val(),s=i.find(".timespent-comment").val(),a=i.find(".timespent-hour").val(),i=i.find(".timespent-min").val(),d=(window.saturne.loader.display($(this)),$(".fiche").find('input[name="token"]').val());let r="?";document.URL.match(/\?/)&&(r="&"),$.ajax({url:document.URL+r+"action=add_timespent&token="+d,data:JSON.stringify({taskID:t,timestamp:e,datehour:o,datemin:n,comment:s,hour:a,min:i}),type:"POST",processData:!1,contentType:!1,success:function(t){$(".loader-spin").remove(),$(".wpeo-loader").removeClass("wpeo-loader"),$("#timespent").removeClass("modal-active"),$("#tablelines3").html($(t).find("#tablelines3"))},error:function(t){}})},window.dolisirh.task.toggleTaskFavorite=function(){let i=$(this).attr("value");var t=$('form[name="addtime"]').find('input[name="token"]').val();let e="?";document.URL.match(/\?/)&&(e="&"),$.ajax({url:document.URL+e+"action=toggleTaskFavorite&taskId="+i+"&token="+t,type:"POST",processData:!1,contentType:!1,success:function(){var t=$("#"+i);t.hasClass("fas")?(t.removeClass("fas"),t.addClass("far")):t.hasClass("far")&&(t.removeClass("far"),t.addClass("fas"))},error:function(t){}})},window.saturne.modal.addMoreOpenModalData=function(t,i){var i=i.find(".timespent"),e=i.attr("data-task-id"),o=i.attr("data-timestamp"),n=i.attr("data-cell"),i=i.attr("data-date");$(".timespent-taskid").val(e),$(".timespent-timestamp").val(o),$(".timespent-cell").val(n),$(".timespent-create").attr("value",e),$(".timespent-date").html(i)},window.dolisirh.task.searchForm=function(t){t.preventDefault();var t=document.getElementById("addtimeform"),t=new FormData(t),i=new FormData;for(const e of t.entries())""!=e[1]&&i.append(e[0],e[1]);window.saturne.loader.display($("#addtimeform"));t=new URL(document.URL);t.searchParams.set("search_user_id",i.get("search_user_id")),window.history.pushState({},"",t.href),$.ajax({url:t.href,type:"POST",data:i,processData:!1,contentType:!1,success:function(t){$(".wpeo-loader").removeClass("wpeo-loader"),$("#addtimeform").html($(t).find("#addtimeform").children())}})}; \ No newline at end of file +"use strict";window.dolisirh||(window.dolisirh={},window.dolisirh.scriptsLoaded=!1),window.dolisirh.scriptsLoaded||(window.dolisirh.init=function(){window.dolisirh.load_list_script()},window.dolisirh.load_list_script=function(){if(!window.dolisirh.scriptsLoaded){let t=void 0,i=void 0;for(t in window.dolisirh)for(i in window.dolisirh[t].init&&window.dolisirh[t].init(),window.dolisirh[t])window.dolisirh[t]&&window.dolisirh[t][i]&&window.dolisirh[t][i].init&&window.dolisirh[t][i].init();window.dolisirh.scriptsLoaded=!0}},window.dolisirh.refresh=function(){let t=void 0,i=void 0;for(t in window.dolisirh)for(i in window.dolisirh[t].refresh&&window.dolisirh[t].refresh(),window.dolisirh[t])window.dolisirh[t]&&window.dolisirh[t][i]&&window.dolisirh[t][i].refresh&&window.dolisirh[t][i].refresh()},$(document).ready(window.dolisirh.init)),window.dolisirh.certificate={},window.dolisirh.certificate.init=function(){window.dolisirh.certificate.event()},window.dolisirh.certificate.event=function(){$(document).on("change","#element_type",window.dolisirh.certificate.reloadField)},window.dolisirh.certificate.reloadField=function(){var t=$(this).val(),i=window.saturne.toolbox.getToken(),o=window.saturne.toolbox.getQuerySeparator(document.URL);$.ajax({url:document.URL+o+"element_type="+t+"&token="+i,type:"POST",processData:!1,contentType:!1,success:function(t){$(".field_element_type").replaceWith($(t).find(".field_element_type")),$(".field_fk_element").replaceWith($(t).find(".field_fk_element"))},error:function(){}})},window.dolisirh.task={},window.dolisirh.task.init=function(){window.dolisirh.task.event()},window.dolisirh.task.event=function(){$(document).on("click",".auto-fill-timespent",window.dolisirh.task.addTimeSpent),$(document).on("click",".auto-fill-timespent-project",window.dolisirh.task.divideTimeSpent),$(document).on("click",".show-only-favorite-tasks",window.dolisirh.task.showOnlyFavoriteTasks),$(document).on("click",".show-only-tasks-with-timespent",window.dolisirh.task.showOnlyTasksWithTimeSpent),$(document).on("click",".select-logic-operators-mode",window.dolisirh.task.selectLogicOperatorsMode),$(document).on("click",".show-closed-projects",window.dolisirh.task.showClosedProjects),$(document).on("click",".show-sticky-total-timespent-info",window.dolisirh.task.showStickyTotalTimeSpentInfo),$(document).on("click",".timespent-create",window.dolisirh.task.createTimeSpent),$(document).on("click",".toggleTaskFavorite",window.dolisirh.task.toggleTaskFavorite)},window.dolisirh.task.addTimeSpent=function(){var t=$(".non-consumed-time-minute").val(),i=$(".non-consumed-time-hour").val();$(".inputhour").val(""),$(".inputminute").val(""),$(this).closest(".duration").find(".inputhour").val(i),$(this).closest(".duration").find(".inputminute").val(t)},window.dolisirh.task.divideTimeSpent=function(){var t=$(this).closest(".project-line").attr("id");let i,o;var e=+$(".non-consumed-time-minute").val()+60*+$(".non-consumed-time-hour").val(),n=$("."+t).length;let s=parseInt(e/n);$(".inputhour").val(""),$(".inputminute").val(""),$("."+t).each(function(){o=parseInt(s/60),i=s%60,$(this).find(".inputhour").val(o),$(this).find(".inputminute").val(i)})},window.dolisirh.task.showOnlyFavoriteTasks=function(){var t=$(".id-container").find('input[name="token"]').val();let i="?";document.URL.match(/\?/)&&(i="&");let o;o=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=show_only_favorite_tasks&token="+t,type:"POST",processData:!1,data:JSON.stringify({showOnlyFavoriteTasks:o}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.showOnlyTasksWithTimeSpent=function(){var t=$(".id-container").find('input[name="token"]').val();let i="?";document.URL.match(/\?/)&&(i="&");let o;o=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=show_only_tasks_with_timespent&token="+t,type:"POST",processData:!1,data:JSON.stringify({showOnlyTasksWithTimeSpent:o}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.selectLogicOperatorsMode=function(){var t=window.saturne.toolbox.getToken(),i=window.saturne.toolbox.getQuerySeparator(document.URL);let o;o=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=select_logic_operators_mode&token="+t,type:"POST",processData:!1,data:JSON.stringify({selectLogicOperatorsMode:o}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.showClosedProjects=function(){var t=window.saturne.toolbox.getToken(),i=window.saturne.toolbox.getQuerySeparator(document.URL);let o;o=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=show_closed_projects&token="+t,type:"POST",processData:!1,data:JSON.stringify({showClosedProjects:o}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.showStickyTotalTimeSpentInfo=function(){var t=window.saturne.toolbox.getToken(),i=window.saturne.toolbox.getQuerySeparator(document.URL);let o;o=$(this).is(":checked")?1:0,$.ajax({url:document.URL+i+"action=show_sticky_total_timespent_info&token="+t,type:"POST",processData:!1,data:JSON.stringify({showStickyTotalTimeSpentInfo:o}),contentType:!1,success:function(){window.location.reload()},error:function(){}})},window.dolisirh.task.createTimeSpent=function(){var t=$(this).attr("value"),i=$(this).closest(".timespent-add-modal").find(".timespent-container"),o=i.find(".timespent-timestamp").val(),e=i.find(".timespent-datehour").val(),n=i.find(".timespent-datemin").val(),s=i.find(".timespent-comment").val(),a=i.find(".timespent-hour").val(),i=i.find(".timespent-min").val(),d=(window.saturne.loader.display($(this)),$(".fiche").find('input[name="token"]').val());let r="?";document.URL.match(/\?/)&&(r="&"),$.ajax({url:document.URL+r+"action=add_timespent&token="+d,data:JSON.stringify({taskID:t,timestamp:o,datehour:e,datemin:n,comment:s,hour:a,min:i}),type:"POST",processData:!1,contentType:!1,success:function(t){$(".loader-spin").remove(),$(".wpeo-loader").removeClass("wpeo-loader"),$("#timespent").removeClass("modal-active"),$("#tablelines3").html($(t).find("#tablelines3"))},error:function(t){}})},window.dolisirh.task.toggleTaskFavorite=function(){let i=$(this).attr("value");var t=$('form[name="addtime"]').find('input[name="token"]').val();let o="?";document.URL.match(/\?/)&&(o="&"),$.ajax({url:document.URL+o+"action=toggleTaskFavorite&taskId="+i+"&token="+t,type:"POST",processData:!1,contentType:!1,success:function(){var t=$("#"+i);t.hasClass("fas")?(t.removeClass("fas"),t.addClass("far")):t.hasClass("far")&&(t.removeClass("far"),t.addClass("fas"))},error:function(t){}})},window.saturne.modal.addMoreOpenModalData=function(t,i){var i=i.find(".timespent"),o=i.attr("data-task-id"),e=i.attr("data-timestamp"),n=i.attr("data-cell"),i=i.attr("data-date");$(".timespent-taskid").val(o),$(".timespent-timestamp").val(e),$(".timespent-cell").val(n),$(".timespent-create").attr("value",o),$(".timespent-date").html(i)}; \ No newline at end of file diff --git a/js/modules/task.js b/js/modules/task.js index 5fcb6df..9ba6d49 100644 --- a/js/modules/task.js +++ b/js/modules/task.js @@ -68,7 +68,6 @@ window.dolisirh.task.event = function() { $(document).on('click', '.show-sticky-total-timespent-info', window.dolisirh.task.showStickyTotalTimeSpentInfo); $(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 ); }; /** @@ -421,46 +420,3 @@ 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')); - - let url = new URL(document.URL); - url.searchParams.set('search_user_id', newFormData.get('search_user_id')); - - // rewrite url without reload - window.history.pushState({}, '', url.href); - - $.ajax({ - url: url.href, - type: "POST", - data: newFormData, - processData: false, - contentType: false, - success: function (resp) { - $('.wpeo-loader').removeClass('wpeo-loader'); - $('#addtimeform').html($(resp).find('#addtimeform').children()) - }, - }); -}