form.mjs 23.7 KB
Newer Older
1
"use strict";
2
import "../../node_modules/jstodotxt/jsTodoExtensions.js";
3
import { resetModal, handleError, userData, setUserData, translations, getConfirmation } from "../render.js";
4
import { _paq } from "./matomo.mjs";
5
import { RecExtension, SugarDueExtension, ThresholdExtension } from "./todotxtExtensions.mjs";
6
import { generateFilterData } from "./filters.mjs";
7
import { items, item, setTodoComplete } from "./todos.mjs";
8
import { datePickerInput } from "./datePicker.mjs";
9
import { createModalJail } from "../configs/modal.config.mjs";
10
import * as recurrencePicker from "./recurrencePicker.mjs";
11

12
13
14
const autoCompleteContainer = document.getElementById("autoCompleteContainer");
const recurrencePickerInput = document.getElementById("recurrencePickerInput");
const modalFormAlert = document.getElementById("modalFormAlert");
15
const modalForm = document.getElementById("modalForm");
ransome1's avatar
ransome1 committed
16
const modalFormInputLabel = document.getElementById("modalFormInputLabel");
17
18
19
20
const modalFormInputResize = document.getElementById("modalFormInputResize");
const modalBackground = document.querySelectorAll('.modal-background');
const modalClose = document.querySelectorAll('.close');
const priorityPicker = document.getElementById("priorityPicker");
ransome1's avatar
ransome1 committed
21
const btnSave = document.getElementById("btnSave");
22
23
const btnItemStatus = document.getElementById("btnItemStatus");

ransome1's avatar
ransome1 committed
24
modalFormInputLabel.innerHTML = translations.todoTxtSyntax;
25
26

btnItemStatus.onclick = function() {
27
  setTodoComplete(modalForm.getAttribute("data-item")).then(response => {
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    resetModal().then(function(result) {
      console.log(result);
    }).catch(function(error) {
      handleError(error);
    });
    console.log(response);
    // trigger matomo event
    if(userData.matomoEvents) _paq.push(["trackEvent", "Form", "Click on Done/In progress"]);
  }).catch(error => {
    handleError(error);
  });
}
modalFormInputResize.onclick = function() {
  toggleInputSize(this.getAttribute("data-input-type"));
  // trigger matomo event
  if(userData.matomoEvents) _paq.push(["trackEvent", "Form", "Click on Resize"]);
}
ransome1's avatar
ransome1 committed
45
46
47
48
49
50
51
52
53
54
55
56
btnSave.onclick = function() {
  submitForm().then(response => {
    console.log(response);
  }).catch(error => {
    handleError(error);
  });
  // trigger matomo event
  if(userData.matomoEvents) _paq.push(["trackEvent", "Form", "Click on Submit"]);
}

document.getElementById("modalFormInput").addEventListener("keyup", event => {
  keyUp();
57
});
ransome1's avatar
ransome1 committed
58
59
60
61
62

document.getElementById("modalFormInput").addEventListener("keydown", event => {
  keyDown();
});

ransome1's avatar
ransome1 committed
63
64
65
66
67
68
document.getElementById("modalFormInput").onfocus = function() {
  modalForm.classList.add("is-focused");
}
document.getElementById("modalFormInput").onblur = function() {
  modalForm.classList.remove("is-focused");
}
69
modalForm.addEventListener("submit", function(event) {
ransome1's avatar
ransome1 committed
70
  event.preventDefault;
71
});
72
modalForm.addEventListener ("click", function() {
73
  // close recurrence picker if click is outside of recurrence container
74
  if(!event.target.closest("#recurrencePickerContainer") && event.target!=recurrencePickerInput) document.getElementById("recurrencePickerContainer").classList.remove("is-active")
75
});
76
77
78
79
80
81
82
83
84
85
86
87
priorityPicker.addEventListener("change", e => {
  setPriority(e.target.value).then(response => {
    console.log(response);
  }).catch(error => {
    handleError(error);
  });
});
priorityPicker.onfocus = function() {
  // close suggestion box if focus comes to priority picker
  autoCompleteContainer.classList.remove("is-active");
};

