All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.js.expressions_evaluator.js Maven / Gradle / Ivy

AUI.add(
	'liferay-ddm-form-renderer-expressions-evaluator',
	function(A) {
		var ExpressionsEvaluator = A.Component.create(
			{
				ATTRS: {
					enabled: {
						value: true
					},

					evaluationURL: {
						value: '/o/dynamic-data-mapping-form-evaluator/'
					},

					form: {
					}
				},

				NAME: 'liferay-ddm-form-renderer-expressions-evaluator',

				prototype: {
					initializer: function() {
						var instance = this;

						instance.after('evaluationEnded', instance._afterEvaluationEnded);
						instance.after('evaluationStarted', instance._afterEvaluationStarted);
					},

					evaluate: function(callback) {
						var instance = this;

						var enabled = instance.get('enabled');

						var form = instance.get('form');

						if (instance._request) {
							instance._request.stop();
						}

						if (enabled && form && !instance.evaluating()) {
							instance.fire('evaluationStarted');

							instance._evaluate(
								function(result) {
									instance.fire(
										'evaluationEnded',
										{
											result: result
										}
									);

									if (callback) {
										callback.apply(instance, arguments);
									}
								}
							);
						}
					},

					evaluating: function() {
						var instance = this;

						return instance._evaluating === true;
					},

					_afterEvaluationEnded: function() {
						var instance = this;

						instance._evaluating = null;
					},

					_afterEvaluationStarted: function() {
						var instance = this;

						instance._evaluating = true;
					},

					_evaluate: function(callback) {
						var instance = this;

						var form = instance.get('form');

						instance._request = A.io.request(
							instance.get('evaluationURL'),
							{
								data: {
									languageId: form.get('locale'),
									serializedDDMForm: JSON.stringify(form.get('definition')),
									serializedDDMFormValues: JSON.stringify(form.toJSON())
								},
								dataType: 'JSON',
								method: 'POST',
								on: {
									failure: function(event) {
										if (event.details[1].statusText !== 'abort') {
											callback.call(instance, null);
										}
										callback.call(instance, {});
									},
									success: function() {
										var result = this.get('responseData');

										callback.call(instance, result);
									}
								}
							}
						);
					}
				}
			}
		);

		Liferay.namespace('DDM.Renderer').ExpressionsEvaluator = ExpressionsEvaluator;
	},
	'',
	{
		requires: ['aui-component', 'aui-io-request']
	}
);




© 2015 - 2025 Weber Informatics LLC | Privacy Policy