Advertisement
MD500_Pilot

manage_events

Sep 3rd, 2022 (edited)
1,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.40 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <title>Open Training Events</title>
  4.     <link href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" rel="stylesheet" />
  5.     <style>
  6.       body {
  7.         font-family: "Arial";
  8.       }
  9.     </style>
  10.   </head>
  11.    <link rel="stylesheet" href="{{ url_for('static', filename='css/success.css') }}" rel="stylesheet" type="text/css">
  12. <link rel="stylesheet" href="{{ url_for('static', filename='css/buttons.css') }}" rel="stylesheet" type="text/css">
  13.    <style>
  14.     body {
  15.       background-image: url('https://internal/map_background.gif');
  16.    }
  17.     </style>
  18.     <style>
  19.       img {
  20.         width: 11%;
  21.         height: auto;
  22.       }
  23.     </style>
  24.  
  25.     <p style="text-align:center;"><img src="{{url_for('static', filename='loft_front.png')}}" ></p>
  26.   <center>
  27.   <iframe src="https://free.timeanddate.com/clock/i767eypi/n770/fs12/tct/pct/ftb/tt0/th1" frameborder="0" width="252" height="16" allowtransparency="true"></iframe>
  28.   <body>
  29.     <div><center>
  30.  
  31.       <div id="table"></div>
  32.     </div>
  33.     <script src="https://unpkg.com/gridjs/dist/gridjs.umd.js"></script>
  34.     <script>
  35.       const tableDiv = document.getElementById('table');
  36.  
  37.       const updateUrl = (prev, query) => {
  38.         return prev + (prev.indexOf('?') >= 0 ? '&' : '?') + new URLSearchParams(query).toString();
  39.       };
  40.  
  41.       const editableCellAttributes = (data, row, col) => {
  42.           if (row) {
  43.             return {contentEditable: 'true', 'data-element-id': row.cells[0].data};
  44.           }
  45.           else {
  46.             return {};
  47.           }
  48.       };
  49.  
  50.       new gridjs.Grid({
  51.         columns: [
  52.           { id: 'id', name: 'Event ID', width: '130px', sort: false},
  53.           { id: 'aircraft', name: 'Aircraft', width: '130px', 'attributes': editableCellAttributes },
  54.           { id: 'training_under_part', name: 'Part', width: '120px', 'attributes': editableCellAttributes },
  55.           { id: 'event_type', name: 'Event Type', sort: false, 'attributes': editableCellAttributes },
  56.           { id: 'event_start_time', name: 'Start Time', sort: false, 'attributes': editableCellAttributes },
  57.           { id: 'event_date', name: 'Event Date', sort: false, 'attributes': editableCellAttributes },
  58.           { id: 'client', name: 'Client', sort: false, 'attributes': editableCellAttributes },
  59.           { id: 'notes', name: 'Notes', sort: false, 'attributes': editableCellAttributes },
  60.           { id: 'assigned', name: 'Assigned', sort: false, 'attributes': editableCellAttributes },
  61.           { id: 'instructor_accepted', name: 'Instructor', sort: false, 'attributes': editableCellAttributes },
  62.           { id: 'delete_link', name: 'Delete', sort: false },
  63.  
  64.         ],
  65.  
  66.         style: {
  67.           table: {
  68.             border: '3px solid #ccc'
  69.           },
  70.           th: {
  71.             'background-color': 'rgba(0, 0, 0, 0.2)',
  72.             color: '#000',
  73.             'border-bottom': '3px solid #ccc',
  74.             'text-align': 'center'
  75.           },
  76.           td: {
  77.             'text-align': 'center',
  78.             'font-size': '14px',
  79.             'font-family': 'Arial'
  80.           }
  81.         },
  82.         server: {
  83.           url: '/api/data',
  84.           then: results => results.data,
  85.           total: results => results.total,
  86.         },
  87.         search: {
  88.           enabled: true,
  89.           server: {
  90.             url: (prev, search) => {
  91.               return updateUrl(prev, {search});
  92.             },
  93.           },
  94.         },
  95.         sort: {
  96.           enabled: true,
  97.           multiColumn: true,
  98.           server: {
  99.             url: (prev, columns) => {
  100.               const columnIds = ['id', 'aircraft', 'training_under_part', 'event_type', 'event_start_time', 'event_date', 'client', 'notes', 'assigned', 'instructor_accepted', 'delete_link'];
  101.               const sort = columns.map(col => (col.direction === 1 ? '+' : '-') + columnIds[col.index]);
  102.               return updateUrl(prev, {sort});
  103.             },
  104.           },
  105.         },
  106.         pagination: {
  107.           enabled: true,
  108.           server: {
  109.             url: (prev, page, limit) => {
  110.               return updateUrl(prev, {start: page * limit, length: limit});
  111.             },
  112.           },
  113.         },
  114.       }).render(tableDiv);
  115.  
  116.       let savedValue;
  117.  
  118.       tableDiv.addEventListener('focusin', ev => {
  119.         if (ev.target.tagName === 'TD') {
  120.           savedValue = ev.target.textContent;
  121.         }
  122.       });
  123.  
  124.       tableDiv.addEventListener('focusout', ev => {
  125.         if (ev.target.tagName === 'TD') {
  126.           if (savedValue !== ev.target.textContent) {
  127.             fetch('/api/data', {
  128.               method: 'POST',
  129.               headers: {'Content-Type': 'application/json'},
  130.               body: JSON.stringify({
  131.                 id: ev.target.dataset.elementId,
  132.                 [ev.target.dataset.columnId]: ev.target.textContent
  133.               }),
  134.             });
  135.           }
  136.           savedValue = undefined;
  137.         }
  138.       });
  139.  
  140.       tableDiv.addEventListener('keydown', ev => {
  141.         if (ev.target.tagName === 'TD') {
  142.           if (ev.key === 'Escape') {
  143.             ev.target.textContent = savedValue;
  144.             ev.target.blur();
  145.           }
  146.           else if (ev.key === 'Enter') {
  147.             ev.preventDefault();
  148.             ev.target.blur();
  149.           }
  150.         }
  151.       });
  152.     </script><br>
  153.     <center>
  154.        <a class="tank_manager_button" href="{{ url_for('add_events') }}">Add Training Event</a><br><br>
  155.   </body>
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement