$this->addField('username', Text::class, __('Nom d\'utilisateur'), ['when' => ['protocol' => $this->getUsernameProtocols()]]);
$this->addField('password', Password::class, __('Mot de passe'), ['when' => ['protocol' => $this->getPasswordProtocols()]]);
$this->addField('base_path', Text::class, __('Chemin de base'), ['default' => '/']);
- $this->addField('base_url', URL::class, __('URL de base'), ['default' => 'https://']);
+ $this->addField('base_url', URL::class, __('URL de base'), ['default' => 'https://', 'column' => true]);
}
public static function getAllServers()
{
-
if (null === static::$_servers) {
static::$_servers = [];
foreach (static::where('created_ok', '1')->get() as $server) {
- static::$_servers[$server->id] = ['name' => $server->name, 'base_url' => $server->base_url];
+ static::$_servers[$server->id] = static::_getOneServer($server);
}
}
return static::$_servers;
}
+ /**
+ * @param $server static
+ * @return void
+ */
+ protected static function _getOneServer($server)
+ {
+ return ['name' => $server->name, 'base_url' => $server->base_url ?: $server->base_path];
+ }
+
protected function getProtocols()
{
return ['FTP' => __('FTP non sécurisé'), 'FTPS' => __('FTP sécurisé explicite sur TLS'), 'FTPES' => __('FTP sécurisé implicite sur TLS'), 'SFTP' => 'SFTP'];
/**
- * @param $protocol
* @return Driver
*/
- public function getTransferDriver($protocol)
+ public function getTransferDriver()
{
if (in_array($this->getProtocol(), $this->getFTPProtocols())) {
return new FTP($this);
<label>{!! __('Chemin') !!}</label>
<div class="input-group">
<div class="input-group-prepend"><span class="input-group-text prefix"></span></div>
- <input @include('crud::fields.inc.attributes')
- value="{{ $value['path'] }}"
+ <input data-class="external_path_server_path" @include('crud::fields.inc.attributes')
+ value="{{ $value['path'] }}"
type="text"
name="{{ $field['name'] }}[path]"
></div>
@push('crud_fields_scripts')
<script>
+ function liveslugify(text) {
+ return text
+ .toString()// Cast to string (optional)
+ .replace(/\/+/g,'fwdslash')
+ .normalize('NFKD') // The normalize() using NFKD method returns the Unicode Normalization Form of a given string.
+ .replace(/\s+/g, '-') // Replace spaces with -
+ .replace(/[^\w\-]+/g, '') // Remove all non-word chars
+ .replace(/\_/g, '-') // Replace _ with -
+ .replace(/\-\-+/g, '-') // Replace multiple - with single -
+ //.replace(/\-$/g, '') // Remove trailing -
+ .replace(/fwdslash/g,'/');
+ }
+
$(function () {
function updateServer(s) {
var prefix = $(s).find('option[value="' + $(s).val() + '"]').data('prefix');
- console.log($(s).val(), prefix,(s).find('option[value="' + $(s).val() + '"]'));
+ console.log($(s).val(), prefix, (s).find('option[value="' + $(s).val() + '"]'));
$(s).closest('.external_path__wrapper').find('.prefix').text(prefix);
}
updateServer($(this));
});
+ $(document).on('keyup keydown', '[data-class="external_path_server_path"]', function () {
+ $(this).val(liveslugify($(this).val()));
+ });
+
$('[data-class="external_path_server_select"]').each(function () {
updateServer($(this));
});