소스 검색

Autogenerate subscriber name from e-mail on the UI if it's empty. Closes #525.

Kailash Nadh 3 년 전
부모
커밋
bc9252f410
2개의 변경된 파일14개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      frontend/src/utils.js
  2. 12 0
      frontend/src/views/SubscriberForm.vue

+ 2 - 0
frontend/src/utils.js

@@ -103,6 +103,8 @@ export default class Utils {
   // https://stackoverflow.com/a/12034334
   escapeHTML = (html) => html.replace(/[&<>"'`=/]/g, (s) => htmlEntities[s]);
 
+  titleCase = (str) => str[0].toUpperCase() + str.substr(1).toLowerCase();
+
   // UI shortcuts.
   confirm = (msg, onConfirm, onCancel) => {
     Dialog.confirm({

+ 12 - 0
frontend/src/views/SubscriberForm.vue

@@ -165,6 +165,18 @@ export default Vue.extend({
     },
 
     onSubmit() {
+      // If there is no name, auto-generate one from the e-mail.
+      if (!this.form.name) {
+        let name = '';
+        [name] = this.form.email.toLowerCase().split('@');
+
+        if (name.includes('.')) {
+          this.form.name = name.split('.').map((c) => this.$utils.titleCase(c)).join(' ');
+        } else {
+          this.form.name = this.$utils.titleCase(name);
+        }
+      }
+
       if (this.isEditing) {
         this.updateSubscriber();
         return;