From b12d0388c971d947a247d5cf0c3c7d3f7dbe3cae Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 18 Sep 2019 09:41:25 +0200 Subject: [PATCH] #1074 Undo changes button for forms --- front/core/components/autocomplete/autocomplete.js | 6 +++--- front/core/components/watcher/watcher.js | 11 ++++++++++- front/core/components/watcher/watcher.spec.js | 10 ++++++++++ modules/agency/front/basic-data/index.html | 5 ++--- modules/claim/front/basic-data/index.html | 1 + modules/client/front/basic-data/index.html | 5 ++--- modules/client/front/basic-data/locale/es.yml | 3 ++- modules/client/front/billing-data/index.html | 1 + modules/client/front/fiscal-data/index.html | 4 ++-- modules/client/front/web-access/index.html | 1 + modules/item/front/basic-data/index.html | 1 + modules/item/front/botanical/index.html | 1 + modules/item/front/tax/index.html | 7 +++++++ modules/order/front/basic-data/index.html | 1 + modules/route/front/basic-data/index.html | 1 + modules/worker/front/basic-data/index.html | 1 + modules/worker/front/pbx/index.html | 1 + 17 files changed, 47 insertions(+), 13 deletions(-) diff --git a/front/core/components/autocomplete/autocomplete.js b/front/core/components/autocomplete/autocomplete.js index 91a88704a..469bb9e93 100755 --- a/front/core/components/autocomplete/autocomplete.js +++ b/front/core/components/autocomplete/autocomplete.js @@ -7,10 +7,10 @@ import './style.scss'; /** * Input with option selector. * - * @property {String} valueField The data field name that should be shown - * @property {String} showFiled The data field name that should be used as value + * @property {String} showFiled The data field name that should be shown + * @property {String} valueField The data field name that should be used as value * @property {Array} data Static data for the autocomplete - * @property {Object} intialData A initial data to avoid the server request used to get the selection + * @property {Object} intialData An initial data to avoid the server request used to get the selection * @property {Boolean} multiple Wether to allow multiple selection * @property {Object} selection Current object selected * diff --git a/front/core/components/watcher/watcher.js b/front/core/components/watcher/watcher.js index 84383f477..a085ee45f 100644 --- a/front/core/components/watcher/watcher.js +++ b/front/core/components/watcher/watcher.js @@ -39,7 +39,7 @@ export default class Watcher extends Component { throw new Error('URL parameter ommitted'); } - $onChanges(changes) { + $onChanges() { if (this.data) this.updateOriginalData(); } @@ -222,6 +222,15 @@ export default class Watcher extends Component { this.setPristine(); } + loadOriginalData() { + Object.keys(this.data).forEach(key => { + delete this.data[key]; + }); + + this.data = Object.assign(this.data, this.orgData); + this.setPristine(); + } + copyInNewObject(data) { let newCopy = {}; if (data && typeof data === 'object') { diff --git a/front/core/components/watcher/watcher.spec.js b/front/core/components/watcher/watcher.spec.js index 5bdbf56c8..32de7dda7 100644 --- a/front/core/components/watcher/watcher.spec.js +++ b/front/core/components/watcher/watcher.spec.js @@ -249,4 +249,14 @@ describe('Component vnWatcher', () => { }); }); }); + + describe(`loadOriginalData()`, () => { + it(`should iterate over the current data object, delete all properties then assign the ones from original data`, () => { + controller.data = {name: 'Bruce'}; + controller.orgData = {name: 'Batman'}; + controller.loadOriginalData(); + + expect(controller.data).toEqual(controller.orgData); + }); + }); }); diff --git a/modules/agency/front/basic-data/index.html b/modules/agency/front/basic-data/index.html index 5cff23eb1..7f4ed91ef 100644 --- a/modules/agency/front/basic-data/index.html +++ b/modules/agency/front/basic-data/index.html @@ -75,8 +75,7 @@ - - + + diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html index 9ff12acf7..b626f57c7 100644 --- a/modules/claim/front/basic-data/index.html +++ b/modules/claim/front/basic-data/index.html @@ -59,5 +59,6 @@ + diff --git a/modules/client/front/basic-data/index.html b/modules/client/front/basic-data/index.html index 6fb455a76..f994d1905 100644 --- a/modules/client/front/basic-data/index.html +++ b/modules/client/front/basic-data/index.html @@ -43,7 +43,6 @@ - @@ -64,6 +62,7 @@ + diff --git a/modules/client/front/basic-data/locale/es.yml b/modules/client/front/basic-data/locale/es.yml index 7d7722e43..139d86d7d 100644 --- a/modules/client/front/basic-data/locale/es.yml +++ b/modules/client/front/basic-data/locale/es.yml @@ -11,4 +11,5 @@ You can save multiple emails: >- Puede guardar varios correos electrónicos encadenándolos mediante comas sin espacios, ejemplo: user@dominio.com, user2@dominio.com siendo el primer correo electrónico el principal -Contact: Contacto \ No newline at end of file +Contact: Contacto +Undo changes: Deshacer cambios \ No newline at end of file diff --git a/modules/client/front/billing-data/index.html b/modules/client/front/billing-data/index.html index a7bcb71bd..d923123b7 100644 --- a/modules/client/front/billing-data/index.html +++ b/modules/client/front/billing-data/index.html @@ -85,6 +85,7 @@ + diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index ceae68fb7..acd2d6947 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -120,8 +120,8 @@ - - + + + + diff --git a/modules/item/front/botanical/index.html b/modules/item/front/botanical/index.html index 4742f7067..c1b6c32e4 100644 --- a/modules/item/front/botanical/index.html +++ b/modules/item/front/botanical/index.html @@ -42,5 +42,6 @@ + \ No newline at end of file diff --git a/modules/item/front/tax/index.html b/modules/item/front/tax/index.html index 60b1114b5..9265c34ff 100644 --- a/modules/item/front/tax/index.html +++ b/modules/item/front/tax/index.html @@ -4,6 +4,12 @@ data="classes" auto-load="true"> + +
@@ -23,5 +29,6 @@ +
\ No newline at end of file diff --git a/modules/order/front/basic-data/index.html b/modules/order/front/basic-data/index.html index 672ae92fa..7a76d937f 100644 --- a/modules/order/front/basic-data/index.html +++ b/modules/order/front/basic-data/index.html @@ -67,5 +67,6 @@ + diff --git a/modules/route/front/basic-data/index.html b/modules/route/front/basic-data/index.html index fb14d4098..da58ead63 100644 --- a/modules/route/front/basic-data/index.html +++ b/modules/route/front/basic-data/index.html @@ -72,5 +72,6 @@ + diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index b12689c1d..5c2f4d6cd 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -32,5 +32,6 @@ + diff --git a/modules/worker/front/pbx/index.html b/modules/worker/front/pbx/index.html index c0b34a73b..1bb1bb265 100644 --- a/modules/worker/front/pbx/index.html +++ b/modules/worker/front/pbx/index.html @@ -15,5 +15,6 @@ +