Create a LOTO sequence list UI component

by Michael Prosser

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.14.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.14.1/jquery-ui.min.js"></script>

CSS

.loto-sequencer-window{
  position: fixed;
  left: 0px;
  right: 0px;
  top: 0px;
  bottom: 0px;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 999999;
}
.loto-sequencer-window>div {
  max-width: 1000px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  max-height: 90%;
  overflow: auto;
  background-color: #fff;
  max-width: 100%;
  padding: 20px;
  width: 600px;
  font-family: helvetica;
  overflow-x: hidden;
}
.loto-sequencer-window>div>h1 {
  margin: 0px;
  margin-bottom: 0px;
  color: #fff;
  text-transform: uppercase;
  font-size: 20px;
  font-weight: normal;
  background-color: #2a2a2a;
  padding: 10px;
  padding-left: 12px;
  margin-left: -20px;
  margin-right: -20px;
  margin-top: -20px;
  line-height: 26px;
}
.loto-sequencer-window>div h3{
  margin: 0px;
  margin-top: 10px;
  font-size: 15px;
  font-weight: normal;
}
.loto-sequencer-window>div h4{
  margin: 0px;
  margin-bottom: 0px;
  font-size: 13px;
  position: relative;
  font-weight: normal;
}
.loto-sequencer-window>div h4 button.loto-sequence-order-sort-enable{
  position: absolute;
  right: 0px;
  top: -15px;
  background-color: #356db0;
  border: none;
  color: #fff;
  padding: 6px;
  width: 190px;
  cursor: pointer;
  transition: all 0.3s;
  text-align: left;
  font-size: 12px;
}
.loto-sequencer-window>div h4 button.loto-sequence-order-sort-enable>input{
  pointer-events: none;
  vertical-align: middle;
}
.loto-sequencer-window>div>h1>button.close-button {
  position: absolute;
  right: 5px;
  top: 5px;
  border: solid 1px #fff;
  background-color: transparent;
  color: #fff;
  padding: 7px;
  width: 31px;
  cursor: pointer;
}
.loto-sequencer-window>div>ul {
  list-style: none;
  margin: 0px;
  padding: 4px;
  background-color: #222;
  margin-bottom: 20px;
  margin-top: 10px;
}
.loto-sequencer-window>div>ul:empty:after{
  content: "No Sequence Data Found...

JavaScript

/*

sequenceData example

[
  {
    name: "Sequence #1",
    procedures: [
      {
        procedure_type_id: "1",
        equipment_id: "1"
      }
    ]
  }
]

*/


class LOTOSequencer{

  constructor(parentElement,facilityID,facilityName,equipmentID,equipmentName,equipmentCommonName,sequenceData){

    this.parentElement = parentElement;
    this.facilityID = facilityID;
    this.facilityName = facilityName;
    this.equipmentID = equipmentID;
    this.equipmentName = equipmentName;
    this.equipmentCommonName = equipmentCommonName;
    this.sequenceData = sequenceData;
    
    this.ui;

    this.build();

  }

  confirmDelete(header,message,callback){

    let confirmation = $(`<div class="confirm-delete-sequence"><div><h1>${header}</h1><p>${message}</p><div class="buttons"><button class="cancel">Cancel</button> <button class="ok">OK</button></div></div></div>`);

    $('body').append(confirmation);

    confirmation.find('button.cancel').click(function(){

      confirmation.remove();

    });

    confirmation.find('button.ok').click(function(){

      if(typeof(callback) == 'function'){

        callback();

      }

      confirmation.remove();

    });

  }

  build(){

    $('.loto-sequencer-window').remove();

    this.ui = $(`<div class="loto-sequencer-window"><div><h1>LOTO Procedure Sequencing<button class="close-button">X</button><h1><h3>Location: <strong>${this.facilityName}</strong></h3><h4>Equipment Item: <strong>${this.equipmentName}</strong></h4><h4>Common Name: <strong>${this.equipmentCommonName}</strong><button class="loto-sequence-order-sort-enable"><input type="checkbox"> Enable Sequence Reorder</button></h4><ul class="loto-sequence-list"></ul><button class="add-loto-sequence-button"><span>+</span> Add Sequence</button><button class="save-loto-sequence-button">Save Sequence Data</button></div></div>`);

    this.ui.find('button.add-loto-sequence-button').click(() =>...