field manager: foreign fielld
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -117,7 +117,8 @@
|
||||
"type": "foreign",
|
||||
"link": "account",
|
||||
"field": "type",
|
||||
"readOnly": true
|
||||
"readOnly": true,
|
||||
"view": "views/fields/foreign-enum"
|
||||
},
|
||||
"opportunityRole": {
|
||||
"type": "enum",
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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('');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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'
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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'
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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'
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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'
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user