Implement Address block with chainSelect state/county
[civicrm-core.git] / ext / afform / core / ang / af / Fieldset.js
1 (function(angular, $, _) {
2 // Example usage: <af-form><af-entity name="Person" type="Contact" /> ... <fieldset af-fieldset="Person> ... </fieldset></af-form>
3 angular.module('af').directive('afFieldset', function() {
4 return {
5 restrict: 'A',
6 require: ['afFieldset', '^afForm'],
7 bindToController: {
8 modelName: '@afFieldset'
9 },
10 link: function($scope, $el, $attr, ctrls) {
11 var self = ctrls[0];
12 self.afFormCtrl = ctrls[1];
13 },
14 controller: function($scope){
15 this.getDefn = function() {
16 return this.afFormCtrl.getEntity(this.modelName);
17 };
18 this.getData = function() {
19 return this.afFormCtrl.getData(this.modelName);
20 };
21 this.getName = function() {
22 return this.modelName;
23 };
24 this.getEntityType = function() {
25 return this.afFormCtrl.getEntity(this.modelName).type;
26 };
27 this.getFieldData = function() {
28 var data = this.getData();
29 if (!data.length) {
30 data.push({fields: {}});
31 }
32 return data[0].fields;
33 };
34 }
35 };
36 });
37 })(angular, CRM.$, CRM._);