From f085d2140cd2bc0b824379317119151ec3fab9cf Mon Sep 17 00:00:00 2001 From: yuri Date: Thu, 16 Aug 2018 16:47:16 +0300 Subject: [PATCH] fix strip url --- .../Metadata/Company/entityDefs.json | 3 +- .../metadata/entityDefs/Account.json | 3 +- .../Resources/metadata/entityDefs/Lead.json | 3 +- .../Espo/Resources/i18n/en_US/Admin.json | 3 +- .../Espo/Resources/metadata/fields/url.json | 4 +++ client/src/views/fields/url.js | 35 ++++++++++++++++++- 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/application/Espo/Core/Templates/Metadata/Company/entityDefs.json b/application/Espo/Core/Templates/Metadata/Company/entityDefs.json index 4faf5902f9..c6223d0d18 100644 --- a/application/Espo/Core/Templates/Metadata/Company/entityDefs.json +++ b/application/Espo/Core/Templates/Metadata/Company/entityDefs.json @@ -9,7 +9,8 @@ "type": "text" }, "website": { - "type": "url" + "type": "url", + "strip": true }, "emailAddress": { "type": "email" diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json index 8f8c25f2de..f00a04a2de 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json @@ -7,7 +7,8 @@ "trim": true }, "website": { - "type": "url" + "type": "url", + "strip": true }, "emailAddress": { "type": "email", diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Lead.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Lead.json index 8300a1c5d2..76b392efb8 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Lead.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Lead.json @@ -57,7 +57,8 @@ "readOnly": true }, "website": { - "type": "url" + "type": "url", + "strip": true }, "address": { "type": "address", diff --git a/application/Espo/Resources/i18n/en_US/Admin.json b/application/Espo/Resources/i18n/en_US/Admin.json index 2215391549..abd6e63cac 100644 --- a/application/Espo/Resources/i18n/en_US/Admin.json +++ b/application/Espo/Resources/i18n/en_US/Admin.json @@ -165,7 +165,8 @@ "maxFileSize": "Max File Size (Mb)", "isPersonalData": "Is Personal Data", "useIframe": "Use Iframe", - "useNumericFormat": "Use Numeric Format" + "useNumericFormat": "Use Numeric Format", + "strip": "Strip" }, "messages": { "upgradeVersion": "EspoCRM will be upgraded to version {version}. Please be patient as this may take a while.", diff --git a/application/Espo/Resources/metadata/fields/url.json b/application/Espo/Resources/metadata/fields/url.json index 4b333320f5..6197b71549 100644 --- a/application/Espo/Resources/metadata/fields/url.json +++ b/application/Espo/Resources/metadata/fields/url.json @@ -13,6 +13,10 @@ "name":"maxLength", "type":"int" }, + { + "name": "strip", + "type": "bool" + }, { "name":"audited", "type":"bool" diff --git a/client/src/views/fields/url.js b/client/src/views/fields/url.js index 2179726384..6cd53e0c03 100644 --- a/client/src/views/fields/url.js +++ b/client/src/views/fields/url.js @@ -47,6 +47,31 @@ Espo.define('views/fields/url', 'views/fields/varchar', function (Dep) { }, Dep.prototype.data.call(this)); }, + afterRender: function () { + Dep.prototype.afterRender.call(this); + + if (this.mode === 'edit') { + if (this.params.strip) { + this.$element.on('change', function () { + var value = this.$element.val() || ''; + value = this.strip(value); + this.$element.val(value); + }.bind(this)); + } + } + }, + + strip: function (value) { + value = value.trim(); + if (value.indexOf('http://') === 0) { + value = value.substr(7); + } else if (value.indexOf('https://') === 0) { + value = value.substr(8); + } + value = value.replace(/\/+$/, ''); + return value; + }, + getUrl: function () { var url = this.model.get(this.name); if (url && url != '') { @@ -56,8 +81,16 @@ Espo.define('views/fields/url', 'views/fields/varchar', function (Dep) { return url; } return url; + }, + + fetch: function () { + var data = Dep.prototype.fetch.call(this); + + if (this.params.strip) { + data[this.name] = this.strip(data[this.name]); + } + return data; } }); }); -