Commits

Takafumi Arakaki  committed a4a24be

Editing without page transition

  • Participants
  • Parent commits 1627187

Comments (0)

Files changed (5)

File neorg/static/neorg.coffee

     for i of arrowKeyArray
       unBindKeydown arrowKeyArray[i]
 
+neorgEdit = ->
+  $("#edit-form").show()
+  $("#edit-form-textarea").focus()
+  return false
+
 neorgInit = ->
   $(".neorg-gene-image-link").colorbox neorgCBSetting
 
+  eform = $("#edit-form")
+  if eform
+    $("a.page-action-edit").click neorgEdit
+
+    if eform.is(":visible")
+      $("#edit-form-textarea").focus()
+
 
 # export functions as global function
 # see: http://stackoverflow.com/questions/4214731/

File neorg/templates/edit.html

 {% extends "page.html" %}
 {%- block title_prefix %}Edit - {% endblock -%}
 {%- block title_root -%}{{ "<root page>" }}{% endblock -%}
-{% block body %}
-  <form action="{{ url_for('save', page_path=page_path) }}"
-        method="post" class="add-entry">
-    <textarea name="page_text" rows="20" cols="80">{{ page_text }}</textarea>
-    <input type="submit" name="save" value="Save" />
-    <input type="submit" name="preview" value="Preview" />
-    <input type="submit" name="cancel" value="Cancel" />
-    <input type="submit" name="delete" value="Delete" />
-  </form>
-  {{ super() }}
-{% endblock %}

File neorg/templates/layout.html

           {% if temp_path %}
           <a href="{{ url_for('edit', page_path=temp_path) }}">Edit Template</a>
           {% else %}
-          <a href="{{ url_for('edit', page_path=page_path) }}">Edit</a>
+          <a href="{{ url_for('edit', page_path=page_path) }}"
+	     class="page-action-edit">Edit</a>
           {% endif %}
         </div>
         <div style="clear: both;"> </div>
     </div>
   <script type='text/javascript'>
     neorgInit();
+    {% if hide_edit_form is defined and hide_edit_form -%}
+    $("#edit-form").hide();
+    {%- endif %}
   </script>
   </body>
 </html>

File neorg/templates/page.html

     Organize your experiments and find out more!
 {%- endblock %}
 {% block body %}
+  {% if page_text is defined -%}
+  <form action="{{ url_for('save', page_path=page_path) }}"
+        method="post" class="add-entry" id="edit-form">
+    <textarea name="page_text" rows="20" cols="80" id="edit-form-textarea">
+      {{- page_text -}}
+    </textarea>
+    <input type="submit" name="save" value="Save" />
+    <input type="submit" name="preview" value="Preview" />
+    <input type="submit" name="cancel" value="Cancel" />
+    <input type="submit" name="delete" value="Delete" />
+  </form>
+  {%- endif %}
   <div>
     {{ page_html|safe }}
   </div>

File neorg/web.py

         return render_template("page.html",
                                title=path_as_title(page_path),
                                page_path=page_path,
-                               page_html=page_html)
+                               page_html=page_html,
+                               page_text=page_text if page_text else '',
+                               hide_edit_form=True)
     else:
         generated = gene_from_template(page_path)
         if generated:
                 return redirect(url_for('descendants',
                                         page_path=page_path))
             else:
+                flash('Page {0} does not exist and does not have sub-pages. '
+                      'You can add new contents.'
+                      .format(page_path))
                 return redirect(url_for('edit', page_path=page_path))