From 93693acd0c83699a15b6582e97a9e9d3631050b7 Mon Sep 17 00:00:00 2001 From: nelo Date: Fri, 13 Jan 2017 15:07:11 +0100 Subject: [PATCH] dialog confirmar guardar cambio clientes --- @salix/app/src/components.js | 3 +- .../app/src/components/confirm/confirm.html | 11 -------- @salix/app/src/components/confirm/confirm.js | 18 ------------ @salix/crud/src/client/basic-data/index.html | 1 + @salix/crud/src/client/basic-data/index.js | 19 +++++++++---- @salix/crud/src/client/client.js | 2 ++ @salix/crud/src/client/confirm/index.html | 11 ++++++++ @salix/crud/src/client/confirm/index.js | 28 +++++++++++++++++++ 8 files changed, 57 insertions(+), 36 deletions(-) delete mode 100644 @salix/app/src/components/confirm/confirm.html delete mode 100644 @salix/app/src/components/confirm/confirm.js create mode 100644 @salix/crud/src/client/confirm/index.html create mode 100644 @salix/crud/src/client/confirm/index.js diff --git a/@salix/app/src/components.js b/@salix/app/src/components.js index 464af178e..905f67603 100644 --- a/@salix/app/src/components.js +++ b/@salix/app/src/components.js @@ -4,5 +4,4 @@ export {NAME as ACTIONS, COMPONENT as ACTIONS_COMPONENT} from './components/left export {NAME as LEFT_MENU, COMPONENT as LEFTMENU_COMPONENT} from './components/left-menu/left-menu'; export {NAME as MENU_ITEM, COMPONENT as MENU_ITEM_COMPONENT} from './components/left-menu/menu-item'; export {NAME as TOPBAR, COMPONENT as TOPBAR_COMPONENT} from './components/topbar/topbar'; -export {NAME as SEARCHBAR, COMPONENT as SEARCHBAR_COMPONENT} from './components/searchbar/searchbar'; -export {NAME as CONFIRM, COMPONENT as CONFIRM_COMPONENT} from './components/confirm/confirm'; \ No newline at end of file +export {NAME as SEARCHBAR, COMPONENT as SEARCHBAR_COMPONENT} from './components/searchbar/searchbar'; \ No newline at end of file diff --git a/@salix/app/src/components/confirm/confirm.html b/@salix/app/src/components/confirm/confirm.html deleted file mode 100644 index b24bb62df..000000000 --- a/@salix/app/src/components/confirm/confirm.html +++ /dev/null @@ -1,11 +0,0 @@ - -
-

- Allow this site to collect usage data to improve your experience? -

-
-
- - -
-
\ No newline at end of file diff --git a/@salix/app/src/components/confirm/confirm.js b/@salix/app/src/components/confirm/confirm.js deleted file mode 100644 index 95a41f42a..000000000 --- a/@salix/app/src/components/confirm/confirm.js +++ /dev/null @@ -1,18 +0,0 @@ -import template from './confirm.html'; -import {module} from '../../module'; - -export const NAME = 'vnConfirm'; -export const COMPONENT = { - template: template, - controllerAs: 'dialogController', - controller: function(){ - this.accept = function(){ - return true; - } - - this.cancel = function(){ - return false; - } - } -}; -module.component(NAME, COMPONENT); diff --git a/@salix/crud/src/client/basic-data/index.html b/@salix/crud/src/client/basic-data/index.html index 03c5c6ddb..28d0e9da0 100644 --- a/@salix/crud/src/client/basic-data/index.html +++ b/@salix/crud/src/client/basic-data/index.html @@ -26,3 +26,4 @@ + diff --git a/@salix/crud/src/client/basic-data/index.js b/@salix/crud/src/client/basic-data/index.js index 2466919c0..6268312cf 100644 --- a/@salix/crud/src/client/basic-data/index.js +++ b/@salix/crud/src/client/basic-data/index.js @@ -8,14 +8,17 @@ export const COMPONENT = { bindings: { client: '<' }, - controller: function($http, copyObject, equalsObject, $transitions) { + controller: function($http, copyObject, equalsObject, $transitions, $state) { var self = this; + var deregister = $transitions.onStart({ }, callback); this.$onChanges = function (changes) { - if(this.client) + if(this.client){ this.clientOld = copyObject(this.client); + this.client.navigate = false; + } } this.$onDestroy = function(){ @@ -28,8 +31,14 @@ export const COMPONENT = { ); function callback(transition) { - if(!equalsObject(self.client, self.clientOld) && !confirm("¿Desea salir sin guardar los cambios?")) - return false; + if(!equalsObject(self.client, self.clientOld) && !self.client.navigate){ + self.state = transition.to().name; + var dialog = document.querySelector('dialog'); + dialog.showModal(); + return false; + } + else + self.client = copyObject(self.clientOld); } this.submit = function() { @@ -43,5 +52,5 @@ export const COMPONENT = { }; } }; -COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions']; +COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$state']; module.component(NAME, COMPONENT); diff --git a/@salix/crud/src/client/client.js b/@salix/crud/src/client/client.js index 366853b42..a90f8541a 100644 --- a/@salix/crud/src/client/client.js +++ b/@salix/crud/src/client/client.js @@ -22,3 +22,5 @@ export {NAME as CLIENT_CREATE, COMPONENT as CLIENT_CREATE_COMPONENT} from './create/index'; export {NAME as CLIENT_ADDRESSES_DATA_INDEX, COMPONENT as CLIENT_ADDRESSES_DATA_INDEX_COMPONENT} from './addresses-data/index'; +export {NAME as CLIENT_CONFIRM_INDEX, + COMPONENT as CLIENT_CONFIRM_INDEX_COMPONENT} from './confirm/index'; diff --git a/@salix/crud/src/client/confirm/index.html b/@salix/crud/src/client/confirm/index.html new file mode 100644 index 000000000..ed2f19b32 --- /dev/null +++ b/@salix/crud/src/client/confirm/index.html @@ -0,0 +1,11 @@ + +
+

+ Allow this site to collect usage data to improve your experience? +

+
+
+ + +
+
\ No newline at end of file diff --git a/@salix/crud/src/client/confirm/index.js b/@salix/crud/src/client/confirm/index.js new file mode 100644 index 000000000..f2960612a --- /dev/null +++ b/@salix/crud/src/client/confirm/index.js @@ -0,0 +1,28 @@ +import template from './index.html'; +import {module} from '../../module'; + +export const NAME = 'vnConfirmClient'; +export const COMPONENT = { + template: template, + controllerAs: 'clientConfirm', + bindings: { + state: '<', + client: '=' + }, + controller: function($state, $element, copyObject){ + + var dialog = $element.find('dialog')[0] + + this.accept = function(){ + this.client.navigate = true; + $state.go(this.state); + dialog.close(); + } + + this.cancel = function(){ + dialog.close(); + } + } +}; +COMPONENT.controller.$inject = ['$state', '$element', 'copyObject']; +module.component(NAME, COMPONENT);