|
23 | 23 | </p> |
24 | 24 | <p class="text-gray-800 "> |
25 | 25 | <strong>Reported on</strong> |
26 | | - <span class="font-light text-2xl"><a href="">{{ object.url }}</a></span> |
| 26 | + <span class="font-light text-2xl"><a href="" class="issue-domain">{{ object.url }}</a></span> |
27 | 27 | </p> |
28 | 28 |
|
29 | | - <p class="text-black font-bold text-6xl text-center w-[90%] xl:w-[60%] mt-5 leading-snug"> |
| 29 | + <p class="text-black font-bold text-6xl text-center w-[90%] xl:w-[60%] mt-5 leading-snug issue-desc editables"> |
30 | 30 | {{ object.description }} |
31 | 31 | </p> |
| 32 | + <div class="form form-inline mt-2" style="display: none;"> |
| 33 | + {% csrf_token %} |
| 34 | + <input type="hidden" name="issue_pk" id="issue_pk" value="{{ object.id }}"> |
| 35 | + <input type="text" name="domain" placeholder="Domain" class="form-control" value="" required> |
| 36 | + <input type="text" name="description" placeholder="Bug Description" class="form-control" value="" |
| 37 | + required> |
| 38 | + <select name="label" class="form-control" required> |
| 39 | + <option value="0">General</option> |
| 40 | + <option value="1">Number error</option> |
| 41 | + <option value="2">Functional</option> |
| 42 | + <option value="3">Performance</option> |
| 43 | + <option value="4">Security</option> |
| 44 | + <option value="5">Typo</option> |
| 45 | + <option value="6">Design</option> |
| 46 | + </select> |
| 47 | + <button class="font-bold bg-red-600 px-5 py-2 text-white rounded-xl save-issue">Save</button> |
| 48 | + <button class="font-bold bg-gray-600 px-5 py-2 text-white rounded-xl cancel-edit">Cancel</button> |
| 49 | + </div> |
32 | 50 |
|
33 | 51 | </div> |
34 | 52 | </div> |
|
160 | 178 | </form> |
161 | 179 | {% endif %} |
162 | 180 | </div> |
| 181 | + <!-- add a delete button here like anonymous button --> |
| 182 | + <div class="w-full flex justify-between my-3"> |
| 183 | + <p class="text-3xl font-bold">Delete Issue:</p> |
| 184 | + <a href="/delete_issue/{{ object.id }}" |
| 185 | + onclick="return confirm('Are you sure you want to delete this issue?')"><button |
| 186 | + class="font-bold bg-red-600 px-5 py-1 text-white rounded-xl"> Yes <i class="fa fa-check"></i></button></a> |
| 187 | + </div> |
| 188 | + <!-- add a edit button here like delete button --> |
| 189 | + <div class="w-full flex justify-between my-3"> |
| 190 | + <p class="text-3xl font-bold">Edit Issue:</p> |
| 191 | + <a class="font-bold bg-red-600 hover:text-white px-5 py-1 text-white rounded-xl edit-issue">Yes <i class="fa fa-check"></i></a> |
| 192 | + </div> |
163 | 193 | {% endif %} |
164 | 194 | </div> |
165 | 195 | </div> |
@@ -376,8 +406,81 @@ <h2 class="mb-2 text-xl font-bold leading-tight text-gray-900 "> |
376 | 406 | }) |
377 | 407 | }) |
378 | 408 |
|
379 | | - |
| 409 | + function sanitizeURL(url) { |
| 410 | + var a = document.createElement('a'); |
| 411 | + a.href = encodeURI(url); |
| 412 | + return a.href; |
| 413 | + } |
380 | 414 |
|
381 | | - </script> |
| 415 | + var label = "{{object.label}}"; |
| 416 | + $(document).on('click', '.edit-issue', function (e) { |
| 417 | + $issue_desc = $('.issue-desc').text().trim(); |
| 418 | + $('.form input[name=description]').val($issue_desc); |
| 419 | + $('.form input[name=domain]').val($('.issue-domain').text()); |
| 420 | + $('.form select').val(label); |
| 421 | + $('.editables').hide(); |
| 422 | + $('.form').show(); |
| 423 | + }); |
| 424 | + |
| 425 | + $(document).on('click', '.cancel-edit', function (e) { |
| 426 | + $('.form').hide(); |
| 427 | + $('.editables').show(); |
| 428 | + }); |
| 429 | + |
| 430 | + $(document).on('click', '.save-issue', function (e) { |
| 431 | + e.preventDefault(); |
| 432 | + |
| 433 | + if ($('.form input[name=description]').val().trim().length == 0 || |
| 434 | + $('.form input[name=domain]').val().trim().length == 0) { |
| 435 | + return; |
| 436 | + } |
| 437 | + var dom_regex = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi; |
| 438 | + dom_regex = new RegExp(dom_regex); |
| 439 | + var domain_url = $('.form input[name=domain]').val(); |
| 440 | + if (domain_url.match(dom_regex) == null) { |
| 441 | + alert('Enter a valid url'); |
| 442 | + return; |
| 443 | + } |
| 444 | + |
| 445 | + |
| 446 | + $.ajax({ |
| 447 | + type: 'POST', |
| 448 | + url: '/issue/edit/', |
| 449 | + data: { |
| 450 | + issue_pk: $('#issue_pk').val(), |
| 451 | + domain: $('.form input[name=domain]').val(), |
| 452 | + description: $('.form input[name=description]').val(), |
| 453 | + label: $('.form select').val(), |
| 454 | + csrfmiddlewaretoken: $('.form input[name=csrfmiddlewaretoken]').val(), |
| 455 | + }, |
| 456 | + success: function (data) { |
| 457 | + $('.issue-desc').text($('.form input[name=description]').val()); |
| 458 | + $('.issue-domain').text($('.form input[name=domain]').val()); |
| 459 | + var sanitizedDomain = sanitizeURL($('.form input[name=domain]').val()); |
| 460 | + $('.issue-domain').attr("href", sanitizedDomain); |
| 461 | + label = $('.form select').val(); |
| 462 | + var l = $(".form select option[value='" + label + "']").text(); |
| 463 | + $('.bug-label').text(l); |
| 464 | + $('.form').hide(); |
| 465 | + $('.editables').show(); |
| 466 | + $.notify("Issue updated!", { |
| 467 | + style: "custom", |
| 468 | + className: "success" |
| 469 | + }); |
| 470 | + if (data === "Domain Created") |
| 471 | + $.notify("Domain Added!", { |
| 472 | + style: "custom", |
| 473 | + className: "success" |
| 474 | + }); |
| 475 | + }, |
| 476 | + error: function () { |
| 477 | + $.notify("Some error occurred!", { |
| 478 | + style: "custom", |
| 479 | + className: "danger" |
| 480 | + }); |
| 481 | + } |
| 482 | + }); |
| 483 | + }); |
| 484 | +</script> |
382 | 485 |
|
383 | 486 | {% endblock %} |
0 commit comments