Canh Ngo pushed to branch feature/cmng-psp1-CHANNELMGR-604 at cms-community / 
hippo-addon-channel-manager


Commits:
f023f4b0 by Canh Ngo at 2016-05-26T16:24:38+02:00
CHANNELMGR-604 simplify channel-property directive with error object

- - - - -


5 changed files:

- 
frontend-ng/src/angularjs/channel/actions/settings/property/property.controller.js
- 
frontend-ng/src/angularjs/channel/actions/settings/property/property.directive.js
- frontend-ng/src/angularjs/channel/actions/settings/property/property.html
- frontend-ng/src/angularjs/channel/actions/settings/property/property.spec.js
- frontend-ng/src/angularjs/channel/actions/settings/settings.html


Changes:

=====================================
frontend-ng/src/angularjs/channel/actions/settings/property/property.controller.js
=====================================
--- 
a/frontend-ng/src/angularjs/channel/actions/settings/property/property.controller.js
+++ 
b/frontend-ng/src/angularjs/channel/actions/settings/property/property.controller.js
@@ -53,11 +53,6 @@ export class ChannelPropertyCtrl {
     }
   }
 
-  getFieldErrorObject() {
-    const formField = this.form[this.field];
-    return formField && formField.$error;
-  }
-
   getDropDownListValues() {
     if (!this.annotation || this.annotation.type !== 'DropDownList') {
       this.$log.debug(`Field '${this.field}' is not a dropdown.`);


=====================================
frontend-ng/src/angularjs/channel/actions/settings/property/property.directive.js
=====================================
--- 
a/frontend-ng/src/angularjs/channel/actions/settings/property/property.directive.js
+++ 
b/frontend-ng/src/angularjs/channel/actions/settings/property/property.directive.js
@@ -22,7 +22,7 @@ export function channelPropertyDirective() {
     bindToController: {
       field: '@channelProperty',
       value: '=channelPropertyValue',
-      form: '=channelPropertiesForm',
+      error: '=channelPropertiesError',
       data: '=channelPropertiesData',
     },
     templateUrl: 'channel/actions/settings/property/property.html',


=====================================
frontend-ng/src/angularjs/channel/actions/settings/property/property.html
=====================================
--- a/frontend-ng/src/angularjs/channel/actions/settings/property/property.html
+++ b/frontend-ng/src/angularjs/channel/actions/settings/property/property.html
@@ -33,7 +33,7 @@
         {{choice}}
       </md-option>
     </md-select>
-    <div ng-messages="channelProperty.getFieldErrorObject()">
+    <div ng-messages="channelProperty.error">
       <div ng-message="required">{{ 'VALIDATION_REQUIRED' | translate }}</div>
     </div>
   </md-input-container>
@@ -66,7 +66,7 @@
         <md-icon class="material-icons">search</md-icon>
       </md-button>
     </div>
-    <div ng-messages="channelProperty.getFieldErrorObject()">
+    <div ng-messages="channelProperty.error">
       <div ng-message="required">{{ 'VALIDATION_REQUIRED' | translate }}</div>
     </div>
   </md-input-container>
@@ -95,7 +95,7 @@
         <md-icon class="material-icons">search</md-icon>
       </md-button>
     </div>
-    <div ng-messages="channelProperty.getFieldErrorObject()">
+    <div ng-messages="channelProperty.error">
       <div ng-message="required">{{ 'VALIDATION_REQUIRED' | translate }}</div>
     </div>
   </md-input-container>
@@ -106,7 +106,7 @@
            ng-required="channelProperty.required"
            ng-model="channelProperty.value"
            ng-disabled="channelProperty.readOnly">
-    <div ng-messages="channelProperty.getFieldErrorObject()">
+    <div ng-messages="channelProperty.error">
       <div ng-message="required">{{ 'VALIDATION_REQUIRED' | translate }}</div>
     </div>
   </md-input-container>


=====================================
frontend-ng/src/angularjs/channel/actions/settings/property/property.spec.js
=====================================
--- 
a/frontend-ng/src/angularjs/channel/actions/settings/property/property.spec.js
+++ 
b/frontend-ng/src/angularjs/channel/actions/settings/property/property.spec.js
@@ -62,13 +62,13 @@ describe('ChannelProperty', () => {
     $scope = $rootScope.$new();
     $scope.field = field;
     $scope.value = value;
-    $scope.form = { };
+    $scope.fieldError = { };
     $scope.data = channelInfoDescription;
 
     $element = angular.element(`
       <div channel-property="{{field}}"
            channel-property-value="value"
-           channel-properties-form="form"
+           channel-properties-error="fieldError"
            channel-properties-data="data"></div>
     `);
     $compile($element)($scope);


=====================================
frontend-ng/src/angularjs/channel/actions/settings/settings.html
=====================================
--- a/frontend-ng/src/angularjs/channel/actions/settings/settings.html
+++ b/frontend-ng/src/angularjs/channel/actions/settings/settings.html
@@ -31,7 +31,7 @@
       <div ng-repeat="field in fieldGroup.value"
            channel-property="{{field}}"
            channel-property-value="channelSettings.values[field]"
-           channel-properties-form="form"
+           channel-properties-error="form[field].$error"
            channel-properties-data="channelSettings.channelInfoDescription">
       </div>
     </div>
@@ -40,7 +40,7 @@
          ng-repeat="field in channelSettings.getUngroupedFields()"
          channel-property="{{field}}"
          channel-property-value="channelSettings.values[field]"
-         channel-properties-form="form"
+         channel-properties-error="form[field].$error"
          channel-properties-data="channelSettings.channelInfoDescription">
     </div>
 



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/f023f4b0ce7ef8e9fecbe0f92b4e0b86888782dd
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to