From d47e7ffb16b9daef2f1642ff1573c21ef4ee3740 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Fri, 25 Nov 2022 08:23:57 +0100 Subject: [PATCH] change component location --- front/core/components/index.js | 1 - front/salix/components/index.js | 1 + front/salix/components/sendSms/index.html | 45 +++++++++++++++++ front/salix/components/sendSms/index.js | 52 ++++++++++++++++++++ front/salix/components/sendSms/locale/es.yml | 9 ++++ front/salix/components/sendSms/style.scss | 5 ++ 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 front/salix/components/sendSms/index.html create mode 100644 front/salix/components/sendSms/index.js create mode 100644 front/salix/components/sendSms/locale/es.yml create mode 100644 front/salix/components/sendSms/style.scss diff --git a/front/core/components/index.js b/front/core/components/index.js index 723b39bafe..86ab892122 100644 --- a/front/core/components/index.js +++ b/front/core/components/index.js @@ -53,4 +53,3 @@ import './datalist'; import './contextmenu'; import './rating'; import './smart-table'; -import './sendSms'; diff --git a/front/salix/components/index.js b/front/salix/components/index.js index ce4ad585aa..d712a8a40d 100644 --- a/front/salix/components/index.js +++ b/front/salix/components/index.js @@ -16,3 +16,4 @@ import './user-popover'; import './upload-photo'; import './bank-entity'; import './log'; +import './sendSms'; diff --git a/front/salix/components/sendSms/index.html b/front/salix/components/sendSms/index.html new file mode 100644 index 0000000000..6915942c2d --- /dev/null +++ b/front/salix/components/sendSms/index.html @@ -0,0 +1,45 @@ + + +
+
Send SMS
+ + + + + + + + + + + {{'Characters remaining' | translate}}: + + {{$ctrl.charactersRemaining()}} + + + +
+
+ + + + +
\ No newline at end of file diff --git a/front/salix/components/sendSms/index.js b/front/salix/components/sendSms/index.js new file mode 100644 index 0000000000..ab57d3acad --- /dev/null +++ b/front/salix/components/sendSms/index.js @@ -0,0 +1,52 @@ +import ngModule from '../../module'; +import './style.scss'; +import Dialog from '../../../core/components/dialog'; + +export default class sendSmsDialog extends Dialog { + constructor($element, $scope, $http, $translate, vnApp) { + super($element, $scope, $http, $translate, vnApp); + + new CustomEvent('openSmsDialog', { + detail: { + this: this + } + }); + document.addEventListener('openSmsDialog', e => { + this.route = e.detail.route; + this.$.SMSDialog.show(); + }); + } + + charactersRemaining() { + const element = this.sms.message; + const maxLength = 160; + return maxLength - element.length; + } + + onResponse() { + try { + if (!this.sms.destination) + throw new Error(`The destination can't be empty`); + if (!this.sms.message) + throw new Error(`The message can't be empty`); + if (this.charactersRemaining() < 0) + throw new Error(`The message it's too long`); + + this.$http.post(this.route, this.sms).then(res => { + this.vnApp.showMessage(this.$t('SMS sent!')); + }); + } catch (e) { + this.vnApp.showError(this.$t(e.message)); + return false; + } + return true; + } +} + +ngModule.vnComponent('vnSmsDialog', { + template: require('./index.html'), + controller: sendSmsDialog, + bindings: { + sms: '<', + } +}); diff --git a/front/salix/components/sendSms/locale/es.yml b/front/salix/components/sendSms/locale/es.yml new file mode 100644 index 0000000000..64c3fcca67 --- /dev/null +++ b/front/salix/components/sendSms/locale/es.yml @@ -0,0 +1,9 @@ +Send SMS: Enviar SMS +Destination: Destinatario +Message: Mensaje +SMS sent!: ¡SMS enviado! +Characters remaining: Carácteres restantes +The destination can't be empty: El destinatario no puede estar vacio +The message can't be empty: El mensaje no puede estar vacio +The message it's too long: El mensaje es demasiado largo +Special characters like accents counts as a multiple: Carácteres especiales como los acentos cuentan como varios \ No newline at end of file diff --git a/front/salix/components/sendSms/style.scss b/front/salix/components/sendSms/style.scss new file mode 100644 index 0000000000..84571a5f42 --- /dev/null +++ b/front/salix/components/sendSms/style.scss @@ -0,0 +1,5 @@ +@import "variables"; + +.SMSDialog { + min-width: 400px +} \ No newline at end of file