88
89
modalBackground.forEach(function(el) {
  el.onclick = function() {
90
91
92
93
94
95
96
97
98
99
100
    const modalObject = document.getElementById(el.parentElement.id);
    // if modal is modalForm and input is equal the data item
    if(modalObject.id === "modalForm" && modalForm.getAttribute("data-item") !== modalFormInput.value) {
      getConfirmation(resetModal, translations.modalBackgroundAttention, modalObject);
    } else {
      resetModal(modalObject).then(function(result) {
        console.log(result);
      }).catch(function(error) {
        handleError(error);
      });
    }
101
102
103
104
    // trigger matomo event
    if(userData.matomoEvents) _paq.push(["trackEvent", "Modal", "Click on Background"]);
  }
});
105

106
107
108
109
110
111
112
modalClose.forEach(function(el) {
  el.onclick = function() {
    if(el.getAttribute("data-message")) {
      // persist closed message, so it won't show again
      if(!userData.dismissedMessages.includes(el.getAttribute("data-message"))) userData.dismissedMessages.push(el.getAttribute("data-message"))
      setUserData("dismissedMessages", userData.dismissedMessages);
      // trigger matomo event
113
      if(userData.matomoEvents) _paq.push(["trackEvent", "Message", "Click on Close"]);
114
115
    } else {
      // trigger matomo event
116
      if(userData.matomoEvents) _paq.push(["trackEvent", "Modal", "Click on Close"]);
117
118
119
120
    }
    el.parentElement.parentElement.classList.remove("is-active");
  }
});
121

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// TODO add try catch
function keyUp() {
  // do not show suggestion container if Escape has been pressed
  if(event.key==="Escape") {
    autoCompleteContainer.classList.remove("is-active");
    return false;
  }
  modalFormInputEvent();
}

