Web-access con put i post

This commit is contained in:
Javi Gallego 2017-01-25 12:59:03 +01:00
parent 278d764575
commit e4c5b8ea7d
2 changed files with 23 additions and 27 deletions

View File

@ -16,19 +16,28 @@ export const COMPONENT = {
if (!equalsObject(this.account, this.accountOld)) {
var newAccount = modified(this.account, this.accountOld);
newAccount.modify = "WebAccess";
newAccount.id = this.client.id;
$http.put('/client/api/Accounts', newAccount).then(
json => {
this.account = json.data;
self.copyAccount();
}
);
if (this.account.id) {
$http.put(`/client/api/Accounts/${this.client.id}`, newAccount).then(
json => {
this.client.account = json.data;
self.copyAccount();
}
);
} else {
newAccount.id = this.client.id;
$http.post('/client/api/Accounts', newAccount).then(
json => {
this.client.account = json.data;
copyObject(this.client.account, this.accountOld);
}
);
}
}
};
this.$onChanges = function(changes) {
if (this.client) {
this.getAccount(this.client.id);
this.copyAccount();
}
};
@ -37,7 +46,7 @@ export const COMPONENT = {
};
function callback(transition) {
if (!equalsObject(self.account, self.accountOld)) {
if (!equalsObject(self.client.account, self.accountOld)) {
self.state = transition.to().name;
var dialog = $element[0].querySelector('dialog');
dialog.showModal();
@ -46,17 +55,9 @@ export const COMPONENT = {
}
this.copyAccount = function() {
this.account = this.client.account;
this.accountOld = {};
copyObject(this.account, this.accountOld);
};
this.getAccount = function(clientId) {
$http.get(`/client/api/Accounts/${clientId}`).then(
json => {
this.account = json.data;
this.copyAccount();
}
);
copyObject(this.client.account, this.accountOld);
};
}
};

11
db.json
View File

@ -9,7 +9,7 @@
"Country": 10,
"Province": 44,
"Agency": 4,
"Account": 23,
"Account": 31,
"ClientObservation": 1269
},
"models": {
@ -24,7 +24,7 @@
"14": "{\"name\":\"Cliente 1\",\"id\":14,\"street\":\"Aaaaaaaaaa\",\"fi\":\"1234567890A\",\"socialName\":\"Cliente 1\",\"fax\":\"963242100\",\"dischargeDate\":\"01/01/2017\",\"telefono\":\"963242100\",\"salesPerson\":\"2\",\"email\":\"informatica@verdnatura.es\",\"city\":\"asdf\",\"postcode\":\"asdf\",\"phone\":\"asdf\",\"mobile\":\"asdf\",\"credit\":2345,\"cyc\":8547,\"iban\":\"asdf\",\"dueDay\":345,\"gestdoc\":2435,\"surcharge\":true,\"navigate\":true}",
"15": "{\"name\":\"afsdf\",\"fi\":\"12341234rasf\",\"socialName\":\"asdfasd\",\"dueDay\":5,\"id\":15,\"payMethod\":\"2\",\"salesPerson\":\"1\",\"modify\":\"BasicData\",\"iban\":\"sdfgsdfgsdfg\"}",
"16": "{\"name\":\"floristeria laasdfas\",\"fi\":\"2345234523d\",\"socialName\":\"23452345assdfgsdfgt\",\"active\":true,\"dueDay\":5,\"id\":16,\"modify\":\"FiscalData\",\"email\":\"asdfopi jso@aosijf.com\",\"phone\":\"654654654\",\"mobile\":\"654456456\",\"fax\":\"456456456\",\"street\":\"asdfasdf\"}",
"17": "{\"name\":\"ccccdddddd\",\"fi\":\"asasdadsa\",\"socialName\":\"asdadasda\",\"active\":false,\"dueDay\":5,\"id\":17,\"modify\":\"BasicData\"}"
"17": "{\"name\":\"ccccdddddd\",\"fi\":\"asasdadsa\",\"socialName\":\"asdadasda\",\"active\":true,\"dueDay\":5,\"id\":17,\"modify\":\"Active\"}"
},
"PaymentMethod": {
"1": "{\"name\":\"Tarjeta\",\"id\":1}",
@ -114,12 +114,7 @@
"3": "{\"name\":\"DHL\",\"id\":3}"
},
"Account": {
"1": "{\"id\":1,\"password\":\"joselito\",\"name\":\"asdf\"}",
"12": "{\"id\":12,\"name\":\"javierete\"}",
"14": "{\"id\":14,\"active\":true,\"name\":\"f\"}",
"15": "{\"id\":15,\"name\":\"asdf\"}",
"16": "{\"id\":16,\"name\":\"joselito\",\"active\":true}",
"17": "{\"id\":17,\"name\":\"pepe\",\"active\":true}"
"1": "{\"id\":1,\"password\":\"joselito\",\"name\":\"asdf\"}"
},
"ClientObservation": {
"1258": "{\"text\":\"Nota de prueba 1\",\"creationDate\":\"2017-01-17T15:24:23.320Z\",\"client\":12,\"salesPerson\":\"user\",\"id\":1258}",