Separación de notas en listar y crear
This commit is contained in:
parent
28451aced9
commit
aa23160aee
|
@ -10,6 +10,7 @@ export const COMPONENT = {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.clientId = $state.params.id;
|
this.clientId = $state.params.id;
|
||||||
this.address = {};
|
this.address = {};
|
||||||
|
|
||||||
$http.get('/client/api/Agencies').then(
|
$http.get('/client/api/Agencies').then(
|
||||||
json => this.agencies = json.data
|
json => this.agencies = json.data
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,6 +13,7 @@ export const COMPONENT = {
|
||||||
this.copyAddress();
|
this.copyAddress();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$http.get('/client/api/Agencies').then(
|
$http.get('/client/api/Agencies').then(
|
||||||
json => this.agencies = json.data
|
json => this.agencies = json.data
|
||||||
);
|
);
|
||||||
|
|
|
@ -26,5 +26,7 @@ export {NAME as CLIENT_ADDRESSES_DATA_EDIT_INDEX,
|
||||||
COMPONENT as CLIENT_ADDRESSES_DATA_EDIT_INDEX_COMPONENT} from './addresses-data-edit/index';
|
COMPONENT as CLIENT_ADDRESSES_DATA_EDIT_INDEX_COMPONENT} from './addresses-data-edit/index';
|
||||||
export {NAME as CLIENT_CONFIRM_INDEX,
|
export {NAME as CLIENT_CONFIRM_INDEX,
|
||||||
COMPONENT as CLIENT_CONFIRM_INDEX_COMPONENT} from './confirm/index';
|
COMPONENT as CLIENT_CONFIRM_INDEX_COMPONENT} from './confirm/index';
|
||||||
|
export {NAME as NEW_NOTE_INDEX,
|
||||||
|
COMPONENT as NEW_NOTE_INDEX_COMPONENT} from './new-note/index';
|
||||||
|
|
||||||
import {default as changePassword} from './change-password/index';
|
import {default as changePassword} from './change-password/index';
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<form name="form" ng-submit="form.$valid && newNote.submit()" pad-medium>
|
||||||
|
<vn-card>
|
||||||
|
<vn-vertical pad-large>
|
||||||
|
<vn-title>Nueva nota</vn-title>
|
||||||
|
<vn-textarea label="Nueva nota" model="newNote.note.text" focus padd-medium-top></vn-textarea>
|
||||||
|
</vn-vertical>
|
||||||
|
</vn-card>
|
||||||
|
<vn-button-bar>
|
||||||
|
<vn-submit label="Guardar"></vn-submit>
|
||||||
|
</vn-button-bar>
|
||||||
|
</form>
|
||||||
|
<vn-dialog-confirm object="newNote.note" object-old="newNote.noteOld" state="newNote.state"></vn-dialog-confirm>
|
|
@ -0,0 +1,54 @@
|
||||||
|
import template from './index.html';
|
||||||
|
import {module} from '../../module';
|
||||||
|
|
||||||
|
export const NAME = 'vnNewNote';
|
||||||
|
export const COMPONENT = {
|
||||||
|
template: template,
|
||||||
|
controllerAs: 'newNote',
|
||||||
|
controller: function($http, $state, copyObject, equalsObject, $transitions, $element) {
|
||||||
|
|
||||||
|
this.client = $state.params.id;
|
||||||
|
this.note = {text: null};
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var deregister = $transitions.onStart({ }, callback);
|
||||||
|
|
||||||
|
this.submit = function() {
|
||||||
|
if (this.note) {
|
||||||
|
let observation = this.createNote();
|
||||||
|
$http.post('/client/api/ClientObservations', observation).then(
|
||||||
|
json => {
|
||||||
|
this.note = json.data;
|
||||||
|
this.copyNote();
|
||||||
|
$state.go('clientCard.notes');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$onDestroy = function() {
|
||||||
|
deregister();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.createNote = () => {
|
||||||
|
let observation = {client: this.client, text: this.note.text, salesPerson: 'user', modify: 'ClientObservation'};
|
||||||
|
return observation;
|
||||||
|
};
|
||||||
|
|
||||||
|
function callback(transition) {
|
||||||
|
if (!equalsObject(self.note, self.noteOld)) {
|
||||||
|
self.state = transition.to().name;
|
||||||
|
var dialog = $element[0].querySelector('dialog');
|
||||||
|
dialog.showModal();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.copyNote = () => {
|
||||||
|
this.noteOld = {}
|
||||||
|
copyObject(this.note, this.noteOld);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
COMPONENT.controller.$inject = ['$http', '$state', 'copyObject', 'equalsObject', '$transitions', '$element'];
|
||||||
|
module.component(NAME, COMPONENT);
|
|
@ -1,19 +1,14 @@
|
||||||
<form name="form" ng-submit="form.$valid && observation.submit()" pad-medium>
|
<vn-card ng-show="observation.observations.length" pad-medium>
|
||||||
<vn-card>
|
|
||||||
<vn-vertical pad-large>
|
<vn-vertical pad-large>
|
||||||
<vn-title>Notas</vn-title>
|
<vn-title>Notas</vn-title>
|
||||||
<vn-textarea label="Notas" model="observation.newNote" focus padd-medium-top></vn-textarea>
|
|
||||||
</vn-vertical>
|
|
||||||
</vn-card>
|
|
||||||
<vn-button-bar>
|
|
||||||
<vn-submit label="Guardar"></vn-submit>
|
|
||||||
</vn-button-bar>
|
|
||||||
<vn-card ng-show="observation.observations.length" margin-small-top>
|
|
||||||
<vn-vertical pad-large style="max-height: 300px; overflow: auto;">
|
|
||||||
<div ng-repeat="n in observation.observations">
|
<div ng-repeat="n in observation.observations">
|
||||||
<p><b>{{n.creationDate | date:'medium'}} {{n.salesPerson}}</b></p>
|
<div class="notes-date">{{n.creationDate | date:'medium'}} {{n.salesPerson}}</div>
|
||||||
<p>{{n.text}}</p>
|
{{n.text}}
|
||||||
</div>
|
</div>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
</form>
|
<vn-float-button
|
||||||
|
fixed-bottom-right
|
||||||
|
ng-click="observation.newObservation()"
|
||||||
|
icon="add">
|
||||||
|
</vn-float-button>
|
|
@ -1,3 +1,4 @@
|
||||||
|
import './style.css';
|
||||||
import template from './index.html';
|
import template from './index.html';
|
||||||
import {module} from '../../module';
|
import {module} from '../../module';
|
||||||
|
|
||||||
|
@ -8,48 +9,13 @@ export const COMPONENT = {
|
||||||
bindings: {
|
bindings: {
|
||||||
client: '<'
|
client: '<'
|
||||||
},
|
},
|
||||||
controller: function($http, copyObject, equalsObject, $transitions, $element) {
|
controller: function($http, $state) {
|
||||||
var self = this;
|
|
||||||
var deregister = $transitions.onStart({ }, callback);
|
|
||||||
|
|
||||||
this.submit = function() {
|
|
||||||
if (this.newNote) {
|
|
||||||
this.client.modify = "ClientObservation";
|
|
||||||
let observation = {
|
|
||||||
client: this.client.id,
|
|
||||||
text: this.newNote,
|
|
||||||
creationDate: new Date(),
|
|
||||||
salesPerson: 'user'
|
|
||||||
};
|
|
||||||
|
|
||||||
$http.put('/client/api/ClientObservations', observation).then(
|
|
||||||
() => {
|
|
||||||
this.newNote = "";
|
|
||||||
this.observations.unshift(observation);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.$onChanges = function(changes) {
|
this.$onChanges = function(changes) {
|
||||||
if (this.client) {
|
if (this.client) {
|
||||||
this.getObservation(this.client.id);
|
this.getObservation(this.client.id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$onDestroy = function() {
|
|
||||||
deregister();
|
|
||||||
};
|
|
||||||
|
|
||||||
function callback(transition) {
|
|
||||||
if (!equalsObject(self.observation, self.observationOld)) {
|
|
||||||
self.state = transition.to().name;
|
|
||||||
var dialog = $element[0].querySelector('dialog');
|
|
||||||
dialog.showModal();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.observations = [];
|
|
||||||
this.getObservation = function(clientId) {
|
this.getObservation = function(clientId) {
|
||||||
let json = JSON.stringify({where: {client: this.client.id}, order: 'creationDate DESC'});
|
let json = JSON.stringify({where: {client: this.client.id}, order: 'creationDate DESC'});
|
||||||
$http.get(`/client/api/clientObservations?filter=${json}`).then(
|
$http.get(`/client/api/clientObservations?filter=${json}`).then(
|
||||||
|
@ -58,7 +24,11 @@ export const COMPONENT = {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.newObservation = () => {
|
||||||
|
$state.go("clientCard.newNote", {id: this.client.id});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element'];
|
COMPONENT.controller.$inject = ['$http', '$state'];
|
||||||
module.component(NAME, COMPONENT);
|
module.component(NAME, COMPONENT);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
.notes-date{
|
||||||
|
font-family: raleway-bold;
|
||||||
|
}
|
|
@ -55,6 +55,12 @@
|
||||||
description: "Notas",
|
description: "Notas",
|
||||||
icon: "insert_drive_file"
|
icon: "insert_drive_file"
|
||||||
}, {
|
}, {
|
||||||
|
url: "/new-note",
|
||||||
|
state: "clientCard.newNote",
|
||||||
|
component: "vn-new-note",
|
||||||
|
description: "Nueva nota",
|
||||||
|
icon: "insert_drive_file"
|
||||||
|
},{
|
||||||
url: "/create",
|
url: "/create",
|
||||||
state: "create",
|
state: "create",
|
||||||
component: "vn-client-create",
|
component: "vn-client-create",
|
||||||
|
|
|
@ -6,9 +6,29 @@ module.exports = function(Address) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Address.observe('before save', function (ctx, next) {
|
Address.observe('before save', function (ctx, next) {
|
||||||
if (ctx.data.enabled && ctx.data.default) {
|
var data = getData(ctx);
|
||||||
ctx.Model.update({client: ctx.data.client}, {default: false});
|
if (isEnabled(data) && isDefault(data)) {
|
||||||
|
updateData(ctx);
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getData(ctx){
|
||||||
|
if(ctx.data)
|
||||||
|
return ctx.data;
|
||||||
|
else
|
||||||
|
return ctx.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEnabled(data){
|
||||||
|
return data.isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDefault(data){
|
||||||
|
return data.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateData(ctx){
|
||||||
|
ctx.Model.update({client: ctx.data.client}, {default: false});
|
||||||
|
}
|
||||||
};
|
};
|
|
@ -0,0 +1,21 @@
|
||||||
|
module.exports = function(ClientObservation) {
|
||||||
|
|
||||||
|
ClientObservation.validate('text',isEnabled,{message: 'Se debe rellenar el campo de texto'});
|
||||||
|
function isEnabled(err) {
|
||||||
|
if (!this.text) err();
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientObservation.observe('before save', function (ctx, next) {
|
||||||
|
ctx.instance.creationDate = Date();
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
ClientObservation.on('attached', function() {
|
||||||
|
var override = ClientObservation.find;
|
||||||
|
ClientObservation.find = function(filter, callback) {
|
||||||
|
var elements = override.apply(this, arguments);
|
||||||
|
//return elements;
|
||||||
|
elements = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
|
@ -11,11 +11,11 @@
|
||||||
},
|
},
|
||||||
"text": {
|
"text": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Fiscal indetifier"
|
"description": "Text"
|
||||||
},
|
},
|
||||||
"creationDate": {
|
"creationDate": {
|
||||||
"type": "date",
|
"type": "date",
|
||||||
"description": "Fiscal indetifier"
|
"description": "Creation Date"
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
"salesPerson": {
|
"salesPerson": {
|
||||||
|
|
Loading…
Reference in New Issue