// TODO add try and catch
function keyDown() {
  // regular submit
  if(document.getElementById("modalFormInput").type !=="textarea" && event.key === "Enter") {
    submitForm().then(response => {
      console.log(response);
    }).catch(error => {
      handleError(error);
    });
    // trigger matomo event
    if(userData.matomoEvents) _paq.push(["trackEvent", "Form", "Pressed Enter for Submit"]);
  }

  // submit form with Ctrl/CMD and Enter
  if(event.key==="Enter" && (event.ctrlKey || event.metaKey)) {
    submitForm().then(response => {
      console.log(response);
    }).catch(error => {
      handleError(error);
    });
    // trigger matomo event
    if(userData.matomoEvents) _paq.push(["trackEvent", "Form", "Pressed Ctrl/CMD and Enter for Submit"]);
  }
}
156
157
158
159
160
161
162
163
function getCaretPosition(inputId) {
  var content = inputId;
  if((content.selectionStart!=null)&&(content.selectionStart!=undefined)){
    var position = content.selectionStart;
    return position;
  } else {
    return false;
  }
164
}
165
166
function positionAutoCompleteContainer() {
  // Adjust position of suggestion box to input field
167
168
  let modalFormInputPosition = document.getElementById("modalFormInput").getBoundingClientRect();
  autoCompleteContainer.style.width = document.getElementById("modalFormInput").offsetWidth + "px";
ransome1's avatar
ransome1 committed
169
  autoCompleteContainer.style.top = modalFormInputPosition.top + document.getElementById("modalFormInput").offsetHeight - 40 + "px";
170
171
  autoCompleteContainer.style.left = modalFormInputPosition.left + "px";
}
ransome1's avatar
ransome1 committed
172
function modalFormInputEvent(event) {
173
  positionAutoCompleteContainer();
174
  resizeInput(document.getElementById("modalFormInput"));
175
176
  let autoCompleteValue ="";
  let autoCompletePrefix = "";
177
  let caretPosition = getCaretPosition(document.getElementById("modalFormInput"));
178
  let autoCompleteCategory = "";
179
180
181
182
183
184
185
186
187
  if((document.getElementById("modalFormInput").value.charAt(caretPosition-2) === " " || document.getElementById("modalFormInput").value.charAt(caretPosition-2) === "\n") && (document.getElementById("modalFormInput").value.charAt(caretPosition-1) === "@" || document.getElementById("modalFormInput").value.charAt(caretPosition-1) === "+")) {
    autoCompleteValue = document.getElementById("modalFormInput").value.substr(caretPosition, document.getElementById("modalFormInput").value.lastIndexOf(" ")).split(" ").shift();
    autoCompletePrefix = document.getElementById("modalFormInput").value.charAt(caretPosition-1);
  } else if(document.getElementById("modalFormInput").value.charAt(caretPosition) === " ") {
    autoCompleteValue = document.getElementById("modalFormInput").value.substr(document.getElementById("modalFormInput").value.lastIndexOf(" ", caretPosition-1)+2).split(" ").shift();
    autoCompletePrefix = document.getElementById("modalFormInput").value.charAt(document.getElementById("modalFormInput").value.lastIndexOf(" ", caretPosition-1)+1);
  } else if(document.getElementById("modalFormInput").value.charAt(document.getElementById("modalFormInput").value.lastIndexOf(" ", caretPosition)+1) === "@" || document.getElementById("modalFormInput").value.charAt(document.getElementById("modalFormInput").value.lastIndexOf(" ", caretPosition)+1) === "+") {
    autoCompleteValue = document.getElementById("modalFormInput").value.substr(document.getElementById("modalFormInput").value.lastIndexOf(" ", caretPosition)+2).split(" ").shift();
    autoCompletePrefix = document.getElementById("modalFormInput").value.charAt(document.getElementById("modalFormInput").value.lastIndexOf(" ", caretPosition)+1);
188
189
190
191
192
193
194
  } else {
    autoCompleteContainer.classList.remove("is-active");
    autoCompleteContainer.blur();
    return false;
  }
  // suppress suggestion box if caret is at the end of word
  if(autoCompletePrefix==="+" || autoCompletePrefix==="@") {
ransome1's avatar
ransome1 committed
195
    if(autoCompletePrefix==="+") {
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
      autoCompleteCategory = "projects";
    } else if(autoCompletePrefix=="@") {
      autoCompleteCategory = "contexts";
    }
    // parsed data will be passed to generate filter data and build the filter buttons
    generateFilterData(autoCompleteCategory, autoCompleteValue, autoCompletePrefix, caretPosition).then(response => {
      console.log(response);
    }).catch (error => {
      handleError(error);
    });
  } else {
    autoCompleteContainer.classList.remove("is-active");
    autoCompleteContainer.blur();
  }
}
ransome1's avatar
ransome1 committed
211
212
// TODO add try catch
async function resizeInput(input) {
213
214
  // resizing modalFormInput
  if(input.tagName==="TEXTAREA" && input.id==="modalFormInput") {
ransome1's avatar
ransome1 committed
215
216
217
218
    // reduce height after lines are being deleted
    input.style.height = "auto"
    // wait until the textarea is rendered
    await input.scrollHeight;
219
220
221
222
223
224
    input.style.height = input.scrollHeight+"px";
    return false;
  } else if (input.type==="text" && input.id==="modalFormInput") {
    return false;
  }
  // resizing all other input
225
226
227
228
229
230
  if(input.value) {
    input.style.width = input.value.length + 6 + "ch";
  } else if(!input.value && input.placeholder) {
    input.style.width = input.placeholder.length + 6 + "ch";
  }
}
231
232
233
234
235
236
237
238
239
240
241
242
243
function setPriority(priority) {
  try {
    const setPriorityInput = function(priority) {
      if(priority===null) {
        priorityPicker.selectedIndex = 0;
      } else {
        Array.from(priorityPicker.options).forEach(function(option) {
          if(option.value===priority) {
            priorityPicker.selectedIndex = option.index;
          }
        });
      }
    }
244
    let todo = new TodoTxtItem(document.getElementById("modalFormInput").value);
245
246
247
248
249
250
251
252
253
254
255
256
    if((priority==="down" || priority==="up") && !todo.priority) {
      todo.priority = "A";
    } else if(priority==="up" && todo.priority!="a") {
      todo.priority = String.fromCharCode(todo.priority.charCodeAt(0)-1).toUpperCase();
    } else if(priority==="down" && todo.priority!="z") {
      todo.priority = String.fromCharCode(todo.priority.charCodeAt(0)+1).toUpperCase();
    } else if(priority && priority.match(/[A-Z]/i)) {
      todo.priority = priority.toUpperCase();
    } else {
      todo.priority = null;
    }
    if(todo.priority===null || todo.priority.match(/[a-z]/i)) {
257
      document.getElementById("modalFormInput").value = todo.toString();
258
259
260
261
262
263
264
265
266
267
268
269
270
      setPriorityInput(todo.priority);
      // trigger matomo event
      if(userData.matomoEvents) _paq.push(["trackEvent", "Form", "Priority changed to: " + todo.priority]);
      return Promise.resolve("Success: Priority changed to " + todo.priority)
    }
    return Promise.resolve("Info: Priority unchanged")
  } catch(error) {
    error.functionName = setPriority.name;
    return Promise.reject(error);
  }
}
function setDueDate(days) {
  try {
271
    const todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new DueExtension() ]);
