Commit 60cdbdaf authored by colemanw's avatar colemanw
Browse files

Implement Address block with chainSelect state/county

parent 79e72ae9
(function(angular, $, _) {
var id = 0;
// Example usage: <div af-fieldset="myModel"><af-field name="do_not_email" /></div>
angular.module('af').directive('afField', function() {
angular.module('af').directive('afField', function(crmApi4) {
return {
restrict: 'E',
require: ['^^afForm', '^^afFieldset', '?^^afJoin', '?^^afRepeatItem'],
......@@ -30,6 +30,28 @@
}, [])
};
};
// ChainSelect - watch control field & reload options as needed
if ($scope.defn.input_type === 'ChainSelect') {
$scope.$watch('dataProvider.getFieldData()[defn.input_attrs.controlField]', function(val) {
if (val) {
var params = {
where: [['name', '=', $scope.fieldName]],
select: ['options'],
loadOptions: true,
values: {}
};
params.values[$scope.defn.input_attrs.controlField] = val;
crmApi4($scope.dataProvider.getEntityType(), 'getFields', params, 0)
.then(function(data) {
$scope.defn.options.length = 0;
_.transform(data.options, function(options, label, key) {
options.push({key: key, label: label});
}, $scope.defn.options);
});
}
});
}
}
};
});
......
......@@ -21,6 +21,9 @@
this.getName = function() {
return this.modelName;
};
this.getEntityType = function() {
return this.afFormCtrl.getEntity(this.modelName).type;
};
this.getFieldData = function() {
var data = this.getData();
if (!data.length) {
......
......@@ -15,6 +15,9 @@
},
controller: function($scope) {
var self = this;
this.getEntityType = function() {
return this.entity;
};
this.getData = function() {
var data, fieldsetData;
if (self.repeatItem) {
......
......@@ -19,7 +19,7 @@
},
controller: function($scope) {
this.getItems = $scope.getItems = function() {
var data = $scope.afJoin ? $scope.afJoin.getData() : $scope.afFieldset.getData();
var data = getEntityController().getData();
while ($scope.min && data.length < $scope.min) {
data.push(getRepeatType() === 'join' ? {} : {fields: {}, joins: {}});
}
......@@ -31,6 +31,11 @@
}
this.getRepeatType = getRepeatType;
function getEntityController() {
return $scope.afJoin || $scope.afFieldset;
}
this.getEntityController = getEntityController;
$scope.addItem = function() {
$scope.getItems().push(getRepeatType() === 'join' ? {} : {fields: {}});
};
......@@ -64,6 +69,10 @@
this.getFieldData = function() {
return this.afRepeat.getRepeatType() === 'join' ? this.item : this.item.fields;
};
this.getEntityType = function() {
return this.afRepeat.getEntityController().getEntityType();
};
}
};
});
......
<input crm-ui-select="{data: select2Options, multiple: defn.input_attrs.multiple, placeholder: defn.input_attrs.placeholder}" id="{{ fieldId }}" ng-model="dataProvider.getFieldData()[fieldName]" />
<div class="af-container af-layout-inline">
<af-field name="street_address" />
<af-field name="location_type_id" />
</div>
<div class="af-container af-layout-inline">
<af-field name="city" />
<af-field name="state_province_id" />
<af-field name="country_id" />
<af-field name="postal_code" />
</div>
{
"title": "Address Block (default)",
"block": "Contact",
"join": "Address",
"repeat": true
}
......@@ -358,6 +358,7 @@
#afGuiEditor .af-gui-field-input-type-select .input-group-btn {
position: initial;
}
#afGuiEditor .af-gui-field-input-type-chainselect .input-group .dropdown-toggle,
#afGuiEditor .af-gui-field-input-type-select .input-group .dropdown-toggle {
padding: 3px 11px;
}
......
<div class="form-inline">
<div class="input-group">
<input autocomplete="off" class="form-control" placeholder="{{ ts('Select') }}" title="{{ ts('Click to add placeholder text') }}" ng-model="getSet('input_attrs.placeholder')" ng-model-options="{getterSetter: true}" type="text" />
<div class="input-group-btn">
<button type="button" class="btn btn-default disabled dropdown-toggle"><i class="crm-i fa-caret-down"></i></button>
</div>
</div>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment