PageSourceSearch

https://retainyourbrain.com/components/admin/propogation/editPropogation.controller.js

js retainyourbrain.com collected 2026-09-28 08:37:56 UTC 6,277 bytes, 130 lines download raw bytes

1(function () {
2    'use strict';
3
4    angular.module('saddleApp.controllers')
5        .controller('adminEditPropogation', adminEditPropogation);
6
7    adminEditPropogation.$inject = ["$filter", "requestFactory", "settingsFactory", "utilsFactory", "forms", "form", "propogations", "formInput", "formInputGroup", "toFormInput", "toForm", "formInputOptions", "toFormInputOptions", "formInputRanges", "formInputTypesById", "toFormInputOptionsIndexById"];
8
9    function adminEditPropogation($filter, requestFactory, settingsFactory, utilsFactory, forms, form, propogations, formInput, formInputGroup, toFormInput, toForm, formInputOptions, toFormInputOptions, formInputRanges, formInputTypesById, toFormInputOptionsIndexById) {
10        
11        var vm = this;
12        
13        vm.forms = forms;
14        vm.form = form;
15        vm.propogations = propogations;
16        vm.formInput = formInput;
17        vm.formInputGroup = formInputGroup;
18        vm.toFormInput = toFormInput;
19        vm.toForm = toForm;
20        vm.formInputOptions = formInputOptions.filter(option => option.enabled);
21        vm.toFormInputOptions = toFormInputOptions.filter(option => option.enabled);;
22        vm.formInputRanges = formInputRanges;
23        vm.formInputTypesById = formInputTypesById;
24        vm.formInputType = vm.formInputTypesById[vm.formInput.formInputTypeId];
25        vm.toFormInputOptionsIndexById = toFormInputOptionsIndexById; // index in toFormInputOptions array, less RAM usage, no objects duplication
26
27        vm.propogationExistByFromFormInputOptionId = {};
28        function updatePropogationExistByFormInputOptionId() {
29            for(let i = 0; i < vm.formInputOptions.length; i++) {
30                const formInputOption = vm.formInputOptions[i];
31                let propogation = $filter('filter')(vm.propogations, { fromFormInputOptionId: formInputOption.id }).pop();
32                if(propogation) {
33                    vm.propogationExistByFromFormInputOptionId[formInputOption.id] = true;
34                } else {
35                    vm.propogationExistByFromFormInputOptionId[formInputOption.id] = false;
36                }
37            }
38        }
39        updatePropogationExistByFormInputOptionId();
40
41
42        vm.initNewPropogation = function() {
43            vm.newPropogation = {
44                fromFormInputId: vm.formInput.id,
45                toFormInputId: vm.toFormInput.id
46            };
47        }
48        
49        vm.inputErrorMessagePartial = settingsFactory.inputErrorMessagePartial;
50        
51        vm.submitPropogation = function() {
52            vm.newPropogation.created = utilsFactory.nowUnixTimestamp();
53            console.log('vm.newPropogation', vm.newPropogation);
54            return requestFactory.post('propogation', vm.newPropogation).then(function(response){
55                if(response.status == 201) {
56                    /* add inserted id to object */
57                    vm.newPropogation.id = response.data.insertId;
58                    // add fromFormInputLabel, fromFormInputQuestion, fromFormName, fromFormInputOptionLetter if numeric, and fromFormInputOptionText if numeric
59                    vm.newPropogation.fromFormInputLabel = formInput.label;
60                    vm.newPropogation.fromFormInputQuestion = formInput.question;
61                    if(vm.formInput.formInputTypeId == 2 || vm.formInput.formInputTypeId == 3) {
62                        let fromFormInputOption = $filter('getById')(vm.formInputOptions, vm.newPropogation.fromFormInputOptionId);
63                        vm.newPropogation.fromFormInputOptionLetter = fromFormInputOption.optionLetter;
64                        vm.newPropogation.fromFormInputOptionText = fromFormInputOption.optionText;
65                    }
66                    /* exclusion saved, add to list */
67                    vm.propogations.push(vm.newPropogation);
68                    /* clear new propogation to clean up form inputs */
69                    vm.initNewPropogation();
70
71                    updatePropogationExistByFormInputOptionId();
72                }
73            });
74        }
75        
76        
77        vm.deletePropogation = function(propogationId){
78            return requestFactory.delete('propogation', propogationId).then(function(){
79                /* find propogation */
80                let deletedIndex = $filter('getIndexById')(vm.propogations, propogationId);
81                
82                /* remove element from array */    
83                vm.propogations.splice(deletedIndex,1);
84
85                vm.propogations = vm.propogations.filter(p => p.id != propogationId);
86
87                updatePropogationExistByFormInputOptionId();
88            });
89        }
90
91        vm.submitEnabled = function(){
92            let enabled = false;
93            let propogationCount = 0;
94
95            if(vm.propogations && vm.propogations.length > 0){
96                propogationCount = vm.propogations.length;
97            }
98
99            /* is this an input with options?*/
100            if(vm.formInputType.minOptions > 0 && vm.toFormInputOptions){
101                if(propogationCount < vm.formInputOptions.length){
102                    /* are selected options defined for new propogation? */
103                    if(vm.newPropogation.toFormInputOptionId && vm.newPropogation.fromFormInputOptionId){
104                        enabled = true;
105                    }
106                    else{
107                        vm.disabledMessage = 'There are no options selected. You must select from/to options.';
108                    }
109                }
110                else{
111                    vm.disabledMessage = 'The maximum number of propogations have been submitted. There is a propogation for each input option.';
112                }
113            }
114            /* numeric input. only one propogation allowed */
115            else{
116                if(propogationCount == 0){
117                    enabled = true;
118                }
119                else{
120                    vm.disabledMessage = 'Only one propogation is needed for a numeric input. The value from the source input will be copied to the destination input, and the destination input will be hidden.'
121                }
122            }
123            return enabled;
124        }
125        
126        vm.initNewPropogation();
127        
128        return vm;
129    }
130})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.