From 3e6fd7e8fd419ed999fe38ee48519dae98988081 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Mon, 14 May 2018 21:14:41 +0200 Subject: [ticket/15664] Ajaxify ext actions in ACP PHPBB3-15664 --- phpBB/adm/style/acp_ext_actions.html | 6 ++++ phpBB/adm/style/acp_ext_delete_data.html | 40 ---------------------- phpBB/adm/style/acp_ext_disable.html | 34 ------------------- phpBB/adm/style/acp_ext_enable.html | 40 ---------------------- phpBB/adm/style/acp_ext_list.html | 19 +++-------- phpBB/adm/style/admin.js | 58 ++++++++++++++++++++++++++++++++ phpBB/adm/style/ajax.js | 28 +++++++++++++++ 7 files changed, 97 insertions(+), 128 deletions(-) create mode 100644 phpBB/adm/style/acp_ext_actions.html delete mode 100644 phpBB/adm/style/acp_ext_delete_data.html delete mode 100644 phpBB/adm/style/acp_ext_disable.html delete mode 100644 phpBB/adm/style/acp_ext_enable.html (limited to 'phpBB/adm/style') diff --git a/phpBB/adm/style/acp_ext_actions.html b/phpBB/adm/style/acp_ext_actions.html new file mode 100644 index 0000000000..b9c2febbe5 --- /dev/null +++ b/phpBB/adm/style/acp_ext_actions.html @@ -0,0 +1,6 @@ +{% for action in enabled.actions %} +{{ action.L_ACTION }}{% if not action.S_LAST_ROW %} | {% endif %} +{% endfor %} +{% for action in disabled.actions %} +{{ action.L_ACTION }}{% if not action.S_LAST_ROW %} | {% endif %} +{% endfor %} \ No newline at end of file diff --git a/phpBB/adm/style/acp_ext_delete_data.html b/phpBB/adm/style/acp_ext_delete_data.html deleted file mode 100644 index 0f3adb7cfe..0000000000 --- a/phpBB/adm/style/acp_ext_delete_data.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

-

{L_EXTENSION_DELETE_DATA_EXPLAIN}

- - -
-

{L_MIGRATION_EXCEPTION_ERROR}

-

{MIGRATOR_ERROR}

-

{L_RETURN_TO_EXTENSION_LIST}

-
- -
-

{L_CONFIRM_MESSAGE}

-
- -
-
- {L_EXTENSION_DELETE_DATA} - - -
-
- -
-

{L_EXTENSION_DELETE_DATA_IN_PROGRESS}

-
- -
-

{L_EXTENSION_DELETE_DATA_SUCCESS}

-
-

{L_RETURN_TO_EXTENSION_LIST}

-
- - - diff --git a/phpBB/adm/style/acp_ext_disable.html b/phpBB/adm/style/acp_ext_disable.html deleted file mode 100644 index d2b5c46fe8..0000000000 --- a/phpBB/adm/style/acp_ext_disable.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

-

{L_EXTENSION_DISABLE_EXPLAIN}

- - -
-

{L_CONFIRM}

-

{L_CONFIRM_MESSAGE}

-
- -
-
- - -
-
- -
-

{L_EXTENSION_DISABLE_IN_PROGRESS}

-
- -
-

{L_EXTENSION_DISABLE_SUCCESS}

-
-

{L_RETURN_TO_EXTENSION_LIST}

-
- - - diff --git a/phpBB/adm/style/acp_ext_enable.html b/phpBB/adm/style/acp_ext_enable.html deleted file mode 100644 index 8a4a35359e..0000000000 --- a/phpBB/adm/style/acp_ext_enable.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

-

{L_EXTENSION_ENABLE_EXPLAIN}

- - -
-

{L_MIGRATION_EXCEPTION_ERROR}

-

{MIGRATOR_ERROR}

-

{L_RETURN_TO_EXTENSION_LIST}

-
- -
-

{L_CONFIRM}

-

{L_CONFIRM_MESSAGE}

-
- -
-
- - -
-
- -
-

{L_EXTENSION_ENABLE_IN_PROGRESS}

-
- -
-

