]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: New delete volumes bulk action on volume list page
authorMarcin Haba <marcin.haba@bacula.pl>
Sun, 27 Jun 2021 16:11:19 +0000 (18:11 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:25 +0000 (09:03 +0100)
gui/baculum/protected/Web/Pages/VolumeList.page
gui/baculum/protected/Web/Pages/VolumeList.php

index eeef9e7bda1b3729d07b9f747495f100f0e901e5..bbe0aa754259c3f301ad03fe584c1c8bb3fa6974 100644 (file)
@@ -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);
        </prop:ClientSide.OnComplete>
 </com:TCallback>
+<com:TCallback ID="DeleteVolumesAction" OnCallback="deleteVolumes">
+       <prop:ClientSide.OnLoading>
+               oBulkActionsModal.clear_output(bulk_actions_output_id);
+               oBulkActionsModal.show_loader(true);
+       </prop:ClientSide.OnLoading>
+       <prop:ClientSide.OnComplete>
+               oBulkActionsModal.show_loader(false);
+               oVolumeList.reset_filters();
+       </prop:ClientSide.OnComplete>
+</com:TCallback>
 <com:Application.Web.Portlets.BulkActionsModal
        ID="BulkActions"
-       RefreshPageBtn="true"
+       RefreshPageBtn="false"
        />
 </com:TContent>
index a1b93fddddd4d1f82d587199722034c57c3c1f7f..3a1df651f681bb021f1e2341d620d14045473391 100644 (file)
@@ -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]);
        }
 }
 ?>