if (column.link) {
ctrl.onChangeLink(column, column.link.path, '');
} else {
- var defaultLink = ctrl.getLinks()[0];
+ var defaultLink = ctrl.getLinks(column.key)[0];
column.link = {path: defaultLink ? defaultLink.path : 'civicrm/'};
ctrl.onChangeLink(column, null, column.link.path);
}
}
};
- this.getLinks = function() {
+ this.getLinks = function(columnKey) {
if (!ctrl.links) {
- ctrl.links = buildLinks();
+ ctrl.links = {'*': buildLinks()};
}
- return ctrl.links;
+ if (!columnKey) {
+ return ctrl.links['*'];
+ }
+ var expr = ctrl.getExprFromSelect(columnKey),
+ info = searchMeta.parseExpr(expr),
+ joinEntity = '';
+ if (info.field.fk_entity || info.field.name !== info.field.fieldName) {
+ joinEntity = info.prefix + (info.field.fk_entity ? info.field.name : info.field.name.substr(0, info.field.name.lastIndexOf('.')));
+ } else if (info.prefix) {
+ joinEntity = info.prefix.replace('.', '');
+ }
+ if (!ctrl.links[joinEntity]) {
+ ctrl.links[joinEntity] = _.filter(ctrl.links['*'], function(link) {
+ return joinEntity === (link.join || '');
+ });
+ }
+ return ctrl.links[joinEntity];
};
// Build a list of all possible links to main entity or join entities
if (entityCount[joinEntity.name] > 1) {
link.title += ' ' + entityCount[joinEntity.name];
}
+ link.join = joinName[1];
links.push(link);
});
});
_.each((joinEntity || {}).paths, function(path) {
var link = _.cloneDeep(path);
link.path = link.path.replace(/\[id/g, '[' + idField);
+ link.join = idField;
links.push(link);
});
}
};
this.$onInit = function() {
+ var defaultLinks = _.filter(ctrl.links, function(link) {
+ return !link.join;
+ });
if (!ctrl.group.length) {
- if (ctrl.links.length) {
- _.each(_.pluck(ctrl.links, 'path'), ctrl.addItem);
+ if (defaultLinks.length) {
+ _.each(_.pluck(defaultLinks, 'path'), ctrl.addItem);
} else {
ctrl.addItem('civicrm/');
}
<option value="_blank">{{:: ts('New tab') }}</option>
<option value="crm-popup">{{:: ts('Popup dialog') }}</option>
</select>
- <crm-search-admin-link-select ng-if="col.link" link="col.link" on-change="$ctrl.parent.onChangeLink(col, before, after)" api-entity="$ctrl.apiEntity" api-params="$ctrl.apiParams" links=":: $ctrl.parent.getLinks()">
+ <crm-search-admin-link-select ng-if="col.link" link="col.link" on-change="$ctrl.parent.onChangeLink(col, before, after)" api-entity="$ctrl.apiEntity" api-params="$ctrl.apiParams" links=":: $ctrl.parent.getLinks(col.key)">
</crm-search-admin-link-select>
</div>
<div class="form-inline crm-search-admin-flex-row">