272
273
274
275
276
277
278
279
280
281
    if(days===0) {
      todo.due = undefined;
      todo.dueString = undefined;
    } else if(days && todo.due) {
      todo.due = new Date(new Date(todo.dueString).setDate(new Date(todo.dueString).getDate() + days));
      todo.dueString = todo.due.toISOString().substr(0, 10);
    } else if(days && !todo.due) {
      todo.due = new Date(new Date().setDate(new Date().getDate() + days));
      todo.dueString = todo.due.toISOString().substr(0, 10);
    }
282
    document.getElementById("modalFormInput").value = todo.toString();
283
284
285
286
287
288
    return Promise.resolve("Success: Due date changed to " + todo.dueString)
  } catch(error) {
    error.functionName = setDueDate.name;
    return Promise.reject(error);
  }
}
289
290
function show(todo, templated) {
  try {
ransome1's avatar
ransome1 committed
291
292
    // switch to textarea if needed
    if(userData.useTextarea) toggleInputSize("input");
293
    // remove any previously set data-item attributes
294
295
    //modalForm.removeAttribute("data-item");
    modalForm.setAttribute("data-item", "");
296
297
    // adjust size of recurrence picker input field
    datePickerInput.value = null;
298
    recurrencePickerInput.value = null;
299
    document.getElementById("modalFormInput").value = null;
300
301
    modalFormAlert.innerHTML = null;
    modalFormAlert.parentElement.classList.remove("is-active", 'is-warning', 'is-danger');
302
    //
303
304
305
    if(todo) {
      // replace invisible multiline ascii character with new line
      // we need to check if there already is a due date in the object
306
      todo = new TodoTxtItem(todo, [ new DueExtension(), new HiddenExtension(), new RecExtension(), new ThresholdExtension() ]);
307
308
309
310
311
312
      // set the priority
      setPriority(todo.priority);
      //
      if(templated === true) {
        // this is a new templated todo task
        // erase the original creation date and description
313
        todo.date = new Date();
314
        todo.text = "____________";
315
        document.getElementById("modalFormInput").value = todo.toString();
ransome1's avatar
ransome1 committed
316
        //modalTitle.innerHTML = translations.addTodo;
317
        // automatically select the placeholder description
318
        let selectStart = document.getElementById("modalFormInput").value.indexOf(todo.text);
319
        let selectEnd = selectStart + todo.text.length;
320
        document.getElementById("modalFormInput").setSelectionRange(selectStart, selectEnd);
ransome1's avatar
ransome1 committed
321
        btnItemStatus.classList.add("is-hidden");
322
      } else {
323
324
        // pass todo string to form data item
        modalForm.setAttribute("data-item", todo.toString());
325
        // this is an existing todo task to be edited
326
327
328
329
330
        // replace special char with line breaks before passing it to textarea
        if(userData.useTextarea) document.getElementById("modalFormInput").value = todo.toString().replaceAll(String.fromCharCode(16),"\r\n");
        // replace special char with space before passing it to regular input
        if(!userData.useTextarea) document.getElementById("modalFormInput").value = todo.toString().replaceAll(String.fromCharCode(16)," ");
        //document.getElementById("modalFormInput").value = todo.toString();
ransome1's avatar
ransome1 committed
331
332
        //modalTitle.innerHTML = translations.editTodo;
        btnItemStatus.classList.remove("is-hidden");
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
      }
      // only show the complete button on open items
      if(todo.complete === false) {
        btnItemStatus.innerHTML = translations.done;
      } else {
        btnItemStatus.innerHTML = translations.inProgress;
      }
      // if there is a recurrence
      if(todo.rec) {
        recurrencePicker.setInput(todo.rec).then(function(result) {
          console.log(result);
        }).catch(function(error) {
          handleError(error);
        });
      }
      // if so we paste it into the input field
      if(todo.dueString) {
        datePickerInput.value = todo.dueString;
      }
    } else {
ransome1's avatar
ransome1 committed
353
354
      //modalTitle.innerHTML = translations.addTodo;
      btnItemStatus.classList.add("is-hidden");
355
356
357
358
    }
    // adjust size of picker inputs
    resizeInput(datePickerInput);
    resizeInput(recurrencePickerInput);
ransome1's avatar
ransome1 committed
359
    //resizeInput(document.getElementById("modalFormInput"));
360
361
    // create the modal jail, so tabbing won't leave modal
    createModalJail(modalForm);
362
363
364
365
    // show modal and set focus to input element
    modalForm.classList.add("is-active");
    // put focus into the input field
    document.getElementById("modalFormInput").focus();
366
367
368
369
370
371
372
373
    return Promise.resolve("Info: Show/Edit todo window opened");
  } catch (error) {
    error.functionName = show.name;
    return Promise.reject(error);
  }
}
function submitForm() {
  try {
374
375
376
377
378
379
    if(userData.file === undefined) {
      modalFormAlert.innerHTML = translations.formErrorWritingFile;
      modalFormAlert.parentElement.classList.remove("is-active", 'is-danger');
      modalFormAlert.parentElement.classList.add("is-active", 'is-warning');
      return Promise.resolve("Info: No todo.txt defined yet");
    }
380
381
    // check if there is an input in the text field, otherwise indicate it to the user
    // input value and data item are the same, nothing has changed, nothing will be written
ransome1's avatar
ransome1 committed
382
    if(modalForm.getAttribute("data-item") === document.getElementById("modalFormInput").value) {
383
384
385
386
387
388
      // close and reset any modal
      resetModal().then(function(result) {
        console.log(result);
      }).catch(function(error) {
        handleError(error);
      });
389
390
      return Promise.resolve("Info: Nothing has changed, won't write anything.");
    // Edit todo
391
    } else if(modalForm.getAttribute("data-item")) {
392
393
394
395
      // get index of todo
      const index = items.objects.map(function(item) {return item.toString(); }).indexOf(modalForm.getAttribute("data-item"));
      // create a todo.txt object
      // replace new lines with spaces (https://stackoverflow.com/a/34936253)
396
      let todo = new TodoTxtItem(document.getElementById("modalFormInput").value.replaceAll(/[\r\n]+/g, String.fromCharCode(16)), [ new SugarDueExtension(), new HiddenExtension(), new RecExtension(), new ThresholdExtension() ]);
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
      // check and prevent duplicate todo
      if(items.objects.map(function(item) {return item.toString(); }).indexOf(todo.toString())!=-1) {
        modalFormAlert.innerHTML = translations.formInfoDuplicate;
        modalFormAlert.parentElement.classList.remove("is-active", 'is-danger');
        modalFormAlert.parentElement.classList.add("is-active", 'is-warning');
        return Promise.resolve("Info: Todo already exists in file, won't write duplicate");
      // check if todo text is empty
      } else if(!todo.text) {
        modalFormAlert.innerHTML = translations.formInfoIncomplete;
        modalFormAlert.parentElement.classList.remove("is-active", 'is-danger');
        modalFormAlert.parentElement.classList.add("is-active", 'is-warning');
        return Promise.resolve("Info: Todo is incomplete");
      }
      // jump to index, remove 1 item there and add the value from the input at that position
      items.objects.splice(index, 1, todo);
    // Add todo
413
    } else if(!modalForm.getAttribute("data-item") && document.getElementById("modalFormInput").value!="") {
414
415
      // in case there hasn't been a passed data item, we just push the input value as a new item into the array
      // replace new lines with spaces (https://stackoverflow.com/a/34936253)
416
      let todo = new TodoTxtItem(document.getElementById("modalFormInput").value.replaceAll(/[\r\n]+/g, String.fromCharCode(16)), [ new SugarDueExtension(), new HiddenExtension(), new RecExtension(), new ThresholdExtension() ]);
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
      // we add the current date to the start date attribute of the todo.txt object
      todo.date = new Date();
      // check and prevent duplicate todo
      if(items.objects.map(function(item) {return item.toString(); }).indexOf(todo.toString())!=-1) {
        modalFormAlert.innerHTML = translations.formInfoDuplicate;
        modalFormAlert.parentElement.classList.remove("is-active", 'is-danger');
        modalFormAlert.parentElement.classList.add("is-active", 'is-warning');
        return Promise.resolve("Info: Todo already exists in file, won't write duplicate");
      // check if todo text is empty
      } else if(!todo.text) {
        modalFormAlert.innerHTML = translations.formInfoIncomplete;
        modalFormAlert.parentElement.classList.remove("is-active", 'is-danger');
        modalFormAlert.parentElement.classList.add("is-active", 'is-warning');
        return Promise.resolve("Info: Todo is incomplete");
      }
      // we build the array
      items.objects.push(todo);
      // mark the todo for anchor jump after next reload
      item.previous = todo.toString();
ransome1's avatar
ransome1 committed
436
    } else if(document.getElementById("modalFormInput").value=="") {
437
438
439
440
441
442
443
444
      modalFormAlert.innerHTML = translations.formInfoNoInput;
      modalFormAlert.parentElement.classList.remove("is-active", 'is-danger');
      modalFormAlert.parentElement.classList.add("is-active", 'is-warning');
      return Promise.resolve("Info: Will not write empty todo");
    }
    //write the data to the file
    // a newline character is added to prevent other todo.txt apps to append new todos to the last line
    window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]);
