';
if(config.buttons.btn_accept != '') {
html += '
' + config.buttons.btn_accept + '';
}
if(value.configuration.buttons.btn_rework != '') {
html += '
' + config.buttons.btn_rework + '';
}
if(value.configuration.buttons.btn_decline != '') {
html += '
' + config.buttons.btn_decline + '';
}
jQuery('.confirmation_container').append(html);
jQuery('.confirmation_container').slideDown();
break;
case 'requestValues':
continueWorkflow(value.configuration.execid, value.configuration.crmid, value.configuration.blockid);
return false;
break;
case 'message':
WorkflowRecordMessages.push(value.configuration);
break;
}
});
this.parseMessages();
}, this));
};
this.generateBtnTrigger = function(buttons) {
jQuery('.wfdButtonHeaderbutton').remove();
if(typeof buttons.headerbtn != 'undefined') {
var html = '';
jQuery.each(buttons.headerbtn, $.proxy(function(index, value) {
var rand = Math.floor(Math.random() * 9999999) + 1000000;
if(value.color != '') {
var cssStyle = 'color:' + value.textcolor + ';background-color: ' + value.color + ';background-image:none;';
} else {
var cssStyle = ''
}
html += '
';
}, this));
jQuery('#appnav .nav ').prepend('' + html + '');
jQuery('.wfdButtonHeaderbutton').on('click', function(e) {
var target = jQuery(e.currentTarget);
var workflowObj = new Workflow();
if(FlexUtils('Workflow2').getViewMode() == 'listview') {
workflowObj.execute(target.data('id'), 0);
} else {
workflowObj.execute(target.data('id'), RedooUtils('Workflow2').getRecordIds()[0]);
}
});
}
};
this.generateDetailViewTopButtons = function(buttons) {
jQuery('.WFDetailViewGroupTop').remove();
var html = '';
jQuery.each(buttons, function(index, value) {
var rand = Math.floor(Math.random() * 9999999) + 1000000;
if(value.color != '') {
var cssStyle = 'color:' + value.textcolor + ';background-color: ' + value.color + ';background-image:none;';
} else {
var cssStyle = ''
}
html += '
';
});
jQuery('.detailViewButtoncontainer .btn-toolbar ').prepend('
' + html + '
');
jQuery('.wfdButtonTopbutton').on('click', function() {
var workflow = new Workflow();
workflow.execute(jQuery(this).data('id'), jQuery('#recordId').val());
});
};
this.generateInlineButtons = function(buttons) {
var final = {};
jQuery.each(buttons, jQuery.proxy(function (index, button) {
jQuery.each(button.config.field, jQuery.proxy(function (fieldIndex, fieldName) {
if (typeof final[fieldName] == 'undefined') {
final[fieldName] = {
config: button.config,
buttons: []
};
}
final[fieldName]['buttons'].push(button);
}, this));
//
}, this));
RedooCache('Workflow2').set('currentInlineButtons', final);
this.showInlineButtons();
};
this.showInlineButtons = function() {
jQuery('.WFInlineButton').remove();
jQuery('.WFDInlineDropdown').remove();
jQuery.each(RedooCache('Workflow2').get('currentInlineButtons', []), jQuery.proxy(function(fieldName, fields) {
var field = RedooUtils('Workflow2').getFieldElement(fieldName);
if(field != false) {
var dropdownHTML = '';
var buttonHTML = '';
jQuery.each(fields['buttons'], jQuery.proxy(function (index, button) {
if(typeof button.config.dropdown == 'undefined' || button.config.dropdown == '0') {
// Buttons shouldn't arranged as DropDown
var existingButtons = jQuery('.WFInlineButton[data-wfid="' + button.workflow_id + '"][data-frontendid="' + button.frontend_id + '"][data-fieldname="' + fieldName + '"]');
if (existingButtons.length > 0) {
jQuery(existingButtons).show().removeClass('tmpbtn');
} else {
buttonHTML = '
';
}
} else {
// Buttons shouldn't arranged as DropDown
//jQuery.each(fields['buttons'], jQuery.proxy(function (index, button) {
dropdownHTML += '';
//}, this));
}
}, this));
jQuery('.WFDInlineDropdown', field).remove();
if(RedooUtils('Workflow2').getViewMode() == 'detailview') {
if(dropdownHTML != '') {
var finalHTML = '
';
field.append(finalHTML);
}
if(buttonHTML != '') {
field.append(buttonHTML);
}
} else if(RedooUtils('Workflow2').getViewMode() == 'summaryview') {
if(dropdownHTML != '') {
var finalHTML = '
';
field.append(finalHTML);
}
console.log(buttonHTML, field);
if(buttonHTML != '') {
field.append(buttonHTML);
}
}
}
}, this));
jQuery('.WFInlineButton.tmpbtn').hide();
jQuery('.WFInlineButton, .WFDInlineDropdown li a').off('click').on('click', function(e) {
e.stopPropagation();
var wfId = jQuery(e.currentTarget).data('wfid');
var workflow = new Workflow();
workflow.execute(wfId, RedooUtils('Workflow2').getRecordIds()[0], function() {});
});
jQuery("div.WFDInlineDropdown").on('click', function(e) {
e.stopPropagation();
jQuery(".dropdown-toggle", e.currentTarget).dropdown('toggle');
});
};
this.setBackgroundMode = function(value) {
this._backgroundMode = value;
};
this.setRequestedData = function(values, relatedKey) {
this._requestValues = values;
this._requestValuesKey = relatedKey;
};
this.allowParallel = function(value) {
this._allowParallel = value?1:0;
};
this.addExtraEnvironment = function(key, value) {
this._extraEnvironment[key] = value;
};
this._executeByTrigger = function(triggerName, ExecutionCallback) {
var Execution = new WorkflowExecution();
Execution.init(this.crmid);
Execution.setRequestedData(this._requestValues, this._requestValuesKey);
if(this._allowParallel == 1) {
Execution.allowParallel();
}
Execution.enableRedirection(ENABLEredirectionOrReloadAfterFinish);
if(typeof ExecutionCallback != 'undefined') {
this._workflowTrigger = triggerName;
}
if(typeof ExecutionCallback != 'undefined') {
Execution.setCallback(ExecutionCallback);
}
jQuery.each(this._extraEnvironment, function(index, value) {
Execution.addEnvironment(index, value);
});
Execution.setBackgroundMode(this._backgroundMode);
Execution.setWorkflowByTrigger(triggerName);
Execution.execute();
};
this._executeById = function(workflow_id, ExecutionCallback) {
var Execution = new WorkflowExecution();
Execution.init(this.crmid);
Execution.setRequestedData(this._requestValues, this._requestValuesKey);
if(this._allowParallel == 1) {
Execution.allowParallel();
}
Execution.enableRedirection(ENABLEredirectionOrReloadAfterFinish);
if(typeof ExecutionCallback != 'undefined') {
this._workflowid = workflow_id;
}
if(typeof ExecutionCallback != 'undefined') {
Execution.setCallback(ExecutionCallback);
}
jQuery.each(this._extraEnvironment, function(index, value) {
Execution.addEnvironment(index, value);
});
Execution.setListViewMode(this._ListViewMode);
Execution.setBackgroundMode(this._backgroundMode);
Execution.setWorkflowById(workflow_id);
Execution.execute();
}; /** ExecuteById **/
this._submitStartfields = function(fields, urlStr) {
app.hideModalWindow();
RedooUtils('Workflow2').blockUI({
'message' : 'Workflow is executing',
// disable if you want key and mouse events to be enable for content that is blocked (fix for select2 search box)
bindEvents: false,
//Fix for overlay opacity issue in FF/Linux
applyPlatformOpacityRules : false
});
jQuery.post("index.php", {
"module" : "Workflow2",
"action" : "Execute",
"file" : "ajaxExecuteWorkflow",
"crmid" : this.crmid,
"workflow" : this._workflowid,
allow_parallel: this._allowParallel,
"startfields": fields
},
jQuery.proxy(function(response) {
RedooUtils('Workflow2').unblockUI();
try {
response = jQuery.parseJSON(response);
} catch (e) {
console.log(response);
return;
}
if(response["result"] == "ok") {
if(ENABLEredirectionOrReloadAfterFinish) {
window.location.reload();
}
} else {
console.log(response);
}
}, this)
);
}
this.closeForceNotification = function(messageId) {
jQuery.post('index.php?module=Workflow2&action=MessageClose', { messageId:messageId, force: 1 });
}
this.parseMessages = function() {
if(typeof WorkflowRecordMessages != 'object' || WorkflowRecordMessages.length == 0) {
return;
}
RedooUtils('Workflow2').loadScript('modules/Workflow2/views/resources/js/noty/jquery.noty.packaged.min.js').then(jQuery.proxy(function()
{
jQuery.each(WorkflowRecordMessages, function(index, value) {
if(typeof WFDvisibleMessages['workflowMessage' + value['id']] != 'undefined' && WFDvisibleMessages['workflowMessage' + value['id']] == true) {
return;
}
var type = 'alert';
switch(value.type) {
case 'success':
type = 'success';
break;
case 'info':
type = 'alert';
break;
case 'error':
type = 'error';
break;
}
value.message = '
' + value.subject + "" + value.message;
if(value.show_until != '') {
value.message += '
' +value.show_until + '';
}
if(WFUserIsAdmin == true) {
value.message += '
(Remove Message)';
}
WFDvisibleMessages['workflowMessage' + value['id']] = true;
if(value.position != -1) {
noty({
text: value.message,
id: 'workflowMessage' + value['id'],
type: value.type,
timeout: false,
'layout': value.position,
'messageId': value.id,
callback: {
"afterClose": function () {
WFDvisibleMessages['workflowMessage' + this.options.messageId] = false;
jQuery.post('index.php?module=Workflow2&action=MessageClose', {messageId: this.options.messageId});
}
}
});
}
});
}), this);
}
this.loadCachedScript = function( url, options ) {
// Allow user to set any option except for dataType, cache, and url
options = jQuery.extend( options || {}, {
dataType: "script",
cache: true,
url: url
});
// Use $.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax( options );
};
}