function ajaxCheckField(&$field, &$user, $reason, $validateParams = null) { global $_CB_framework; static $_CB_fieldajax_outputed = false; static $_CB_fieldajax_validator_outputed = false; $cbSpoofField = cbSpoofField(); $cbSpoofString = cbSpoofString(null, 'fieldclass'); $regAntiSpamFieldName = cbGetRegAntiSpamFieldName(); $regAntiSpamValues = cbGetRegAntiSpams(); $userid = (int) $user->id; $checking = _UE_CHECKING; // . '&start_debug=1', $live_site = $_CB_framework->getCfg('live_site'); $regAntiSpZ = $regAntiSpamValues[0]; $url = "index.php?option=com_comprofiler&task=fieldclass&function=checkvalue&user={$userid}&reason={$reason}"; if ($_CB_framework->getUi() == 2) { $ajaxUrl = $live_site . '/administrator/' . $_CB_framework->backendUrl($url, false, 'raw'); } else { $ajaxUrl = cbSef($url, false, 'raw'); } if ($validateParams !== null && defined('_CB_VALIDATE_NEW')) { if ($_CB_fieldajax_validator_outputed !== true) { cbimport('cb.validator'); cbValidator::addMethod('remotejhtml', <<<EOT jQuery.validator.addMethod("remotejhtml", function(value, element, param) { \t\t\tif ( this.optional(element) ) \t\t\t\treturn "dependency-mismatch"; \t\t\tvar previous = this.previousValue(element); \t\t\tif (!this.settings.messages[element.name] ) \t\t\t\tthis.settings.messages[element.name] = {}; \t\t\tthis.settings.messages[element.name].remote = typeof previous.message == "function" ? previous.message(value) : previous.message; \t\t\tparam = typeof param == "string" && {url:param} || param; \t\t\tvar respField = \$('#'+\$(element).attr('id')+'__Response'); \t\t\tif ( respField.html() != ' ' ) { \t\t\t\tif ( previous.old !== value ) { \t\t\t\t\trespField.fadeOut('medium' ); \t\t\t\t} else { \t\t\t\t\trespField.fadeIn('medium' ); \t\t\t\t} \t\t\t} \t\t\tif ( previous.old !== value && ! this.cbIsOnKeyUp && ! this.cbIsFormSubmitting ) { \t\t\t\tvar inputid = \$(element).attr('id'); \t\t\t\tif ( ! \$('#'+inputid+'__Response').size() ) { \t\t\t\t\tvar respField = '<div class=\\"cb_result_container\\"><div id=\\"' + inputid + '__Response\\"> </div></div>'; \t\t\t\t\t\$(element).parent().each( function() { \t\t\t\t\t\tif (this.tagName.toLowerCase() == 'td') { \t\t\t\t\t\t\t\$(this).append(respField); \t\t\t\t\t\t} else { \t\t\t\t\t\t\t\$(this).after(respField); \t\t\t\t\t\t} \t\t\t\t\t\t\$(inputid+'__Response').hide(); \t\t\t\t\t} ); \t\t\t\t} \t\t\t\tprevious.old = value; \t\t\t\tvar validator = this; \t\t\t\t// this.startRequest(element); \t\t\t\tvar data = {}; \t\t\t\tdata[element.name] = value; \t\t\t\t\$.ajax(\$.extend(true, { \t\t\t\t\ttype: 'POST', \t\t\t\t\turl: '{$ajaxUrl}&field='+encodeURIComponent(inputid), \t\t\t\t\tmode: "abort", \t\t\t\t\tport: "validate" + element.name, \t\t\t\t\tdataType: "html",\t/* """json", */ \t\t\t\t\tdata: 'value=' + encodeURIComponent(value) + '&{$cbSpoofField}=' + encodeURIComponent('{$cbSpoofString}') + '&{$regAntiSpamFieldName}=' + encodeURIComponent('{$regAntiSpZ}'), \t\t\t\t\t/* data: data, */ \t\t\t\t\tsuccess: function(response) { \t\t\t\t\t\t/* never errors on that one: */ \t\t\t\t\t\tvar submitted = validator.formSubmitted; \t\t\t\t\t\tvalidator.prepareElement(element); \t\t\t\t\t\tvalidator.formSubmitted = submitted; \t\t\t\t\t\tvalidator.successList.push(element); \t\t\t\t\t\tvalidator.showErrors(); \t\t\t\t\t\tprevious.valid = response; \t\t\t\t\t\t// validator.stopRequest(element, response); \t\t\t\t\t\tvar respField = \$('#'+\$(element).attr('id')+'__Response'); \t\t\t\t\t\trespField.fadeOut('fast', function() { \t\t\t\t\t\t\trespField.html(response).fadeIn('fast'); \t\t\t\t\t\t} ); \t\t\t\t\t}, \t\t\t\t\terror: function(jqXHR, textStatus) { \t\t\t\t\t\t// validator.stopRequest(element, textStatus); \t\t\t\t\t\tvar respField = \$('#'+\$(element).attr('id')+'__Response'); \t\t\t\t\t\trespField.fadeOut('fast', function() { \t\t\t\t\t\t\trespField.html(textStatus).fadeIn('fast'); \t\t\t\t\t\t} ); \t\t\t\t\t} \t\t\t\t}, param)); \t\t\t\t\$('#'+inputid+'__Response').html('<img alt=\\"\\" src=\\"{$live_site}/components/com_comprofiler/images/wait.gif\\" /> {$checking}').fadeIn('fast'); \t\t\t\treturn true;\t\t// "pending"; \t\t\t} else if( this.pending[element.name] ) { \t\t\t\treturn "pending"; \t\t\t} \t\t\treturn true; // previous.valid; }, 'Ajax Reply Error'); EOT ); /* jQuery.validator.addMethod("remotejhtml", function(value, element, param) { if ( this.optional(element) ) return "dependency-mismatch"; var previous = this.previousValue(element); if (!this.settings.messages[element.name] ) this.settings.messages[element.name] = {}; this.settings.messages[element.name].remote = typeof previous.message == "function" ? previous.message(value) : previous.message; param = typeof param == "string" && {url:param} || param; if ( previous.old !== value && ! this.cbIsOnKeyUp ) { previous.old = value; var validator = this; this.startRequest(element); var data = {}; data[element.name] = value; $.ajax($.extend(true, { type: 'POST', url: '$ajaxUrl&field='+encodeURIComponent(element.id), mode: "abort", port: "validate" + element.name, dataType: "html", data: 'value=' + encodeURIComponent(value) + '&$cbSpoofField=' + encodeURIComponent('$cbSpoofString') + '&$regAntiSpamFieldName=' + encodeURIComponent('$regAntiSpZ'), success: function(response) { if ( response == '' ) { var submitted = validator.formSubmitted; validator.prepareElement(element); validator.formSubmitted = submitted; validator.successList.push(element); validator.showErrors(); } else { var errors = {}; errors[element.name] = response || validator.defaultMessage( element, "remote" ); validator.showErrors(errors); } previous.valid = response; validator.stopRequest(element, response); } }, param)); return "pending"; } else if( this.pending[element.name] ) { return "pending"; } return previous.valid; }, 'Ajax Reply Error'); */ $_CB_fieldajax_validator_outputed = true; } } else { if ($_CB_fieldajax_outputed !== true) { $_CB_framework->outputCbJQuery(<<<EOT \$.fn.cb_field_ajaxCheck = function() { \tif ( ( \$(this).val() != '' ) && ( \$(this).val() != \$(this).data('cblastvalsent') ) ) { \t\tvar inputid = \$(this).attr('id'); \t\tif ( ! \$('#'+inputid+'__Response').size() ) { \t\t\tvar respField = '<div class=\\"cb_result_container\\"><div id=\\"' + inputid + '__Response\\"> </div></div>'; \t\t\t\$(this).parent().each( function() { \t\t\t\tif (this.tagName.toLowerCase() == 'td') { \t\t\t\t\t\$(this).append(respField); \t\t\t\t} else { \t\t\t\t\t\$(this).after(respField); \t\t\t\t} \t\t\t\t\$(inputid+'__Response').hide(); \t\t\t} ); \t\t} \t\tif ( \$('#'+inputid+'__Response').length > 0 ) { \t\t\t\$('#'+inputid+'__Response').html('<img alt=\\"\\" src=\\"{$live_site}/components/com_comprofiler/images/wait.gif\\" /> {$checking}').fadeIn('fast'); \t\t\tvar cbInputField = this; \t\t\tvar lastVal = \$(this).val(); \t\t\t\$(this).data('cblastvalsent', lastVal ); \t\t\t\$.ajax( {\ttype: 'POST', \t\t\t\t\t\turl: '{$ajaxUrl}&field='+encodeURIComponent(inputid), \t\t\t\t\t\tdata: 'value=' + encodeURIComponent( lastVal ) + '&{$cbSpoofField}=' + encodeURIComponent('{$cbSpoofString}') + '&{$regAntiSpamFieldName}=' + encodeURIComponent('{$regAntiSpZ}'), \t\t\t\t\t\tsuccess: function(response) { \t\t\t\t\t\t\tvar respField = \$('#'+\$(cbInputField).attr('id')+'__Response'); \t\t\t\t\t\t\trespField.fadeOut('fast', function() { \t\t\t\t\t\t\t\trespField.html(response).fadeIn('fast'); \t\t\t\t\t\t\t} ); \t\t\t\t\t\t\t\$(cbInputField).data( 'cblastvalchecked', lastVal ); \t\t\t\t\t\t}, \t\t\t\t\t\tdataType: 'html' \t\t\t}); \t\t} \t} }; \$.fn.cb_field_ajaxClear = function() { \tvar respField = \$('#'+\$(this).attr('id')+'__Response'); \tif ( respField.html() != ' ' ) { \t\tif ( \$(this).val() != \$(this).data( 'cblastvalchecked' ) ) { \t\t\trespField.fadeOut('medium' ); \t\t} else { \t\t\trespField.fadeIn('medium' ); \t\t} \t} }; EOT ); $_CB_fieldajax_outputed = true; } } if ($validateParams !== null && defined('_CB_VALIDATE_NEW')) { $validateParams[] = 'remotejhtml:true'; return $this->getMetaClass($field, $validateParams); } else { $_CB_framework->outputCbJQuery("\$('#" . $field->name . "').data( 'cblastvalsent', \$('#" . $field->name . "').val() ).blur( \$.fn.cb_field_ajaxCheck ).keyup( \$.fn.cb_field_ajaxClear );"); return null; } }
function _addSaveAndValidateCode($field, $user, $reason) { global $_CB_framework; $jsSaveCode = $_CB_framework->saveCmsEditorJS($field->name); if ($jsSaveCode) { $_CB_framework->outputCbJQuery("\$('#adminForm').submit( function() { " . $jsSaveCode . " return true; } );"); } if ($this->_isRequired($field, $user, $reason)) { // jQuery handles the onReady aspects very well... : if (defined('_CB_VALIDATE_NEW')) { $jsSaveCode = $_CB_framework->saveCmsEditorJS($field->name, 0, false); cbimport('cb.validator'); cbValidator::addMethod('cbeditorareaRequired' . $field->name, ' jQuery.validator.addMethod("cbeditorareaRequired' . $field->name . '", function(value, element, param) { ' . $jsSaveCode . '; return $(element).hasClass(\'requiredDisabled\') || $(element).closest(\'.fieldCell,.cb_field\').hasClass(\'requiredDisabled\') || $.trim($(element).val()).length > 0; }); $(\'form[name="adminForm"] textarea[name="' . $field->name . '"]\').addClass("required").rules( "add", { cbeditorareaRequired' . $field->name . ': true } );'); } else { $_CB_framework->outputCbJQuery('$(\'form[name="adminForm"] textarea[name="' . $field->name . '"]\').addClass("required");' . 'document.adminForm.' . $field->name . ".setAttribute('mosReq','1');" . 'document.adminForm.' . $field->name . ".setAttribute('mosLabel','" . addslashes($this->getFieldTitle($field, $user, 'text', $reason)) . "');"); } } }