Guest User

Untitled

a guest
Apr 26th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 19.86 KB | Software | 0 0
  1. CREATE.CSHTML
  2. @page
  3. @using SkiaSharp
  4. @model MediaKitManager.Pages_Ticket.CreateModel
  5.  
  6. @{
  7.     ViewData["Title"] = "Create";
  8. }
  9.  
  10. <link rel="stylesheet" href="~/css/neuro.css">
  11. <br>
  12.  
  13. <form method="post">
  14.     <button type="submit" asp-page-handler="TestNotification">Test Notifications</button>
  15. </form>
  16.  
  17. <br><br>
  18. @section Scripts {
  19.     <script src="~/js/ticket-create.js"></script>
  20. }
  21.  
  22.  
  23. @{
  24.     var selectedCourseName = HttpContext.Session.GetString("SelectedCourseName");
  25.     var selectedCourseLevel = HttpContext.Session.GetInt32("SelectedCourseLevel");
  26.    
  27.     var startDate = HttpContext.Session.GetString("StartDate");
  28.     var endDate = HttpContext.Session.GetString("EndDate");
  29. }
  30.  
  31.  
  32. <form id="ticketForm" method="post">
  33.     <div class="card card-neuromorphic">
  34.         <div class="card-body">
  35.             <h2>Loan Request Form</h2>
  36.             <hr />
  37.  
  38.             <div asp-validation-summary="ModelOnly" class="text-danger"></div>
  39.  
  40.             <!-- Basket Items -->
  41.             @if (Model.BasketEquipment.Any())
  42.             {
  43.                 <div class="mt-4">
  44.                     <h4>You have selected the following equipment:</h4>
  45.                     <table class="table project-list-table table-nowrap align-middle table-borderless table-hover">
  46.                         <thead>
  47.                             <tr>
  48.                                 <th>Description</th>
  49.                                 <th>Category</th>
  50.                                 <th>Serial No</th>
  51.                                 <th>Image</th>
  52.                             </tr>
  53.                         </thead>
  54.                         <tbody>
  55.                             @foreach (var item in Model.BasketEquipment)
  56.                             {
  57.                                 <tr>
  58.                                     <td>@item.ItemDescription</td>
  59.                                     <td>@item.Category</td>
  60.                                     <td>@item.SerialNo</td>
  61.                                <td>
  62.     @if (item.EquipmentImage != null && item.EquipmentImage.Length > 0)
  63.    {
  64.        var image = SKBitmap.Decode(item.EquipmentImage);
  65.         if (image != null)
  66.         {
  67.             <img src="data:image/jpeg;base64,@Convert.ToBase64String(item.EquipmentImage)"
  68.                alt="Equipment Image" style="max-width: 175px; max-height: 150px;" />
  69.         }
  70.         else
  71.         {
  72.             <p>No image available</p>
  73.         }
  74.     }
  75.     else
  76.     {
  77.         <p>No image available</p>
  78.     }
  79. </td>
  80.                                 </tr>
  81.                             }
  82.                         </tbody>
  83.                     </table>
  84.                 </div>
  85.             }
  86.             else
  87.             {
  88.                 <div class="alert alert-warning" role="alert">
  89.                     <p class="text-danger">No equipment found! Please leave this page and try to complete your basket again.
  90.                     </p>
  91.                 </div>
  92.             }
  93.         </div>
  94.     </div>
  95.  
  96.     <br>
  97.  
  98.     <!-- Loan Details Section -->
  99.     <div class="card card-neuromorphic">
  100.         <div class="card-body">
  101.             <h3>Loan Details</h3>
  102.             <h5>Please use this section to provide details about your course and the project you are working
  103.                 on.</strong></h5>
  104.             <hr />
  105.             <p><strong>Select the course you are borrowing equipment for:</strong></p>
  106.             <div asp-validation-summary="ModelOnly" class="text-danger"></div>
  107.  
  108.  
  109.  
  110.             <div class="form-group">
  111.                 <label asp-for="Ticket.CourseId" placeholder="Course">Course</label>
  112.                 <input type="text" value="@HttpContext.Session.GetString("SelectedCourseName")" class="form-control"
  113.                    readonly />
  114.             </div><br>
  115.  
  116.             <div class="form-group">
  117.                 <label asp-for="Ticket.Level" placeholder="Level">Level</label>
  118.                 <input type="text" value="@selectedCourseLevel" class="form-control"
  119.                    readonly />
  120.                 <span asp-validation-for="Ticket.Level" class="text-danger"></span>
  121.             </div><br>
  122.  
  123.             <div class="form-group">
  124.                 <input asp-for="Ticket.Subject" placeholder="Topic" class="form-control" />
  125.                 <span asp-validation-for="Ticket.Subject" class="text-danger"></span>
  126.             </div><br>
  127.  
  128.            
  129.  
  130.             <br><br>
  131.  
  132.             <p><strong>Selected Dates: </strong></p>
  133.             <div class="form-group">
  134.                 <input asp-for="Ticket.StartDate" class="form-control" placeholder="Start Date" type="date"
  135.                    value="@startDate" readonly />
  136.                 <span asp-validation-for="Ticket.StartDate" class="text-danger"></span>
  137.             </div>
  138.             <div class="form-group">
  139.                 <input asp-for="Ticket.EndDate" class="form-control" placeholder="End Date" type="date"
  140.                    value="@endDate" readonly />
  141.                 <span asp-validation-for="Ticket.EndDate" class="text-danger"></span>
  142.             </div><br>
  143.  
  144.             <br>
  145.             <p><strong>Please give a brief description of your project:</strong></p>
  146.             <div class="form-group">
  147.                 <input asp-for="Ticket.ProjectDescription" placeholder="Project Description" class="form-control" />
  148.                 <span asp-validation-for="Ticket.ProjectDescription" class="text-danger"></span>
  149.             </div><br>
  150.  
  151.  
  152.             <input type="hidden" id="SerializedLocations" name="SerializedLocations" />
  153.             <input type="hidden" id="SerializedHazards" name="SerializedHazards" />
  154.         </div>
  155.     </div>
  156.  
  157.     <br>
  158.  
  159.     <!-- Risk Assessment Section -->
  160.     <div class="card card-neuromorphic">
  161.         <div class="card-body">
  162.             <h3>Risk Assessment</h3>
  163.             <h5>Please use this section to complete a risk assessment for your project.
  164.                 You must consider the location(s) used for this project and any potential
  165.                 hazards you can forsee. Previously used locations can be recalled from the dropdown
  166.                 menu.</h5>
  167.             </p>
  168.             <hr>
  169.             <div>
  170.                 <h4>Locations</h4>
  171.                 <div class="form-group" class="form-control" style="margin-bottom: 0.5rem;">
  172.                     <select asp-for="SelectedLocationId" asp-items="Model.AvailableLocations" class="form-control">
  173.                         <option value="">Select a location</option>
  174.                     </select>
  175.                 </div>
  176.                 <input id="locationStreet" class="form-control" placeholder="Street" />
  177.                 <input id="locationCity" class="form-control" placeholder="City" />
  178.                 <input id="locationState" class="form-control" placeholder="State" />
  179.                 <input id="locationCountry" class="form-control" placeholder="Country" />
  180.                 <input id="locationPostalCode" class="form-control" placeholder="Postal Code" />
  181.                 <br>
  182.                 <button type="button" onclick="addLocation()" class="btn btn-secondary">Add Location</button>
  183.                 <div id="locationsList" class="mt-3"></div>
  184.             </div>
  185.  
  186.             <br>
  187.             <hr>
  188.  
  189.             <div class="row">
  190.                 <div class="col-6">
  191.                     <h4>Hazards</h4>
  192.                     <p><strong>Describe any hazards you may encounter in your project and how you plan to take action
  193.                             against these risks.</strong></p>
  194.                     <input id="hazardDescription" class="form-control" placeholder="Description" />
  195.                     <input id="hazardMitigationSteps" class="form-control" placeholder="Mitigation Steps" />
  196.                     <br>
  197.                     <p><strong>Assess the level of risk for the hazard:</strong></p>
  198.                     <div class="btn-group" role="group" aria-label="Scale">
  199.                         <button type="button" class="btn btn-secondary btn-hzd" style="background-color:#285F9D"
  200.                            onclick="document.getElementById('hazardHazardLevel').value = 1;">1 Trivial</button>
  201.                         <button type="button" class="btn btn-secondary btn-hzd" style="background-color:#496790"
  202.                            onclick="document.getElementById('hazardHazardLevel').value = 2;">2 Tolerable</button>
  203.                         <button type="button" class="btn btn-secondary btn-hzd" style="background-color:#285F9D"
  204.                            onclick="document.getElementById('hazardHazardLevel').value = 3;">3 Moderate</button>
  205.                         <button type="button" class="btn btn-secondary btn-hzd" style="background-color:#7C7269"
  206.                            onclick="document.getElementById('hazardHazardLevel').value = 4;">4 Substantial</button>
  207.                         <button type="button" class="btn btn-secondary btn-hzd" style="background-color:#E78842"
  208.                            onclick="document.getElementById('hazardHazardLevel').value = 5;">5 Intolerable</button>
  209.                     </div>
  210.                     <br>
  211.                     <input id="hazardHazardLevel" class="form-control" placeholder="Hazard Level" type="number" />
  212.                     <br>
  213.                     <button type="button" onclick="addHazard()" class="btn btn-secondary">Add
  214.                         Hazard</button>
  215.                     <div id="hazardsList" class="mt-3"></div>
  216.                 </div>
  217.                 <div class="col-6">
  218.                     <table class="table project-list-table align-middle table-borderless">
  219.                         <thead>
  220.                             <tr>
  221.                                 <th colspan="4">Hazard Examples</th>
  222.                             </tr>
  223.                         </thead>
  224.                         <tbody>
  225.                             <tr>
  226.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Access / Doorways</td>
  227.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Flammable Materials</td>
  228.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Noise (Equipment / Music / Headphones)</td>
  229.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">How Else Can People Get Hurt (specify below)</td>
  230.                             </tr>
  231.                             <tr>
  232.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Audience Control</td>
  233.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Food Hygiene</td>
  234.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Office Equipment</td>
  235.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Other Hazards -</td>
  236.                             </tr>
  237.                             <tr>
  238.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Confined Spaces</td>
  239.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Hazardous Tools</td>
  240.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Slips and Trips</td>
  241.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">(e.g children, animals)</td>
  242.                             </tr>
  243.                             <tr>
  244.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Theft</td>
  245.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Fire (building fire safety)</td>
  246.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Storage (racks, shelves etc)</td>
  247.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText"></td>
  248.                             </tr>
  249.                             <tr>
  250.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Lighting Equipment</td>
  251.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Working at Height</td>
  252.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Transport (forklift trucks, vehicles, tractors etc)</td>
  253.                                 <td></td>
  254.                             </tr>
  255.                             <tr>
  256.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Electricity (including portable appliances)</td>
  257.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Lifting Equipment</td>
  258.                                 <td class="hazard" onclick="document.getElementById('hazardDescription').value = this.innerText">Weather (hot, cold, lightning etc)</td>
  259.                                 <td></td>
  260.                             </tr>
  261.                         </tbody>
  262.                     </table>
  263.                 </div>
  264.             </div>
  265.             <hr>
  266.  
  267.  
  268.             <!-- Crew Members -->
  269.             <br><br>
  270.             <p><strong>Who else is working on your project? Once you select your course the drop down below will
  271.                     show your classmates.</strong></p>
  272.             <p><strong>Click add crew member to add a classmate to your project crew:</strong></p>
  273.  
  274.             <div class="form-group">
  275.                 <select id="crewMember" asp-items="Model.ClassMates" class="form-control">
  276.                     <option value="">Select a crew member</option>
  277.                 </select><br>
  278.             </div>
  279.             <button type="button" class="btn btn-secondary" onclick="addCrewMember()">Add
  280.                 Crew Member</button>
  281.  
  282.             <br>
  283.             <div id="crewList"></div>
  284.  
  285.             <br><br>
  286.         </div>
  287.     </div>
  288.  
  289.     <br>
  290.  
  291.     <!-- Guardian Consent -->
  292.     @if (Model.IsUserUnder18)
  293.     {
  294.         <div class="card card-neuromorphic">
  295.             <div class="card-body">
  296.                 <h4>Guardian Consent</h4>
  297.                 <h5>Because you are under the age of 18 you need consent from a responsible guardian to complete
  298.                     this request. Your guardian must provide their name, contact number and signature below to
  299.                     verify the request.</h5>
  300.                 <hr>
  301.                 <div class="form-group">
  302.                     <input asp-for="GuardianName" placeholder="Name" class="form-control" id="guardianName" />
  303.                     <span asp-validation-for="GuardianName" class="text-danger"></span>
  304.                 </div>
  305.                 <div class="form-group">
  306.                     <input asp-for="GuardianContactNumber" placeholder="Contact Number" class="form-control"
  307.                        id="guardianContactNumber" />
  308.                     <span asp-validation-for="GuardianContactNumber" class="text-danger"></span>
  309.                 </div>
  310.             </div>
  311.  
  312.  
  313.        
  314.        
  315.             </div>
  316.      
  317.             }
  318.  
  319.  
  320.                      
  321. <canvas id="signature-pad" width="auto" height="auto"></canvas>
  322. <button id="clear">Clear</button>
  323. <button id="save">Save</button>
  324.  
  325. <script src="https://cdn.jsdelivr.net/npm/signature_pad@4.0.0/dist/signature_pad.umd.min.js"></script>
  326. <script>
  327.     var canvas = document.getElementById("signature-pad");
  328.     var signaturePad = new SignaturePad(canvas, { backgroundColor: 'rgb(250,250,250)' });
  329.     document.getElementById("clear").addEventListener('click', function () {
  330.         signaturePad.clear();
  331.     });
  332.     document.getElementById("save").addEventListener('click', function () {
  333.         var dataURL = signaturePad.toDataURL();
  334.         var link = document.createElement('a');
  335.         link.download = 'signature.png';
  336.         link.href = dataURL;
  337.         link.click();
  338.     });
  339. </script>
  340.  
  341.  
  342.  
  343.          
  344.     <br>
  345.  
  346.  
  347.    
  348.  
  349.     <div class="card card-neuromorphic">
  350.         <div class="card-body">
  351.             <p><strong>Check all the information you have entered is correct before you submit your
  352.                     request.</strong></p>
  353.             <p><strong>You must await confirmation before you are able to collect your equipment.</strong></p><br>
  354.  
  355.             <div class="form-group">
  356.                 <input type="submit" value="Submit Request" class="btn btn-primary" />
  357.             </div>
  358.             <br><br><a asp-page="Index">Cancel Request / Back to List</a>
  359.         </div>
  360.     </div>
  361.  
  362. </form>
  363.  
  364.  
  365. CREATE.CSHTML.CS
  366.     public async Task<IActionResult> OnPostUploadSignatureAsync()
  367.         {
  368.             var uploadedSignature = Request.Form.Files["UploadedSignature"];
  369.             if (uploadedSignature == null || uploadedSignature.Length == 0)
  370.             {
  371.                 return BadRequest("No file uploaded or file is empty.");
  372.             }
  373.  
  374.             try
  375.             {
  376.                 using (var memoryStream = new MemoryStream())
  377.                 {
  378.                     await uploadedSignature.CopyToAsync(memoryStream);
  379.                     // Assuming Ticket is a property that has been set up previously
  380.                     Ticket.GuardianSignature = memoryStream.ToArray();
  381.                 }
  382.                 await _context.SaveChangesAsync();
  383.                 return new JsonResult(new { success = true });
  384.             }
  385.             catch (Exception ex)
  386.             {
  387.                 // Log exception here
  388.                 return StatusCode(500, "Internal Server Error: " + ex.Message);
  389.             }
  390.         }
  391.  
  392.  
  393.  
  394.  
  395. ticket-create.js
  396. document.getElementById('ticketForm').addEventListener('submit', function (event) {
  397.     event.preventDefault(); // Prevent the form from submitting the traditional way initially
  398.  
  399.     console.log("Test");
  400.     var signaturePadDataUrl = signaturePad.toDataURL("image/png");
  401.  
  402.     // Convert Data URL to Blob
  403.     function dataURLtoBlob(dataurl) {
  404.         var arr = dataurl.split(','),
  405.             mime = arr[0].match(/:(.*?);/)[1],
  406.             bstr = atob(arr[1]),
  407.             n = bstr.length,
  408.             u8arr = new Uint8Array(n);
  409.         while (n--) {
  410.             u8arr[n] = bstr.charCodeAt(n);
  411.         }
  412.         return new Blob([u8arr], { type: mime });
  413.     }
  414.  
  415.     var blob = dataURLtoBlob(signaturePadDataUrl);
  416.     var formData = new FormData();
  417.     formData.append('UploadedSignature', blob, 'signature.png');
  418.  
  419.     // Verify FormData contents
  420.     for (var pair of formData.entries()) {
  421.         console.log(pair[0] + ', ' + pair[1]);
  422.     }
  423.  
  424.     // Send FormData to the server
  425.     fetch('?handler=UploadSignature', {
  426.         method: 'POST',
  427.         body: formData
  428.     })
  429.     .then(response => {
  430.         if (!response.ok) {
  431.             throw new Error(`Server responded with: ${response.statusText}`);
  432.         }
  433.         return response.json();
  434.     })
  435.     .then(data => {
  436.         console.log('Server Response:', data);
  437.         // Additional actions based on response, like redirecting
  438.         if (data.success) {
  439.             window.location.href = '/Index'; // Redirect on successful upload
  440.         } else {
  441.             alert('Upload failed: ' + data.message);
  442.         }
  443.     })
  444.     .catch(error => {
  445.         console.error('Failed to upload signature:', error);
  446.     });
  447. });
  448.  
Add Comment
Please, Sign In to add comment