add simple task manager in js

This commit is contained in:
Uwe Steinmann 2020-09-24 16:50:50 +02:00
parent 656cc5843f
commit 05a6917102
2 changed files with 44 additions and 27 deletions

View File

@ -1227,32 +1227,49 @@ $(document).ready(function() { /* {{{ */
});
}); /* }}} */
(function( SeedDMSTask, $, undefined ) { /* {{{ */
var approval_count, review_count, workflow_count;
var checkTasks = function() {
$.ajax({url: '../out/out.Tasks.php',
type: 'GET',
dataType: "json",
data: {action: 'mytasks'},
success: function(data) {
if(data) {
if((typeof data.data.approval != 'undefined' && approval_count != data.data.approval.length) ||
(typeof data.data.review != 'undefined' && review_count != data.data.review.length) ||
(typeof data.data.workflow != 'undefined' && workflow_count != data.data.workflow.length)) {
// $("#menu-tasks").html('Loading').hide().load('../out/out.Tasks.php?action=menutasks').fadeIn('500')
$('#menu-tasks > div.ajax').trigger('update', {folderid: seeddms_folder});
approval_count = typeof data.data.approval != 'undefined' ? data.data.approval.length : 0;
review_count = typeof data.data.review != 'undefined' ? data.data.review.length : 0;
workflow_count = typeof data.data.workflow != 'undefined' ? data.data.workflow.length : 0;
}
}
},
timeout: 3000
});
timeOutId = setTimeout(checkTasks, 30000);
var timeout = 1000;
var counter = 0;
var tasks = Array(
{name: 'checktasks', interval: 15, func:
checkTasks = function() {
$.ajax({url: '../out/out.Tasks.php',
type: 'GET',
dataType: "json",
data: {action: 'mytasks'},
success: function(data) {
if(data) {
if((typeof data.data.approval != 'undefined' && approval_count != data.data.approval.length) ||
(typeof data.data.review != 'undefined' && review_count != data.data.review.length) ||
(typeof data.data.workflow != 'undefined' && workflow_count != data.data.workflow.length)) {
// $("#menu-tasks").html('Loading').hide().load('../out/out.Tasks.php?action=menutasks').fadeIn('500')
$('#menu-tasks > div.ajax').trigger('update', {folderid: seeddms_folder});
approval_count = typeof data.data.approval != 'undefined' ? data.data.approval.length : 0;
review_count = typeof data.data.review != 'undefined' ? data.data.review.length : 0;
workflow_count = typeof data.data.workflow != 'undefined' ? data.data.workflow.length : 0;
}
}
},
timeout: 3000
});
}
}
);
SeedDMSTask.add = function(task) {
tasks.push(task);
}
var updateDropFolder = function() {
$('#menu-dropfolder > div.ajax').trigger('update', {folderid: seeddms_folder});
timeOutId = setTimeout(updateDropFolder, 60000);
SeedDMSTask.run = function() {
for(let task of tasks) {
if(counter % task.interval == 0) {
// console.log("Running task '" + task.name + "'");
task.func();
}
}
//console.log(counter);
counter++;
timeOutId = setTimeout(SeedDMSTask.run, timeout);
}
}( window.SeedDMSTask = window.SeedDMSTask || {}, jQuery )); /* }}} */

View File

@ -182,10 +182,10 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
echo '<script src="'.$this->params['absbaseprefix'].'out/out.'.$this->params['class'].'.php?'.http_build_query($tmp).'"></script>'."\n";
echo '<script src="../styles/'.$this->theme.'/application.js"></script>'."\n";
if($this->params['enablemenutasks'] && isset($this->params['user']) && $this->params['user']) {
$this->addFooterJS('checkTasks();');
$this->addFooterJS('SeedDMSTask.run();');
}
if($this->params['enabledropfolderlist'] && isset($this->params['user']) && $this->params['user']) {
$this->addFooterJS('updateDropFolder();');
$this->addFooterJS("SeedDMSTask.add({name: 'dropfolder', interval: 15, func: function(){\$('#menu-dropfolder > div.ajax').trigger('update', {folderid: seeddms_folder});}});");
}
if($this->footerjs) {
$jscode = "$(document).ready(function () {\n";