Menu="Main:2"
Title="Pool Devices"
Tag="bullseye"
Cond="($pool_devices || $var['fsState']=='Stopped')"
---
<?PHP
/* Copyright 2005-2021, Lime Technology
 * Copyright 2012-2021, Bergware International.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 */
?>
<?
function sharename($share) {
  return substr($share,0,-4);
}
$bgcolor = strstr('white,azure',$display['theme']) ? '#f2f2f2' : '#1c1c1c';
?>
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/jquery.ui.css")?>">
<link type="text/css" rel="stylesheet" href="<?autov("/plugins/dynamix.docker.manager/styles/style-{$display['theme']}.css")?>">
<style>
table.divider{margin-top:20px}
</style>
<script>
function validate(poolname) {
  var valid = /^[a-z_]([a-z0-9_-]*[a-z_])*$/;
  var reserved = [<?=implode(',',array_map('escapestring',explode(',',$var['reservedNames'])))?>];
  var shares = [<?=implode(',',array_map('escapestring',array_filter(array_map('sharename',scandir('boot/config/shares')))))?>];
  var pools = [<?=implode(',',array_map('escapestring',$pools))?>];
  if (!poolname.trim()) return false;
  if (reserved.includes(poolname)) {
    swal({title:"_(Invalid pool name)_",text:"_(Do not use reserved names)_",html:true,type:'error',confirmButtonText:"_(Ok)_"});
    return false;
  } else if (shares.includes(poolname)) {
    swal({title:"_(Invalid pool name)_",text:"_(Do not use user share names)_",html:true,type:'error',confirmButtonText:"_(Ok)_"});
    return false;
  } else if (pools.includes(poolname)) {
    swal({title:"_(Invalid pool name)_",text:"_(Pool name already exists)_",html:true,type:'error',confirmButtonText:"_(Ok)_"});
    return false;
  } else if (!valid.test(poolname)) {
    swal({title:"_(Invalid pool name)_",text:"_(Use only lowercase with no special characters or leading/trailing digits)_",type:'error',html:true,confirmButtonText:"_(Ok)_"});
    return false;
  } else {
    return true;
  }
}
function addPoolPopup() {
  var popup = $('#dialogAddPool');
  // Load popup with the template info
  popup.html($("#templatePopupPool").html());
  // Start Dialog section
  popup.dialog({
    title: "_(Add Pool)_",
    resizable: false,
    width: 600,
    modal: true,
    show : {effect:'fade', duration:250},
    hide : {effect:'fade', duration:250},
    buttons: {
    "_(Add)_": function() {
        if (validate($(this).find('input[name="poolName"]').val())) {
          $(this).find('form').submit();
          $(this).dialog('close');
        }
      },
    "_(Cancel)_": function() {
        $(this).dialog('close');
      }
    }
  });
  $(".ui-dialog .ui-dialog-titlebar").addClass('menu');
  $('.ui-dialog .ui-dialog-titlebar-close').css({'display':'none'});
  $(".ui-dialog .ui-dialog-title").css({'text-align':'center','width':'100%'});
  $(".ui-dialog .ui-dialog-content").css({'padding-top':'15px','vertical-align':'bottom'});
  $(".ui-widget-content").css({'background':'<?=$bgcolor?>'});
  $(".ui-button-text").css({'padding':'0px 5px'});
}

<?if ($var['fsState']=='Started'):?>
$('#tab2').bind({click:function() {$('i.toggle').show('slow');}});
<?endif;?>
</script>

<?$i = 0?>
<?foreach ($pools as $pool):?>
<?if (isset($disks[$pool]['devices']) || $var['fsState']=='Stopped'):?>
<table class="disk_status wide<?=$i?' divider':''?>">
<thead><tr><td>_(Device)_</td><td>_(Identification)_</td><td>_(Temp)_.</td><td>_(Reads)_</td><td>_(Writes)_</td><td>_(Errors)_</td><td>_(FS)_</td><td>_(Size)_</td><td>_(Used)_</td><td>_(Free)_</td><td>_(View)_</td></tr></thead>
<tbody id="pool_device<?=$i++?>">
<?foreach (cache_filter($disks) as $disk) if (prefix($disk['name'])==$pool) echo "<tr><td colspan='11'>&nbsp;</td></tr>"?>
</tbody>
</table>
<?endif;?>
<?endforeach;?>
<?if ($var['fsState']=='Stopped'):?>
<input type="button" value="_(Add Pool)_" style="margin:0" onclick="addPoolPopup()">

<div id="dialogAddPool" style="display:none"></div>
<div id="templatePopupPool" style="display:none">
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onsubmit="return validate(this.poolName.value)">
<input type="hidden" name="changeSlots" value="apply">
_(Name)_:
: <input type="text" name="poolName" maxlength="40" value="<?=count($pools)==0?'cache':''?>">

_(Slots)_:
: <select name="poolSlots">
  <?for ($n=1; $n<=$var['MAX_CACHESZ']; $n++):?>
  <?=mk_option(1,$n,$n)?>
  <?endfor;?>
  </select>

</form>
</div>
<?endif;?>

:cache_devices_help:

<?if ($var['fsState'] == "Stopped"):?>
<div></div>
:cache_slots_help:
<?endif;?>
