YadaWeb/src/main/resources/net/yadaframework/views/yada/js/yada.ajax.js
/**
	 * Make an ajax call when a link is clicked, a select is chosen, a checkbox is selected
	 */
Make an ajax call when a link is clicked, a select is chosen, a checkbox is selected
Make an ajax call when a link is clicked a select is chosen a checkbox is selected
function makeAjaxCall(e, $element, handler, allowDefault) {
		if (!allowDefault==true) {
			e.preventDefault();
		}
		if ($element.hasClass("yadaLinkDisabled")) {
			return false;
		}
		var joinedHandler = function(responseText, responseHtml) {
			showFeedbackIfNeeded($element);
			deleteOnSuccess($element);
			responseHtml = updateOnSuccess($element, responseHtml);
			var handlerNames = $element.attr("data-yadaSuccessHandler");
			if (handlerNames===undefined) {
				handlerNames = $element.attr("data-successHandler"); 
			}
			if (handlerNames!=null) {
				var handlerNameArray = yada.listToArray(handlerNames);
				for (var i = 0; i < handlerNameArray.length; i++) {
					executeFunctionByName(handlerNameArray[i], $element, responseText, responseHtml, $element[0]);
				}
			}
			if (handler != null) {
				handler(responseText, responseHtml, $element[0]);
			}
		}
		var url = $element.attr('data-yadaHref');
		if (url==null || url=='') {
			url = $element.attr('href');
		}
		var confirmText = $element.attr("data-yadaConfirm") || $element.attr("data-confirm");
		var data = null;
		var value = [];
		var name = $element.attr("name");
		var noLoader = hasNoLoader($element);	
		if ($element.is("select")) {
			$("option:selected", $element).each(function(){ 
				value.push($(this).val()); 
			});
		} else if ($element.is("input")) {
			if ($element.prop('type')=="checkbox") {
				value.push($element.prop('checked')); 
			} else {
				value.push($element.val());
			}
		}
		if (name !=null) {
			data = {};
			if (value.length>0) {
				data[name] = value;
			}
		}
		if (confirmText!=null && confirmText!="") {
			var title = $element.attr("data-yadaTitle");
			var okButton = $element.attr("data-yadaOkButton") || $element.attr("data-okButton") || yada.messages.confirmButtons.ok;
			var cancelButton = $element.attr("data-yadaCancelButton") || $element.attr("data-cancelButton") || yada.messages.confirmButtons.cancel;
			var okShowsPreviousModal = $element.attr("data-yadaOkShowsPrevious")==null || $element.attr("data-yadaOkShowsPrevious")=="true";
			yada.confirm(title, confirmText, function(result) {
				if (result==true) {
					yada.ajax(url, data, joinedHandler==null?joinedHandler:joinedHandler.bind($element), null, getTimeoutValue($element), noLoader);
				}
			}, okButton, cancelButton, okShowsPreviousModal);
		} else {
			yada.ajax(url, data, joinedHandler==null?joinedHandler:joinedHandler.bind($element), null, null, noLoader);
		}
		return true; 
	}
function makeAjaxCall ( e , $element , handler , allowDefault ) { if ( ! allowDefault == true ) { e . preventDefault ( ) ; } if ( $element . hasClass ( "yadaLinkDisabled" ) ) { return false ; } var joinedHandler = function ( responseText , responseHtml ) { showFeedbackIfNeeded ( $element ) ; deleteOnSuccess ( $element ) ; responseHtml = updateOnSuccess ( $element , responseHtml ) ; var handlerNames = $element . attr ( "data-yadaSuccessHandler" ) ; if ( handlerNames === undefined ) { handlerNames = $element . attr ( "data-successHandler" ) ; } if ( handlerNames != null ) { var handlerNameArray = yada . listToArray ( handlerNames ) ; for ( var i = 0 ; i < handlerNameArray . length ; i ++ ) { executeFunctionByName ( handlerNameArray [ i ] , $element , responseText , responseHtml , $element [ 0 ] ) ; } } if ( handler != null ) { handler ( responseText , responseHtml , $element [ 0 ] ) ; } } var url = $element . attr ( 'data-yadaHref' ) ; if ( url == null || url == '' ) { url = $element . attr ( 'href' ) ; } var confirmText = $element . attr ( "data-yadaConfirm" ) || $element . attr ( "data-confirm" ) ; var data = null ; var value = [ ] ; var name = $element . attr ( "name" ) ; var noLoader = hasNoLoader ( $element ) ; if ( $element . is ( "select" ) ) { $ ( "option:selected" , $element ) . each ( function ( ) { value . push ( $ ( this ) . val ( ) ) ; } ) ; } else if ( $element . is ( "input" ) ) { if ( $element . prop ( 'type' ) == "checkbox" ) { value . push ( $element . prop ( 'checked' ) ) ; } else { value . push ( $element . val ( ) ) ; } } if ( name != null ) { data = { } ; if ( value . length > 0 ) { data [ name ] = value ; } } if ( confirmText != null && confirmText != "" ) { var title = $element . attr ( "data-yadaTitle" ) ; var okButton = $element . attr ( "data-yadaOkButton" ) || $element . attr ( "data-okButton" ) || yada . messages . confirmButtons . ok ; var cancelButton = $element . attr ( "data-yadaCancelButton" ) || $element . attr ( "data-cancelButton" ) || yada . messages . confirmButtons . cancel ; var okShowsPreviousModal = $element . attr ( "data-yadaOkShowsPrevious" ) == null || $element . attr ( "data-yadaOkShowsPrevious" ) == "true" ; yada . confirm ( title , confirmText , function ( result ) { if ( result == true ) { yada . ajax ( url , data , joinedHandler == null ? joinedHandler : joinedHandler . bind ( $element ) , null , getTimeoutValue ( $element ) , noLoader ) ; } } , okButton , cancelButton , okShowsPreviousModal ) ; } else { yada . ajax ( url , data , joinedHandler == null ? joinedHandler : joinedHandler . bind ( $element ) , null , null , noLoader ) ; } return true ; }
Make an ajax call when a link is clicked, a select is chosen, a checkbox is selected
Make an ajax call when a link is clicked a select is chosen a checkbox is selected
// Call, in sequence, the handler specified in data-successHandler and the one passed to this function
 // Legacy
 // Can be a comma-separated list of handlers, which are called in sequence
 // Create data for submission
 // In a select, set the data object to the selected option
 // Could be a multiselect!
 // $(this) is correct here
 // Always send the element value
 // Run other listeners
