diff --git a/@salix/crud/src/client/addresses-data-create/index.js b/@salix/crud/src/client/addresses-data-create/index.js
index 4d774e04f..a0ee6b809 100644
--- a/@salix/crud/src/client/addresses-data-create/index.js
+++ b/@salix/crud/src/client/addresses-data-create/index.js
@@ -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
);
diff --git a/@salix/crud/src/client/addresses-data-edit/index.js b/@salix/crud/src/client/addresses-data-edit/index.js
index 57b6089d7..aaeec8b84 100644
--- a/@salix/crud/src/client/addresses-data-edit/index.js
+++ b/@salix/crud/src/client/addresses-data-edit/index.js
@@ -13,6 +13,7 @@ export const COMPONENT = {
this.copyAddress();
}
);
+
$http.get('/client/api/Agencies').then(
json => this.agencies = json.data
);
diff --git a/@salix/crud/src/client/client.js b/@salix/crud/src/client/client.js
index 16c78caa5..a52404899 100644
--- a/@salix/crud/src/client/client.js
+++ b/@salix/crud/src/client/client.js
@@ -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';
diff --git a/@salix/crud/src/client/new-note/index.html b/@salix/crud/src/client/new-note/index.html
new file mode 100644
index 000000000..7f23706ca
--- /dev/null
+++ b/@salix/crud/src/client/new-note/index.html
@@ -0,0 +1,12 @@
+
+
\ No newline at end of file
diff --git a/@salix/crud/src/client/new-note/index.js b/@salix/crud/src/client/new-note/index.js
new file mode 100644
index 000000000..16ef1dbaf
--- /dev/null
+++ b/@salix/crud/src/client/new-note/index.js
@@ -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);
diff --git a/@salix/crud/src/client/notes/index.html b/@salix/crud/src/client/notes/index.html
index 5c9913cdf..d73dffb71 100644
--- a/@salix/crud/src/client/notes/index.html
+++ b/@salix/crud/src/client/notes/index.html
@@ -1,19 +1,14 @@
-
\ No newline at end of file
+
+
+
+
\ No newline at end of file
diff --git a/@salix/crud/src/client/notes/index.js b/@salix/crud/src/client/notes/index.js
index a0e8b1900..acd61f200 100644
--- a/@salix/crud/src/client/notes/index.js
+++ b/@salix/crud/src/client/notes/index.js
@@ -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);
diff --git a/@salix/crud/src/client/notes/style.css b/@salix/crud/src/client/notes/style.css
new file mode 100644
index 000000000..b5e17c7a7
--- /dev/null
+++ b/@salix/crud/src/client/notes/style.css
@@ -0,0 +1,3 @@
+.notes-date{
+ font-family: raleway-bold;
+}
\ No newline at end of file
diff --git a/@salix/crud/src/client/routes.js b/@salix/crud/src/client/routes.js
index fa5a6f07d..32c741242 100644
--- a/@salix/crud/src/client/routes.js
+++ b/@salix/crud/src/client/routes.js
@@ -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",
diff --git a/services/client/common/models/Address.js b/services/client/common/models/Address.js
index 7db31bc7f..bf94d85a8 100644
--- a/services/client/common/models/Address.js
+++ b/services/client/common/models/Address.js
@@ -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});
+ }
};
\ No newline at end of file
diff --git a/services/client/common/models/ClientObservation.js b/services/client/common/models/ClientObservation.js
new file mode 100644
index 000000000..954465b95
--- /dev/null
+++ b/services/client/common/models/ClientObservation.js
@@ -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;
+ }
+ });
+};
\ No newline at end of file
diff --git a/services/client/common/models/ClientObservation.json b/services/client/common/models/ClientObservation.json
index bca37a29f..119759855 100644
--- a/services/client/common/models/ClientObservation.json
+++ b/services/client/common/models/ClientObservation.json
@@ -11,11 +11,11 @@
},
"text": {
"type": "string",
- "description": "Fiscal indetifier"
+ "description": "Text"
},
"creationDate": {
"type": "date",
- "description": "Fiscal indetifier"
+ "description": "Creation Date"
},
"relations": {
"salesPerson": {