Afform Gui - Support cloning existing forms
[civicrm-core.git] / ext / afform / core / ang / af / afFieldset.directive.js
CommitLineData
291135c4 1(function(angular, $, _) {
a365a0c3 2 // Example usage: <af-form><af-entity name="Person" type="Contact" /> ... <fieldset af-fieldset="Person> ... </fieldset></af-form>
dce8ad72 3 angular.module('af').directive('afFieldset', function() {
291135c4 4 return {
d16b39c3 5 restrict: 'A',
a92d81a1 6 require: ['afFieldset', '?^^afForm'],
344e8290 7 bindToController: {
d16b39c3 8 modelName: '@afFieldset'
291135c4 9 },
344e8290
CW
10 link: function($scope, $el, $attr, ctrls) {
11 var self = ctrls[0];
12 self.afFormCtrl = ctrls[1];
291135c4 13 },
a92d81a1
CW
14 controller: function() {
15 var ctrl = this,
16 localData = [];
17
344e8290 18 this.getData = function() {
a92d81a1 19 return ctrl.afFormCtrl ? ctrl.afFormCtrl.getData(ctrl.modelName) : localData;
17d153bd
CW
20 };
21 this.getName = function() {
344e8290
CW
22 return this.modelName;
23 };
21dff704
CW
24 this.getEntityType = function() {
25 return this.afFormCtrl.getEntity(this.modelName).type;
26 };
344e8290 27 this.getFieldData = function() {
a92d81a1 28 var data = ctrl.getData();
344e8290
CW
29 if (!data.length) {
30 data.push({fields: {}});
31 }
32 return data[0].fields;
a365a0c3 33 };
291135c4
TO
34 }
35 };
36 });
37})(angular, CRM.$, CRM._);