YetiForceCompany/YetiForceCRM

View on GitHub
public_html/layouts/basic/modules/HelpDesk/resources/Edit.min.js

Summary

Maintainability
A
0 mins
Test Coverage
'use strict';

/* {[The file is published on the basis of YetiForce Public License 6.5 that can be found in the following directory: licenses/LicenseEN.txt or yetiforce.com]} */"use strict";Vtiger_Edit_Js("HelpDesk_Edit_Js",{},{/**
         * Register pre save event
         * @param {jQuery} form
         */registerRecordPreSaveEventEvent:function registerRecordPreSaveEventEvent(form){var _this=this;this._super(form),form.on(Vtiger_Edit_Js.recordPreSave,function(e){try{_this.validateToClose(form).done(function(response){!0!==response&&e.preventDefault();});}catch(error){app.errorLog(error),app.showNotify({text:app.vtranslate("JS_ERROR"),type:"error"}),e.preventDefault();}});},validateToClose:function validateToClose(form){var _this2=this,aDeferred=$.Deferred(),closedStatus=app.getMainParams("closeTicketForStatus",!0),status=form.find("[name=\"ticketstatus\"] :selected").val(),progress=$.progressIndicator({position:"html",blockInfo:{enabled:!0}}),isClosedStatusSet=(status in closedStatus),recordId=form.find("[name=\"record\"]").val();if((app.getMainParams("checkIfRecordHasTimeControl")||app.getMainParams("checkIfRelatedTicketsAreClosed"))&&isClosedStatusSet&&recordId){var formData={action:"CheckValidateToClose",module:app.getModuleName(),record:recordId,status:form.find("[name=\"ticketstatus\"] :selected").val()};AppConnector.request({async:!1,url:"index.php",type:"POST",data:formData}).done(function(response){progress.progressIndicator({mode:"hide"}),response.result.hasTimeControl.result&&response.result.relatedTicketsClosed.result?aDeferred.resolve(!0):(!response.result.hasTimeControl.result&&(app.showNotify({text:response.result.hasTimeControl.message,type:"info"}),_this2.addTimeControl({recordId:recordId,url:"index.php?module=OSSTimeControl&view=Edit&sourceModule=HelpDesk&sourceRecord=".concat(recordId,"&relationOperation=true&subprocess=").concat(recordId,"&subprocess=").concat(recordId)})),!response.result.relatedTicketsClosed.result&&app.showNotify({text:response.result.relatedTicketsClosed.message,type:"info"}),aDeferred.resolve(!1));});}else isClosedStatusSet&&!recordId?(app.showNotify({text:app.vtranslate("JS_CANT_CLOSE_NEW_RECROD"),type:"info"}),progress.progressIndicator({mode:"hide"}),aDeferred.resolve(!1)):aDeferred.resolve(!0);return aDeferred.promise()},/**
         * Add time control when closed ticket
         * @param {array} params
         * @returns {Promise}
         */addTimeControl:function addTimeControl(params){var aDeferred=jQuery.Deferred(),parentId=params.recordId,quickCreateParams={},relatedParams={},relatedField="subprocess",fullFormUrl=params.url;relatedParams[relatedField]=parentId;var eliminatedKeys=new Array("view","module","mode","action"),preQuickCreateSave=function preQuickCreateSave(data){var index,queryParam,queryParamComponents,queryParameters=[];if("undefined"!=typeof fullFormUrl&&-1!==fullFormUrl.indexOf("?")){var urlSplit=fullFormUrl.split("?"),queryString=urlSplit[1];for(queryParameters=queryString.split("&"),index=0;index<queryParameters.length;index++)queryParam=queryParameters[index],queryParamComponents=queryParam.split("="),"mode"==queryParamComponents[0]&&"Calendar"==queryParamComponents[1]&&data.find("a[data-tab-name=\"Task\"]").trigger("click");}if(jQuery("<input type=\"hidden\" name=\"sourceModule\" value=\""+"HelpDesk"+"\" />").appendTo(data),jQuery("<input type=\"hidden\" name=\"sourceRecord\" value=\""+parentId+"\" />").appendTo(data),jQuery("<input type=\"hidden\" name=\"relationOperation\" value=\"true\" />").appendTo(data),"undefined"!=typeof relatedField){var field=data.find("[name=\""+relatedField+"\"]");0==field.length&&jQuery("<input type=\"hidden\" name=\""+relatedField+"\" value=\""+parentId+"\" />").appendTo(data);}for(index=0;index<queryParameters.length;index++)queryParam=queryParameters[index],queryParamComponents=queryParam.split("="),"-1"==jQuery.inArray(queryParamComponents[0],eliminatedKeys)&&0==data.find("[name=\""+queryParamComponents[0]+"\"]").length&&jQuery("<input type=\"hidden\" name=\""+queryParamComponents[0]+"\" value=\""+queryParamComponents[1]+"\" />").appendTo(data);};if("undefined"!=typeof fullFormUrl&&-1!==fullFormUrl.indexOf("?"))for(var urlSplit=fullFormUrl.split("?"),queryString=urlSplit[1],queryParameters=queryString.split("&"),index=0;index<queryParameters.length;index++){var queryParam=queryParameters[index],queryParamComponents=queryParam.split("=");"-1"==jQuery.inArray(queryParamComponents[0],eliminatedKeys)&&(relatedParams[queryParamComponents[0]]=queryParamComponents[1]);}return quickCreateParams.data=relatedParams,quickCreateParams.callbackFunction=function(){},quickCreateParams.callbackPostShown=preQuickCreateSave,quickCreateParams.noCache=!0,App.Components.QuickCreate.createRecord("OSSTimeControl",quickCreateParams),aDeferred.promise()}});
//# sourceMappingURL=Edit.min.js.map