From 84130671943d48ff115aaa00db716d37fe6fadfb Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 1 Jul 2014 10:45:42 +0300 Subject: [PATCH] role field dev --- frontend/client/src/views/fields/base.js | 6 ++- .../views/fields/link-multiple-with-role.js | 45 +++++++++++++++---- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/frontend/client/src/views/fields/base.js b/frontend/client/src/views/fields/base.js index 73e8d23177..173c1ffae4 100644 --- a/frontend/client/src/views/fields/base.js +++ b/frontend/client/src/views/fields/base.js @@ -231,7 +231,7 @@ Espo.define('Views.Fields.Base', 'View', function (Dep) { } if (this.mode == 'edit' || this.mode == 'detail') { - this.attributeList = this.getFieldManager().getAttributes(this.fieldType, this.name); + this.attributeList = this.getAttributeList(); this.listenTo(this.model, 'change', function (model, options) { if (this.isRendered) { @@ -274,6 +274,10 @@ Espo.define('Views.Fields.Base', 'View', function (Dep) { setup: function () {}, setupSearch: function () {}, + + getAttributeList: function () { + return this.getFieldManager().getAttributes(this.fieldType, this.name); + }, inlineEditSave: function () { diff --git a/frontend/client/src/views/fields/link-multiple-with-role.js b/frontend/client/src/views/fields/link-multiple-with-role.js index aac53b21a6..762677bc48 100644 --- a/frontend/client/src/views/fields/link-multiple-with-role.js +++ b/frontend/client/src/views/fields/link-multiple-with-role.js @@ -28,23 +28,28 @@ Espo.define('Views.Fields.LinkMultipleWithRole', 'Views.Fields.LinkMultiple', fu setup: function () { Dep.prototype.setup.call(this); - this.columnsName = this.name + 'Columns'; - this.columns = Espo.Utils.clone(this.model.get(this.columnsName) || {}); - this.listenTo(this.model, 'change:' + this.idsName, function () { + this.columnsName = this.name + 'Columns'; + this.columns = Espo.Utils.clone(this.model.get(this.columnsName) || {}); + + this.listenTo(this.model, 'change:' + this.columnsName, function () { this.columns = Espo.Utils.clone(this.model.get(this.columnsName) || {}); }.bind(this)); - this.roleField = this.getMetadata().get('entityDefs.' + this.model.name + '.fields.' + this.name + '.columns.role'); - - this.roleList = this.getMetadata().get('entityDefs.' + this.foreignScope + '.fields.' + this.roleField + '.options'); + this.roleField = this.getMetadata().get('entityDefs.' + this.model.name + '.fields.' + this.name + '.columns.role'); + this.roleList = this.getMetadata().get('entityDefs.' + this.foreignScope + '.fields.' + this.roleField + '.options'); + }, + + getAttributeList: function () { + var list = Dep.prototype.getAttributeList.call(this); + list.push(this.name + 'Columns'); + return list; }, getValueForDisplay: function () { var nameHash = this.nameHash; var string = ''; - var names = []; - + var names = []; for (var id in nameHash) { var role = (this.columns[id] || {}).role || ''; @@ -57,6 +62,22 @@ Espo.define('Views.Fields.LinkMultipleWithRole', 'Views.Fields.LinkMultiple', fu return '
' + names.join('
') + '
'; }, + afterRender: function () { + Dep.prototype.afterRender.call(this); + + if (this.mode == 'edit') { + this.$el.find('select.role').on('change', function (e) { + var $target = $(e.currentTarget); + var value = $target.val(); + var id = $target.data('id'); + this.columns[id] = this.columns[id] || {}; + this.columns[id].role = value; + + this.trigger('change'); + }.bind(this)); + } + }, + addLinkHtml: function (id, name) { var $conteiner = this.$el.find('.link-container'); var $el = $('
').addClass('link-' + id).addClass('list-group-item'); @@ -66,7 +87,7 @@ Espo.define('Views.Fields.LinkMultipleWithRole', 'Views.Fields.LinkMultiple', fu var removeHtml = ''; - var $select = $(''); this.roleList.forEach(function (role) { var selectedHtml = (role == (this.columns[id] || {}).role) ? 'selected': ''; option = ''; @@ -91,6 +112,12 @@ Espo.define('Views.Fields.LinkMultipleWithRole', 'Views.Fields.LinkMultiple', fu $conteiner.append($el); }, + + fetch: function () { + var data = Dep.prototype.fetch.call(this); + data[this.columnsName] = this.columns; + return data; + }, }); });