Sample refactor
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2022-09-22 15:44:35 +02:00
parent 92a476bd05
commit 664fd444cc
4 changed files with 92 additions and 39 deletions

View File

@ -0,0 +1,17 @@
alter table `vn`.`sample`
add model VARCHAR(25) null comment 'Model name in plural';
alter table `vn`.`sample`
add property VARCHAR(25) null comment 'Remote method property name';
UPDATE vn.sample t
SET t.model = 'Clients',
t.property = 'printerSetup'
WHERE t.id = 13;
UPDATE vn.sample t
SET t.model = 'Clients',
t.property = 'clientWelcome'
WHERE t.id = 12;

View File

@ -29,6 +29,12 @@
},
"datepickerEnabled": {
"type": "boolean"
},
"model": {
"type": "string"
},
"property": {
"type": "string"
}
},
"scopes": {

View File

@ -31,6 +31,7 @@
ng-model="$ctrl.clientSample.typeFk"
model="ClientSample.typeFk"
data="samplesVisible"
fields="['id', 'description', 'model']"
show-field="description"
label="Sample"
required="true">
@ -77,7 +78,7 @@
<vn-button
disabled="!sampleType.selection.hasPreview"
label="Preview"
ng-click="$ctrl.showPreview()">
ng-click="$ctrl.preview()">
</vn-button>
<vn-button
class="cancel"

View File

@ -41,56 +41,85 @@ class Controller extends Section {
);
}
showPreview() {
this.send(true, res => {
this.$.showPreview.show();
const dialog = document.body.querySelector('div.vn-dialog');
const body = dialog.querySelector('tpl-body');
const scroll = dialog.querySelector('div:first-child');
// showPreview() {
// this.send(true, res => {
// this.$.showPreview.show();
// const dialog = document.body.querySelector('div.vn-dialog');
// const body = dialog.querySelector('tpl-body');
// const scroll = dialog.querySelector('div:first-child');
body.innerHTML = res.data;
scroll.scrollTop = 0;
});
}
// body.innerHTML = res.data;
// scroll.scrollTop = 0;
// });
// }
sendSample() {
this.send(false, () => {
this.vnApp.showSuccess(this.$t('Notification sent!'));
this.$state.go('client.card.sample.index');
});
}
// sendSample() {
// this.send(false, () => {
// this.vnApp.showSuccess(this.$t('Notification sent!'));
// this.$state.go('client.card.sample.index');
// });
// }
send(isPreview, cb) {
// send(isPreview, cb) {
// const sampleType = this.$.sampleType.selection;
// const params = {
// recipientId: this.$params.id,
// recipient: this.clientSample.recipient,
// replyTo: this.clientSample.replyTo
// };
// if (!params.recipient)
// return this.vnApp.showError(this.$t('Email cannot be blank'));
// if (!sampleType)
// return this.vnApp.showError(this.$t('Choose a sample'));
// if (sampleType.hasCompany && !this.clientSample.companyFk)
// return this.vnApp.showError(this.$t('Choose a company'));
// if (sampleType.hasCompany)
// params.companyId = this.clientSample.companyFk;
// if (sampleType.datepickerEnabled && !this.clientSample.from)
// return this.vnApp.showError(this.$t('Choose a date'));
// if (sampleType.datepickerEnabled)
// params.from = this.clientSample.from;
// let query = `email/${sampleType.code}`;
// if (isPreview)
// query = `email/${sampleType.code}/preview`;
// this.$http.get(query, {params}).then(cb);
// }
preview() {
const sampleType = this.$.sampleType.selection;
const params = {
recipientId: this.$params.id,
recipient: this.clientSample.recipient,
replyTo: this.clientSample.replyTo
};
if (!params.recipient)
return this.vnApp.showError(this.$t('Email cannot be blank'));
const path = `${sampleType.model}/${this.$params.id}/${sampleType.property}Html`;
this.$http.get(path, {params})
.then(response => {
this.$.showPreview.show();
const dialog = document.body.querySelector('div.vn-dialog');
const body = dialog.querySelector('tpl-body');
const scroll = dialog.querySelector('div:first-child');
if (!sampleType)
return this.vnApp.showError(this.$t('Choose a sample'));
body.innerHTML = response.data;
scroll.scrollTop = 0;
});
}
if (sampleType.hasCompany && !this.clientSample.companyFk)
return this.vnApp.showError(this.$t('Choose a company'));
if (sampleType.hasCompany)
params.companyId = this.clientSample.companyFk;
if (sampleType.datepickerEnabled && !this.clientSample.from)
return this.vnApp.showError(this.$t('Choose a date'));
if (sampleType.datepickerEnabled)
params.from = this.clientSample.from;
let query = `email/${sampleType.code}`;
if (isPreview)
query = `email/${sampleType.code}/preview`;
this.$http.get(query, {params}).then(cb);
send() {
this.vnEmail.send(`tickets/${this.id}/credit-request-email`, {
recipientId: this.ticket.client.id,
recipient: $data.email
});
}
getWorkerEmail() {