link multiple primary fix

This commit is contained in:
Yuri Kuznetsov
2024-06-10 09:16:11 +03:00
parent 552983ca33
commit 0558739e67
3 changed files with 37 additions and 7 deletions
@@ -60,7 +60,9 @@
"layout": "listForContact",
"createAttributeMap": {
"accountId": "accountId",
"accountName": "accountName"
"accountName": "accountName",
"id": "contactId",
"name": "contactName"
},
"selectHandler": "handlers/select-related/same-account"
},
@@ -61,7 +61,7 @@ class LinkMultipleWithColumnsWithPrimaryFieldView extends LinkMultipleWithColumn
const $target = $(e.currentTarget);
const id = $target.data('id');
LinkMultipleWithPrimaryFieldView.prototype.switchPrimary.call(this, id);
this.switchPrimary(id);
};
this.primaryId = this.model.get(this.primaryIdAttribute);
@@ -78,8 +78,23 @@ class LinkMultipleWithColumnsWithPrimaryFieldView extends LinkMultipleWithColumn
this.primaryName = id ?
this.nameHash[id] : null;
}
this.trigger('change');
switchPrimary(id) {
const $switch = this.$el.find(`[data-id="${id}"][data-action="switchPrimary"]`);
if (!$switch.hasClass('active')) {
this.$el.find('button[data-action="switchPrimary"]')
.removeClass('active')
.children()
.addClass('text-muted');
$switch.addClass('active').children().removeClass('text-muted');
this.setPrimaryId(id);
this.trigger('change');
}
}
renderLinks() {
@@ -184,7 +199,14 @@ class LinkMultipleWithColumnsWithPrimaryFieldView extends LinkMultipleWithColumn
if ($first.length) {
$first.addClass('active').children().removeClass('text-muted');
this.setPrimaryId($first.data('id'));
const id = $first.data('id');
this.setPrimaryId(id);
if (id !== this.primaryId) {
this.trigger('change');
}
}
}
}
@@ -51,6 +51,8 @@ class LinkMultipleWithPrimaryFieldView extends LinkMultipleFieldView {
$switch.addClass('active').children().removeClass('text-muted');
this.setPrimaryId(id);
this.trigger('change');
}
}
@@ -100,8 +102,6 @@ class LinkMultipleWithPrimaryFieldView extends LinkMultipleFieldView {
this.primaryName = id ?
this.nameHash[id] : null;
this.trigger('change');
}
/**
@@ -249,7 +249,13 @@ class LinkMultipleWithPrimaryFieldView extends LinkMultipleFieldView {
if ($first.length) {
$first.addClass('active').children().removeClass('text-muted');
this.setPrimaryId($first.data('id'));
const id = $first.data('id');
this.setPrimaryId(id);
if (id !== this.primaryId) {
this.trigger('change');
}
}
}
}