EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
ref
Yuri Kuznetsov4708cf00c0e3
diff --git a/client/modules/crm/src/views/account/fields/shipping-address.js b/client/modules/crm/src/views/account/fields/shipping-address.jsindex c46d46b07c..b1081987de 100644--- a/client/modules/crm/src/views/account/fields/shipping-address.js+++ b/client/modules/crm/src/views/account/fields/shipping-address.js@@ -26,93 +26,110 @@* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.************************************************************************/-define('crm:views/account/fields/shipping-address', ['views/fields/address'], function (Dep) {+import AddressFieldView from 'views/fields/address';- return Dep.extend({+export default class extends AddressFieldView {- copyFrom: 'billingAddress',+ copyFrom = 'billingAddress'- setup: function () {- Dep.prototype.setup.call(this);+ setup() {+ super.setup();- this.attributePartList = this.getMetadata().get(['fields', 'address', 'actualFields']) || [];+ this.addActionHandler('copyFromBilling', () => this.copy());- this.allAddressAttributeList = [];+ this.attributePartList = this.getMetadata().get(['fields', 'address', 'actualFields']) || [];- this.attributePartList.forEach(part => {- this.allAddressAttributeList.push(this.copyFrom + Espo.Utils.upperCaseFirst(part));- this.allAddressAttributeList.push(this.name + Espo.Utils.upperCaseFirst(part));- });-- this.listenTo(this.model, 'change', () => {- var isChanged = false;-- this.allAddressAttributeList.forEach(attribute => {- if (this.model.hasChanged(attribute)) {- isChanged = true;- }- });-- if (isChanged) {- if (this.isEditMode() && this.isRendered() && this.$copyButton) {- if (this.toShowCopyButton()) {- this.$copyButton.removeClass('hidden');- } else {- this.$copyButton.addClass('hidden');- }- }- }- });- },+ this.allAddressAttributeList = [];- afterRender: function () {- Dep.prototype.afterRender.call(this);+ this.attributePartList.forEach(part => {+ this.allAddressAttributeList.push(this.copyFrom + Espo.Utils.upperCaseFirst(part));+ this.allAddressAttributeList.push(this.name + Espo.Utils.upperCaseFirst(part));+ });- if (this.mode === 'edit') {- var label = this.translate('Copy Billing', 'labels', 'Account');- this.$copyButton = $('<button class="btn btn-default btn-sm">' + label + '</button>');+ this.listenTo(this.model, 'change', () => {+ let isChanged = false;- this.$copyButton.on('click', () => {- this.copy(this.copyFrom);- });+ for (const attribute of this.allAddressAttributeList) {+ if (this.model.hasChanged(attribute)) {+ isChanged = true;- if (!this.toShowCopyButton()) {- this.$copyButton.addClass('hidden');+ break;}+ }- this.$el.append(this.$copyButton);+ if (!isChanged) {+ return;}- },- copy: function (fieldFrom) {- Object.keys(this.getMetadata().get('fields.address.fields'))- .forEach(attr => {- let destField = this.name + Espo.Utils.upperCaseFirst(attr);- let sourceField = fieldFrom + Espo.Utils.upperCaseFirst(attr);+ if (!this.isEditMode() || !this.isRendered() || !this.copyButtonElement) {+ return;+ }- this.model.set(destField, this.model.get(sourceField));- });- },+ if (this.toShowCopyButton()) {+ this.copyButtonElement.classList.remove('hidden');+ } else {+ this.copyButtonElement.classList.add('hidden');+ }+ });+ }- toShowCopyButton: function () {- var billingIsNotEmpty = false;- var shippingIsNotEmpty = false;+ afterRender() {+ super.afterRender();- this.attributePartList.forEach(part => {- let attribute1 = this.copyFrom + Espo.Utils.upperCaseFirst(part);+ if (this.mode === this.MODE_EDIT && this.element) {+ const label = this.translate('Copy Billing', 'labels', 'Account');- if (this.model.get(attribute1)) {- billingIsNotEmpty = true;- }+ const button = this.copyButtonElement = document.createElement('button');- let attribute2 = this.name + Espo.Utils.upperCaseFirst(part);+ button.classList.add('btn', 'btn-default', 'btn-sm', 'action');+ button.textContent = label;+ button.setAttribute('data-action', 'copyFromBilling')- if (this.model.get(attribute2)) {- shippingIsNotEmpty = true;- }+ if (!this.toShowCopyButton()) {+ button.classList.add('hidden');+ }++ this.element.append(button);+ }+ }++ /**+ * @private+ */+ copy() {+ const fieldFrom = this.copyFrom;++ Object.keys(this.getMetadata().get('fields.address.fields') || {})+ .forEach(attr => {+ const destField = this.name + Espo.Utils.upperCaseFirst(attr);+ const sourceField = fieldFrom + Espo.Utils.upperCaseFirst(attr);++ this.model.set(destField, this.model.get(sourceField));});+ }++ /**+ * @private+ * @return {boolean}+ */+ toShowCopyButton() {+ let billingIsNotEmpty = false;+ let shippingIsNotEmpty = false;++ this.attributePartList.forEach(part => {+ const attribute1 = this.copyFrom + Espo.Utils.upperCaseFirst(part);++ if (this.model.get(attribute1)) {+ billingIsNotEmpty = true;+ }++ const attribute2 = this.name + Espo.Utils.upperCaseFirst(part);++ if (this.model.get(attribute2)) {+ shippingIsNotEmpty = true;+ }+ });- return billingIsNotEmpty && !shippingIsNotEmpty;- },- });-});+ return billingIsNotEmpty && !shippingIsNotEmpty;+ }+}