445
446
447
448
449
450
    // close and reset any modal
    resetModal().then(function(result) {
      console.log(result);
    }).catch(function(error) {
      handleError(error);
    });
451
    // trigger matomo event
452
    if(userData.matomoEvents) _paq.push(["trackEvent", "Form", "Submit"]);
453
454
455
456
457
458
459
460
461
462
    return Promise.resolve("Success: Changes written to file: " + userData.file);
  // if the input field is empty, let users know
  } catch (error) {
    // if writing into file is denied throw alert
    modalFormAlert.innerHTML = translations.formErrorWritingFile + userData.file;
    modalFormAlert.parentElement.classList.add("is-active", 'is-danger');
    error.functionName = submitForm.name;
    return Promise.reject(error);
  }
}
ransome1's avatar
ransome1 committed
463

464
465
466
467
function toggleInputSize(type) {
  let newInputElement;
  switch (type) {
    case "input":
468
      newInputElement = document.createElement("textarea");
469
470
471
472
473
      modalFormInputResize.setAttribute("data-input-type", "textarea");
      modalFormInputResize.innerHTML = "<i class=\"fas fa-compress-alt\"></i>";
      setUserData("useTextarea", true);
      break;
    case "textarea":
474
      newInputElement = document.createElement("input");
475
476
477
478
479
480
481
      newInputElement.type = "text";
      modalFormInputResize.setAttribute("data-input-type", "input");
      modalFormInputResize.innerHTML = "<i class=\"fas fa-expand-alt\"></i>";
      setUserData("useTextarea", false);
      break;
  }
  newInputElement.id = "modalFormInput";
482
  newInputElement.setAttribute("tabindex", 0);
483
  newInputElement.setAttribute("class", "input is-medium");
484
485
486
487
488
489
490
  // replace old element with the new one
  document.getElementById("modalFormInput").replaceWith(newInputElement);
  // replace special char with line break before passing it to textarea
  if(userData.useTextarea && modalForm.getAttribute("data-item")) document.getElementById("modalFormInput").value = document.getElementById("modalForm").getAttribute("data-item").replaceAll(String.fromCharCode(16),"\r\n");
  // replace special char with space before passing it to regular input
  if(!userData.useTextarea && modalForm.getAttribute("data-item")) document.getElementById("modalFormInput").value = document.getElementById("modalForm").getAttribute("data-item").replaceAll(String.fromCharCode(16)," ");

491
  positionAutoCompleteContainer();
492
  resizeInput(document.getElementById("modalFormInput"));
ransome1's avatar
ransome1 committed
493
494
495
  // document.getElementById("modalFormInput").addEventListener("keyup", () => {
  //   modalFormInputEvent();
  // });
ransome1's avatar
ransome1 committed
496
497
498
499
500
501
  document.getElementById("modalFormInput").onfocus = function() {
    modalForm.classList.add("is-focused");
  }
  document.getElementById("modalFormInput").onblur = function() {
    modalForm.classList.remove("is-focused");
  }
502
503
  document.getElementById("modalFormInput").focus();
  createModalJail(modalForm);
ransome1's avatar
ransome1 committed
504
505
506
507
508
509
510

  document.getElementById("modalFormInput").addEventListener("keydown", () => {
    keyDown();
  });
  document.getElementById("modalFormInput").addEventListener("keyup", () => {
    keyUp();
  });
511
512
}

513
514
515
516
517
518
519
520
521
522
window.onresize = function() {
  try {
    positionAutoCompleteContainer();
  } catch(error) {
    error.functionName = "window.onresize";
    handleError(error);
    return Promise.reject(error);
  }
}

ransome1's avatar
ransome1 committed
523
export { show, resizeInput, setPriority, setDueDate, submitForm, toggleInputSize};