Skip to content

Commit

Permalink
[JS] add: ajax and load actions
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-theo committed Apr 29, 2021
1 parent 0712f50 commit 7216738
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 30 deletions.
2 changes: 1 addition & 1 deletion digiriskelement_evaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
<div class="evaluator-assignment">
<div class="evaluator-duration">
<span class="title"><?php echo $langs->trans('Duration'); ?></span>
<?php print '<input type="number" class="duration" name="evaluatorDuration" rows="'.ROWS_2.'" value="'.$conf->global->DIGIRISKDOLIBARR_EVALUATOR_DURATION.'">'; ?>
<?php print '<input type="number" class="duration" name="evaluatorDuration" rows="'.ROWS_2.'" value="'.$conf->global->DIGIRISKDOLIBARR_EVALUATOR_DURATION.'"> min'; ?>
</div>
<div class="evaluator-date">
<span class="title"><?php echo $langs->trans('Date'); ?></span>
Expand Down
7 changes: 4 additions & 3 deletions digiriskelement_risk.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ class="risk-evaluation-cotation cotation"><?php echo $request; ?></div>

// Show here line of result
print '<tr class="oddeven risk-row risk_row_'. $risk->id .'" id="risk_row_'. $risk->id .'">';

print '<tr class="risk-row-content-'. $risk->id . '">';
foreach ($risk->fields as $key => $val)
{
$cssforfield = (empty($val['css']) ? '' : $val['css']);
Expand Down Expand Up @@ -1175,8 +1175,8 @@ class="risk-evaluation-cotation cotation"><?php echo $request; ?></div>
<div class="modal-refresh modal-close"><i class="fas fa-times"></i></div>
</div>
<!-- MODAL RISK EVALUATION LIST CONTENT -->
<div class="modal-content" id="#modalContent">
<ul class="risk-evaluations-list">
<div class="modal-content" id="#modalContent" value="<?php echo $risk->id ?>">
<ul class="risk-evaluations-list risk-evaluations-list-<?php echo $risk->id ?>">
<?php if (!empty($cotationList)) :
foreach ($cotationList as $cotation) : ?>
<li class="risk-evaluation risk-evaluation<?php echo $cotation->id ?>" value="<?php echo $cotation->id ?>">
Expand Down Expand Up @@ -1535,6 +1535,7 @@ class="risk-evaluation-cotation cotation"><?php echo $request; ?></div>

print '</td>';
if (!$i) $totalarray['nbfield']++;
print '</tr>';
print '</tr>'."\n";
$i++;
}
Expand Down
113 changes: 87 additions & 26 deletions js/digiriskdolibarr.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,15 +849,17 @@
window.eoxiaJS.photo.selectPhoto = function( event ) {
let photoID = $(this).attr('value');
let element = $(this).attr('element');
let parent = $(this).closest('.modal-content')

$('.clicked-photo').attr('style', 'none !important');
$('.clicked-photo').removeClass('clicked-photo');
parent.find('.clicked-photo').attr('style', 'none !important');
parent.find('.clicked-photo').removeClass('clicked-photo');

$('.clickable-photo'+photoID).attr('style', 'border: 5px solid #0d8aff !important');
$('.clickable-photo'+photoID).addClass('clicked-photo');
parent.find('.clickable-photo'+photoID).attr('style', 'border: 5px solid #0d8aff !important');
parent.find('.clickable-photo'+photoID).addClass('clicked-photo');

$(this).closest('.'+element+'-photo-container').find('.'+element+'-photo-single .filename').val(parent.find('.clicked-photo .filename').val());
$(this).closest('.'+element+'-photo-container').find('.'+element+'-photo-single img').attr('src' , parent.find('.clicked-photo img').attr('src'));

$(this).closest('.'+element+'-photo-container').find('.'+element+'-photo-single .filename').val($('.clicked-photo .filename').val());
$(this).closest('.'+element+'-photo-container').find('.'+element+'-photo-single img').attr('src' , $('.clicked-photo img').attr('src'));
};

