$scope.myCtrl = this;
this.registerEntity = function registerEntity(entity) {
- schema[entity.name] = entity;
- data[entity.name] = data[entity.name] || {};
+ schema[entity.afName] = entity;
+ data[entity.afName] = data[entity.afName] || {};
};
this.registerField = function(entityName, fieldName) {
schema[entityName].fields.push(fieldName);
this.loadData = function() {
var toLoad = 0;
_.each(schema, function(entity, entityName) {
- if ($routeParams[entityName] || entity.autofill) {
+ if ($routeParams[entityName] || entity.afAutofill) {
toLoad++;
}
});
// "afModelProp" is a basic skeletal directive.
// Example usage: <af-model-list>... <af-model-prop af-name="myModel" af-type="Individual" /> ...</af-model-list>
angular.module('af').directive('afModelProp', function() {
+ // Whitelist of all allowed properties of an af-model
+ // (at least the ones we care about client-side - other's can be added for server-side processing and we'll just ignore them)
+ var modelProps = {
+ afType: '@',
+ afName: '@',
+ afLabel: '@',
+ afAutofill: '@'
+ };
return {
restrict: 'AE',
require: '^afModelList',
- scope: {
- afType: '@',
- afName: '@',
- afLabel: '@',
- afAutofill: '@'
- },
+ scope: modelProps,
link: function($scope, $el, $attr, afModelListCtrl) {
- var ts = $scope.ts = CRM.ts('afform');
- afModelListCtrl.registerEntity({
- id: null,
- type: $scope.afType,
- name: $scope.afName,
- label: $scope.afLabel,
- autofill: $scope.afAutofill,
- fields: []
- });
+ var ts = $scope.ts = CRM.ts('afform'),
+ entity = _.pick($scope, _.keys(modelProps));
+ entity.id = null;
+ entity.fields = [];
+ afModelListCtrl.registerEntity(entity);
// $scope.$watch('afModelProp', function(newValue){$scope.myOptions = newValue;});
}
};
-<div>{{ts('Contact email block for a model of type %1 named %2', {1: afModel.getDefn().type, 2: afModel.getDefn().name})}}</div>
+<div>{{ts('Contact email block for a model of type %1 named %2', {1: afModel.getDefn().afType, 2: afModel.getDefn().afName})}}</div>
-<div>{{ts('Contact name block for a model of type %1 named %2', {1: afModel.getDefn().type, 2: afModel.getDefn().name})}}</div>
+<div>{{ts('Contact name block for a model of type %1 named %2', {1: afModel.getDefn().afType, 2: afModel.getDefn().afName})}}</div>
var ts = $scope.ts = CRM.ts('afform');
$scope.afModel = ctrls[0];
var modelList = ctrls[1];
- $scope.fieldId = $scope.afModel.getDefn().name + '-' + $scope.fieldName;
+ $scope.fieldId = $scope.afModel.getDefn().afName + '-' + $scope.fieldName;
$scope.getData = $scope.afModel.getData;
$scope.getOptions = function() {