From d2bc39f65fae53b13779bfcc68deab3456881529 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 14 Sep 2020 09:50:04 -0500 Subject: [PATCH] replace storage popup with modal --- web/ajax/modal.php | 4 + web/includes/actions/storage.php | 4 +- web/skins/classic/includes/functions.php | 111 +++++++++++++++++++++ web/skins/classic/views/js/options.js | 45 +++++++++ web/skins/classic/views/js/options.js.php | 2 + web/skins/classic/views/options.php | 14 +-- web/skins/classic/views/storage.php | 114 ---------------------- 7 files changed, 171 insertions(+), 123 deletions(-) create mode 100644 web/skins/classic/views/js/options.js delete mode 100644 web/skins/classic/views/storage.php diff --git a/web/ajax/modal.php b/web/ajax/modal.php index 5693c1d4f..8f5cb8ac9 100644 --- a/web/ajax/modal.php +++ b/web/ajax/modal.php @@ -31,6 +31,10 @@ switch ( $modal ) { case 'delconfirm' : $data['html'] = getDelConfirmHTML(); break; + case 'storage' : + if ( !isset($_REQUEST['id']) ) ajaxError('Storage Id Not Provided'); + $data['html'] = getStorageModalHTML($_REQUEST['id']); + break; default : // Maybe don't need both ZM\Warning('Unknown modal '.$modal); diff --git a/web/includes/actions/storage.php b/web/includes/actions/storage.php index 49b5de3de..69ebfae0b 100644 --- a/web/includes/actions/storage.php +++ b/web/includes/actions/storage.php @@ -24,7 +24,7 @@ if ( !canEdit('System') ) { return; } -if ( $action == 'Save' ) { +if ( $action == 'save' ) { $storage = new ZM\Storage($_REQUEST['id']); $changes = $storage->changes($_REQUEST['newStorage']); @@ -33,7 +33,7 @@ if ( $action == 'Save' ) { $storage->save($changes); $refreshParent = true; } - $view = 'none'; + $redirect = '?view=options&tab=storage'; } else { ZM\Error("Unknown action $action in saving Storage"); } diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 8f5703015..8facb1f80 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -905,6 +905,117 @@ function getDelConfirmHTML() { return $result; } +function getStorageModalHTML($sid) { + $result = ''; + $null = ''; + $checked = 'checked="checked"'; + + if ( !canEdit('System') ) return; + + require_once('includes/Server.php'); + require_once('includes/Storage.php'); + + if ( $_REQUEST['id'] ) { + if ( !($newStorage = ZM\Storage::find_one(array('Id'=>$sid)) ) ) { + // Perhaps do something different here, rather than return nothing + return; + } + } else { + $newStorage = new ZM\Storage(); + $newStorage->Name(translate('NewStorage')); + } + + $type_options = array( 'local' => translate('Local'), 's3fs' => translate('s3fs') ); + $scheme_options = array( + 'Deep' => translate('Deep'), + 'Medium' => translate('Medium'), + 'Shallow' => translate('Shallow'), + ); + + $servers = ZM\Server::find( null, array('order'=>'lower(Name)') ); + $ServersById = array(); + foreach ( $servers as $S ) { + $ServersById[$S->Id()] = $S; + } + + // We have to manually insert the csrf key into the form when using a modal generated via ajax call + if ( isset($GLOBALS['csrf']['key']) ) { + $csrf_input = ''.PHP_EOL; + } else { + $csrf_input = ''; + } + + $result .= ''.PHP_EOL; + + return $result; +} + function xhtmlFooter() { global $css; global $cspNonce; diff --git a/web/skins/classic/views/js/options.js b/web/skins/classic/views/js/options.js new file mode 100644 index 000000000..690da7744 --- /dev/null +++ b/web/skins/classic/views/js/options.js @@ -0,0 +1,45 @@ +// Load the Storage Modal HTML via Ajax call +function getStorageModal(sid) { + $j.getJSON(thisUrl + '?request=modal&modal=storage&id=' + sid) + .done(function(data) { + if ( $j('#storageModal').length ) { + $j('#storageModal').replaceWith(data.html); + } else { + $j("body").append(data.html); + } + $j('#storageModal').modal('show'); + // Manage the Save button + $j('#storageSubmitBtn').click(function(evt) { + evt.preventDefault(); + $j('#storageModalForm').submit(); + }); + }) + .fail(function(jqxhr, textStatus, error) { + console.log("Request Failed: " + textStatus + ", " + error); + console.log("Response Text: " + jqxhr.responseText); + }); +} + +function enableStorageModal() { + $j(".storageCol").click(function(evt) { + evt.preventDefault(); + var sid = $j(this).data('sid'); + getStorageModal(sid); + }); + $j('#NewStorageBtn').click(function(evt) { + evt.preventDefault(); + getStorageModal(0); + }); +} + +function initPage() { + var NewStorageBtn = $j('#NewStorageBtn'); + + if ( canEditSystem ) enableStorageModal(); + + NewStorageBtn.prop('disabled', !canEditSystem); +} + +$j(document).ready(function() { + initPage(); +}); diff --git a/web/skins/classic/views/js/options.js.php b/web/skins/classic/views/js/options.js.php index 6947f8da8..5281cde8c 100644 --- a/web/skins/classic/views/js/options.js.php +++ b/web/skins/classic/views/js/options.js.php @@ -3,3 +3,5 @@ var restartWarning = ; if ( restartWarning ) { alert( "" ); } + +var canEditSystem = ; diff --git a/web/skins/classic/views/options.php b/web/skins/classic/views/options.php index 0fb5cb6e4..e1e6f4f78 100644 --- a/web/skins/classic/views/options.php +++ b/web/skins/classic/views/options.php @@ -272,12 +272,12 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as 'lower(Name)') ) as $Storage ) { ?> - Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Id()), $canEdit ) ?> - Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?> - Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Path()), $canEdit ) ?> - Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Type()), $canEdit ) ?> - Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Scheme()), $canEdit ) ?> - Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Server()->Name()), $canEdit ) ?> + Id()), $canEdit, 'class="storageCol" data-sid="'.$Storage->Id().'"' ) ?> + Name()), $canEdit, 'class="storageCol" data-sid="'.$Storage->Id().'"' ) ?> + Path()), $canEdit, 'class="storageCol" data-sid="'.$Storage->Id().'"' ) ?> + Type()), $canEdit, 'class="storageCol" data-sid="'.$Storage->Id().'"' ) ?> + Scheme()), $canEdit, 'class="storageCol" data-sid="'.$Storage->Id().'"' ) ?> + Server()->Name()), $canEdit, 'class="storageCol" data-sid="'.$Storage->Id().'"' ) ?> disk_used_space()) . ' of ' . human_filesize($Storage->disk_total_space()) ?> EventCount().' using '.human_filesize($Storage->event_disk_space()) ?> EventCount() or !$canEdit ) { ?> disabled="disabled"EventCount() ? ' title="Can\'t delete as long as there are events stored here."' : ''?>/> @@ -286,7 +286,7 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
- +
diff --git a/web/skins/classic/views/storage.php b/web/skins/classic/views/storage.php deleted file mode 100644 index b25d12a21..000000000 --- a/web/skins/classic/views/storage.php +++ /dev/null @@ -1,114 +0,0 @@ -$_REQUEST['id'])) ) ) { - $view = 'error'; - return; - } -} else { - $newStorage = new ZM\Storage(); - $newStorage->Name(translate('NewStorage')); -} - -$type_options = array( 'local' => translate('Local'), 's3fs' => translate('s3fs') ); -$scheme_options = array( - 'Deep' => translate('Deep'), - 'Medium' => translate('Medium'), - 'Shallow' => translate('Shallow'), -); - -$servers = ZM\Server::find( null, array('order'=>'lower(Name)') ); -$ServersById = array(); -foreach ( $servers as $S ) { - $ServersById[$S->Id()] = $S; -} -$focusWindow = true; - -xhtmlHeaders(__FILE__, translate('Storage').' - '.$newStorage->Name()); -?> - -
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'Remote / No Specific Server') + $ServersById, $newStorage->ServerId()); ?>
Type()); ?>
Scheme()); ?>
- DoDelete() ? 'checked="checked"' : '' ?>/>Yes - DoDelete() ? '' : 'checked="checked"' ?>/>No -
- Enabled() ? 'checked="checked"' : '' ?>/>Yes - Enabled() ? '' : 'checked="checked"' ?>/>No -
-
- - -
-
-
-
-