- this.getFieldEntityType = function() {
- var joinType = ctrl.entityName.split('-join-');
- return joinType[1] || (ctrl.editor && ctrl.editor.getEntity(joinType[0]).type);
+ this.getFieldEntityType = function(fieldName) {
+ // If entityName is declared for this fieldset, return entity-type or join-type
+ if (ctrl.entityName) {
+ var joinType = ctrl.entityName.split('-join-');
+ return joinType[1] || (ctrl.editor && ctrl.editor.getEntity(joinType[0]).type);
+ }
+ // If entityName is not declared, this field belongs to a search
+ var entityType,
+ prefix = _.includes(fieldName, '.') ? fieldName.split('.')[0] : null;
+ _.each(afGui.meta.searchDisplays, function(searchDisplay) {
+ if (prefix) {
+ _.each(searchDisplay['saved_search.api_params'].join, function(join) {
+ var joinInfo = join[0].split(' AS ');
+ if (prefix === joinInfo[1]) {
+ entityType = joinInfo[0];
+ return false;
+ }
+ });
+ }
+ if (!entityType && fieldName && afGui.getField(searchDisplay['saved_search.api_entity'], fieldName)) {
+ entityType = searchDisplay['saved_search.api_entity'];
+ }
+ if (entityType) {
+ return false;
+ }
+ });
+ return entityType || _.map(afGui.meta.searchDisplays, 'saved_search.api_entity')[0];