editor.layout = {'#children': []};
$scope.entities = {};
- if ($scope.afform.type === 'form') {
+ if (editor.getFormType() === 'form') {
editor.allowEntityConfig = true;
editor.layout['#children'] = afGui.findRecursive($scope.afform.layout, {'#tag': 'af-form'})[0]['#children'];
$scope.entities = _.mapValues(afGui.findRecursive(editor.layout['#children'], {'#tag': 'af-entity'}, 'name'), backfillEntityDefaults);
}
}
- if ($scope.afform.type === 'block') {
+ else if (editor.getFormType() === 'block') {
editor.layout['#children'] = $scope.afform.layout;
editor.blockEntity = $scope.afform.join || $scope.afform.block;
$scope.entities[editor.blockEntity] = backfillEntityDefaults({
});
}
- if ($scope.afform.type === 'search') {
+ else if (editor.getFormType() === 'search') {
editor.layout['#children'] = afGui.findRecursive($scope.afform.layout, {'af-fieldset': ''})[0]['#children'];
-
}
// Set changesSaved to true on initial load, false thereafter whenever changes are made to the model
}, true);
}
+ this.getFormType = function() {
+ return $scope.afform.type;
+ };
+
$scope.updateLayoutHtml = function() {
$scope.layoutHtml = '...Loading...';
crmApi4('Afform', 'convert', {layout: $scope.afform.layout, from: 'deep', to: 'html', formatWhitespace: true})
label: ts('%1 Fields', {1: $scope.getMeta().label}),
fields: filterFields($scope.getMeta().fields)
});
-
+ // Add fields for af-join blocks
_.each(afGui.meta.entities, function(entity, entityName) {
if (check(ctrl.editor.layout['#children'], {'af-join': entityName})) {
$scope.fieldList.push({
function filterFields(fields) {
return _.transform(fields, function(fieldList, field) {
if (!search || _.contains(field.name, search) || _.contains(field.label.toLowerCase(), search)) {
- fieldList.push({
- "#tag": "af-field",
- name: field.name
- });
+ fieldList.push(fieldDefaults(field));
}
}, []);
}
+
+ function fieldDefaults(field) {
+ var tag = {
+ "#tag": "af-field",
+ name: field.name
+ };
+ return tag;
+ }
}
function buildBlockList(search) {
function filterFields(fields, prefix) {
return _.transform(fields, function(fieldList, field) {
if (!search || _.contains(field.name, search) || _.contains(field.label.toLowerCase(), search)) {
- fieldList.push({
- "#tag": "af-field",
- name: (prefix ? prefix + '.' : '') + field.name
- });
+ fieldList.push(fieldDefaults(field, prefix));
}
}, []);
}
+
+ function fieldDefaults(field, prefix) {
+ var tag = {
+ "#tag": "af-field",
+ name: (prefix ? prefix + '.' : '') + field.name
+ };
+ if (field.input_type === 'Select') {
+ tag.defn = {input_attrs: {multiple: true}};
+ } else if (field.input_type === 'Date') {
+ tag.defn = {input_type: 'Select', search_range: true};
+ } else if (field.options) {
+ tag.defn = {input_type: 'Select', input_attrs: {multiple: true}};
+ }
+ return tag;
+ }
}
function buildElementList(search) {
};
this.isSearch = function() {
- return !_.isEmpty($scope.meta.searchDisplays);
+ return ctrl.editor.getFormType() === 'search';
};
this.canBeRange = function() {