aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/templates/wiki/edit.html
blob: c0cb8de636a4d4371c94da57c3ea7d89219397ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
{% extends "wiki/article.html" %}
{% load wiki_tags i18n sekizai_tags static %}


{% block wiki_pagetitle %}
  Edit: {{ article.current_revision.title }}
{% endblock %}

{% block wiki_contents_tab %}

  {% if not user.is_authenticated %}
    <p class="alert alert-warning">
      {% trans "<strong>Warning:</strong> You are not logged in. Your IP address will be logged." %}
      <a href="{% url 'wiki:login' %}?next={% url 'wiki:edit' article_id=article.id path=urlpath.path %}">{% trans "Click here to log in" %} &raquo;</a>
    </p>
  {% endif %}

  <div class="columns">

    <div class="column is-two-thirds">
      <form method="POST" class="form-horizontal" id="article_edit_form">
        {% with edit_form as form %}
          {% include "wiki/includes/editor.html" %}
        {% endwith %}

        <button class="button is-light" type="submit" name="preview" value="1" id="id_preview"
                formaction="{% url 'wiki:preview' path=urlpath.path article_id=article.id %}"
                formtarget="previewWindow"
        >
          <span class="icon">
            <i class="fas fa-eye"></i>
          </span>
          <span>Preview</span>
        </button>
        <button class="button is-primary" type="submit" name="save" value="1" id="id_save">
          <span class="icon">
            <i class="fas fa-save"></i>
          </span>
          <span>Save Changes</span>
        </button>

        <div class="is-pulled-right">
          {% if user.is_authenticated and urlpath.path %}
            <a href="{% url 'wiki:move' path=urlpath.path article_id=article.id %}" class="button is-warning ">
              <span class="icon">
                <i class="fas fa-random"></i>
              </span>
              <span>Move Article</span>
            </a>
          {% endif %}
          {% if article|can_delete:user %}
            <a href="{% url 'wiki:delete' path=urlpath.path article_id=article.id %}" class="button is-danger">
              <span class="icon">
                <i class="fas fa-trash"></i>
              </span>
              <span>Delete Article</span>
            </a>
          {% endif %}
        </div>

        <br />
        <br />

      </form>
    </div>

    <div class="column is-one-third" id="wiki-edit-sidebar">
      {% include "wiki/includes/editor_sidebar.html" %}
    </div>

  </div>

  <div style="clear: both"></div>

  <div class="modal" id="previewModal">
    <div class="modal-background"></div>
    <div class="modal-card" style="height: 80%; width: 80%;">
      <div class="modal-card-head">
        <p class="modal-card-title">Article Preview</p>
      </div>
      <div class="modal-card-body" style="padding: 0; overflow: hidden;">
        <iframe name="previewWindow" frameborder="0" style="width: 100%; height: 100%;"></iframe>
      </div>
      <div class="modal-card-foot">
        <button class="button is-light" aria-label="close">
          <span class="icon">
            <i class="fas fa-arrow-left"></i>
          </span>
          <span>Back</span>
        </button>
        <a class="button is-primary" id="id_preview_save_changes">
          <span class="icon">
            <i class="fas fa-save"></i>
          </span>
          <span>Save Changes</span>
        </a>
      </div>
    </div>
  </div>

  <script src="{% static "js/wiki/modal.js" %}" type="text/javascript"></script>

  <script type="text/javascript">
    {# I'm sorry this JS sucks, it came with the wiki, just stuck right in here. #}

    $(document).ready(function() {
      let article_edit_form = $("#article_edit_form");
      let click_time = 0;

      $("#article_edit_form :input").change(function() {
         article_edit_form.data("changed",true);
      });

      if (article_edit_form.find(".alert-danger").length > 0 || article_edit_form.find(".has-error").length > 0 ) {
        // Set the forms status as "changed" if there was a submission error
        article_edit_form.data("changed",true);
      }

      window.onbeforeunload = confirmOnPageExit;

      article_edit_form.on("submit", function (ev) {
          now = Date.now();
          elapsed = now-click_time;
          click_time = now;
          if (elapsed < 3000)
              ev.preventDefault();
          window.onbeforeunload = null;
          return true;
      });
      $("#id_preview").click(function () {
          open_modal("previewModal");
          return true;
      });
      $("#id_preview_save_changes").on("click", function (ev) {
          ev.preventDefault();
          $("#id_save").trigger("click");
      });
    });

    var confirmOnPageExit = function (e) {
      if ($("#article_edit_form").data("changed")) {
        e = e || window.event;
        var message = "You have unsaved changes!";
        // For IE6-8 and Firefox prior to version 4
        if (e) {
            e.returnValue = message;
        }
        // For Chrome, Safari, IE8+ and Opera 12+
        return message;
      } else {
        // If the form hasn't been changed, don't display the pop-up
        return;
      }
    };
  </script>

  <script type="text/javascript">
    $(document).ready( function() {
      $('.sidebar-form').each(function () {
        $(this).submit( function() {
          this.unsaved_article_title.value = $('#id_title').val();
          this.unsaved_article_content.value = $('#id_content').val();
        });
      });
    });
  </script>

  <script language="javascript">
    $(document).ready(function() {
      $("#id_revision").val('{{ article.current_revision.id }}');
    });
  </script>
{% endblock %}