From 291135c4b1f920f4ac211c33a8b7edf695a3fc04 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 3 May 2019 16:36:37 -0700 Subject: [PATCH] afModel*, afBlock*, afField - Add skeletal directives --- ext/afform/core/ang/af/Model.js | 27 +++++++++++++++ ext/afform/core/ang/af/ModelList.js | 34 +++++++++++++++++++ ext/afform/core/ang/af/ModelProp.js | 24 +++++++++++++ ext/afform/core/ang/afBlock/ContactEmail.html | 1 + ext/afform/core/ang/afBlock/ContactEmail.js | 15 ++++++++ ext/afform/core/ang/afBlock/ContactName.html | 1 + ext/afform/core/ang/afBlock/ContactName.js | 15 ++++++++ ext/afform/core/ang/afField/afField.html | 3 ++ ext/afform/core/ang/afField/afField.js | 17 ++++++++++ 9 files changed, 137 insertions(+) create mode 100644 ext/afform/core/ang/af/Model.js create mode 100644 ext/afform/core/ang/af/ModelList.js create mode 100644 ext/afform/core/ang/af/ModelProp.js create mode 100644 ext/afform/core/ang/afBlock/ContactEmail.html create mode 100644 ext/afform/core/ang/afBlock/ContactEmail.js create mode 100644 ext/afform/core/ang/afBlock/ContactName.html create mode 100644 ext/afform/core/ang/afBlock/ContactName.js create mode 100644 ext/afform/core/ang/afField/afField.html create mode 100644 ext/afform/core/ang/afField/afField.js diff --git a/ext/afform/core/ang/af/Model.js b/ext/afform/core/ang/af/Model.js new file mode 100644 index 0000000000..8a07e9f5d3 --- /dev/null +++ b/ext/afform/core/ang/af/Model.js @@ -0,0 +1,27 @@ +(function(angular, $, _) { + // "afModel" is a basic skeletal directive. + // Example usage: ... ... ... + angular.module('af').directive('afModel', function() { + return { + restrict: 'AE', + require: '^afModelList', + scope: { + afName: '@' + }, + link: function($scope, $el, $attr, afModelListCtrl) { + $scope.afModelListCtrl = afModelListCtrl; + // $scope.$watch('afName', function(newValue){ + // // $scope.myOptions = newValue; + // $scope.modelDefn = afModelListCtrl.getEntity(newValue); + // console.log('Lookup entity', newValue, $scope.modelDefn); + // }); + }, + controller: function($scope){ + this.getDefn = function getDefn() { + return $scope.afModelListCtrl.getEntity($scope.afName); + // return $scope.modelDefn; + } + } + }; + }); +})(angular, CRM.$, CRM._); diff --git a/ext/afform/core/ang/af/ModelList.js b/ext/afform/core/ang/af/ModelList.js new file mode 100644 index 0000000000..1c6fc6f207 --- /dev/null +++ b/ext/afform/core/ang/af/ModelList.js @@ -0,0 +1,34 @@ +(function(angular, $, _) { + // "afModelList" is a basic skeletal directive. + // Example usage: + angular.module('af').directive('afModelList', function() { + return { + restrict: 'AE', + scope: { + // afModelList: '=', + ctrl: '@' + }, + link: function($scope, $el, $attr) {}, + controller: ['$scope', function($scope) { + var entities = {}; + + $scope.$parent[$scope.ctrl] = this; + + this.registerEntity = function registerEntity(entity) { + // console.log('register', entity.name); + entities[entity.name] = entity; + }; + this.getEntity = function getEntity(name) { + // console.log('get', name); + return entities[name]; + }; + + // TODO: Support for tapping into load+save API calls + + this.submit = function submit() { + CRM.alert('TODO: Submit'); + }; + }] + }; + }); +})(angular, CRM.$, CRM._); diff --git a/ext/afform/core/ang/af/ModelProp.js b/ext/afform/core/ang/af/ModelProp.js new file mode 100644 index 0000000000..ef44b79feb --- /dev/null +++ b/ext/afform/core/ang/af/ModelProp.js @@ -0,0 +1,24 @@ +(function(angular, $, _) { + // "afModelProp" is a basic skeletal directive. + // Example usage: ... ... + angular.module('af').directive('afModelProp', function() { + return { + restrict: 'AE', + require: '^afModelList', + scope: { + afType: '@', + afName: '@', + afLabel: '@' + }, + link: function($scope, $el, $attr, afModelListCtrl) { + var ts = $scope.ts = CRM.ts('afform'); + afModelListCtrl.registerEntity({ + type: $scope.afType, + name: $scope.afName, + label: $scope.afLabel + }); + // $scope.$watch('afModelProp', function(newValue){$scope.myOptions = newValue;}); + } + }; + }); +})(angular, CRM.$, CRM._); diff --git a/ext/afform/core/ang/afBlock/ContactEmail.html b/ext/afform/core/ang/afBlock/ContactEmail.html new file mode 100644 index 0000000000..680a4f1eca --- /dev/null +++ b/ext/afform/core/ang/afBlock/ContactEmail.html @@ -0,0 +1 @@ +
{{ts('Contact email block for a model of type %1 named %2', {1: afModel.getDefn().type, 2: afModel.getDefn().name})}}
diff --git a/ext/afform/core/ang/afBlock/ContactEmail.js b/ext/afform/core/ang/afBlock/ContactEmail.js new file mode 100644 index 0000000000..88c744effe --- /dev/null +++ b/ext/afform/core/ang/afBlock/ContactEmail.js @@ -0,0 +1,15 @@ +(function(angular, $, _) { + // Example usage:
+ angular.module('afBlock').directive('afBlockContactEmail', function() { + return { + restrict: 'AE', + require: ['^afModel'], + templateUrl: '~/afBlock/ContactEmail.html', + scope: {}, + link: function($scope, $el, $attr, ctrls) { + var ts = $scope.ts = CRM.ts('afform'); + $scope.afModel = ctrls[0]; + } + }; + }); +})(angular, CRM.$, CRM._); diff --git a/ext/afform/core/ang/afBlock/ContactName.html b/ext/afform/core/ang/afBlock/ContactName.html new file mode 100644 index 0000000000..e1155b04b6 --- /dev/null +++ b/ext/afform/core/ang/afBlock/ContactName.html @@ -0,0 +1 @@ +
{{ts('Contact name block for a model of type %1 named %2', {1: afModel.getDefn().type, 2: afModel.getDefn().name})}}
diff --git a/ext/afform/core/ang/afBlock/ContactName.js b/ext/afform/core/ang/afBlock/ContactName.js new file mode 100644 index 0000000000..16001f812c --- /dev/null +++ b/ext/afform/core/ang/afBlock/ContactName.js @@ -0,0 +1,15 @@ +(function(angular, $, _) { + // Example usage: + angular.module('afBlock').directive('afBlockContactName', function() { + return { + restrict: 'AE', + require: ['^afModel'], + templateUrl: '~/afBlock/ContactName.html', + scope: {}, + link: function($scope, $el, $attr, ctrls) { + var ts = $scope.ts = CRM.ts('afform'); + $scope.afModel = ctrls[0]; + } + }; + }); +})(angular, CRM.$, CRM._); diff --git a/ext/afform/core/ang/afField/afField.html b/ext/afform/core/ang/afField/afField.html new file mode 100644 index 0000000000..3590517913 --- /dev/null +++ b/ext/afform/core/ang/afField/afField.html @@ -0,0 +1,3 @@ +
+ {{ts('Single field for %1::%2', {1: afModel.getDefn().type,2: fieldName})}} +
diff --git a/ext/afform/core/ang/afField/afField.js b/ext/afform/core/ang/afField/afField.js new file mode 100644 index 0000000000..911e8deed2 --- /dev/null +++ b/ext/afform/core/ang/afField/afField.js @@ -0,0 +1,17 @@ +(function(angular, $, _) { + // Example usage: + angular.module('afField').directive('afField', function() { + return { + restrict: 'AE', + require: ['^afModel'], + templateUrl: '~/afField/afField.html', + scope: { + fieldName: '@' + }, + link: function($scope, $el, $attr, ctrls) { + var ts = $scope.ts = CRM.ts('afform'); + $scope.afModel = ctrls[0]; + } + }; + }); +})(angular, CRM.$, CRM._); -- 2.25.1