Commit 285781f1 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Refactoriza ligeramente generador de forms

parent f55c79ba
Loading
Loading
Loading
Loading
+88 −81
Original line number Diff line number Diff line
@@ -192,21 +192,31 @@ define([

			this.inherited(arguments);

			var type, model, label, getModel, props, actions,
				nodes = query('[data-redmic-type]', this.domNode),
			var nodes = query('[data-redmic-type]', this.domNode),
				defsList = [];

			nodes.forEach(function(node) {

				this._startupNode(node, defsList);
			}, this);

			promiseAll(defsList).then(lang.hitch(this, function(results) {

				this.emit('inputs', this.inputs);
			}));
		},

		_startupNode: function(node, defsList) {

			// Si el nodo no tiene atributos, nos vamos
			if (!node.attributes) {
				return;
			}

			// Obtenemos las propiedades definidas desde el nodo
				type = domAttr.get(node, 'data-redmic-type');
				model = domAttr.get(node, 'data-redmic-model');
				props = domAttr.get(node, 'data-redmic-props');
			var type = domAttr.get(node, 'data-redmic-type'),
				model = domAttr.get(node, 'data-redmic-model'),
				props = domAttr.get(node, 'data-redmic-props'),
				actions = domAttr.get(node, 'data-redmic-actions');

			var propertyName, targetProp,
@@ -265,33 +275,34 @@ define([

			// Procedemos a crear el input
			var inputWidgetDfd = this._createInput(type, propsToJSON, propertyName, targetProp, propsInputModule);

			defsList.push(inputWidgetDfd);

				inputWidgetDfd && inputWidgetDfd.then(
					lang.hitch(this, function(controlsNode, propertyName, parentInput, propsToJSON, inputWidget) {
			inputWidgetDfd && inputWidgetDfd.then(lang.hitch(this, this._onInputCreated, {
				controlsNode: controlsNode,
				propertyName: propertyName,
				parentInput: parentInput,
				propsToJSON: propsToJSON
			}));
		},

		_onInputCreated: function(args, inputWidget) {

			var inputProps = args.propsToJSON;
			var obj = {
				channel: inputWidget.getChannel(),
							node: controlsNode,
							isValid: propsToJSON.required ? false : true
				node: args.controlsNode,
				isValid: inputProps.required ? false : true
			};

						if (parentInput) {
							obj.parent = parentInput;
			if (args.parentInput) {
				obj.parent = args.parentInput;
			}

						if (propsToJSON.propertyNameDependence) {
							obj.propertyNameDependence = propsToJSON.propertyNameDependence;
			if (inputProps.propertyNameDependence) {
				obj.propertyNameDependence = inputProps.propertyNameDependence;
			}

						this.inputs[propertyName] = obj;
				}, controlsNode, propertyName, parentInput, propsToJSON));

			}, this);

			promiseAll(defsList).then(lang.hitch(this, function(results) {
				this.emit('inputs', this.inputs);
			}));
			this.inputs[args.propertyName] = obj;
		},

		_stringToJson: function(/*String*/ stringToConvert) {
@@ -591,10 +602,6 @@ define([
			this.inherited(arguments);

			this._chkWidthAndChangeClass();

			/*clearTimeout(this._timeoutHandler);

			this._timeoutHandler = setTimeout(lang.hitch(this, this._chkWidthAndChangeClass), this.timeout);*/
		},

		_chkWidthAndChangeClass: function() {