/* * 2003-2018 Business Tech * * @author Business Tech SARL * @copyright 2003-2018 Business Tech SARL */ // declare main object of module var FpcModule = function(sName) { // set name this.name = sName; // set name this.oldVersion = false; // set translated js msgs this.msgs = {}; // stock error array this.aError = []; // set url of admin img this.sImgUrl = ''; // set url of module's web service this.sWebService = ''; // set response this.response = null; // set this in obj context var oThis = this; /* * show() method show effect and assign HTML in * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us * @param string sId : container to show in * @param string sHtml : HTML to display * @return - */ this.show = function(sId, sHtml) { $("#" + sId).html(sHtml).css('style', 'none'); $("#" + sId).show('fast'); }; /* * hide() method hide effect and delete html * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us * @param string sId : container to hide in * @return - */ this.hide = function(sId) { $("#" + sId).hide('fast', function() { $("#" + sId).html(''); } ); }; /* * form() method check all fields of current form and execute : XHR or submit => used for update all admin config * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us * @see ajax * @param string sForm : form * @param string sURI : query params used for XHR * @param string sRequestParam : param action and type in order to send with post mode * @param string sToDisplay : * @param string sToHide : force to hide specific ID * @param bool bSubmit : used only for sending main form * @param bool bFancyBox : used only for fancybox in xhr * @param string sCallback : * @param string sErrorType : * @param string sLoadBar : * @return string : HTML returned by smarty */ this.form = function(sForm, sURI, sRequestParam, sToDisplay, sToHide, bSubmit, bFancyBox, sCallback, sErrorType, sLoadBar) { // set loading bar if (sLoadBar) { $('#'+sLoadBar).show(); } // set return validation var aError = []; // get all fields of form var fields = $("#" + sForm).serializeArray(); // set counter var iCounter = 0; // set bIsError var bIsError = false; // check element form jQuery.each(fields, function(i, field) { bIsError = false; switch(field.name) { case 'id' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.id; bIsError = true; } break; case 'secret' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.secret; bIsError = true; } break; case 'callback' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.callback; bIsError = true; } break; case 'scope' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.scope; bIsError = true; } break; case 'developerKey' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.developerKey; bIsError = true; } break; case 'socialEmail' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.socialEmail; bIsError = true; } break; case 'fbpscDefaultConnectText' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.defaultText; bIsError = true; } break; case 'fbpscPrefixCode' : if (field.value == '' && $('input:radio[name="fbpscEnableVoucher"]').val() == 'true') { oThis.aError[iCounter] = oThis.msgs.prefixCode; bIsError = true; } break; case 'fbpscApiRequestType' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.apiType; bIsError = true; } break; case 'fbpscHtmlElement' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.htmlElement; bIsError = true; } break; case 'fbpscPositionName' : if (field.value == '') { oThis.aError[iCounter] = oThis.msgs.positionName; bIsError = true; } break; case 'sCssPaddingTop' : if (field.value == '' || $.isNumeric( field.value ) == false) { oThis.aError[iCounter] = oThis.msgs.padding; bIsError = true; } break; case 'sCssPaddingRight' : if (field.value == '' || $.isNumeric( field.value ) == false ) { oThis.aError[iCounter] = oThis.msgs.padding; bIsError = true; } break; case 'sCssPaddingBottom' : if (field.value == '' || $.isNumeric( field.value ) == false ) { oThis.aError[iCounter] = oThis.msgs.padding; bIsError = true; } break; case 'sCssPaddingLeft' : if (field.value == '' || $.isNumeric( field.value ) == false ) { oThis.aError[iCounter] = oThis.msgs.padding; bIsError = true; } break; case 'sCssMarginTop' : if (field.value == '' || $.isNumeric( field.value ) == false) { oThis.aError[iCounter] = oThis.msgs.margin; bIsError = true; } break; case 'sCssMarginRight' : if (field.value == '' || $.isNumeric( field.value ) == false ) { oThis.aError[iCounter] = oThis.msgs.margin; bIsError = true; } break; case 'sCssMarginBottom' : if (field.value == '' || $.isNumeric( field.value ) == false ) { oThis.aError[iCounter] = oThis.msgs.margin; bIsError = true; } break; case 'sCssMarginLeft' : if (field.value == '' || $.isNumeric( field.value ) == false ) { oThis.aError[iCounter] = oThis.msgs.margin; bIsError = true; } break; default: break; } if (($('input[name="' + field.name + '"]') != undefined || $('textarea[name="' + field.name + '"]') != undefined || $('select[name="' + field.name + '"]').length != undefined) && bIsError == true) { if ($('input[name="' + field.name + '"]').length != 0) { $('input[name="' + field.name + '"]').parent().addClass('has-error has-feedback'); $('input[name="' + field.name + '"]').append(''); } if ($('textarea[name="' + field.name + '"]').length != 0) { $('textarea[name="' + field.name + '"]').parent().addClass('has-error has-feedback'); $('textarea[name="' + field.name + '"]').append(''); } if ($('select[name="' + field.name + '"]').length != 0) { $('select[name="' + field.name + '"]').parent().addClass('has-error has-feedback'); $('select[name="' + field.name + '"]').append(''); } ++iCounter; } }); if (oThis.aError.length == 0 && !bIsError) { // use case - Ajax request if (bSubmit == undefined || bSubmit == null || !bSubmit) { if (sLoadBar && sToHide != null) { oThis.hide(sToHide, true); } // format object of fields in string to execute Ajax request var sFormParams = $.param(fields); if (sRequestParam != null && sRequestParam != '') { sFormParams = sRequestParam + '&' + sFormParams; } // execute Ajax request this.ajax(sURI, sFormParams, sToDisplay, sToHide, bFancyBox, null, sLoadBar); return true; } // use case - send form else { // hide loading bar if (sLoadBar) { $('#'+sLoadBar).hide(); } document.forms[sForm].submit(); return true; } } else { $('#'+sLoadBar).hide(); } // display errors this.displayError(sErrorType); return false; }; /* * ajax() method execute XHR * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us * @param string sURI : query params used for XHR * @param string sParams : * @param string sToShow : * @param string sToHide : * @param bool bFancyBox : used only for fancybox in xhr * @param bool bFancyBoxActivity : used only for fancybox in xhr * @param string sLoadBar : used only for loading * @return string : HTML returned by smarty */ this.ajax = function(sURI, sParams, sToShow, sToHide, bFancyBox, bFancyBoxActivity, sLoadBar) { if(bFancyBox && bFancyBoxActivity != false) { //$.fancybox.showActivity(); } sParams = 'sMode=xhr' + ((sParams == null || sParams == undefined) ? '' : '&' + sParams) ; // configure XHR $.ajax({ type : 'POST', url : sURI, data : sParams, dataType : 'html', success: function(data) { // hide loading bar if (sLoadBar) { $('#'+sLoadBar).hide(); } if(bFancyBox) { // update fancybox content $.fancybox(data); // use case - update only widget list if (sToShow == oThis.name + 'ConnectorList') { oThis.ajax('' + sURI, 'sAction=display&sType=connectors', '' + sToShow + '', '' + sToHide + ''); } // use case - update widget list and hook list else if (sToShow == oThis.name + 'HookList') { sToShow = sToHide = oThis.name + 'ConnectorList'; oThis.ajax('' + sURI + 'connectors', 'sAction=display&sType=connectors', '' + sToShow + '', '' + sToHide + ''); sToShow = sToHide = oThis.name + 'HookList'; oThis.ajax('' + sURI + 'hooks', 'sAction=display&sType=hooks', '' + sToShow + '', '' + sToHide + ''); } else if (sToShow == oThis.name + 'HookAdvanced') { oThis.ajax('' + sURI, 'sAction=display&sType=hookAdvanced', '' + sToShow + '', '' + sToHide + ''); } else if (sToShow == oThis.name + 'ShortCode') { oThis.ajax('' + sURI, 'sAction=display&sType=shortCode', '' + sToShow + '', '' + sToHide + ''); } } else if (sToShow != null && sToHide != null) { // same hide and show if (sToShow == sToHide) { oThis.hide('fast'); $('#' + sToHide).hide('fast'); $('#' + sToHide).empty(); setTimeout('', 1000); oThis.show(sToShow, data); } else { oThis.hide(sToHide); setTimeout('', 1000); oThis.show(sToShow, data); } } else if (sToShow != null) { oThis.show(sToShow, data); } else if (sToHide != null) { oThis.hide(sToHide); } else { oThis.response = data; } }, error: function(xhr, ajaxOptions, thrownError) { $("#" + oThis.name + "FormError").addClass('alert error'); oThis.show("#" + oThis.name + "FormError", '