msramalho / SigTools

📆 Sigarra Tools | An extension that makes the information system of the University of Porto slightly better.
https://chrome.google.com/webstore/detail/sigarra-to-calendar/piefgbacnljenipiifjopkfifeljjkme
Apache License 2.0
37 stars 0 forks source link

Add utility class for creating and attaching modals in the DOM #105

Open fabiodrg opened 2 years ago

fabiodrg commented 2 years ago

Modals were only used for calendar events, but now are used for 'batch email' (#101) and also for grades simulation (#64). The idea is to create an util class that creates the modal skeletons and attaches them in DOM. The skeleton only manages how to open the modal, where to insert it in the DOM and how to close the modal. The skeleton could provide an interface to specify a title, the body and an eventual footer. Using this skeleton modal ensures consistency and avoids duplicated code.

class Modal {
  static id; // to assign unique identifiers and allow multiple modals in the same page context ?
  // title is a string. body and footer are HTMLElements. isPermanent indicates whether the modal should be removed after opening/closing once (all existing modals are like this, although I think it was just because it was easier to avoid clashes between multiple modals)
  constructor(title, body, footer, isPermanent) {}
  // this triggers the modal to open and can be used externally to attach to event listeners and yada yada
  open() {}
}