Commit 61ee581d authored by Hellmich, Christoph's avatar Hellmich, Christoph
Browse files

Tidy up

parent 2cb9abad
......@@ -2,20 +2,28 @@
angular.module('ddaApp').directive('ddaSimpleConditional', function(Wizard, Step, $state) {
function link(scope, element, attr) {
scope.steps = [];
scope.elements = [];
scope.embeddedForm = {
'schema': {},
'data' : {}
};
function addWatcher(scope) {
scope.$watch('field.element', function(newElement, oldElement) {
if (newElement !== oldElement) {
scope.embeddedForm.schema.fields = [];
scope.embeddedForm.data = {};
}
if (scope.field.element) {
scope.embeddedForm.schema.fields = [scope.field.element];
scope.embeddedForm.data[scope.field.element.name] = scope.field.value;
}
console.log(scope.embeddedForm);
if (newElement) {
scope.embeddedForm.schema.fields = [newElement];
}
});
scope.$watch('embeddedForm.data', function(newFormData, oldFormData) {
if (scope.field.element && newFormData[scope.field.element.name]) {
scope.field.value = newFormData[scope.field.element.name];
} else {
scope.field.value = null;
}
}, true);
}
function loadEntities(scope) {
Wizard.steps({
id: $state.params.id
}, function(steps) {
......@@ -40,29 +48,28 @@ angular.module('ddaApp').directive('ddaSimpleConditional', function(Wizard, Step
});
});
});
}
scope.$watch('field.element', function(newElement, oldElement) {
if(newElement !== oldElement) {
scope.embeddedForm.schema.fields = [];
scope.embeddedForm.data = {};
}
function link(scope, element, attr) {
scope.steps = [];
scope.elements = [];
scope.embeddedForm = {
'schema': {},
'data': {}
};
if (newElement) {
scope.embeddedForm.schema.fields = [newElement];
}
});
if (scope.field.element) {
scope.embeddedForm.schema.fields = [scope.field.element];
scope.embeddedForm.data[scope.field.element.name] = scope.field.value;
}
scope.$watch('embeddedForm.data', function(newFormData, oldFormData) {
if (scope.field.element && newFormData[scope.field.element.name]) {
scope.field.value = newFormData[scope.field.element.name];
} else {
scope.field.value = null;
}
}, true);
loadEntities(scope);
addWatcher(scope);
}
var directive = {
link: link
};
return directive;
});
......@@ -14,8 +14,7 @@
</div>
<div fg-property-field="fieldNextStep" fg-property-field-label="Then go to">
<select class="form-control" name="fieldNextStep" ng-model="field.nextStep" ng-options="step as step.name for step in steps track by step.id">
</select>
<select class="form-control" name="fieldNextStep" ng-model="field.nextStep" ng-options="step as step.name for step in steps track by step.id"></select>
</div>
<div fg-property-field="fieldHidden" fg-property-field-label="">
......
<div id="{{ field.$_id }}" class="conditional" ng-class="{ 'hide-condition': field.schema.hidden }">
<span ng-show="field.schema.element.name">If <ins>{{ field.schema.element.name }}</ins> has value <span ng-show="!field.schema.value">&lt;?&gt;</span><ins>{{ field.schema.value }}</ins></span>
<span ng-show="field.schema.nextStep.name">go to <ins>{{ field.schema.nextStep.name }}</ins></span>
<span ng-show="!field.schema.hidden">| <i class="fa fa-eye"></i></span>
<!-- <div jsonify="form.schema.fields"></div> -->
<!-- <div jsonify="field.schema"></div> -->
<!-- <div jsonify="form.data[field.schema.name]"></div> -->
<span ng-show="field.schema.element.name">If
<ins>{{ field.schema.element.name }}</ins>
has value
<span ng-show="!field.schema.value">&lt;?&gt;</span>
<ins>{{ field.schema.value }}</ins>
</span>
<span ng-show="field.schema.nextStep.name">go to
<ins>{{ field.schema.nextStep.name }}</ins>
</span>
<span ng-show="!field.schema.hidden">|
<i class="fa fa-eye"></i>
</span>
</div>
<!-- TODO: See isolated scope http://onehungrymind.com/angularjs-sticky-notes-pt-2-isolated-scope/ http://stackoverflow.com/questions/14049480/what-are-the-nuances-of-scope-prototypal-prototypical-inheritance-in-angularjs -->
<!-- TODO: Get steps from wizardEditor controller through attributs, don-t use wizard or step servoce -->
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment