2016-07-21 10:25:44 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
|
2017-05-01 11:43:54 +02:00
|
|
|
*
|
2016-07-21 10:25:44 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2017-05-01 11:43:54 +02:00
|
|
|
*
|
2016-07-21 10:25:44 +02:00
|
|
|
* This program 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 Affero General Public
|
|
|
|
* License for more details.
|
2017-05-01 11:43:54 +02:00
|
|
|
*
|
2016-07-21 10:25:44 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-05-01 11:43:54 +02:00
|
|
|
/* global odoo */
|
2016-07-21 10:25:44 +02:00
|
|
|
|
2017-05-01 11:43:54 +02:00
|
|
|
odoo.define('web.web_widget_url_check', function(require) {
|
2016-07-21 10:25:44 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-05-01 11:43:54 +02:00
|
|
|
var core = require('web.core');
|
2017-05-01 12:22:24 +02:00
|
|
|
var FieldUrl = core.form_widget_registry.get('url');
|
2017-05-01 11:43:54 +02:00
|
|
|
|
2016-07-21 10:25:44 +02:00
|
|
|
var reUrl = /(?:https?:\/\/)?(?:[\w]+\.)([a-zA-Z\.]{2,6})([\/\w\.-]*)*\/?/;
|
|
|
|
|
2017-05-01 12:22:24 +02:00
|
|
|
FieldUrl.include({
|
2016-07-21 10:25:44 +02:00
|
|
|
is_syntax_valid: function () {
|
2017-06-07 09:49:02 +02:00
|
|
|
if (this.$input) {
|
|
|
|
var val = this.$input.val() || '';
|
|
|
|
return ((val.length === 0) || reUrl.test(val));
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2016-07-21 10:25:44 +02:00
|
|
|
}
|
|
|
|
});
|
2017-06-07 09:49:02 +02:00
|
|
|
|
|
|
|
return { FieldUrl: FieldUrl };
|
|
|
|
|
2017-05-01 12:22:24 +02:00
|
|
|
});
|