diff --git a/application/Espo/Core/Utils/File/Manager.php b/application/Espo/Core/Utils/File/Manager.php index c79f5c16a4..84ea6c5af9 100644 --- a/application/Espo/Core/Utils/File/Manager.php +++ b/application/Espo/Core/Utils/File/Manager.php @@ -249,7 +249,7 @@ class Manager public function putContentsJson($path, $data) { if (!Utils\Json::isJSON($data)) { - $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } return $this->putContents($path, $data, LOCK_EX); @@ -290,7 +290,7 @@ class Manager $data = Utils\Util::merge($savedDataArray, $newDataArray); if ($isReturnJson) { - $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } if ($isPhp) { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json index 4f3cbe3d75..00569f00d9 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json @@ -117,7 +117,8 @@ "type": "foreign", "link": "account", "field": "type", - "readOnly": true + "readOnly": true, + "view": "views/fields/foreign-enum" }, "opportunityRole": { "type": "enum", diff --git a/application/Espo/Resources/metadata/fields/foreign.json b/application/Espo/Resources/metadata/fields/foreign.json index 7042a3a38b..f730bec152 100644 --- a/application/Espo/Resources/metadata/fields/foreign.json +++ b/application/Espo/Resources/metadata/fields/foreign.json @@ -2,13 +2,20 @@ "params":[ { "name":"link", - "type":"varchar" + "type":"varchar", + "view": "views/admin/field-manager/fields/foreign/link", + "required": true }, { "name":"field", - "type":"varchar" + "type":"varchar", + "view": "views/admin/field-manager/fields/foreign/field", + "required": true } ], "filter": true, - "notCreatable": true + "notCreatable": false, + "fieldDefs": { + "readOnly": true + } } diff --git a/client/src/views/admin/field-manager/fields/foreign/field.js b/client/src/views/admin/field-manager/fields/foreign/field.js new file mode 100644 index 0000000000..845d8547af --- /dev/null +++ b/client/src/views/admin/field-manager/fields/foreign/field.js @@ -0,0 +1,132 @@ +/************************************************************************ + * 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/admin/field-manager/fields/foreign/field', 'views/fields/enum', function (Dep) { + + return Dep.extend({ + + typeList: ['varchar', 'enum', 'enumInt', 'enumFloat', 'int', 'float', 'website'], + + setup: function () { + Dep.prototype.setup.call(this); + if (!this.model.isNew()) { + this.setReadOnly(true); + } + this.listenTo(this.model, 'change:field', function () { + this.manageField(); + }, this); + + this.viewValue = this.model.get('view'); + }, + + setupOptions: function () { + this.listenTo(this.model, 'change:link', function () { + this.setupOptionsByLink(); + this.reRender(); + }, this); + this.setupOptionsByLink(); + }, + + setupOptionsByLink: function () { + var link = this.model.get('link'); + + if (!link) { + this.params.options = ['']; + return; + } + + var scope = this.getMetadata().get(['entityDefs', this.options.scope, 'links', link, 'entity']); + + if (!scope) { + this.params.options = ['']; + return; + } + + var fields = this.getMetadata().get(['entityDefs', scope, 'fields']) || {}; + + this.params.options = Object.keys(Espo.Utils.clone(fields)).filter(function (item) { + var type = fields[item].type; + if (!~this.typeList.indexOf(type)) return; + if (fields[item].notStorable) return; + + return true; + }, this); + + this.translatedOptions = {}; + this.params.options.forEach(function (item) { + this.translatedOptions[item] = this.translate(item, 'fields', scope); + }, this); + + this.params.options.unshift(''); + }, + + manageField: function () { + if (!this.model.isNew()) return; + + var link = this.model.get('link'); + var field = this.model.get('field'); + + if (!link || !field) { + return; + } + var scope = this.getMetadata().get(['entityDefs', this.options.scope, 'links', link, 'entity']); + if (!scope) { + return; + } + var type = this.getMetadata().get(['entityDefs', scope, 'fields', field, 'type']); + + if (type == 'enum') { + this.viewValue = 'views/fields/foreign-enum'; + } else if (type == 'enumInt') { + this.viewValue = 'views/fields/foreign-int'; + } else if (type == 'enumFloat') { + this.viewValue = 'views/fields/foreign-float'; + } else if (type == 'varchar') { + this.viewValue = 'views/fields/foreign-varchar'; + } else if (type == 'int') { + this.viewValue = 'views/fields/foreign-int'; + } else if (type == 'float') { + this.viewValue = 'views/fields/foreign-float'; + } else { + this.viewValue = null; + } + }, + + fetch: function () { + var data = Dep.prototype.fetch.call(this); + + if (this.model.isNew()) { + if (this.viewValue) { + data['view'] = this.viewValue; + } + } + return data; + } + }); + +}); diff --git a/client/src/views/admin/field-manager/fields/foreign/link.js b/client/src/views/admin/field-manager/fields/foreign/link.js new file mode 100644 index 0000000000..76a88ea7c4 --- /dev/null +++ b/client/src/views/admin/field-manager/fields/foreign/link.js @@ -0,0 +1,60 @@ +/************************************************************************ + * 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/admin/field-manager/fields/foreign/link', 'views/fields/enum', function (Dep) { + + return Dep.extend({ + + setup: function () { + Dep.prototype.setup.call(this); + if (!this.model.isNew()) { + this.setReadOnly(true); + } + }, + + setupOptions: function () { + var links = this.getMetadata().get(['entityDefs', this.options.scope, 'links']) || {}; + + this.params.options = Object.keys(Espo.Utils.clone(links)).filter(function (item) { + if (links[item].type !== 'belongsTo') return; + if (links[item].noJoin) return; + + return true; + }, this); + + this.translatedOptions = {}; + this.params.options.forEach(function (item) { + this.translatedOptions[item] = this.translate(item, 'links', this.options.scope); + }, this); + + this.params.options.unshift(''); + } + + }); + +}); diff --git a/client/src/views/fields/foreign-enum.js b/client/src/views/fields/foreign-enum.js new file mode 100644 index 0000000000..cdd1cc9096 --- /dev/null +++ b/client/src/views/fields/foreign-enum.js @@ -0,0 +1,54 @@ +/************************************************************************ + * 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/foreign-enum', 'views/fields/enum', function (Dep) { + + return Dep.extend({ + + type: 'foreign', + + setupOptions: function () { + this.params.options = []; + + if (!this.params.field || !this.params.link) return; + + var scope = this.getMetadata().get(['entityDefs', this.model.name, 'links', this.params.link, 'entity']); + if (!scope) { + return; + } + this.params.options = this.getMetadata().get(['entityDefs', scope, 'fields', this.params.field, 'options']) || []; + + this.translatedOptions = {}; + this.params.options.forEach(function(item) { + this.translatedOptions[item] = this.getLanguage().translateOption(item, this.params.field, scope); + }, this); + }, + + }); +}); + diff --git a/client/src/views/fields/foreign-float.js b/client/src/views/fields/foreign-float.js new file mode 100644 index 0000000000..97f403bb0c --- /dev/null +++ b/client/src/views/fields/foreign-float.js @@ -0,0 +1,37 @@ +/************************************************************************ + * 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/foreign-float', 'views/fields/float', function (Dep) { + + return Dep.extend({ + + type: 'foreign' + + }); +}); + diff --git a/client/src/views/fields/foreign-int.js b/client/src/views/fields/foreign-int.js new file mode 100644 index 0000000000..0f856a3eff --- /dev/null +++ b/client/src/views/fields/foreign-int.js @@ -0,0 +1,37 @@ +/************************************************************************ + * 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/foreign-int', 'views/fields/int', function (Dep) { + + return Dep.extend({ + + type: 'foreign' + + }); +}); + diff --git a/client/src/views/fields/foreign-varchar.js b/client/src/views/fields/foreign-varchar.js new file mode 100644 index 0000000000..7bfbc4a7fe --- /dev/null +++ b/client/src/views/fields/foreign-varchar.js @@ -0,0 +1,37 @@ +/************************************************************************ + * 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/foreign-varchar', 'views/fields/varchar', function (Dep) { + + return Dep.extend({ + + type: 'foreign' + + }); +}); + diff --git a/client/src/views/fields/foreign.js b/client/src/views/fields/foreign.js index a125275c61..0833dfb8da 100644 --- a/client/src/views/fields/foreign.js +++ b/client/src/views/fields/foreign.js @@ -24,14 +24,13 @@ * * 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.Foreign', 'Views.Fields.Base', function (Dep) { +Espo.define('views/fields/foreign', 'views/fields/base', function (Dep) { - return Dep.extend({ - - type: 'foreign', - + return Dep.extend({ + + type: 'foreign' }); });