]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
File uploads working now. It is hard coded to only work with file plugin.
authorcash <cash.costello@gmail.com>
Sun, 19 Jun 2011 19:08:02 +0000 (15:08 -0400)
committercash <cash.costello@gmail.com>
Sun, 19 Jun 2011 19:08:02 +0000 (15:08 -0400)
mod/embed/views/default/embed/upload/content.php
mod/embed/views/default/js/embed/embed.php

index b7bcc76a07ffdc8129330e677346fa6d1d0dbd08..24fce811276a5eebfc4fca4c62a7ea805cca2120 100644 (file)
@@ -19,16 +19,21 @@ if ($upload_sections) {
                'value' => $active_section
        ));
 
-       echo "<div class='embed_modal_upload'>";
-       echo "<p>" . elgg_echo('embed:upload_type') . "$input</p>";
-
+       // hack this in for now as we clean up this mess
+       $form_vars = array(
+               'enctype' => 'multipart/form-data',
+               'class' => 'elgg-form',
+       );
+       $upload_content = elgg_view_form('file/upload', $form_vars);
+/*
        if (!$upload_content = elgg_view($upload_sections[$active_section]['view'])) {
                $upload_content = elgg_echo('embed:no_upload_content');
        }
-
-       echo $upload_content . "</div>";
-
-       elgg_load_js('elgg.embed');
+*/
+       echo "<div class='mbm'>" . elgg_echo('embed:upload_type') . "$input</div>";
+       echo "<div class='embed-upload'>";
+       echo $upload_content;
+       echo "</div>";
 
 } else {
        echo elgg_echo('embed:no_upload_sections');
index 3b398af3ae3d4e7085214de6ba32e7714f00e1f2..39d4007154b4e13a06fb921d4f676c333d9af3c8 100644 (file)
@@ -17,6 +17,8 @@ elgg.embed.init = function() {
        $('.embed-wrapper .elgg-pagination a').live('click', elgg.embed.pagination);
 
        $('.embed-section').live('click', elgg.embed.loadTab);
+
+       $('.embed-upload .elgg-form').live('submit', elgg.embed.submit);
 }
 
 /**
@@ -41,6 +43,43 @@ elgg.embed.insert = function(event) {
        event.preventDefault();
 }
 
+/**
+ * Submit an upload form through Ajax
+ *
+ * Requires the jQuery Form Plugin. Because files cannot be uploaded with
+ * XMLHttpRequest, the plugin uses an invisible iframe. This results in the
+ * the X-Requested-With header not being set. To work around this, we are
+ * sending the header as a POST variable and Elgg's code checks for it in
+ * elgg_is_xhr().
+ *
+ * @param {Object} event
+ * @return bool
+ */
+elgg.embed.submit = function(event) {
+       
+       $(this).ajaxSubmit({
+               dataType : 'json',
+               data     : { 'X-Requested-With' : 'XMLHttpRequest'},
+               success  : function(response) {
+                       if (response) {
+                               if (response.system_messages) {
+                                       elgg.register_error(response.system_messages.error);
+                                       elgg.system_message(response.system_messages.success);
+                               }
+                               if (response.status >= 0) {
+                                       // @todo - really this should forward to what the registered defined
+                                       // For example, forward to images tab if an image was uploaded
+                                       var url = elgg.config.wwwroot + 'embed/embed?active_section=file';
+                                       $('.embed-wrapper').parent().load(url);
+                               }
+                       }
+               }
+       });
+
+       // this is bubbling up the DOM and causing a submission so return false
+       return false;
+}
+
 /**
  * Loads the next chunk of content within the lightbox
  *