You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.5 KiB

4 years ago
  1. {% extends "bootstrap/base.html" %}
  2. {% block title %}Technical Incompetence Link Shortener{% endblock %}
  3. {% block styles %}
  4. {{super()}}
  5. <link rel="stylesheet" href="{{url_for('.static', filename='style.css')}}">
  6. {% endblock %}
  7. {% block navbar %}
  8. <nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-dark">
  9. <div class="navbar-brand">Technical Incompetence Link Shortener</div>
  10. <form class="form-inline ml-auto">
  11. {# <div class="custom-control custom-switch">
  12. <input type="checkbox" class="custom-control-input" id="darkSwitch" />
  13. <label class="custom-control-label" for="darkSwitch">Dark Mode</label>
  14. </div>
  15. <div class="navbar-text" style="margin-right: 20px; ">{{ user['userName'] }}</div> #}
  16. <a class="btn btn-primary" href="/logout" role="button">Logout</a>
  17. </form>
  18. </nav>
  19. {% endblock %}
  20. {% block content %}
  21. <div class="container" style="margin-top: 15px">
  22. <div id="success-alert" class="alert alert-success" role="alert" style="display: none;">
  23. This is a success alert—check it out!
  24. </div>
  25. <div id="error-alert" class="alert alert-danger" role="alert" style="display: none;">
  26. This is a danger alert—check it out!
  27. </div>
  28. <form>
  29. <div class="row justify-content-center">
  30. <div class="col-lg-6">
  31. <label for="formGroupExampleInput4">URL</label>
  32. <input id="link-form" type="text" class="form-control" placeholder="https://example.com">
  33. <br>
  34. <button type="button" class="btn btn-primary" onclick="shortenUrl();">Shorten Link</button>
  35. <br>
  36. </div>
  37. </div>
  38. </form>
  39. </div>
  40. {% endblock %}
  41. {% block scripts %}
  42. {{ super() }}
  43. <script>
  44. function shortenUrl() {
  45. url = $('#link-form').val();
  46. if (url.trim().length === 0) {
  47. showError('URL is required');
  48. return false;
  49. }
  50. $.ajax({
  51. url: '/shorten',
  52. method: 'POST',
  53. data: { "url": url },
  54. success: function(data) {
  55. if (data !== 'Error')
  56. showSuccess(data);
  57. else
  58. showError('URL cannot be empty');
  59. }
  60. });
  61. }
  62. function showError(error) {
  63. hideSuccess();
  64. $('#error-alert').text(error);
  65. $('#error-alert').show();
  66. }
  67. function showSuccess(message) {
  68. hideError();
  69. $('#success-alert').html(message);
  70. $('#success-alert').show();
  71. }
  72. function hideError(error) {
  73. $('#error-alert').hide();
  74. }
  75. function hideSuccess(error) {
  76. $('#success-alert').hide();
  77. }
  78. </script>
  79. {% endblock %}