Afform Gui - Support cloning existing forms
[civicrm-core.git] / ext / afform / core / ang / af / afFieldset.directive.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() {
15 var ctrl = this,
16 localData = [];
17
18 this.getData = function() {
19 return ctrl.afFormCtrl ? ctrl.afFormCtrl.getData(ctrl.modelName) : localData;
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 = ctrl.getData();
29 if (!data.length) {
30 data.push({fields: {}});
31 }
32 return data[0].fields;
33 };
34 }
35 };
36 });
37 })(angular, CRM.$, CRM._);