It also fixes a bug with saving size directives reported by Catin King.
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"ReRunFailedLevels": {
"Required": false,
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"CatalogFiles": {
"Required": false,
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"MigrationLowBytes": {
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"NextPool": {
"Required": false,
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"ReRunFailedLevels": {
"Required": false,
"Required": false,
"ValueType": "size32",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"MaximumBlockSize": {
"Required": false,
"ValueType": "maxblocksize",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"PaddingSize": {
"Required": false,
"ValueType": "size32",
"DefaultValue": 4096,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"FileAlignment": {
"Required": false,
"ValueType": "size32",
"DefaultValue": 4096,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"MaximumVolumeSize": {
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"MaximumFileSize": {
"Required": false,
"ValueType": "size64",
"DefaultValue": 1000000000,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"VolumeCapacity": {
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"MinimumFeeSpace": {
"Required": false,
"ValueType": "size64",
"DefaultValue": 5000000,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"MaximumConcurrentJobs": {
"Required": false,
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"MaximumJobSpoolSize": {
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"DriveIndex": {
"Required": false,
"Required": false,
"ValueType": "size64",
"DefaultValue": 0,
- "FieldType": "TextBox"
+ "FieldType": "Size"
},
"MountPoint": {
"Required": false,
var Units = {
- formats: [
- {format: 'second', value: 1},
- {format: 'minute', value: 60},
- {format: 'hour', value: 60},
- {format: 'day', value: 24}
- ],
- units: ['K', 'M', 'G', 'T', 'P'],
+ units: {
+ size: [
+ {short: '', long: 'byte', value: 1},
+ {short: 'K', long: 'kilobyte', value: 1000},
+ {short: 'M', long: 'megabyte', value: 1000},
+ {short: 'G', long: 'gigabyte', value: 1000},
+ {short: 'T', long: 'terabyte', value: 1000},
+ {short: 'P', long: 'petabyte', value: 1000}
+ ],
+ time: [
+ {long: 'second', value: 1},
+ {long: 'minute', value: 60},
+ {long: 'hour', value: 60},
+ {long: 'day', value: 24}
+ ]
+ },
get_decimal_size: function(size) {
var dec_size;
var size_unit = 'B';
- var units = Units.units.slice(0);
-
+ var units = [];
+ for (var u in Units.units.size) {
+ units.push(Units.units.size[u].short);
+ }
+ units.shift(); // remove "byte" unit
if (size === null) {
size = 0;
}
}
return dec_size;
},
+ format_size: function(size_bytes, format) {
+ var reminder;
+ var f = this.units.size[0].long;
+ for (var i = 0; i < this.units.size.length; i++) {
+ if (this.units.size[i].long != format && size_bytes) {
+ reminder = size_bytes % this.units.size[i].value
+ if (reminder === 0) {
+ size_bytes /= this.units.size[i].value;
+ f = this.units.size[i].long;
+ continue;
+ }
+ break;
+ }
+ }
+ var ret = {value: size_bytes, format: f};
+ return ret;
+ },
format_time_period: function(time_seconds, format) {
var reminder;
- var f;
- for (var i = 0; i < this.formats.length; i++) {
- if (this.formats[i].format != format) {
- reminder = time_seconds % this.formats[i].value;
+ var f = this.units.time[0].long;
+ for (var i = 0; i < this.units.time.length; i++) {
+ if (this.units.time[i].long != format && time_seconds) {
+ reminder = time_seconds % this.units.time[i].value;
if (reminder === 0) {
- time_seconds /= this.formats[i].value;
- f = this.formats[i].format;
+ time_seconds /= this.units.time[i].value;
+ f = this.units.time[i].long;
continue;
}
break;
Prado::using('Application.Web.Portlets.DirectiveComboBox');
Prado::using('Application.Web.Portlets.DirectiveInteger');
Prado::using('Application.Web.Portlets.DirectiveListBox');
+Prado::using('Application.Web.Portlets.DirectiveSize');
Prado::using('Application.Web.Portlets.DirectiveText');
Prado::using('Application.Web.Portlets.DirectiveTimePeriod');
Prado::using('Application.Web.Portlets.DirectiveRunscript');
'DirectiveInteger',
'DirectiveListBox',
'DirectiveText',
+ 'DirectiveSize',
'DirectiveTimePeriod'
);
<com:Application.Web.Portlets.DirectiveTimePeriod />
</prop:TrueTemplate>
</com:Application.Web.Portlets.BConditional>
+ <com:Application.Web.Portlets.BConditional BCondition="<%#($this->Data['field_type'] === 'Size')%>">
+ <prop:TrueTemplate>
+ <com:Application.Web.Portlets.DirectiveSize />
+ </prop:TrueTemplate>
+ </com:Application.Web.Portlets.BConditional>
<com:Application.Web.Portlets.BConditional BCondition="<%#($this->Data['field_type'] === 'ComboBox')%>">
<prop:TrueTemplate>
<com:Application.Web.Portlets.DirectiveComboBox />
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2018 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+Prado::using('System.Web.UI.ActiveControls.TActiveLabel');
+Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
+Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList');
+Prado::using('Application.Web.Portlets.DirectiveTemplate');
+
+class DirectiveSize extends DirectiveTemplate {
+
+ const SIZE_FORMAT = 'SizeFormat';
+ const DEFAULT_SIZE_FORMAT = 'byte';
+
+ private $size_formats = array(
+ array('format' => 'byte', 'value' => 1, 'label' => 'Bytes'),
+ array('format' => 'kilobyte', 'value' => 1000, 'label' => 'Kilobytes'),
+ array('format' => 'megabyte', 'value' => 1000, 'label' => 'Megabytes'),
+ array('format' => 'gigabyte', 'value' => 1000, 'label' => 'Gigabytes'),
+ array('format' => 'terabyte', 'value' => 1000, 'label' => 'Terabytes')
+ );
+
+ public function getValue() {
+ $value = $this->Directive->Text;
+ if (is_numeric($value)) {
+ settype($value, 'integer');
+ $size_format = $this->SizeFormat->SelectedValue;
+ $value = $this->getValueBytes($value, $size_format);
+ } else {
+ $value = null;
+ }
+ return $value;
+ }
+
+ public function getSizeFormat() {
+ return $this->getViewState(self::SIZE_FORMAT, self::DEFAULT_SIZE_FORMAT);
+ }
+
+ public function setSizeFormat($format) {
+ $this->setViewState(self::SIZE_FORMAT, $format);
+ }
+
+ public function getSizeFormats() {
+ $size_formats = array();
+ for ($i = 0; $i < count($this->size_formats); $i++) {
+ $format = array(
+ 'label' => Prado::localize($this->size_formats[$i]['label']),
+ 'format' => $this->size_formats[$i]['format']
+ );
+ array_push($size_formats, $format);
+ }
+ return $size_formats;
+ }
+
+ public function createDirective() {
+ $size_format = $this->getSizeFormat();
+ $directive_value = $this->getDirectiveValue();
+ $default_value = $this->getDefaultValue();
+ if ($this->getInConfig() === false) {
+ if ($default_value !== 0) {
+ $directive_value = $default_value;
+ } else {
+ $directive_value = 0;
+ }
+ }
+ $formatted_value = $this->formatSize($directive_value, $size_format);
+ $this->Directive->Text = $formatted_value['value'];
+ $this->SizeFormat->DataSource = $this->size_formats;
+ $this->SizeFormat->SelectedValue = $formatted_value['format'];
+ $this->SizeFormat->dataBind();
+ $this->Label->Text = $this->getLabel();
+ $validate = $this->getRequired();
+ $this->DirectiveValidator->setVisible($validate);
+ }
+
+ /**
+ * Convert original size in bytes into given size format.
+ *
+ * Note, if there is not possible to convert size value into given format
+ * then there will be returned value converted by using as close format as possible.
+ * Example:
+ * size_value: 121000
+ * given format: byte
+ * returned value: 121
+ * returned format: kilobyte
+ */
+ private function formatSize($size_bytes, $format) {
+ $value = $size_bytes;
+ for ($i = 0; $i < count($this->size_formats); $i++) {
+ if ($this->size_formats[$i]['format'] != $format) {
+ $remainder = $value % $this->size_formats[$i]['value'];
+ if ($remainder === 0) {
+ $value /= $this->size_formats[$i]['value'];
+ $format = $this->size_formats[$i]['format'];
+ continue;
+ }
+ break;
+ }
+ break;
+ }
+ $result = array('value' => $value, 'format' => $format);
+ return $result;
+ }
+
+ private function getValueBytes($value, $size_format) {
+ for ($i = 0; $i < count($this->size_formats); $i++) {
+ $value *= $this->size_formats[$i]['value'];
+ if ($this->size_formats[$i]['format'] === $size_format) {
+ break;
+ }
+ }
+ return $value;
+ }
+}
+?>
--- /dev/null
+<div class="w3-row w3-margin-bottom<%=!$this->display_directive ? ' hide' : '';%>">
+ <div class="w3-col w3-quarter"><com:TActiveLabel ID="Label" ActiveControl.EnableUpdate="false" Visible="<%=$this->display_directive%>" />:</div>
+ <div class="w3-col w3-threequarter directive_value">
+ <com:TActiveTextBox ID="Directive"
+ OnTextChanged="saveValue"
+ CssClass="w3-input w3-border w3-third"
+ Visible="<%=$this->display_directive%>"
+ ActiveControl.EnableUpdate="false"
+ />
+ <com:TActiveDropDownList
+ ID="SizeFormat"
+ CssClass="w3-select w3-border w3-quarter"
+ DataTextField="label"
+ DataValueField="format"
+ Visible="<%=$this->display_directive%>"
+ ActiveControl.EnableUpdate="false"
+ AutoPostBack="false"
+ OnSelectedIndexChanged="saveValue"
+ /> <%=$this->getRequired() ? ' <i class="fa fa-asterisk w3-text-red" style="line-height: 40px"></i>' : ''%>
+ <i class="fa fa-undo reset_btn" onclick="var fsize = Units.format_size(parseInt('<%=$this->getDefaultValue()%>', 10), 'byte'); document.getElementById('<%=$this->Directive->ClientID%>').value = fsize.value; document.getElementById('<%=$this->SizeFormat->ClientID%>').value = fsize.format;" alt="<%[ Reset to default value ]%>" title="<%[ Reset to default value ]%>"></i>
+ <i class="fa fa-trash-alt remove_btn" onclick="document.getElementById('<%=$this->Directive->ClientID%>').value = '';" alt="<%[ Remove directive ]%>" title="<%[ Remove directive ]%>"></i>
+ <com:TRequiredFieldValidator
+ ID="DirectiveValidator"
+ ValidationGroup="Directive"
+ Display="Dynamic"
+ ControlToValidate="Directive"
+ FocusOnError="true"
+ Text="Field required."
+ Enabled="<%=$this->getRequired() && $this->getShow()%>"
+ />
+ </div>
+</div>
DataValueField="format"
Visible="<%=$this->display_directive%>"
ActiveControl.EnableUpdate="false"
+ AutoPostBack="false"
+ OnSelectedIndexChanged="saveValue"
/> <%=$this->getRequired() ? ' <i class="fa fa-asterisk w3-text-red" style="line-height: 40px"></i>' : ''%>
<i class="fa fa-undo reset_btn" onclick="var ftime = Units.format_time_period(parseInt('<%=$this->getDefaultValue()%>', 10), 'second'); document.getElementById('<%=$this->Directive->ClientID%>').value = ftime.value; document.getElementById('<%=$this->TimeFormat->ClientID%>').value = ftime.format;" alt="<%[ Reset to default value ]%>" title="<%[ Reset to default value ]%>"></i>
<i class="fa fa-trash-alt remove_btn" onclick="document.getElementById('<%=$this->Directive->ClientID%>').value = '';" alt="<%[ Remove directive ]%>" title="<%[ Remove directive ]%>"></i>