Separación de notas en listar y crear

This commit is contained in:
nelo 2017-01-18 14:48:35 +01:00
parent 28451aced9
commit aa23160aee
12 changed files with 143 additions and 58 deletions

View File

@ -10,6 +10,7 @@ export const COMPONENT = {
var self = this;
this.clientId = $state.params.id;
this.address = {};
$http.get('/client/api/Agencies').then(
json => this.agencies = json.data
);

View File

@ -13,6 +13,7 @@ export const COMPONENT = {
this.copyAddress();
 }
);
$http.get('/client/api/Agencies').then(
json => this.agencies = json.data
);

View File

@ -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';
export {NAME as CLIENT_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';

View File

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

View File

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

View File

@ -1,19 +1,14 @@
<form name="form" ng-submit="form.$valid && observation.submit()" pad-medium>
<vn-card>
<vn-vertical pad-large>
<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;">
<vn-card ng-show="observation.observations.length" pad-medium>
<vn-vertical pad-large>
<vn-title>Notas</vn-title>
<div ng-repeat="n in observation.observations">
<p><b>{{n.creationDate | date:'medium'}} {{n.salesPerson}}</b></p>
<p>{{n.text}}</p>
<div class="notes-date">{{n.creationDate | date:'medium'}} {{n.salesPerson}}</div>
{{n.text}}
</div>
</vn-vertical>
</vn-card>
</form>
</vn-vertical>
</vn-card>
<vn-float-button
fixed-bottom-right
ng-click="observation.newObservation()"
icon="add">
</vn-float-button>

View File

@ -1,3 +1,4 @@
import './style.css';
import template from './index.html';
import {module} from '../../module';
@ -8,48 +9,13 @@ export const COMPONENT = {
bindings: {
client: '<'
},
controller: function($http, copyObject, equalsObject, $transitions, $element) {
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);
}
);
}
};
controller: function($http, $state) {
this.$onChanges = function(changes) {
if (this.client) {
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) {
let json = JSON.stringify({where: {client: this.client.id}, order: 'creationDate DESC'});
$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);

View File

@ -0,0 +1,3 @@
.notes-date{
font-family: raleway-bold;
}

View File

@ -55,6 +55,12 @@
description: "Notas",
icon: "insert_drive_file"
}, {
url: "/new-note",
state: "clientCard.newNote",
component: "vn-new-note",
description: "Nueva nota",
icon: "insert_drive_file"
},{
url: "/create",
state: "create",
component: "vn-client-create",

View File

@ -6,9 +6,29 @@ module.exports = function(Address) {
}
Address.observe('before save', function (ctx, next) {
if (ctx.data.enabled && ctx.data.default) {
ctx.Model.update({client: ctx.data.client}, {default: false});
var data = getData(ctx);
if (isEnabled(data) && isDefault(data)) {
updateData(ctx);
}
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});
}
};

View File

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

View File

@ -11,11 +11,11 @@
},
"text": {
"type": "string",
"description": "Fiscal indetifier"
"description": "Text"
},
"creationDate": {
"type": "date",
"description": "Fiscal indetifier"
"description": "Creation Date"
},
"relations": {
"salesPerson": {