fix strip url

This commit is contained in:
yuri
2018-08-16 16:47:16 +03:00
parent 4f2117453d
commit f085d2140c
6 changed files with 46 additions and 5 deletions

View File

@@ -9,7 +9,8 @@
"type": "text"
},
"website": {
"type": "url"
"type": "url",
"strip": true
},
"emailAddress": {
"type": "email"

View File

@@ -7,7 +7,8 @@
"trim": true
},
"website": {
"type": "url"
"type": "url",
"strip": true
},
"emailAddress": {
"type": "email",

View File

@@ -57,7 +57,8 @@
"readOnly": true
},
"website": {
"type": "url"
"type": "url",
"strip": true
},
"address": {
"type": "address",

View File

@@ -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 <strong>{version}</strong>. Please be patient as this may take a while.",

View File

@@ -13,6 +13,10 @@
"name":"maxLength",
"type":"int"
},
{
"name": "strip",
"type": "bool"
},
{
"name":"audited",
"type":"bool"

View File

@@ -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;
}
});
});