|
861 | 861 | }
|
862 | 862 | };
|
863 | 863 |
|
864 |
| - ko.components.register('multi-input', { |
865 |
| - viewModel: function(params) { |
866 |
| - var self = this; |
867 |
| - |
868 |
| - self.observableValues = ko.observableArray(); |
869 |
| - |
870 |
| - // This method updates the values parameter with the contents of the managed array. |
871 |
| - function syncValues() { |
872 |
| - var rawValues = []; |
873 |
| - for (var i=0; i<self.observableValues().length; i++) { |
874 |
| - rawValues.push(self.observableValues()[i].val()); |
875 |
| - } |
876 |
| - params.values(rawValues); |
877 |
| - } |
878 |
| - |
879 |
| - function newValue(value) { |
880 |
| - var observable = ko.observable(value || ''); |
881 |
| - observable.subscribe(syncValues); |
882 |
| - self.observableValues.push({val:observable}); |
883 |
| - } |
884 |
| - |
885 |
| - self.addValue = function() { |
886 |
| - newValue(); |
887 |
| - }; |
888 |
| - |
889 |
| - self.removeValue = function(value) { |
890 |
| - self.observableValues.remove(value); |
891 |
| - }; |
892 |
| - |
893 |
| - if (params.values()) { |
894 |
| - for (var i=0; i<params.values().length; i++) { |
895 |
| - newValue(params.values()[i]); |
896 |
| - } |
897 |
| - } |
898 |
| - |
899 |
| - self.observableValues.subscribe(syncValues); |
900 |
| - }, |
901 |
| - template: {element:'template-multi-input'} |
902 |
| - |
903 |
| - }); |
904 |
| - |
905 |
| - ko.components.register('condition-trajectory', { |
906 |
| - viewModel: function (params) { |
907 |
| - var self = this; |
908 |
| - var offsets = ["Very poor", "Poor", "Good", "Very good"]; |
909 |
| - var trajectories = ["Improving", "Deteriorating", "Stable", "Unclear"]; |
910 |
| - |
911 |
| - var width = 75; |
912 |
| - var boxWidth = 30; |
913 |
| - self.boxPosition = ko.computed(function() { |
914 |
| - var condition = ko.utils.unwrapObservable(params.condition); |
915 |
| - var index = offsets.indexOf(condition); |
916 |
| - return index * width + width/2 - boxWidth/2; |
917 |
| - }); |
918 |
| - self.title = ko.computed(function() { |
919 |
| - var condition = ko.utils.unwrapObservable(ko.trajectory); |
920 |
| - return "Condition: "+condition+", Trajectory: "+params.trajectory; |
921 |
| - }); |
922 |
| - |
923 |
| - self.trajectoryTemplate = ko.computed(function() { |
924 |
| - var trajectory = ko.utils.unwrapObservable(params.trajectory); |
925 |
| - if (trajectory) { |
926 |
| - return 'template-trajectory-'+trajectory.toLowerCase(); |
927 |
| - } |
928 |
| - return 'template-trajectory-none'; |
929 |
| - }); |
930 |
| - |
931 |
| - }, |
932 |
| - template:{element:'template-condition-trajectory'} |
933 |
| - |
934 |
| - }); |
935 |
| - |
936 | 864 | /**
|
937 | 865 | * Extends the target as a ecodata.forms.DataModelItem. This is required to support many of the
|
938 | 866 | * dynamic behaviour features, including warnings and conditional validation rules.
|
|
0 commit comments