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) {
}.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,
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.
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>
*/
class VolumeList extends BaculumWebPage {
- const USE_CACHE = true;
+ const USE_CACHE = false;
public $volumes;
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,
$result[] = implode(PHP_EOL, $ret->output);
}
$this->getCallbackClient()->update($this->BulkActions->BulkActionsOutput, implode(PHP_EOL, $result));
+ $this->updateVolumes($sender, $param);
}
/**
$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]);
}
}
?>