controller: function wfEditableFieldController()

in public/components/editable-field/editable-field.js [114:151]


        controller: function wfEditableFieldController($scope, $element, $attrs) {

            // one time bind of wfEditableType
            $scope.editableType = $attrs.wfEditableType;

            $scope.preserveWhitespace = $scope.editableType === 'textarea';

            this.setEditMode = (newMode) => {
                $scope.onEditableEditModeUpdate({
                    newMode: newMode
                });
                $scope.isEditMode = !!newMode;
            };

            this.setErrors = (errors) => $scope.editableErrors = errors;

            $scope.$watch('isEditMode', (newValue, oldValue) => {
                if (newValue) {
                    $attrs.$addClass(CLASS_EDITABLE_EDITMODE);
                } else {
                    $attrs.$removeClass(CLASS_EDITABLE_EDITMODE);
                }

                // Broadcast changed edit mode when value changes on the applied scope.
                if (newValue !== oldValue) {
                    $scope.$broadcast('wfEditable.changedEditMode', newValue, oldValue);
                }
            });

            $scope.commit = () => {
                $scope.$broadcast('wfEditable.commit');
            };

            $scope.cancel = () => {
                $scope.$broadcast('wfEditable.cancel');
            };

        }