From 81692371ec771e02fb2f29e4f2bc4249e24d3326 Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 5 Oct 2016 15:35:53 +0300 Subject: [PATCH] search by hasOne link --- application/Espo/Core/SelectManagers/Base.php | 9 ++- .../metadata/entityDefs/Account.json | 3 +- .../metadata/entityDefs/Contact.json | 7 +- .../metadata/entityDefs/Opportunity.json | 3 +- client/src/views/fields/link-one.js | 73 +++++++++++++++++++ 5 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 client/src/views/fields/link-one.js diff --git a/application/Espo/Core/SelectManagers/Base.php b/application/Espo/Core/SelectManagers/Base.php index caeaa66ed0..715a99ba79 100644 --- a/application/Espo/Core/SelectManagers/Base.php +++ b/application/Espo/Core/SelectManagers/Base.php @@ -257,18 +257,21 @@ class Base $defs = $relDefs[$link]; if ($relationType == 'manyMany') { - $this->addJoin($link, $result); + $this->addJoin([$link, $link . 'Filter'], $result); $midKeys = $seed->getRelationParam($link, 'midKeys'); if (!empty($midKeys)) { $key = $midKeys[1]; - $part[$link . 'Middle.' . $key] = $idsValue; + $part[$link . 'Filter' . 'Middle.' . $key] = $idsValue; } - } else if ($relationType== 'belongsTo') { + } else if ($relationType == 'belongsTo') { $key = $seed->getRelationParam($link, 'key'); if (!empty($key)) { $part[$key] = $idsValue; } + } else if ($relationType == 'hasOne') { + $this->addJoin([$link, $link . 'Filter'], $result); + $part[$link . 'Filter' . '.id'] = $idsValue; } else { return; } diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json index c039678264..e04c511362 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json @@ -164,7 +164,8 @@ "type": "link", "layoutMassUpdateDisabled": true, "layoutListDisabled": true, - "readOnly": true + "readOnly": true, + "view": "views/fields/link-one" } }, "links": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json index 27c800e25f..d25a4c27ad 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json @@ -182,13 +182,16 @@ "type": "link", "layoutMassUpdateDisabled": true, "layoutListDisabled": true, - "readOnly": true + "readOnly": true, + "notStorable": true, + "view": "views/fields/link-one" }, "originalLead": { "type": "link", "layoutMassUpdateDisabled": true, "layoutListDisabled": true, - "readOnly": true + "readOnly": true, + "view": "views/fields/link-one" } }, "links": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json index 5c9ff101bf..7b524e6ac2 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json @@ -74,7 +74,8 @@ "type": "link", "layoutMassUpdateDisabled": true, "layoutListDisabled": true, - "readOnly": true + "readOnly": true, + "view": "views/fields/link-one" }, "createdAt": { "type": "datetime", diff --git a/client/src/views/fields/link-one.js b/client/src/views/fields/link-one.js new file mode 100644 index 0000000000..86cf4ee1c8 --- /dev/null +++ b/client/src/views/fields/link-one.js @@ -0,0 +1,73 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko + * Website: http://www.espocrm.com + * + * EspoCRM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EspoCRM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EspoCRM. If not, see http://www.gnu.org/licenses/. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +Espo.define('views/fields/link-one', 'views/fields/link', function (Dep) { + + return Dep.extend({ + + readOnly: true, + + searchTypeList: ['is', 'isOneOf'], + + fetchSearch: function () { + var type = this.$el.find('select.search-type').val(); + var value = this.$el.find('[name="' + this.idName + '"]').val(); + + if (type == 'isOneOf') { + var data = { + type: 'linkedWith', + field: this.name, + value: this.searchData.oneOfIdList, + oneOfIdList: this.searchData.oneOfIdList, + oneOfNameHash: this.searchData.oneOfNameHash, + data: { + type: type + } + }; + return data; + + } else { + if (!value) { + return false; + } + var data = { + type: 'linkedWith', + field: this.name, + value: value, + valueName: this.$el.find('[name="' + this.nameName + '"]').val(), + data: { + type: type + } + }; + return data; + } + }, + + }); +}); +