/**
Expand Down Expand Up @@ -898,13 +900,15 @@
contentType: false,
});

$(this).closest('.modal-container').find('.ecm-photo-list').empty();
window.eoxiaJS.loader.display($(this).closest('.modal-container').find('.ecm-photo-list'));
let elementParent = $(this).closest('.modal-container').find('.ecm-photo-list');
elementParent.load( document.URL + ' .ecm-photo-list-');

elementParent.empty();
window.eoxiaJS.loader.display(elementParent);

setTimeout(function(){
elementParent.load( document.URL + ' .ecm-photo-list-');
elementParent.removeClass('wpeo-loader');
}, 1000);
}, 800);
};

/**
Expand Down Expand Up @@ -1068,7 +1072,23 @@
taskPost = '&tasktitle=' + encodeURI(task);
}

$('.fichecenter').load( document.URL + '&action=add' + categoryPost + descriptionPost + methodPost + cotationPost + criteres + photoPost + commentPost + taskPost + ' .fichecenter');
$.ajax({
url: document.URL + '&action=add' + categoryPost + descriptionPost + methodPost + cotationPost + criteres + photoPost + commentPost + taskPost,
type: "POST",
processData: false,
contentType: false
});

let elementParent = $('.div-table-responsive');

elementParent.empty();
window.eoxiaJS.loader.display($('.fichecenter'));
elementParent.load( document.URL + ' .div-table-responsive');
elementParent.find('.titre.inlineblock').load( document.URL + ' .opacitymedium.colorblack.paddingleft');
setTimeout(function(){
$('.fichecenter').removeClass('wpeo-loader');
}, 800);

};

/**
Expand Down Expand Up @@ -1114,7 +1134,24 @@
descriptionPost = '&riskComment=' + encodeURI(description);
}

$(this).closest('.div-table-responsive').load( document.URL + '&action=saveRisk&riskID=' + editedRiskId + categoryPost + descriptionPost + ' .div-table-responsive');
$.ajax({
url: document.URL + '&action=saveRisk&riskID=' + editedRiskId + categoryPost + descriptionPost,
type: "POST",
processData: false,
contentType: false
});

let elementParent = $('.div-table-responsive:not(.list-titre)');

window.eoxiaJS.loader.display($(this).closest('.risk-row-content-' + editedRiskId));

setTimeout(function(){
elementParent.empty()
elementParent.load( document.URL + ' .div-table-responsive');
$(this).closest('.risk-row-content-' + editedRiskId).removeClass('wpeo-loader');
}, 800);

//$(this).closest('.div-table-responsive').load( document.URL + '&action=saveRisk&riskID=' + editedRiskId + categoryPost + descriptionPost + ' .div-table-responsive');
};

/**
Expand Down Expand Up @@ -1224,23 +1261,16 @@
* @return {int}
*/
window.eoxiaJS.evaluation.getDynamicScale = function (cotation) {
let scale = 0
switch (true) {
case (cotation === 0):
case (cotation < 48):
scale = 1
return scale;
return 1;
case (cotation < 51):
scale = 2
return scale;
return 2;
case (cotation < 79):
scale = 3
return scale;
return 3;
case (cotation < 101):
scale = 4
return scale;
case (cotation === 0):
scale = 1
return scale;
return 4;
}
};

Expand Down Expand Up @@ -1293,7 +1323,22 @@
}
})

$(this).closest('.fichecenter').load( document.URL + '&action=addEvaluation' + riskToAssignPost + methodPost + cotationPost + criteres + photoPost + commentPost + ' .fichecenter');
$.ajax({
url: document.URL + '&action=addEvaluation' + riskToAssignPost + methodPost + cotationPost + criteres + photoPost + commentPost,
type: "POST",
processData: false,
contentType: false
});

let elementParent = $('.div-table-responsive:not(.list-titre)');

window.eoxiaJS.loader.display($(this).closest('.risk-row-content-' + riskToAssign));

setTimeout(function(){
elementParent.empty()
elementParent.load( document.URL + ' .div-table-responsive');
$(this).closest('.risk-row-content-' + riskToAssign).removeClass('wpeo-loader');
}, 800);
};

/**
Expand Down Expand Up @@ -1360,7 +1405,23 @@
}
})

element.load( document.URL + '&action=saveEvaluation&evaluationID=' + evaluationID + methodPost + cotationPost + criteres + photoPost + commentPost + ' .risk-evaluation'+evaluationID);
$.ajax({
url: document.URL + '&action=saveEvaluation&evaluationID=' + evaluationID + methodPost + cotationPost + criteres + photoPost + commentPost,
type: "POST",
processData: false,
contentType: false
});

let elementParent = $(this).closest('.modal-content');
let riskId = elementParent.attr('value');
window.eoxiaJS.loader.display(elementParent);
elementParent.empty()

setTimeout(function(){
elementParent.load( document.URL + ' .risk-evaluations-list-'+riskId);
elementParent.removeClass('wpeo-loader');
}, 800);

element.find('#risk_evaluation_edit'+evaluationID).removeClass('modal-active');
};

Expand Down

0 comments on commit 7216738

Please sign in to comment.