]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #4086 handling containers for embed uploading
authorCash Costello <cash.costello@gmail.com>
Sat, 17 Dec 2011 15:37:25 +0000 (10:37 -0500)
committerCash Costello <cash.costello@gmail.com>
Sat, 17 Dec 2011 15:37:25 +0000 (10:37 -0500)
mod/embed/start.php
mod/embed/views/default/embed/layout.php
mod/embed/views/default/js/embed/embed.php
mod/file/views/default/embed/file_upload/content.php

index 015c0c0e41eddc41d3f27130e5ed31c5661787d1..94021947623ea0775b9fe25855f1442cb62f06c7 100644 (file)
@@ -37,10 +37,15 @@ function embed_longtext_menu($hook, $type, $items, $vars) {
        if (elgg_get_context() == 'embed') {
                return $items;
        }
+
+       $url = 'embed';
+       if (elgg_get_page_owner_guid()) {
+               $url = 'embed?container_guid=' . elgg_get_page_owner_guid();
+       }
        
        $items[] = ElggMenuItem::factory(array(
                'name' => 'embed',
-               'href' => "embed",
+               'href' => $url,
                'text' => elgg_echo('embed:media'),
                'rel' => 'lightbox',
                'link_class' => "elgg-longtext-control elgg-lightbox embed-control embed-control-{$vars['id']}",
@@ -64,7 +69,9 @@ function embed_longtext_menu($hook, $type, $items, $vars) {
  */
 function embed_select_tab($hook, $type, $items, $vars) {
 
-       $tab_name = array_pop(explode('/', full_url()));
+       // can this ba called from page handler instead?
+       $page = get_input('page');
+       $tab_name = array_pop(explode('/', $page));
        foreach ($items as $item) {
                if ($item->getName() == $tab_name) {
                        $item->setSelected();
@@ -85,6 +92,11 @@ function embed_select_tab($hook, $type, $items, $vars) {
  */
 function embed_page_handler($page) {
 
+       $container_guid = (int)get_input('container_guid');
+       if ($container_guid) {
+               elgg_set_page_owner_guid($container_guid);
+       }
+
        echo elgg_view('embed/layout');
 
        // exit because this is in a modal display.
@@ -120,15 +132,17 @@ function embed_list_items($entities, $vars = array()) {
  */
 function embed_get_list_options($options = array()) {
 
+       $container_guids = array(elgg_get_logged_in_user_guid());
        if (elgg_get_page_owner_guid()) {
-               $container_guid = elgg_get_page_owner_guid();
-       } else {
-               $container_guid = elgg_get_logged_in_user_guid();
+               $page_owner_guid = elgg_get_page_owner_guid();
+               if ($page_owner_guid != elgg_get_logged_in_user_guid()) {
+                       $container_guids[] = $page_owner_guid;
+               }
        }
 
        $defaults = array(
                'limit' => 6,
-               'container_guid' => $container_guid,
+               'container_guids' => $container_guids,
                'item_class' => 'embed-item',
        );
 
index c1e43f13cdd68e8868a1c759ea6e3d2c91528e61..e906160b1b8c56b52b768c342f3575a88ceffc7a 100644 (file)
@@ -21,10 +21,17 @@ if ($selected->getData('view')) {
        }
 }
 
+
+$container_info = elgg_view('input/hidden', array(
+       'name' => 'embed_container_guid',
+       'value' => elgg_get_page_owner_guid(),
+));
+
 echo <<<HTML
 <div class="embed-wrapper">
        $title
        $menu
        $tab
+       $container_info
 </div>
 HTML;
index 54b9c391d310e10e8393a0f619517414176c0b2d..5fd534a09d2d08f5b7907bc4820d2c6c58042f90 100644 (file)
@@ -80,9 +80,13 @@ elgg.embed.submit = function(event) {
                                if (response.status >= 0) {
                                        var forward = $('input[name=embed_forward]').val();
                                        var url = elgg.normalize_url('embed/tab/' + forward);
+                                       url = elgg.embed.addContainerGUID(url);
                                        $('.embed-wrapper').parent().load(url);
                                }
                        }
+               },
+               error: function(xhr, status) {
+                       // nothing for now
                }
        });
 
@@ -98,8 +102,27 @@ elgg.embed.submit = function(event) {
  * @return void
  */
 elgg.embed.forward = function(event) {
-       $('.embed-wrapper').parent().load($(this).attr('href'));
+       // make sure container guid is passed
+       var url = $(this).attr('href');
+       url = elgg.embed.addContainerGUID(url);
+
+       $('.embed-wrapper').parent().load(url);
        event.preventDefault();
 };
 
+/**
+ * Adds the container guid to a URL
+ *
+ * @param {string} url
+ * @return string
+ */
+elgg.embed.addContainerGUID = function(url) {
+       if (url.indexOf('container_guid=') == -1) {
+               var guid = $('input[name=embed_container_guid]').val();
+               return url + '?container_guid=' + guid;
+       } else {
+               return url;
+       }
+};
+
 elgg.register_hook_handler('init', 'system', elgg.embed.init);
index 4d3db0d97f85c5198d11344e56bbf589e1991358..8b630c828ca9ac758fba7e52b64775303cd77bc1 100644 (file)
@@ -7,7 +7,8 @@ $form_vars = array(
        'enctype' => 'multipart/form-data',
        'class' => 'elgg-form-embed',
 );
-echo elgg_view_form('file/upload', $form_vars);
+$body_vars = array('container_guid' => elgg_get_page_owner_guid());
+echo elgg_view_form('file/upload', $form_vars, $body_vars);
 
 // the tab we want to be forwarded to after upload is complete
 echo elgg_view('input/hidden', array(