]> git.ipfire.org Git - ipfire.org.git/blame - src/templates/wiki/edit.html
wiki: Add code feature to editor
[ipfire.org.git] / src / templates / wiki / edit.html
CommitLineData
d398ca08
MT
1{% extends "base.html" %}
2
3{% block title %}{% if page %}{{ _("Edit %s") % page.title }}{% else %}{{ _("Create A New Page") }}{% end %}{% end block %}
4
6c13ca2d
MT
5{% block sidebar %}
6 {% set help = backend.wiki.get_page("/wiki/edit") %}
7
8 {% if help %}
9 {% raw help.html %}
10 {% end %}
11{% end block %}
12
d398ca08 13{% block main %}
2901b734 14 <div class="card mb-4">
d398ca08
MT
15 <div class="card-body">
16 <h4 class="card-title">
17 {% if page %}{{ _("Edit %s") % page.title }}{% else %}{{ _("Create A New Page") }}{% end %}
18 </h4>
19
40cb87a4 20 <form action="" method="POST">
d398ca08
MT
21 {% raw xsrf_form_html() %}
22
feeace6e
MT
23 <div class="form-group editor">
24 <div class="btn-toolbar mb-3" role="toolbar">
a563f064 25 <div class="btn-group btn-group-sm mr-2" role="group">
eea47e20
MT
26 <button type="button" class="btn btn-secondary"
27 id="bold" title="{{ _("Bold") }} [{{ _("Ctrl") }}-B]">
feeace6e
MT
28 <i class="fas fa-bold"></i>
29 </button>
eea47e20
MT
30 <button type="button" class="btn btn-secondary"
31 id="italic" title="{{ _("Italic") }} [{{ _("Ctrl") }}-I]">
feeace6e
MT
32 <i class="fas fa-italic"></i>
33 </button>
8dea0e28
MT
34 <button type="button" class="btn btn-secondary"
35 id="code" title="{{ _("Code") }} [{{ _("Ctrl") }}-C]">
36 <i class="fas fa-code"></i>
37 </button>
feeace6e 38 </div>
a563f064 39
18c36357 40 <div class="btn-group btn-group-sm mr-2" role="group">
eea47e20
MT
41 <button type="button" class="btn btn-secondary"
42 id="headline-up" title="{{ _("Headline one level up") }}">
18c36357
MT
43 <i class="fas fa-chevron-left"></i>
44 </button>
eea47e20
MT
45 <button type="button" class="btn btn-secondary"
46 id="headline" title="{{ _("Headline") }} [{{ _("Ctrl") }}-H]">
18c36357
MT
47 <i class="fas fa-heading"></i>
48 </button>
eea47e20
MT
49 <button type="button" class="btn btn-secondary"
50 id="headline-down" title="{{ _("Headline one level down") }}">
18c36357
MT
51 <i class="fas fa-chevron-right"></i>
52 </button>
53 </div>
54
eea47e20
MT
55 <a class="btn btn-sm btn-secondary" href="{{ path }}/_files"
56 target="_blank" title="{{ _("Files") }}">
a563f064
MT
57 <i class="fas fa-images"></i>
58 </a>
feeace6e
MT
59 </div>
60
2901b734 61 <textarea class="form-control" rows="16" name="content" id="content" placeholder="{{ _("Text") }}"
d398ca08
MT
62 >{% if page and page.markdown %}{{ page.markdown }}{% end %}</textarea>
63 </div>
64
65 <div class="form-group row">
db82550d
MT
66 <label class="col-sm-4 col-form-label">{{ _("What has changed?") }}</label>
67 <div class="col-sm-8">
d398ca08
MT
68 <input type="text" class="form-control" name="changes" required>
69 </div>
70 </div>
71
f2e25ded 72 {% if page and not page.is_watched_by(current_user) %}
917d9cfa 73 <div class="form-group form-check">
47a206ca
MT
74 <div class="custom-control custom-checkbox">
75 <input type="checkbox" class="custom-control-input" name="watch" id="watch" checked>
76 <label class="custom-control-label" for="watch">{{ _("Watch this page") }}</label>
77 </div>
bfb776cd 78
47a206ca 79 <small class="form-text text-muted">
bfb776cd 80 {{ _("Get notified when this page is changed") }}
47a206ca 81 </small>
917d9cfa
MT
82 </div>
83 {% end %}
d64a1e35 84
d398ca08
MT
85 <button type="submit" class="btn btn-primary btn-block">
86 {% if page %}{{ _("Save Page") }}{% else %}{{ _("Create Page") }}{% end %}
87 </button>
88 </form>
89 </div>
90 </div>
2901b734
MT
91
92 <div id="preview" class="fade show">
93 <div class="d-flex align-items-center mb-4">
94 <h4 class="mb-0">{{ _("Preview") }}</h4>
95 <div id="spinner" class="spinner-border ml-auto" role="status" aria-hidden="true"></div>
96 </div>
97
98 <div class="card">
99 <div class="card-body mb-0">
100 <div id="preview-content" class="wiki-content mb-0">
101 {{ _("Loading...") }}
102 </div>
103 </div>
104 </div>
105 </div>
106{% end block %}
107
108{% block javascript %}
3c8524b4
MT
109 {% import os.path %}
110
feeace6e 111 <script src="{{ static_url("js/editor.js") }}"></script>
2901b734
MT
112 <script type="text/javascript">
113 var update = null;
114
115 $(document).ready(function() {
116 var preview = $("#preview");
117 preview.hide();
118
119 $("#content").on("keyup", function(e) {
120 if (update)
121 clearTimeout(update);
122
123 var content = $(this).val();
124
125 // If the field is all empty, we will hide it
126 if (content)
127 preview.show();
128 else
129 preview.hide();
130
131 // Go into update mode
132 preview.addClass("updating");
133
134 update = setTimeout(function() {
135 var c = $("#preview-content");
136
ec606db5 137 $.post("{{ os.path.join(path, "_render") }}", { content : content },
2901b734
MT
138 function(data) {
139 c.html(data);
140
141 // Update finished
142 preview.removeClass("updating");
143 }
144 );
145 }, 750);
146 });
147 });
148 </script>
d398ca08 149{% end block %}