Don't write field defn unless changed
authorColeman Watts <coleman@civicrm.org>
Thu, 7 Nov 2019 00:07:20 +0000 (19:07 -0500)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:20 +0000 (19:13 -0700)
ext/afform/gui/ang/afGuiEditor.js
ext/afform/gui/ang/afGuiEditor/config-entity.html
ext/afform/gui/ang/afGuiEditor/field.html

index ecbdeddf6e92325cc0a92ca33bac48770f83d598..65a2f86a0bd0ba822d15677182cd8510ccf434d0 100644 (file)
           $timeout(function() {
             initialize(_.cloneDeep(newForm));
             editor.addEntity('Contact');
+            $scope.layout['#children'].push({
+              "#tag": "button",
+              "ng-click": "modelListCtrl.submit()",
+              "#children": [
+                {
+                  "#text": "Submit"
+                }
+              ]
+            });
           });
         }
 
@@ -47,7 +56,6 @@
           $scope.layout = getTags($scope.afform.layout, 'af-form')[0];
           evaluate($scope.layout['#children']);
           $scope.entities = getTags($scope.layout['#children'], 'af-entity', 'name');
-          expandFields($scope.layout['#children']);
           _.each(_.keys($scope.entities), buildFieldList);
 
           // Set changesSaved to true on initial load, false thereafter whenever changes are made to the model
             $scope.fieldList[entityName].push({
               "#tag": "af-field",
               name: field.name,
-              defn: _.cloneDeep(_.pick(field, ['title', 'input_type', 'input_attrs']))
+              defn: {}
             });
           });
         }
       controller: function($scope) {
 
         $scope.getEntity = function() {
-          return $scope.editor.getEntity($scope.entityName);
+          return $scope.editor ? $scope.editor.getEntity($scope.entityName) : {};
         };
 
         $scope.getDefn = function() {
-          return $scope.editor.getField($scope.getEntity().type, $scope.node.name);
+          return $scope.editor ? $scope.editor.getField($scope.getEntity().type, $scope.node.name) : {};
         };
       }
     };
     return {
       restrict: "A",
       require: "ngModel",
+      scope: {
+        defaultValue: '='
+      },
       link: function(scope, element, attrs, ngModel) {
         var ts = CRM.ts();
 
         function read() {
           var htmlVal = element.html();
           if (!htmlVal) {
-            htmlVal = ts('Unnamed');
+            htmlVal = scope.defaultValue;
             element.html(htmlVal);
           }
           ngModel.$setViewValue(htmlVal);
         }
 
         ngModel.$render = function() {
-          element.html(ngModel.$viewValue || ' ');
+          element.html(ngModel.$viewValue || scope.defaultValue);
         };
 
         // Special handling for enter and escape keys
           }
           // Escape: undo
           if (e.which === 27) {
-            element.html(ngModel.$viewValue || ' ');
+            element.html(ngModel.$viewValue || scope.defaultValue);
             element.blur();
           }
         });
index cf32fadf031173e9724eae4d0033d6e3cb44cf4d..e5c48d3ffe24e80671ddb9cec32599ec4a891e1a 100644 (file)
@@ -21,7 +21,7 @@
     <legend>{{ ts('Fields') }}</legend>
     <div class="af-gui-field-select-list" ui-sortable="{update: rebuildFieldList, items: '> div:not(.disabled)', connectWith: '[data-entity=' + selectedEntity + '] [ui-sortable]'}" ng-model="fieldList[selectedEntity]">
       <div ng-repeat="field in fieldList[selectedEntity]" ng-class="{disabled: fieldInUse(selectedEntity, field.name)}">
-        {{ field.defn.title }}
+        {{ editor.getField(editor.getEntity(selectedEntity).type, field.name).title }}
       </div>
     </div>
   </fieldset>
index e3a55a518f60268df08052f167efb6ddfc160a90..01cc02d74acb8440d4889d6975b746e2de83f89a 100644 (file)
@@ -2,6 +2,6 @@
   <span>{{ getEntity().label + ': ' + getDefn().title }}</span>
 </div>
 <div>
-  <label>{{ getDefn().title }}</label>
+  <label af-gui-editable ng-model="node.defn.title" default-value="getDefn().title">{{ node.defn.title || getDefn().title }}</label>
   <input class="form-control" disabled placeholder="{{ node.name }}" />
 </div>