Ver Fonte

Recuperation données pour édition

Arthur Brandao há 5 anos atrás
pai
commit
4f2f138c82
1 ficheiros alterados com 19 adições e 6 exclusões
  1. 19 6
      src/edit.html

+ 19 - 6
src/edit.html

@@ -39,12 +39,12 @@
                 <div class="row">
                     <div class="col s12 m6 offset-m3 input-field">
                         <i class="material-icons prefix">title</i>
-                        <input id="titre" type="text" class="validate">
-                        <label for="titre">Titre</label>
+                        <input id="title" type="text" class="validate">
+                        <label for="title">Titre</label>
                     </div>
                 </div>
                 <div class="row">
-                    <textarea></textarea>
+                    <textarea id="content"></textarea>
                 </div>
             </div>
         </main>
@@ -67,8 +67,21 @@
                 });
                 // Load tooltip
                 const tooltip = M.Tooltip.init(document.querySelectorAll('.tooltipped'))[0];
-                // Load MD editor
-                const simplemde = new SimpleMDE({
+                // Load data if update and markdown editor
+                if (GET.id) {
+                    loadData().then(data => {
+                        $('#title').val(data[GET.id].title);
+                        $('#content').val(data[GET.id].content);
+                        M.updateTextFields();
+                        loadMarkdownEditor();
+                    });
+                } else {
+                    loadMarkdownEditor();
+                }  
+            });
+
+            function loadMarkdownEditor() {
+                return new SimpleMDE({
                     placeholder: 'Écrire ici ...',
                     spellChecker: false,
                     toolbar: [
@@ -82,7 +95,7 @@
                         return md.toHTML();
                     }
                 });
-            });
+            }
         </script>
     </body>
 </html>