Files
crm.clientright.ru/modules/Workflow2/views/resources/js/RequestValuesForm2.js

327 lines
55 KiB
JavaScript
Raw Normal View History

/*
* @copyright 2016-2017 Redoo Networks GmbH
* @link https://redoo-networks.com/
* This file is part of a vTigerCRM module, implemented by Redoo Networks GmbH and must not used without permission.
*/
jQuery.loadScript = function (url, arg1, arg2) {
var cache = false, callback = null;
//arg1 and arg2 can be interchangable
if ($.isFunction(arg1)){
callback = arg1;
cache = arg2 || cache;
} else {
cache = arg1 || cache;
callback = arg2 || callback;
}
var load = true;
//check all existing script tags in the page for the url
jQuery('script[type="text/javascript"]')
.each(function () {
return load = (url != $(this).attr('src'));
});
if (load){
//didn't find it in the page, so load it
jQuery.ajax({
type: 'GET',
url: url,
success: callback,
dataType: 'script',
cache: cache
});
} else {
//already loaded so just call the callback
if (jQuery.isFunction(callback)) {
callback.call(this);
};
};
};
jQuery.loadScript("modules/Workflow2/views/resources/js/jquery.form.min.js");
var RequestValuesForm2 = function (fieldKey, completeData) {
"use strict";
this.completeData = completeData;
this.callback = null;
this.fieldsKey = fieldKey;
this.getKey = function() {
return this.fieldsKey;
};
this.show = function(FormHtml, FormScript) {
var WFDLanguage = {
'Execute Workflow': this.completeData.language['Execute Workflow'],
'Headline': this.completeData.language['Headline'],
'StopText': this.completeData.language['StopText'],
};
if(typeof this.completeData['form_settings'] !== 'undefined' && typeof this.completeData['form_settings']['width'] !== 'undefined') {
var width = this.completeData['form_settings']['width'];
} else {
var width = '600px';
}
var html = '<div class="modal-dialog modelContainer" style="width:' + width + ';">';
html += '<link rel="stylesheet" href="layouts/v7/modules/Workflow2/resources/css/Modal.css?' + new Date().getTime() + '" type="text/css" media="screen" />';
html += '<div class="modal-header"><div class="clearfix"><div class="pull-right " ><button type="button" class="close" aria-label="Close" data-dismiss="modal"><span aria-hidden="true" class="fa fa-close"></span></button></div><h4 class="pull-left">' + WFDLanguage['Headline'] + '</h4></div></div>';
html += "<form method='POST' onsubmit='return false;' id='wf_startfields' enctype='multipart/form-data'>";
html += '<input type="hidden" name="userqueue_id" value="' + this.completeData['userqueue_id'] + '" />';
html += "<div id='workflow_startfield_executer' style='display:none;width:100%;height:100%;top:0px;left:0px;background-image:url(modules/Workflow2/icons/modal_white.png);border:1px solid #777777; position:absolute;text-align:center;'><img src='modules/Workflow2/icons/sending.gif'></div>";
html += '<div class="modal-content">';
html += "<div class='wfLimitHeightContainer requestValueForm'>";
// html += "<p style='margin-left:15px;'><strong>" + message + "</strong></p>";
html += FormHtml;
html += "</div>"; // .wfLimitHeightContainer
html += "<div class='clearfix'></div>";
html += '<div class="modal-footer "><center>';
html += "<button type='submit' name='submitStartField' class='btn btn-success pull-right'><i class='icon-ok' style='color: #ffffff;'></i> " + WFDLanguage['Execute Workflow'] + "</button>";
//if(typeof stoppable != 'undefined' && stoppable == true) {
var execId = this.completeData.execId.split('##');execId = execId[0];
html += "<button type='button' name='submitStartField' class='pull-left btn btn-danger' style='float:left;' onclick='stopWorkflow(\"" + execId + "\",\"" + this.completeData.crmId + "\",\"" + this.completeData.blockId + "\", true);app.hideModalWindow();'><i class='icon-remove'></i> " + WFDLanguage['StopText'] + "</button>";
//}
html += '</center></div></form></div></div>';
FlexUtils('Workflow2').showModalBox(html).then(jQuery.proxy(function(data) {
jQuery('.MakeSelect2', data).select2();
createReferenceFields('.requestValueForm');
// if(pausable == false) {
// jQuery(".blockUI").off("click");
// }
if(FormScript != '') {
jQuery.globalEval( FormScript )
}
jQuery('.materialstyle input, .materialstyle select, .materialstyle textarea', data).on('blur', function() {
// check if the input has any value (if we've typed into it)
if (jQuery(this).val()) {
jQuery(this).addClass('used');
} else {
jQuery(this).removeClass('used');
}
}).trigger('blur');
jQuery('.materialstyle .select2-container, .materialstyle input[type="file"]', data).each(function (index, ele) {
// console.log(ele, jQuery(ele).closest('.materialstyle'));
jQuery(ele).closest('.materialstyle').addClass('fixedUsed');
});
jQuery('.materialstyle input[type="text"], .materialstyle input[type="email"]', data).inputfit({
minSize:11,
maxSize:14
});
var quickCreateForm = jQuery('form#wf_startfields');
jQuery('.wfLimitHeightContainer', quickCreateForm).css('maxHeight', (jQuery( window ).height() - 250) + 'px');
var instance = jQuery('#wf_startfields').parsley({
excluded: 'input[type=button], input[type=submit], input[type=reset]',
inputs: 'input, textarea, select, input[type=hidden], :hidden',
});
jQuery('#wf_startfields').on('submit', jQuery.proxy(function() {
var valid = true;
jQuery('#wf_startfields .RequiredCheck:not(.select2-container)').each(function(index, ele) {
if(jQuery(ele).val() == '') {
jQuery(ele).closest('.materialstyle').addClass('ErrorField');
value = false;
return;
}
jQuery(ele).closest('.materialstyle').removeClass('ErrorField');
});
if(valid === false) {
return;
}
if(typeof this.callback == 'function') {
FlexUtils('Workflow2').hideModalBox();
this.callback.call(
this,
this.getKey(),
jQuery("#wf_startfields").serializeArray(),
jQuery("#wf_startfields").serialize(),
jQuery("#wf_startfields")
);
}
return false;
}, this));
}, this));
};
this.setCallback = function(callback) {
this.callback = callback;
};
this.showOLD = function (windowContent, fieldsKey, message, callback, stoppable, pausable, options) {
if(typeof WFDLanguage === 'undefined') {
var WFDLanguage = {
'These Workflow requests some values': 'This Workflow requests some values',
'Execute Workflow': 'Execute Workflow',
'Executing Workflow ...': 'Executing Workflow ...',
'stop Workflow': 'stop Workflow'
};
}
if(typeof options == 'undefined') {
var options = {
'successText' : WFDLanguage['Execute Workflow'],
'stopOnClose' : false
};
}
if(typeof pausable == 'undefined') {
pausable = true;
}
this.fieldsKey = fieldsKey;
this.windowContent = windowContent;
console.log(windowContent, fieldsKey, message, callback, stoppable, pausable, options);
};
};
function createReferenceFields(parentEle) {
jQuery('.insertReferencefield', parentEle).each(function(index, value) {
var ele = jQuery(value);
if(ele.data('parsed') == '1') {
return;
}
ele.data('parsed', '1');
var fieldName = ele.data('name');
var moduleName = ele.data('module');
var parentField = ele.data('parentfield');
if(typeof parentField == 'undefined') {
parentField = '';
}
if(typeof fieldId == 'undefined') {
fieldId = fieldName.replace(/[^a-zA-Z0-9]/g, '');
}
var valueID = ele.data('crmid');
var valueLabel = ele.data('label');
if(typeof valueID == 'undefined') {
valueID = '';
valueLabel = '';
}
//value = value.replace(/\<\!--\?/g, '<?').replace(/\?--\>/g, '?>');
var html = '';
html += '<table border=0 cellpadding=0 cellspacing=0><td data-parentfield="' + parentField + '"><input type="hidden" disabled="disabled" value="' + moduleName + '" name="popupReferenceModule" /><input name="' + fieldName + '" data-module="' + moduleName + '" type="hidden" value="' + valueID + '" class="sourceField" data-displayvalue="' + valueLabel + '" />';
html += '<div class="row-fluid input-prepend input-append"><span class="add-on clearReferenceSelection cursorPointer"><i class="icon-remove-sign SWremoveReferenc" title="Clear"></i></span>';
html += '<input id="' + fieldName + '_display" name="' + fieldName + '_display" type="text" class="marginLeftZero autoComplete" ' + (valueID != ''?'readonly="true"':'') + ' value="' + valueLabel + '" placeholder="Search" />';
html += '<span class="add-on relatedPopup cursorPointer"><i class="icon-search relatedPopup" title="Select" ></i></span></td></table>';
ele.html(html);
jQuery('.autoComplete', ele).attr('readonly', 'readonly');
jQuery('.clearReferenceSelection', ele).on('click', function(e){
var element = jQuery(e.currentTarget);
var parentTdElement = element.closest('td');
var fieldNameElement = parentTdElement.find('.sourceField');
var fieldName = fieldNameElement.attr('name');
fieldNameElement.val('');
parentTdElement.find('#'+fieldName+'_display').removeAttr('readonly').val('');
element.trigger(Vtiger_Edit_Js.referenceDeSelectionEvent);
e.preventDefault();
});
jQuery('.relatedPopup', ele).on('click', function(e){
var thisInstance = this;
var parentElem = jQuery(e.target).closest('td');
var editInstance = Vtiger_Edit_Js.getInstance();
var params = editInstance.getPopUpParams(parentElem);
if(jQuery(parentElem).data('parentfield') != '') {
params['related_parent_id'] = jQuery('input[name="' + jQuery(parentElem).data('parentfield') + '"]').val();
params['related_parent_module'] = jQuery('input[name="' + jQuery(parentElem).data('parentfield') + '"]').data('module');
}
var isMultiple = false;
if(params.multi_select) {
isMultiple = true;
}
var sourceFieldElement = jQuery('input[class="sourceField"]',parentElem);
var prePopupOpenEvent = jQuery.Event(Vtiger_Edit_Js.preReferencePopUpOpenEvent);
sourceFieldElement.trigger(prePopupOpenEvent);
if(prePopupOpenEvent.isDefaultPrevented()) {
return ;
}
var popupInstance =Vtiger_Popup_Js.getInstance();
popupInstance.show(params,function(data){
var responseData = JSON.parse(data);
var dataList = new Array();
for(var id in responseData){
var data = {
'name' : responseData[id].name,
'id' : id
}
dataList.push(data);
if(!isMultiple) {
editInstance.setReferenceFieldValue(parentElem, data);
}
}
if(isMultiple) {
sourceFieldElement.trigger(Vtiger_Edit_Js.refrenceMultiSelectionEvent,{'data':dataList});
}
sourceFieldElement.trigger(Vtiger_Edit_Js.postReferenceSelectionEvent,{'data':responseData});
});
});
});
}
!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):t(jQuery)}(function(t){t.fn.inputfit=function(i){var n=t.extend({minSize:10,maxSize:!1},i);return this.each(function(){var i=t(this);if(i.is(":input")){i.off("keyup.inputfit keydown.inputfit");var e=parseFloat(n.maxSize||i.css("font-size"),10),f=i.width(),s=i.data("inputfit-clone");s||(s=t("<div></div>",{css:{fontSize:i.css("font-size"),fontFamily:i.css("font-family"),fontStyle:i.css("font-style"),fontWeight:i.css("font-weight"),fontVariant:i.css("font-variant"),letterSpacing:i.css("letter-spacing"),whiteSpace:"nowrap",position:"absolute",left:"-9999px",visibility:"hidden"}}).insertAfter(i),i.data("inputfit-clone",s)),i.on("keyup.inputfit keydown.inputfit",function(){var i=t(this);s.text(i.val());var o=f/(s.width()||1),a=parseInt(i.css("font-size"),10),c=Math.floor(a*o);c>e&&(c=e),c<n.minSize&&(c=n.minSize),i.css("font-size",c),s.css("font-size",c)}).triggerHandler("keyup.inputfit")}}),this}});
/*!
* Parsley.js
* Version 2.8.1 - built Sat, Feb 3rd 2018, 2:27 pm
* http://parsleyjs.org
* Guillaume Potier - <guillaume@wisembly.com>
* Marc-Andre Lafortune - <petroselinum@marc-andre.ca>
* MIT Licensed
*/
function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,i=Array(e.length);t<e.length;t++)i[t]=e[t];return i}return Array.from(e)}var _slice=Array.prototype.slice,_slicedToArray=function(){function e(e,t){var i=[],n=!0,r=!1,s=void 0;try{for(var a,o=e[Symbol.iterator]();!(n=(a=o.next()).done)&&(i.push(a.value),!t||i.length!==t);n=!0);}catch(l){r=!0,s=l}finally{try{!n&&o["return"]&&o["return"]()}finally{if(r)throw s}}return i}return function(t,i){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e};!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):e.parsley=t(e.jQuery)}(this,function(e){"use strict";function t(e,t){return e.parsleyAdaptedCallback||(e.parsleyAdaptedCallback=function(){var i=Array.prototype.slice.call(arguments,0);i.unshift(this),e.apply(t||M,i)}),e.parsleyAdaptedCallback}function i(e){return 0===e.lastIndexOf(D,0)?e.substr(D.length):e}/**
* inputevent - Alleviate browser bugs for input events
* https://github.com/marcandre/inputevent
* @version v0.0.3 - (built Thu, Apr 14th 2016, 5:58 pm)
* @author Marc-Andre Lafortune <github@marc-andre.ca>
* @license MIT
*/
function n(){var t=this,i=window||global;_extends(this,{isNativeEvent:function(e){return e.originalEvent&&e.originalEvent.isTrusted!==!1},fakeInputEvent:function(i){t.isNativeEvent(i)&&e(i.target).trigger("input")},misbehaves:function(i){t.isNativeEvent(i)&&(t.behavesOk(i),e(document).on("change.inputevent",i.data.selector,t.fakeInputEvent),t.fakeInputEvent(i))},behavesOk:function(i){t.isNativeEvent(i)&&e(document).off("input.inputevent",i.data.selector,t.behavesOk).off("change.inputevent",i.data.selector,t.misbehaves)},install:function(){if(!i.inputEventPatched){i.inputEventPatched="0.0.3";for(var n=["select",'input[type="checkbox"]','input[type="radio"]','input[type="file"]'],r=0;r<n.length;r++){var s=n[r];e(document).on("input.inputevent",s,{selector:s},t.behavesOk).on("change.inputevent",s,{selector:s},t.misbehaves)}}},uninstall:function(){delete i.inputEventPatched,e(document).off(".inputevent")}})}var r=1,s={},a={attr:function(e,t,i){var n,r,s,a=new RegExp("^"+t,"i");if("undefined"==typeof i)i={};else for(n in i)i.hasOwnProperty(n)&&delete i[n];if(!e)return i;for(s=e.attributes,n=s.length;n--;)r=s[n],r&&r.specified&&a.test(r.name)&&(i[this.camelize(r.name.slice(t.length))]=this.deserializeValue(r.value));return i},checkAttr:function(e,t,i){return e.hasAttribute(t+i)},setAttr:function(e,t,i,n){e.setAttribute(this.dasherize(t+i),String(n))},getType:function(e){return e.getAttribute("type")||"text"},generateID:function(){return""+r++},deserializeValue:function(e){var t;try{return e?"true"==e||"false"!=e&&("null"==e?null:isNaN(t=Number(e))?/^[\[\{]/.test(e)?JSON.parse(e):e:t):e}catch(i){return e}},camelize:function(e){return e.replace(/-+(.)?/g,function(e,t){return t?t.toUpperCase():""})},dasherize:function(e){return e.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()},warn:function(){var e;window.console&&"function"==typeof window.console.warn&&(e=window.console).warn.apply(e,arguments)},warnOnce:function(e){s[e]||(s[e]=!0,this.warn.apply(this,arguments))},_resetWarnings:function(){s={}},trimString:function(e){return e.replace(/^\s+|\s+$/g,"")},parse:{date:function S(e){var t=e.match(/^(\d{4,})-(\d\d)-(\d\d)$/);if(!t)return null;var i=t.map(function(e){return parseInt(e,10)}),n=_slicedToArray(i,4),r=(n[0],n[1]),s=n[2],a=n[3],S=new Date(r,s-1,a);return S.getFullYear()!==r||S.getMonth()+1!==s||S.getDate()!==a?null:S},string:function(e){return e},integer:function(e){return isNaN(e)?null:parseInt(e,10)},number:function(e){if(isNaN(e))throw null;return parseFloat(e)},"boolean":function(e){return!/^\s*false\s*$/i.test(e)},object:function(e){return a.deserializeValue(e)},regexp:function(e){var t="";return/^\/.*\/(?:[gimy]*)$/.test(e)?(t=e.replace(/.*\/([gimy]*)$/,"$1"),e=e.replace(new RegExp("^/(.*?)/"+t+"$"),"$1")):e="^"+e+"$",new RegExp(e,t)}},parseRequirement:function(e,t){var i=this.parse[e||"string"];if(!i)throw'Unknown requirement specification: "'+e+'"';var n=i(t);if(null===n)throw"Requirement is not a "+e+': "'+t+'"';return n},namespaceEvents:function(t,i){return t=this.trimString(t||"").split(/\s+/),t[0]?e.map(t,function(e){return e+"."+i}).join(" "):""},difference:function(t,i){var n=[];return e.each(t,function(e,t){i.indexOf(t)==-1&&n.push(t)}),n},all:function(t){return e.when.apply(e,_toConsumableArray(t).concat([42,42]))},objectCreate:Object.create||function(){var e=function(){};return function(t){if(arguments.length>1)throw Error("Second argument not supported");if("object"!=typeof t)throw TypeError("Argument must be an object");e.prototype=t;var i=new e;return e.prototype=null,i}}(),_SubmitSelector:'input[type="submit"], button:submit'},o={namespace:"data-parsley-",inputs:"input, textarea, select",excluded:"input[type=button], input[type=submit], input[type=reset], input[type=hidden]",priorityEnabled:!0,multiple:null,group:null,uiEnabled:!0,validationThreshold:3,focus:"first",trigger:!1,triggerAfterFailure:"input",errorClass:"parsley-error",successClass:"parsley-success",classHandler:function(e){},errorsContainer:function(e){},erro
var i=[];return this._findRelated().filter(":checked").each(function(){i.push(e(this).val())}),i}}return"SELECT"===this.element.nodeName&&null===this.$element.val()?[]:this.$element.val()},_init:function(){return this.$elements=[this.$element],this}};var P=function(t,i,n){this.element=t,this.$element=e(t);var r=this.$element.data("Parsley");if(r)return"undefined"!=typeof n&&r.parent===window.Parsley&&(r.parent=n,r._resetOptions(r.options)),"object"==typeof i&&_extends(r.options,i),r;if(!this.$element.length)throw new Error("You must bind Parsley on an existing element.");if("undefined"!=typeof n&&"Form"!==n.__class__)throw new Error("Parent instance must be a Form instance");return this.parent=n||window.Parsley,this.init(i)};P.prototype={init:function(e){return this.__class__="Parsley",this.__version__="2.8.1",this.__id__=a.generateID(),this._resetOptions(e),"FORM"===this.element.nodeName||a.checkAttr(this.element,this.options.namespace,"validate")&&!this.$element.is(this.options.inputs)?this.bind("parsleyForm"):this.isMultiple()?this.handleMultiple():this.bind("parsleyField")},isMultiple:function(){var e=a.getType(this.element);return"radio"===e||"checkbox"===e||"SELECT"===this.element.nodeName&&null!==this.element.getAttribute("multiple")},handleMultiple:function(){var t,i,n=this;if(this.options.multiple=this.options.multiple||(t=this.element.getAttribute("name"))||this.element.getAttribute("id"),"SELECT"===this.element.nodeName&&null!==this.element.getAttribute("multiple"))return this.options.multiple=this.options.multiple||this.__id__,this.bind("parsleyFieldMultiple");if(!this.options.multiple)return a.warn("To be bound by Parsley, a radio, a checkbox and a multiple select input must have either a name or a multiple option.",this.$element),this;this.options.multiple=this.options.multiple.replace(/(:|\.|\[|\]|\{|\}|\$)/g,""),t&&e('input[name="'+t+'"]').each(function(e,t){var i=a.getType(t);"radio"!==i&&"checkbox"!==i||t.setAttribute(n.options.namespace+"multiple",n.options.multiple)});for(var r=this._findRelated(),s=0;s<r.length;s++)if(i=e(r.get(s)).data("Parsley"),"undefined"!=typeof i){this.$element.data("FieldMultiple")||i.addElement(this.$element);break}return this.bind("parsleyField",!0),i||this.bind("parsleyFieldMultiple")},bind:function(t,i){var n;switch(t){case"parsleyForm":n=e.extend(new w(this.element,this.domOptions,this.options),new l,window.ParsleyExtend)._bindFields();break;case"parsleyField":n=e.extend(new x(this.element,this.domOptions,this.options,this.parent),new l,window.ParsleyExtend);break;case"parsleyFieldMultiple":n=e.extend(new x(this.element,this.domOptions,this.options,this.parent),new $,new l,window.ParsleyExtend)._init();break;default:throw new Error(t+"is not a supported Parsley type")}return this.options.multiple&&a.setAttr(this.element,this.options.namespace,"multiple",this.options.multiple),"undefined"!=typeof i?(this.$element.data("FieldMultiple",n),n):(this.$element.data("Parsley",n),n._actualizeTriggers(),n._trigger("init"),n)}};var V=e.fn.jquery.split(".");if(parseInt(V[0])<=1&&parseInt(V[1])<8)throw"The loaded version of jQuery is too old. Please upgrade to 1.8.x or better.";V.forEach||a.warn("Parsley requires ES5 to run properly. Please include https://github.com/es-shims/es5-shim");var T=_extends(new l,{element:document,$element:e(document),actualizeOptions:null,_resetOptions:null,Factory:P,version:"2.8.1"});_extends(x.prototype,y.Field,l.prototype),_extends(w.prototype,y.Form,l.prototype),_extends(P.prototype,l.prototype),e.fn.parsley=e.fn.psly=function(t){if(this.length>1){var i=[];return this.each(function(){i.push(e(this).parsley(t))}),i}if(0!=this.length)return new P(this[0],t)},"undefined"==typeof window.ParsleyExtend&&(window.ParsleyExtend={}),T.options=_extends(a.objectCreate(o),window.ParsleyConfig),window.ParsleyConfig=T.options,window.Parsley=window.psly=T,T.Utils=a,window.ParsleyUtils={},e.each(a,function(e,t){"function"==typeof t&&(window.ParsleyUtils[e]=function(){return a.warnOnce("Accessing `window.ParsleyUtils` is deprecated. Use `window.Parsley.Utils` i