diff --git a/application/Espo/Modules/Crm/Resources/i18n/en_US/Account.json b/application/Espo/Modules/Crm/Resources/i18n/en_US/Account.json index c713d76f03..054f35b331 100644 --- a/application/Espo/Modules/Crm/Resources/i18n/en_US/Account.json +++ b/application/Espo/Modules/Crm/Resources/i18n/en_US/Account.json @@ -35,6 +35,7 @@ } }, "labels": { - "Create Account": "Create Account" + "Create Account": "Create Account", + "Copy Billing": "Copy Billing" } } diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json index af9b9610f9..be8ecb8b5a 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json @@ -53,7 +53,8 @@ "type": "varchar" }, "shippingAddress": { - "type": "address" + "type": "address", + "view": "Crm:Account.Fields.ShippingAddress" }, "shippingAddressStreet": { "type": "text", diff --git a/frontend/client/modules/crm/src/views/account/fields/shipping-address.js b/frontend/client/modules/crm/src/views/account/fields/shipping-address.js new file mode 100644 index 0000000000..3b890b7097 --- /dev/null +++ b/frontend/client/modules/crm/src/views/account/fields/shipping-address.js @@ -0,0 +1,52 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014 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/. + ************************************************************************/ + +Espo.define('Crm:Views.Account.Fields.ShippingAddress', 'Views.Fields.Address', function (Dep) { + + return Dep.extend({ + + copyFrom: 'billingAddress', + + afterRender: function () { + Dep.prototype.afterRender.call(this); + + if (this.mode == 'edit') { + var label = this.translate('Copy Billing', 'labels', 'Accounts'); + $btn = $('').on('click', function () { + this.copy(this.copyFrom); + }.bind(this)); + this.$el.append($btn); + } + }, + + copy: function (fieldFrom) { + var attrList = Object.keys(this.getMetadata().get('fields.address.fields')).forEach(function (attr) { + destField = this.name + Espo.Utils.upperCaseFirst(attr); + sourceField = fieldFrom + Espo.Utils.upperCaseFirst(attr); + + this.model.set(destField, this.model.get(sourceField)); + }, this); + + }, + + }); +}); + diff --git a/frontend/client/src/views/fields/address.js b/frontend/client/src/views/fields/address.js index 9191b5e144..d04e754741 100644 --- a/frontend/client/src/views/fields/address.js +++ b/frontend/client/src/views/fields/address.js @@ -44,14 +44,32 @@ Espo.define('Views.Fields.Address', 'Views.Fields.Base', function (Dep) { return data; }, - afterRender: function () { - if (this.mode == 'edit') { + afterRender: function () { + var self = this; + + if (this.mode == 'edit') { this.$street = this.$el.find('[name="' + this.streetField + '"]'); this.$postalCode = this.$el.find('[name="' + this.postalCodeField + '"]'); this.$state = this.$el.find('[name="' + this.stateField + '"]'); this.$city = this.$el.find('[name="' + this.cityField + '"]'); this.$country = this.$el.find('[name="' + this.countryField + '"]'); + this.$street.on('change', function () { + self.trigger('change'); + }); + this.$postalCode.on('change', function () { + self.trigger('change'); + }); + this.$state.on('change', function () { + self.trigger('change'); + }); + this.$city.on('change', function () { + self.trigger('change'); + }); + this.$country.on('change', function () { + self.trigger('change'); + }); + this.$street.on('input', function (e) { var numberOfLines = e.currentTarget.value.split('\n').length; var numberOfRows = this.$street.prop('rows');