{L_EXTENSION_ENABLE_SUCCESS}

-
-

{L_RETURN_TO_EXTENSION_LIST}

-
- - - diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index 8e2c7452a3..c3c3b3fb66 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -42,8 +42,8 @@ - - + + class="hidden"> {L_EXTENSIONS_ENABLED} @@ -59,17 +59,12 @@ {L_DETAILS} - - title="{enabled.actions.L_ACTION_EXPLAIN}">{enabled.actions.L_ACTION} -  |  - + - - - + class="hidden"> {L_EXTENSIONS_DISABLED} @@ -87,14 +82,10 @@ {L_DETAILS} - - title="{disabled.actions.L_ACTION_EXPLAIN}">{disabled.actions.L_ACTION} -  |  - + - diff --git a/phpBB/adm/style/admin.js b/phpBB/adm/style/admin.js index 551c78a4a3..b7c25b7c86 100644 --- a/phpBB/adm/style/admin.js +++ b/phpBB/adm/style/admin.js @@ -228,6 +228,64 @@ function parse_document(container) }); } +/** + * Extension actions helper functions + */ +function move_to_enabled(element) +{ + var disabled_header = document.querySelector('#ext_disabled_header'); + disabled_header.parentNode.insertBefore(element, disabled_header); + element.classList.remove('ext_disabled'); + element.classList.add('ext_enabled'); +} +function move_to_disabled(element) +{ + var table_body = document.querySelector('#ext_disabled_header').parentNode; + table_body.appendChild(element); + element.classList.remove('ext_enabled'); + element.classList.add('ext_disabled'); +} +function set_actions(container, actions) { + container.innerHTML = ''; + for (var i = 0; i < actions.length; i++) { + var a = document.createElement('a'); + a.href = actions[i].U_ACTION.split('&').join('&'); // replace all occurances + a.title = actions[i].L_ACTION_EXPLAIN; + if (actions[i].COLOR) { + a.style = actions[i].COLOR; + } + a.innerHTML = actions[i].L_ACTION; + // ajaxify this action as well + phpbb.ajaxify({ + selector: a, + refresh: false, + callback: actions[i].ACTION_AJAX + }); + + container.appendChild(a); + + if (i < actions.length - 1) { + container.innerHTML += ' | '; + } + } +} +function show_enabled_header() { + document.querySelector('#ext_enabled_header').classList.remove('hidden'); +} +function show_disabled_header() { + document.querySelector('#ext_disabled_header').classList.remove('hidden'); +} +function hide_disabled_header_if_empty() { + if (!document.querySelector('.ext_disabled')) { + document.querySelector('#ext_disabled_header').classList.add('hidden'); + } +} +function hide_enabled_header_if_empty() { + if (!document.querySelector('.ext_enabled')) { + document.querySelector('#ext_enabled_header').classList.add('hidden'); + } +} + /** * Run onload functions */ diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index 895bb056e5..644e74bef7 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -157,6 +157,34 @@ phpbb.addAjaxCallback('row_delete', function(res) { } }); +/** + * Callbacks for extension actions + */ +phpbb.addAjaxCallback('ext_enable', function(res) { + if (res.EXT_ENABLE_SUCCESS) { + move_to_enabled(this.parentNode.parentNode); + set_actions(this.parentNode, res.ACTIONS); + show_enabled_header(); + hide_disabled_header_if_empty(); + } +}); +phpbb.addAjaxCallback('ext_delete_data', function(res) { + if (res.EXT_DELETE_DATA_SUCCESS) { + move_to_disabled(this.parentNode.parentNode); + set_actions(this.parentNode, res.ACTIONS); + show_disabled_header(); + hide_enabled_header_if_empty(); + } +}); +phpbb.addAjaxCallback('ext_disable', function(res) { + if (res.EXT_DISABLE_SUCCESS) { + move_to_disabled(this.parentNode.parentNode); + set_actions(this.parentNode, res.ACTIONS); + show_disabled_header(); + hide_enabled_header_if_empty(); + } +}); + /** * Handler for submitting permissions form in chunks * This call will submit permissions forms in chunks of 5 fieldsets. -- cgit v1.2.1