renommer fichier dans widget file (ref #240)

This commit is contained in:
afornerot 2021-03-15 14:19:34 +01:00
parent 3438392632
commit 49e2527337
3 changed files with 115 additions and 6 deletions

View File

@ -181,6 +181,9 @@ class FileController extends Controller
public function uploadAction($id,$type,Request $request,$access="config") public function uploadAction($id,$type,Request $request,$access="config")
{ {
$canupdate =$this->getPermission($access,$id);
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
$subdirectory=$request->get("subdirectory"); $subdirectory=$request->get("subdirectory");
$forcereload=(is_null($request->get("forcereload"))?true:$request->get("forcereload")); $forcereload=(is_null($request->get("forcereload"))?true:$request->get("forcereload"));
@ -198,8 +201,10 @@ class FileController extends Controller
public function subdirectoryAction($id,$type,Request $request,$access="config") public function subdirectoryAction($id,$type,Request $request,$access="config")
{ {
$subdirectory=$request->get("subdirectory"); $canupdate =$this->getPermission($access,$id);
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
$subdirectory=$request->get("subdirectory");
$defaultData = []; $defaultData = [];
$form = $this->createFormBuilder() $form = $this->createFormBuilder()
->add('subdirectory', TextType::class,["label"=>"Répertoire"]) ->add('subdirectory', TextType::class,["label"=>"Répertoire"])
@ -239,6 +244,78 @@ class FileController extends Controller
]); ]);
} }
public function renameAction($id,$oldname, Request $request,$access="config")
{
$canupdate =$this->getPermission($access,$id);
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
$subdirectory=$request->get("subdirectory");
$form = $this->createFormBuilder()
->add('subdirectory', TextType::class,["label"=>"Renommer"])
->add('submit', SubmitType::class,["label"=>"Valider"])
->getForm();
$form->handleRequest($request);
$toclose=false;
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
if($data["subdirectory"]=="thumb"||$data["subdirectory"]=="thumbmini"||$data["subdirectory"]=="__trash") {
$form->addError(new FormError('Nom réservé, merci de choisir un autre nom'));
$this->get('session')->getFlashBag()->clear();
$request->getSession()->getFlashBag()->add("error", 'Nom réservé, merci de choisir un autre nom');
}
else {
$fs = new Filesystem();
$fulldirectory=$this->get('kernel')->getRootDir()."/../uploads/file/".$id;
if($subdirectory) $fulldirectory.="/".$subdirectory;
$urlsource= $fulldirectory."/".$oldname;
$urldestination = $fulldirectory."/".$data["subdirectory"];
if($urlsource!=$urldestination) {
if($fs->exists($urldestination)) {
$form->addError(new FormError('Ce nom existe déjà'));
$this->get('session')->getFlashBag()->clear();
$request->getSession()->getFlashBag()->add("error", 'Ce nom existe déjà');
}
elseif($fs->exists($urlsource)) {
if(is_dir($urlsource)) {
$fs->mirror($urlsource,$urldestination);
$fs->remove($urlsource);
}
else {
$fs->rename($urlsource,$urldestination,true);
$urlsource= $fulldirectory."/thumb/".$oldname;
$urldestination = $fulldirectory."/thumb/".$data["subdirectory"];
$fs->rename($urlsource,$urldestination,true);
$urlsource= $fulldirectory."/thumbmini/".$oldname;
$urldestination = $fulldirectory."/thumbmini/".$data["subdirectory"];
$fs->rename($urlsource,$urldestination,true);
}
$toclose=true;
}
}
}
} else $form->get('subdirectory')->setData($oldname);
return $this->render('CadolesCoreBundle:File:subdirectory.html.twig',[
'useheader' => false,
'usemenu' => false,
'usesidebar' => false,
'access' => $access,
'id' => $id,
'subdirectory' => $subdirectory,
'form' => $form->createView(),
'toclose' => $toclose,
]);
}
public function trashAction(Request $request,$access="config") public function trashAction(Request $request,$access="config")
{ {
// S'assurer que c'est un appel ajax // S'assurer que c'est un appel ajax
@ -255,7 +332,9 @@ class FileController extends Controller
$dirsource =$request->request->get('subdirectory'); $dirsource =$request->request->get('subdirectory');
$namesource =$request->request->get('filename'); $namesource =$request->request->get('filename');
$this->getPermission($access,$directory); $canupdate =$this->getPermission($access,$directory);
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
$fs = new Filesystem(); $fs = new Filesystem();
// Déplacer le fichier // Déplacer le fichier
@ -316,7 +395,9 @@ class FileController extends Controller
$dirsource =$request->request->get('subdirectory'); $dirsource =$request->request->get('subdirectory');
$namesource =$request->request->get('filename'); $namesource =$request->request->get('filename');
$this->getPermission($access,$directory); $canupdate =$this->getPermission($access,$directory);
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
$fs = new Filesystem(); $fs = new Filesystem();
// Déplacer le fichier // Déplacer le fichier
@ -365,7 +446,9 @@ class FileController extends Controller
{ {
$output=array(); $output=array();
$this->getPermission($access,$directory); $canupdate =$this->getPermission($access,$directory);
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
$fs = new Filesystem(); $fs = new Filesystem();
$url=$this->get('kernel')->getRootDir()."/../uploads/file/".$directory."/__trash"; $url=$this->get('kernel')->getRootDir()."/../uploads/file/".$directory."/__trash";
if($fs->exists($url)) { if($fs->exists($url)) {
@ -388,7 +471,9 @@ class FileController extends Controller
$filename=$request->request->get('filename'); $filename=$request->request->get('filename');
if($subdirectory) $directory.="/".$subdirectory; if($subdirectory) $directory.="/".$subdirectory;
$this->getPermission($access,$directory); $canupdate =$this->getPermission($access,$directory);
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
$fs = new Filesystem(); $fs = new Filesystem();
$url=$this->get('kernel')->getRootDir()."/../uploads/file/".$directory."/".$filename; $url=$this->get('kernel')->getRootDir()."/../uploads/file/".$directory."/".$filename;
if($fs->exists($url)) { if($fs->exists($url)) {
@ -418,7 +503,9 @@ class FileController extends Controller
$namedestination =$request->request->get('namedestination'); $namedestination =$request->request->get('namedestination');
$this->getPermission($access,$directory); $canupdate =$this->getPermission($access,$directory);
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
$fs = new Filesystem(); $fs = new Filesystem();
// Déplacer le fichier // Déplacer le fichier

View File

@ -74,6 +74,10 @@ cadoles_core_config_file_subdirectory:
path: /config/file/subdirectory/{id}/{type} path: /config/file/subdirectory/{id}/{type}
defaults: { _controller: CadolesCoreBundle:File:subdirectory, access: config } defaults: { _controller: CadolesCoreBundle:File:subdirectory, access: config }
cadoles_core_config_file_rename:
path: /config/file/rename/{id}/{oldname}
defaults: { _controller: CadolesCoreBundle:File:rename, access: config }
cadoles_core_config_file_trash: cadoles_core_config_file_trash:
path: /config/file/trash/ path: /config/file/trash/
defaults: { _controller: CadolesCoreBundle:File:trash, access: config } defaults: { _controller: CadolesCoreBundle:File:trash, access: config }
@ -119,6 +123,10 @@ cadoles_core_user_file_subdirectory:
path: /user/file/subdirectory/{id}/{type} path: /user/file/subdirectory/{id}/{type}
defaults: { _controller: CadolesCoreBundle:File:subdirectory, access: user } defaults: { _controller: CadolesCoreBundle:File:subdirectory, access: user }
cadoles_core_user_file_rename:
path: /user/file/rename/{id}/{oldname}
defaults: { _controller: CadolesCoreBundle:File:rename, access: user }
cadoles_core_user_file_trash: cadoles_core_user_file_trash:
path: /user/file/trash/ path: /user/file/trash/
defaults: { _controller: CadolesCoreBundle:File:trash, access: user } defaults: { _controller: CadolesCoreBundle:File:trash, access: user }

View File

@ -33,6 +33,10 @@
text-transform: initial !important; text-transform: initial !important;
} }
a.item-update {
right: 25px;
}
{% endblock %} {% endblock %}
@ -142,6 +146,10 @@
<i class="fa fa-trash" title="Supprimer le dossier"></i> <i class="fa fa-trash" title="Supprimer le dossier"></i>
</a> </a>
{% else %} {% else %}
<a style="cursor:pointer;" data-toggle="modal" data-target="#mymodal" onClick="ModalLoad('mymodal','Modification Répertoire','{{ path('cadoles_core_'~access~'_file_rename',{'id': directory,'subdirectory':subdirectory,'oldname':dir.name}) }}');" class="item-update">
<i class="fa fa-file" title="Modifier le dossier"></i>
</a>
<a style="cursor:pointer;" onClick="trashFile('{{ directory }}','{{subdirectory}}','{{dir.name|e('js')|raw }}')" class="item-delete"> <a style="cursor:pointer;" onClick="trashFile('{{ directory }}','{{subdirectory}}','{{dir.name|e('js')|raw }}')" class="item-delete">
<i class="fa fa-trash" title="Supprimer le dossier"></i> <i class="fa fa-trash" title="Supprimer le dossier"></i>
</a> </a>
@ -181,6 +189,10 @@
<i class="fa fa-trash" title="Supprimer le fichier"></i> <i class="fa fa-trash" title="Supprimer le fichier"></i>
</a> </a>
{% else %} {% else %}
<a style="cursor:pointer;" data-toggle="modal" data-target="#mymodal" onClick="ModalLoad('mymodal','Modification Fichier','{{ path('cadoles_core_'~access~'_file_rename',{'id': directory,'subdirectory':subdirectory,'oldname':file.name}) }}');" class="item-update">
<i class="fa fa-file" title="Modifier le fichier"></i>
</a>
<a style="cursor:pointer;" onClick="trashFile('{{ directory }}','{{subdirectory}}','{{file.name|e('js')|raw }}')" class="item-delete"> <a style="cursor:pointer;" onClick="trashFile('{{ directory }}','{{subdirectory}}','{{file.name|e('js')|raw }}')" class="item-delete">
<i class="fa fa-trash" title="Supprimer le fichier"></i> <i class="fa fa-trash" title="Supprimer le fichier"></i>
</a> </a>
@ -234,6 +246,8 @@
else { else {
color = "#{{ color["main"]}}"; color = "#{{ color["main"]}}";
} }
$(".item-update").css("color",color);
$(".item-update > i").css("color",color);
$(".item-delete").css("color",color); $(".item-delete").css("color",color);
$(".item-delete > i").css("color",color); $(".item-delete > i").css("color",color);
$(".item-restaure").css("color",color); $(".item-restaure").css("color",color);