dialog confirmar guardar cambio clientes

This commit is contained in:
nelo 2017-01-13 15:07:11 +01:00
parent 30e5bd9c0b
commit 93693acd0c
8 changed files with 57 additions and 36 deletions

View File

@ -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';
export {NAME as SEARCHBAR, COMPONENT as SEARCHBAR_COMPONENT} from './components/searchbar/searchbar';

View File

@ -1,11 +0,0 @@
<dialog class="mdl-dialog">
<div class="mdl-dialog__content">
<p>
Allow this site to collect usage data to improve your experience?
</p>
</div>
<div class="mdl-dialog__actions mdl-dialog__actions--full-width">
<button type="button" class="mdl-button" ng-click="dialogController.accept()">Agree</button>
<button type="button" class="mdl-button close" ng-click="dialogController.cancel()">Disagree</button>
</div>
</dialog>

View File

@ -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);

View File

@ -26,3 +26,4 @@
</vn-vertical>
</vn-card>
</form>
<vn-confirm-client client="basicData.client" state="basicData.state"></vn-confirm-client>

View File

@ -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);

View File

@ -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';

View File

@ -0,0 +1,11 @@
<dialog class="mdl-dialog">
<div class="mdl-dialog__content">
<p>
Allow this site to collect usage data to improve your experience?
</p>
</div>
<div class="mdl-dialog__actions mdl-dialog__actions--full-width">
<button type="button" class="mdl-button" ng-click="clientConfirm.accept()">Agree</button>
<button type="button" class="mdl-button close" ng-click="clientConfirm.cancel()">Disagree</button>
</div>
</dialog>

View File

@ -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);