Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { captureDOM } from '../index.js';
- // Global Functions
- const stopPropagation = (event) => {
- event.stopPropagation();
- }
- // Modules
- const manageList = (function () {
- // Initializing important variables
- // Used in createList for the bulletinBoard array
- let idCounter = 1;
- let bulletinBoard = [];
- // Creating a Checklist Factory Function
- const listFactory = (
- id, title, description, creationDate,
- dueDate, priority, list,
- ) => {
- return {
- id, title, description, creationDate,
- dueDate, priority, list,
- };
- };
- // This counter is used to add IDs to the new listList objects
- const createList = (event) => {
- // Preventing the page from reloading
- event.preventDefault();
- // Puling form data
- let fd = new FormData(captureDOM.form);
- // WITH DATE FNS ADD THE CURRENT DATE TODAY, FOR THE CREATION DATE
- // Creating a placeholder list to carry all of our information
- let newList = listFactory();
- newList['id'] = idCounter;
- newList['list'] = [];
- // This is placeholder
- newList['creationDate'] = 'Today';
- let key;
- for (key of fd.keys(key)) {
- newList[key] = fd.get(key);
- }
- // Resetting form values
- captureDOM.form.reset();
- // now that we are done creating the list, we add the list to
- // our bulletinBoard, then increment our idCounter
- bulletinBoard[idCounter] = newList;
- idCounter++;
- };
- // This will delete a todo list from the bulletinBoard array
- // when the trashcan with the corresponding ID is clicked
- const deleteList = () => {
- }
- return {
- bulletinBoard: bulletinBoard,
- createList: createList,
- };
- })();
- // This module will hold all functions related to creating the DOM
- const createPage = (function () {
- // Initializing Variables
- // Used in bulletinBoard as a counter
- let i = 0;
- // Creating Functions
- // This function toggles the display property of the form
- const toggleForm = (configuration, x) => {
- switch (configuration){
- case 'toggle' :
- if(x.classList.contains('hidden') == true) {
- x.classList.remove('hidden');
- }
- else {
- x.classList += ' hidden';
- }
- break;
- case 'add' :
- x.classList += ' hidden';
- break;
- case 'remove' :
- x.classList.remove('hidden');
- break;
- }
- }
- // Function to create our lists, either through a loop or single increments
- // This feature is dependent on the configuration setting used
- // The two settings are "add" or "loop"
- const bulletinBoard = (configuration) => {
- // Function to add list to the DOM
- const bulletinBoardSetup = (i) => {
- if (i === 0) {
- i++;
- return;
- }
- // Creating Elements
- const list = document.createElement('section');
- const title = document.createElement('h2');
- const description = document.createElement('p');
- const dueDate = document.createElement('p');
- const deleteButton = document.createElement('img');
- // Manipulating Elements
- // List Section
- list.dataset.id = manageList.bulletinBoard[i]['id'];
- list.className = 'list-section';
- // List Title
- title.className = 'list-title';
- title.textContent = manageList.bulletinBoard[i]['title'];
- // List Description
- description.className = 'list-description';
- description.textContent = manageList.bulletinBoard[i]['description'];
- // List Due Date
- dueDate.className = 'list-due-date';
- dueDate.textContent = manageList.bulletinBoard[i]['dueDate'];
- // List Delete Button
- deleteButton.dataset.id = manageList.bulletinBoard[i]['id'];
- deleteButton.className = 'list-delete-button';
- // Appending Elements
- captureDOM.content.appendChild(list);
- list.append(title, description, dueDate, deleteButton);
- }
- // This is used to render all stored lists
- if (configuration === 'loop') {
- for(let i = 0; i < manageList.bulletinBoard.length; i++){
- bulletinBoardSetup(i);
- }
- }
- if (configuration === 'add') {
- bulletinBoardSetup(i);
- }
- i++;
- // This will create each list's specific page
- const list = () => {
- }
- }
- return {
- bulletinBoard: bulletinBoard,
- toggleForm: toggleForm,
- }
- })();
- export { manageList, createPage, stopPropagation };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement