
Please wait. This can take some minutes ...
Project download
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
Project price only 1 $
You can buy this project and download/modify it how often you want.
Information
com.xresch.cfw.features.jobs.resources.cfw_jobs.js Maven / Gradle / Ivy
/**************************************************************************************************************
* This file contains various javascript examples.
* For your convenience, this code is highly redundant for eassier copy&paste.
* @author Reto Scheiwiller, (c) Copyright 2019
**************************************************************************************************************/
var CFWJOBS_URL = "./jobs";
var CFWJOBS_LAST_OPTIONS = null;
/******************************************************************
* Reset the view.
******************************************************************/
function cfwjobs_createTabs(){
var pillsTab = $("#pills-tab");
if(pillsTab.length == 0){
var list = $('');
list.append('- My Jobs
');
if(CFW.hasPermission("Jobs: Admin")){
list.append('- Admin
');
}
var parent = $("#cfw-container");
parent.append(list);
parent.append('');
}
}
/******************************************************************
* Create Role
******************************************************************/
function cfwjobs_add_selectTask(){
params = {action: "fetch", item: "tasks"};
CFW.http.getJSON(CFWJOBS_URL, params,
function(data) {
if(data.success){
//-------------------------
// Sort by Name
var sortedTasks = _.sortBy(data.payload, ['NAME']);
//-------------------------
// Select Button
var actionButtons = [];
actionButtons.push(
function (record, id){
return '';
});
//-----------------------------------
// Render Data
var rendererSettings = {
data: sortedTasks,
idfield: 'NAME',
visiblefields: ['NAME', 'DESCRIPTION'],
actions: actionButtons,
rendererSettings: {
table: {narrow: true, filterable: true}
},
};
var result = CFW.render.getRenderer('table').render(rendererSettings);
CFW.ui.showModalMedium(
"Select Task",
result,
"CFW.cache.clearCache(); cfwjobs_draw(CFWJOBS_LAST_OPTIONS)"
);
}
});
}
/******************************************************************
* Create Role
******************************************************************/
function cfwjobs_add_createJob(taskname){
var createJobDiv = $('');
CFW.ui.showModalMedium(
"Create Job",
createJobDiv,
"CFW.cache.clearCache(); cfwjobs_draw(CFWJOBS_LAST_OPTIONS)"
);
//-----------------------------------
// Load Form
//-----------------------------------
CFW.http.createForm(CFWJOBS_URL, {action: "getform", item: "createjob", taskname: taskname}, createJobDiv);
}
/******************************************************************
* Edit Role
******************************************************************/
function cfwjobs_edit(id){
//-----------------------------------
// Details
//-----------------------------------
var detailsDiv = $('');
CFW.ui.showModalMedium(
"Edit Job",
detailsDiv,
"CFW.cache.clearCache(); cfwjobs_draw(CFWJOBS_LAST_OPTIONS)"
);
//-----------------------------------
// Load Form
//-----------------------------------
CFW.http.createForm(CFWJOBS_URL, {action: "getform", item: "editjob", id: id}, detailsDiv);
}
/******************************************************************
* Delete
******************************************************************/
function cfwjobs_delete(id){
params = {action: "delete", item: "job", id: id};
CFW.http.getJSON(CFWJOBS_URL, params,
function(data) {
if(data.success){
//CFW.ui.showModalSmall('Success!', 'The selected '+item+' were deleted.');
//clear cache and reload data
CFW.cache.clearCache();
cfwjobs_draw(CFWJOBS_LAST_OPTIONS);
}else{
CFW.ui.showModalSmall("Error!", 'The selected person could NOT be deleted.');
}
});
}
/******************************************************************
* Execute
******************************************************************/
function cfwjobs_execute(id){
params = {action: "execute", item: "job", id: id};
CFW.http.getJSON(CFWJOBS_URL, params,
function(data) {
if(data.success){
//do nothing
}
});
}
/******************************************************************
* Delete
******************************************************************/
function cfwjobs_duplicate(id){
params = {action: "duplicate", item: "job", id: id};
CFW.http.getJSON(CFWJOBS_URL, params,
function(data) {
if(data.success){
CFW.cache.clearCache();
cfwjobs_draw(CFWJOBS_LAST_OPTIONS);
}
});
}
/******************************************************************
*
******************************************************************/
function cfwjobs_printMyJobs(){
cfwjobs_printJobs('myjoblist');
}
/******************************************************************
*
******************************************************************/
function cfwjobs_printAdminJobs(){
cfwjobs_printJobs('adminjoblist');
}
/******************************************************************
*
******************************************************************/
function cfwjobs_formatMessages(record, value){
//-------------------------
// Handle Null
if(CFW.utils.isNullOrEmpty(value)
|| value == "[]"
|| value.length == 0
|| value.length == undefined){
return ' ';
}
//-------------------------
// Find highest severity INFO, SUCCESS, WARNING, ERROR
// Create Popup message
var highestSeverity = 'INFO';
var popupMessage = 'Message(s) of last execution:';
for(let index in value){
current = value[index];
popupMessage += '- '+current.type+': '+current.message+'
'
if(highestSeverity != 'ERROR'){
if(current.type == 'ERROR'){ highestSeverity = 'ERROR'; continue; }
if(highestSeverity != 'WARNING'){
if(current.type == 'WARNING'){ highestSeverity = 'WARNING'; continue; }
if(highestSeverity != 'SUCCESS'){
if(current.type == 'SUCCESS'){ highestSeverity = 'SUCCESS'; continue; }
}
}
}
}
popupMessage += '
';
//-------------------------
// Create Icon
var icon;
switch(highestSeverity){
case 'INFO': icon = $(''); break;
case 'SUCCESS': icon = $(''); break;
case 'WARNING': icon = $(''); break;
case 'ERROR': icon = $(''); break;
}
//-------------------------
// add Popover
icon.popover({
trigger: 'hover',
html: true,
placement: 'auto',
boundary: 'window',
// title: 'Details',
sanitize: false,
content: popupMessage
})
return icon;
}
/******************************************************************
* Full example using the dataviewer renderer.
*
* @param data as returned by CFW.http.getJSON()
******************************************************************/
function cfwjobs_printJobs(itemType){
var parent = $("#tab-content");
parent.html("");
//--------------------------------
// Button
var addButton = $('');
parent.append(addButton);
//======================================
// Prepare actions
var actionButtons = [];
//-------------------------
// Execute Button
actionButtons.push(
function (record, id){
return '';
});
//-------------------------
// Edit Button
actionButtons.push(
function (record, id){
return '';
});
//-------------------------
// Duplicate Button
actionButtons.push(
function (record, id){
return '';
});
//-------------------------
// Delete Button
actionButtons.push(
function (record, id){
return '';
});
//-------------------------
// Visible Fields
var fieldsWithOwner = ['JSON_LASTRUN_MESSAGES', 'PK_ID', 'OWNER', 'JOB_NAME', 'TASK_NAME', 'DESCRIPTION', 'IS_ENABLED', 'SCHEDULE_START', 'SCHEDULE_END', 'SCHEDULE_INTERVAL', 'JSON_PROPERTIES', 'LAST_RUN_TIME']
var fieldsWithoutOwner = ['JSON_LASTRUN_MESSAGES', 'PK_ID', 'JOB_NAME', 'TASK_NAME', 'DESCRIPTION', 'IS_ENABLED', 'SCHEDULE_START', 'SCHEDULE_END', 'SCHEDULE_INTERVAL', 'JSON_PROPERTIES', 'LAST_RUN_TIME']
var visiblefields;
if(itemType == 'adminjoblist'){
visiblefields = fieldsWithOwner;
}else{
visiblefields = fieldsWithoutOwner;
}
//-----------------------------------
// Render Data
var rendererSettings = {
data: null,
idfield: 'PK_ID',
bgstylefield: null,
textstylefield: null,
titlefields: ['JOB_NAME'],
titleformat: '{0}',
visiblefields: visiblefields,
labels: {
JSON_LASTRUN_MESSAGES: "Messages",
PK_ID: "ID",
IS_ENABLED: "Enabled",
JSON_SCHEDULE: "Schedule",
JSON_PROPERTIES: "Properties",
},
customizers: {
JSON_LASTRUN_MESSAGES: cfwjobs_formatMessages,
DESCRIPTION: function(record, value) {
return ''+CFW.utils.nullTo(value, " ")+'';
},
IS_ENABLED: function(record, value) {
return ''+value+'';
},
//JSON_SCHEDULE: function(record, value) { return CFW.format.cfwSchedule(value); },
SCHEDULE_START: function(record, value) { return CFW.format.epochToTimestamp(value); },
SCHEDULE_END: function(record, value) {
if(value == null) return " ";
if(isNaN(value)){
return value;
}else{
return CFW.format.epochToTimestamp(parseInt(value));
}
},
LAST_RUN_TIME: function(record, value) { return CFW.format.epochToTimestamp(value); },
JSON_PROPERTIES: function(record, value) {
if(value.children != null
&& value.children.length == 0){
delete value.children;
}
let div = $('');
div.append(CFW.format.objectToHTMLList(value));
return div;
},
},
actions: actionButtons,
// bulkActions: {
// "Edit": function (elements, records, values){ alert('Edit records '+values.join(',')+'!'); },
// "Delete": function (elements, records, values){ $(elements).remove(); },
// },
// bulkActionsPos: "both",
rendererSettings: {
dataviewer: {
storeid: itemType,
sortfields: fieldsWithoutOwner,
datainterface: {
url: CFWJOBS_URL,
item: itemType,
//preprocess: function(data){ CFW.format.splitCFWSchedule(data, 'JSON_SCHEDULE') }
},
renderers: [
{ label: 'Table',
name: 'table',
renderdef: {
labels: {
JSON_LASTRUN_MESSAGES: " ",
PK_ID: "ID",
IS_ENABLED: "Enabled",
JSON_SCHEDULE: "Schedule",
JSON_PROPERTIES: "Properties",
},
rendererSettings: {
table: { filterable: false, narrow: true},
},
}
},
// { label: 'Smaller Table',
// name: 'table',
// renderdef: {
// visiblefields: ['FIRSTNAME', 'LASTNAME', 'EMAIL', 'LIKES_TIRAMISU'],
// actions: [],
// rendererSettings: {
// table: {filterable: false, narrow: true},
// },
// }
// },
{ label: 'Panels',
name: 'panels',
renderdef: {
labels: { JSON_LASTRUN_MESSAGES: "Messages Last Run" }
}
},
{ label: 'Cards',
name: 'cards',
renderdef: {
labels: { JSON_LASTRUN_MESSAGES: "Messages Last Run" }
}
},
{ label: 'Tiles',
name: 'tiles',
renderdef: {
visiblefields: ['PK_ID', 'TASK_NAME'],
rendererSettings: {
tiles: {
popover: false,
border: '2px solid black'
},
},
}
},
{ label: 'CSV',
name: 'csv',
renderdef: {
labels: { JSON_LASTRUN_MESSAGES: "Messages Last Run" }
}
},
{ label: 'JSON',
name: 'json',
renderdef: {}
}
],
},
},
};
var renderResult = CFW.render.getRenderer('dataviewer').render(rendererSettings);
parent.append(renderResult);
}
/******************************************************************
* Main method for building the different views.
*
* @param options Array with arguments:
* {
* tab: 'myjoblist|adminjoblist',
* }
* @return
******************************************************************/
function cfwjobs_initialDraw(){
cfwjobs_createTabs();
//-----------------------------------
// Restore last tab
var tabToDisplay = CFW.cache.retrieveValueForPage("cfwjobs-lasttab", "myjoblist");
$('#cfw-container').css('max-width', '100%');
$('#tab-'+tabToDisplay).addClass('active');
cfwjobs_draw({tab: tabToDisplay});
}
function cfwjobs_draw(options){
CFWJOBS_LAST_OPTIONS = options;
CFW.cache.storeValueForPage("cfwjobs-lasttab", options.tab);
$("#tab-content").html("");
CFW.ui.toggleLoader(true);
window.setTimeout(
function(){
switch(options.tab){
case "myjoblist": cfwjobs_printMyJobs();
break;
case "adminjoblist": cfwjobs_printAdminJobs();
break;
default: CFW.ui.addToastDanger('This tab is unknown: '+options.tab);
}
CFW.ui.toggleLoader(false);
}, 50);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy