Browse Source

Improve the new file javascript; Still getting that issue

master
Dashie der otter 4 months ago
parent
commit
324f9e548a
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755
5 changed files with 51 additions and 11 deletions
  1. 1
    1
      TODO.org
  2. 4
    0
      static/css/custom.css
  3. 13
    10
      static/js/GitxtNewPost.js
  4. 17
    0
      templates/gitxt/edit.tmpl
  5. 16
    0
      templates/gitxt/new.tmpl

+ 1
- 1
TODO.org View File

@@ -8,7 +8,7 @@
8 8
 
9 9
 ** TODO Add line-break option
10 10
 ** TODO Add more checks for <nil> fields wrongly used, like issue with non existant file
11
-** TODO Add pictures from git with zz_.png; Edit web interface, and add file; wrong duplicate !!
11
+** TODO If a binary file, or huge one is added from git, we get weird submit results and can't update from interface
12 12
 
13 13
 ** DONE Non existant file in git for raw file: git_object_lookup_prefix: Assertion `repo && object_out && id' failed.
14 14
 ** DONE Can't add files with filename "/some/thing/foo.bar"

+ 4
- 0
static/css/custom.css View File

@@ -351,4 +351,8 @@ div.admin-dashboard div.divider {
351 351
     border-top: 1px solid rgba(34,36,38,.15);
352 352
     border-bottom: 1px solid rgba(255,255,255,.1);
353 353
     margin: 1rem 0;
354
+}
355
+
356
+div.form.placeholders {
357
+    display: none;
354 358
 }

+ 13
- 10
static/js/GitxtNewPost.js View File

@@ -5,26 +5,29 @@
5 5
 $(document).on("click", "#add_new_form", function() {
6 6
     console.log("adding a new file fields");
7 7
     // Clone the file template
8
-    let new_file = $("div.files > div").last().clone();
8
+    let last_file = $("div.files > div").last();
9
+    let last_index = parseInt(last_file.data("id"));
9 10
 
10
-    // Empty the inputs
11
-    new_file.find("input[type='text']").val("");
12
-    new_file.find("textarea[type='text']").val("");
11
+    // Clone the template on end of form
12
+    let new_file = $("div.form.placeholders > div").clone();
13 13
 
14 14
     // Update the index
15
-    let index = parseInt(new_file.data("id"));
16
-    let newIndex = index + 1;
15
+    let newIndex = last_index + 1;
16
+
17
+    // Empty fields
18
+    new_file.find("input[type='text']").val("");
19
+    new_file.find("textarea[type='text']").val("");
17 20
 
18 21
     // This only works in debugger, not here, thank you JS
19 22
     //new_file.data("id", newIndex);
20 23
     new_file.attr("data-id", newIndex);
21 24
 
22 25
     new_file.attr("class", "form_" + newIndex + " gitxt_new_file");
23
-    new_file.find("label[for='file_"+index+"_filename']").attr("for", "file_"+newIndex+"_filename");
24
-    new_file.find("label[for='file_"+index+"_content']").attr("for", "file_"+newIndex+"_content");
26
+    new_file.find("label[for='file_INDEX_filename']").attr("for", "file_"+newIndex+"_filename");
27
+    new_file.find("label[for='file_INDEX_content']").attr("for", "file_"+newIndex+"_content");
25 28
 
26
-    new_file.find("input[id='file_"+index+"_filename']").attr("id", "file_"+newIndex+"_filename");
27
-    new_file.find("textarea[id='file_"+index+"_content']").attr("id", "file_"+newIndex+"_content");
29
+    new_file.find("input[id='file_INDEX_filename']").attr("id", "file_"+newIndex+"_filename");
30
+    new_file.find("textarea[id='file_INDEX_content']").attr("id", "file_"+newIndex+"_content");
28 31
 
29 32
     new_file.find("div[class='file_idx']").html("file " + newIndex);
30 33
 

+ 17
- 0
templates/gitxt/edit.tmpl View File

@@ -32,6 +32,23 @@
32 32
                     </div>
33 33
                 </div>
34 34
 
35
+                <div class="form placeholders">
36
+                    <div class="form_INDEX gitxt_new_file" data-id="INDEX">
37
+                        <div class="filename">
38
+                            <div class="input-group">
39
+                                <div class="input-group-addon"><i class="fa fa-file-code-o" aria-hidden="true"></i></div>
40
+                                <input type="text" name="files_filename" id="file_INDEX_filename" class="form-control" value="" placeholder='{{$.i18n.Tr "gitxt.file_filename_placeholder"}}'>
41
+                                <div class="input-group-addon btn btn-delete-file"><i class="fa fa-remove" aria-hidden="true"></i></div>
42
+                            </div>
43
+                        </div>
44
+
45
+                        <div class="content form-group">
46
+                            <textarea rows="15" type="text" name="files_content" id="file_INDEX_content" class="form-control" placeholder='{{$.i18n.Tr "gitxt.file_content_placeholder"}}'></textarea>
47
+                        </div>
48
+                    </div>
49
+                </div>
50
+
51
+
35 52
                 <div class="files">
36 53
                     {{range $index, $value := .FilesContent}}
37 54
                         <div class="form_{{$index}} gitxt_new_file" data-id="{{$index}}">

+ 16
- 0
templates/gitxt/new.tmpl View File

@@ -32,6 +32,22 @@
32 32
                     </div>
33 33
                 </div>
34 34
 
35
+                <div class="form placeholders">
36
+                    <div class="form_INDEX gitxt_new_file" data-id="INDEX">
37
+                        <div class="filename">
38
+                            <div class="input-group">
39
+                                <div class="input-group-addon"><i class="fa fa-file-code-o" aria-hidden="true"></i></div>
40
+                                <input type="text" name="files_filename" id="file_INDEX_filename" class="form-control" value="" placeholder='{{$.i18n.Tr "gitxt.file_filename_placeholder"}}'>
41
+                                <div class="input-group-addon btn btn-delete-file"><i class="fa fa-remove" aria-hidden="true"></i></div>
42
+                            </div>
43
+                        </div>
44
+
45
+                        <div class="content form-group">
46
+                            <textarea rows="15" type="text" name="files_content" id="file_NUMBER_content" class="form-control" placeholder='{{$.i18n.Tr "gitxt.file_content_placeholder"}}'></textarea>
47
+                        </div>
48
+                    </div>
49
+                </div>
50
+
35 51
                 <div class="files">
36 52
                     {{range $index, $value := .FilesContent}}
37 53
                         <div class="form_{{$index}} gitxt_new_file" data-id="{{$index}}">

Loading…
Cancel
Save