From: Marcin Haba Date: Sun, 27 Jun 2021 16:11:19 +0000 (+0200) Subject: baculum: New delete volumes bulk action on volume list page X-Git-Tag: Release-11.0.6~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f82b7019ff70b25aedac66b6e32cd3124995bf63;p=thirdparty%2Fbacula.git baculum: New delete volumes bulk action on volume list page --- diff --git a/gui/baculum/protected/Web/Pages/VolumeList.page b/gui/baculum/protected/Web/Pages/VolumeList.page index eeef9e7bd..bbe0aa754 100644 --- a/gui/baculum/protected/Web/Pages/VolumeList.page +++ b/gui/baculum/protected/Web/Pages/VolumeList.page @@ -160,16 +160,35 @@ var oVolumeList = { before: function() { oBulkActionsModal.show_output(true); } + }, + { + action: 'delete', + label: '<%[ Delete ]%>', + value: 'mediaid', + callback: <%=$this->DeleteVolumesAction->ActiveControl->Javascript%>, + before: function() { + oBulkActionsModal.show_output(true); + } } ], ids: { volume_list: 'volume_list', volume_list_body: 'volume_list_body' }, - init: function() { - this.set_table(); - this.set_bulk_actions(); - this.set_events(); + init: function(data) { + if (this.table) { + var page = this.table.page(); + this.table.clear().rows.add(data).draw(); + this.table.page(page).draw(false); + this.table_toolbar.style.display = 'none'; + } else { + this.set_table(data); + this.set_bulk_actions(); + this.set_events(); + } + }, + update: function(data) { + oVolumeList.init(data); }, set_events: function() { document.getElementById(this.ids.volume_list).addEventListener('click', function(e) { @@ -178,9 +197,9 @@ var oVolumeList = { }.bind(this)); }.bind(this)); }, - set_table: function() { + set_table: function(data) { this.table = $('#' + this.ids.volume_list).DataTable({ - data: <%=json_encode($this->volumes)%>, + data: data, deferRender: true, dom: 'lB<"table_toolbar">frtip', stateSave: true, @@ -503,9 +522,23 @@ var oVolumeList = { actions: '<%[ Actions ]%>', ok: '<%[ OK ]%>' }); + }, + reset_filters: function() { + // reset table filters + var page = this.table.page(); + this.table.search('').columns().search('').draw(); + this.table.page(page).draw(false); + + // reset select values (table engine does not do it automatically) + this.table.columns().every(function() { + var select = this.footer().querySelector('th > select'); + if (select) { + select.value = ''; + } + }); } }; -oVolumeList.init(); +oVolumeList.init(<%=json_encode($this->volumes)%>); /** * Defne bulk actions output id here because expression tags (< % = % >) cannot * be defined in the TCallback ClientSide properties. @@ -530,8 +563,18 @@ var bulk_actions_output_id = '<%=$this->SourceTemplateControl->BulkActions->Bulk oBulkActionsModal.show_loader(false); + + + oBulkActionsModal.clear_output(bulk_actions_output_id); + oBulkActionsModal.show_loader(true); + + + oBulkActionsModal.show_loader(false); + oVolumeList.reset_filters(); + + diff --git a/gui/baculum/protected/Web/Pages/VolumeList.php b/gui/baculum/protected/Web/Pages/VolumeList.php index a1b93fddd..3a1df651f 100644 --- a/gui/baculum/protected/Web/Pages/VolumeList.php +++ b/gui/baculum/protected/Web/Pages/VolumeList.php @@ -31,7 +31,7 @@ Prado::using('Application.Web.Class.BaculumWebPage'); */ class VolumeList extends BaculumWebPage { - const USE_CACHE = true; + const USE_CACHE = false; public $volumes; @@ -40,11 +40,11 @@ class VolumeList extends BaculumWebPage { if ($this->IsPostBack || $this->IsCallBack) { return; } - $this->setVolumes(); + $this->volumes = $this->getVolumes(); } - public function setVolumes() { - $this->volumes = $this->getModule('api')->get( + public function getVolumes() { + return $this->getModule('api')->get( array('volumes'), null, true, @@ -74,6 +74,7 @@ class VolumeList extends BaculumWebPage { $result[] = implode(PHP_EOL, $ret->output); } $this->getCallbackClient()->update($this->BulkActions->BulkActionsOutput, implode(PHP_EOL, $result)); + $this->updateVolumes($sender, $param); } /** @@ -98,6 +99,45 @@ class VolumeList extends BaculumWebPage { $result[] = implode(PHP_EOL, $ret->output); } $this->getCallbackClient()->update($this->BulkActions->BulkActionsOutput, implode(PHP_EOL, $result)); + $this->updateVolumes($sender, $param); + } + + /** + * Delete multiple volumes. + * Used for bulk actions. + * + * @param TCallback $sender callback object + * @param TCallbackEventPrameter $param event parameter + * @return none + */ + public function deleteVolumes($sender, $param) { + $result = []; + $mediaids = explode('|', $param->getCallbackParameter()); + for ($i = 0; $i < count($mediaids); $i++) { + $ret = $this->getModule('api')->remove( + ['volumes', intval($mediaids[$i])] + ); + if ($ret->error !== 0) { + $result[] = $ret->output; + break; + } + $result[] = implode(PHP_EOL, $ret->output); + } + $this->getCallbackClient()->update($this->BulkActions->BulkActionsOutput, implode(PHP_EOL, $result)); + $this->updateVolumes($sender, $param); + } + + /** + * Update volumes callback. + * It updates volume table data. + * + * @param TCallback $sender callback object + * @param TCallbackEventPrameter $param event parameter + * @return none + */ + public function updateVolumes($sender, $param) { + $volumes = $this->getVolumes(); + $this->getCallbackClient()->callClientFunction('oVolumeList.update', [$volumes]); } } ?>