Skip to content

Commit

Permalink
add functionality to rewrite url while browsing in media library and …
Browse files Browse the repository at this point in the history
…pages
  • Loading branch information
Kuchtin committed Mar 11, 2024
1 parent ab84b70 commit 6f6ae6e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions conf/uri_map.php
Expand Up @@ -45,6 +45,7 @@
'^/backoffice/surveys/([0-9]*)/edit$' => '/index.php?request=bo/backoffice_wrapper.bo/backoffice.bo/component/survey_edit&id=$1',
'^/backoffice/marketing$' => '/index.php?request=bo/backoffice_wrapper.bo/backoffice.bo/pages/marketing',
'^/backoffice/media$' => '/index.php?request=bo/backoffice_wrapper.bo/backoffice.bo/pages/advanced.bo/pages/server_browser',
'^/backoffice/media/([a-zA-Z0-9_.-/]*)$' => '/index.php?request=bo/backoffice_wrapper.bo/backoffice.bo/pages/advanced.bo/pages/server_browser~open=$1~',
'^/backoffice/taxonomy$' => '/index.php?request=bo/backoffice_wrapper.bo/backoffice.bo/pages/advanced.bo/pages/taxonomy.bo/component/taxonomy_edit',
'^/backoffice/advanced/taxonomy/properties/([0-9]*)$' => '/index.php?request=bo/backoffice_wrapper.bo/backoffice.bo/pages/advanced.bo/pages/taxonomy~id=$1~.bo/component/taxonomy_edit~id=$1~',
'^/backoffice/advanced/taxonomy/add/([0-9]*)$' => '/index.php?request=bo/backoffice_wrapper.bo/backoffice.bo/pages/advanced.bo/pages/taxonomy~id=$1~.bo/component/taxonomy_add~parent=$1~',
Expand Down
4 changes: 2 additions & 2 deletions controllers/bo/component/server_browser_menu.php
Expand Up @@ -115,7 +115,7 @@ public function getListForDirectories($directories) {
protected function isNodeActive(&$item)
{
$preg = str_replace("/", "\/", quotemeta($item['id']));
return (preg_match("/{$preg}$/", $_SESSION['server_browser_last_open_folder']));
return (preg_match("/{$preg}$/", $this->GET['open'] ?? $_SESSION['server_browser_last_open_folder']));
}

/**
Expand All @@ -124,7 +124,7 @@ protected function isNodeActive(&$item)
protected function isNodeOpen(&$item)
{
$preg = str_replace("/", "\/", quotemeta($item['id']));
return (preg_match("/{$preg}/", $_SESSION['server_browser_last_open_folder']));
return (preg_match("/{$preg}/", $this->GET['open'] ?? $_SESSION['server_browser_last_open_folder']));
}

}
Expand Down
11 changes: 7 additions & 4 deletions controllers/bo/pages/server_browser.php
Expand Up @@ -17,7 +17,7 @@ public function mainAction() {

if ($this->GET['directory']) $base_folder = $this->GET['directory'];
else $base_folder = 'var/files/';

if ($this->GET['role']) $role = $this->GET['role'];
else $role = 'main';

Expand All @@ -33,11 +33,14 @@ public function mainAction() {

if ($this->GET['file_id']) $file_id = $this->GET['file_id'];
else $file_id = 0;

$_Onyx_Request = new Onyx_Request("bo/component/server_browser_menu~directory=$base_folder:type=$type:role=$role:node_id=$node_id:relation=$relation:file_id=$file_id:expand_all=1:type=d~");

if ($this->GET['open']) $open = $this->GET['open'];
else $open = null;

$_Onyx_Request = new Onyx_Request("bo/component/server_browser_menu~directory=$base_folder:type=$type:role=$role:node_id=$node_id:relation=$relation:file_id=$file_id:open=$open:expand_all=1:type=d~");
$this->tpl->assign("SERVER_BROWSER_TREE", $_Onyx_Request->getContent());

$_Onyx_Request = new Onyx_Request("bo/component/server_browser_file_list~type=$type:role=$role:node_id=$node_id:relation=$relation:file_id=$file_id~");
$_Onyx_Request = new Onyx_Request("bo/component/server_browser_file_list~type=$type:role=$role:node_id=$node_id:relation=$relation:file_id=$file_id:open=$open~");
$this->tpl->assign("SERVER_BROWSER_FILE_LIST", $_Onyx_Request->getContent());

return true;
Expand Down
23 changes: 23 additions & 0 deletions share/js/backoffice.js
Expand Up @@ -122,6 +122,29 @@ function initBackofficeUI() {

// create dialog
$("<div/>").attr('id','onyx-dialog').appendTo('body');

// rewrite url on page select
$('#pages-node-menu a').on('click', function() {
let newLink = window.location.origin + '/backoffice/pages/' + $(this).attr('href').replace('#', '');

if(window.history.pushState) {
window.history.pushState({}, $(this).find('span').html(), newLink);
}
});

// rewrite url on media browser
$('#browser-tree a').on('click', function() {
let newLink = window.location.origin + '/backoffice/media/' + $(this).attr('href').replace('#', '');

if(window.history.pushState) {
window.history.pushState({}, $(this).find('span').html(), newLink);
}
});

// fix for history.pushState so page refreshes on back button
$(window).bind("popstate", function() {
window.location = location.href
});
}

/**
Expand Down

0 comments on commit 6f6ae6e

Please sign in to comment.