[extensions-web] Add inline editing/uploading to main.js



commit adee77b502ffccebbc318c147d1ce3e9fcf27ca3
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Dec 18 05:53:34 2011 -0500

    Add inline editing/uploading to main.js
    
    With this, we can finally remove the global document.ready block from
    the main template.

 .../extensions/templates/extensions/detail.html    |    1 +
 .../templates/extensions/detail_edit.html          |    9 ---------
 sweettooth/static/js/main.js                       |   19 ++++++++++---------
 sweettooth/templates/base.html                     |    5 -----
 4 files changed, 11 insertions(+), 23 deletions(-)
---
diff --git a/sweettooth/extensions/templates/extensions/detail.html b/sweettooth/extensions/templates/extensions/detail.html
index aaf0e30..9504ee3 100644
--- a/sweettooth/extensions/templates/extensions/detail.html
+++ b/sweettooth/extensions/templates/extensions/detail.html
@@ -23,6 +23,7 @@
 {% endblock %}
 
     <div class="extension single-page"
+         data-epk="{{ extension.pk }}"
          data-uuid="{{ extension.uuid }}"
          data-ver-url-base="{% url extensions-version-detail ext_pk=extension.pk slug=extension.slug pk='' %}"
          data-svm="{{ shell_version_map }}">
diff --git a/sweettooth/extensions/templates/extensions/detail_edit.html b/sweettooth/extensions/templates/extensions/detail_edit.html
index c1be95c..843cd7b 100644
--- a/sweettooth/extensions/templates/extensions/detail_edit.html
+++ b/sweettooth/extensions/templates/extensions/detail_edit.html
@@ -119,12 +119,3 @@
   <input type="file" accept="image/*">
 </div>
 {% endblock %}
-
-{% block document-ready %}{{ block.super }}
-    $("#extension_name, #extension_url").csrfEditable("{% url extensions-ajax-inline pk=extension.pk %}");
-    $("#extension_description").csrfEditable("{% url extensions-ajax-inline pk=extension.pk %}", {"type": "textarea"});
-    require(['uploader'], function() {
-        $(".screenshot.upload").uploadify("{% url extensions-ajax-screenshot pk=extension.pk %}?geometry=300x200");
-        $(".icon.upload").uploadify("{% url extensions-ajax-icon pk=extension.pk %}");
-    });
-{% endblock %}
diff --git a/sweettooth/static/js/main.js b/sweettooth/static/js/main.js
index 2f96ad9..7808012 100644
--- a/sweettooth/static/js/main.js
+++ b/sweettooth/static/js/main.js
@@ -1,6 +1,6 @@
 "use strict";
 
-require(['jquery', 'messages', 'extensions',
+require(['jquery', 'messages', 'extensions', 'uploader',
          'jquery.cookie', 'jquery.jeditable',
          'jquery.timeago', 'jquery.rating'], function($, messages) {
     if (!$.ajaxSettings.headers)
@@ -90,7 +90,6 @@ require(['jquery', 'messages', 'extensions',
         });
 
         $('#local_extensions').addLocalExtensions();
-        $('#error_report').fillInErrors();
         $('.extension.single-page').addExtensionSwitch();
         $('.comment .rating').each(function() {
             $(this).find('input').rating();
@@ -127,12 +126,14 @@ require(['jquery', 'messages', 'extensions',
             return false;
         });
 
-        if (window._SW)
-            try {
-                window._SW();
-            } catch(e) {
-                if (console && console.error)
-                    console.error(e);
-            }
+        var pk = $('.extension.single-page').data('epk');
+        if (pk) {
+            var inlineEditURL = '/ajax/edit/' + pk;
+            $('#extension_name, #extension_url').csrfEditable(inlineEditURL);
+            $('#extension_description').csrfEditable(inlineEditURL, {type: 'textarea'});
+
+            $('.screenshot.upload').uploadify('/upload/screenshot/'+pk+'?geometry=300x200');
+            $('.icon.upload').uploadify('/upload/icon/'+pk);
+        }
     });
 });
diff --git a/sweettooth/templates/base.html b/sweettooth/templates/base.html
index 318c759..d0e5454 100644
--- a/sweettooth/templates/base.html
+++ b/sweettooth/templates/base.html
@@ -8,11 +8,6 @@
           href="{% url extensions-rss-feed %}" title="Latest extensions in GNOME Shell Extensions" />
     {% block head %} {% endblock %}
     <title>{% block title %}GNOME Shell Extensions{% endblock %}</title>
-    <script>
-window._SW = function() {
-{% block document-ready %}{% endblock %}
-};
-    </script>
     <script src="/static/js/jquery.js"></script>
     <script data-main="/static/js/{% block js-main %}main{% endblock %}.js" src="/static/js/require.js"></script>
   </head>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]