Ersetzfunktion Standard fertig

This commit is contained in:
holger.trampe 2020-03-30 22:41:32 +02:00
parent 2104211454
commit 6b3776d3c4
3 changed files with 224 additions and 28 deletions

View File

@ -133,6 +133,7 @@ a.disabled {
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
<div class="dropdown-header">Dateioptionen</div>
<a class="dropdown-item" href="javascript:moveFile({{file.pk}})">Verschieben</a>
<a class="dropdown-item" href="javascript:replaceFile({{file.pk}})">Ersetzen</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="javascript:delDataFileObje({{file.pk}})" >Löschen</a>
</div>
@ -247,6 +248,26 @@ a.disabled {
</div>
</div>
<!-- SelfFile ERROR -->
<div class="modal fade" id="replaceerrModal" tabindex="-1" role="dialog" data-backdrop="static" aria-labelledby="groupDelFunction" aria-hidden="true">
<div class="modal-dialog " role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Ersetzungsfehler</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Schließen">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Sie können die Datei nicht mit sich selbst ersetzen.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal">Schließen</button>
</div>
</div>
</div>
</div>
<!-- CONFIRMA DELETE FILE -->
<div class="modal fade" id="delDataFile" tabindex="-1" role="dialog" data-backdrop="static" aria-labelledby="groupDelFunction" aria-hidden="true">
<div class="modal-dialog " role="document">
@ -259,6 +280,7 @@ a.disabled {
</div>
<div class="modal-body">
Datei <b><span id="filenametodel"></span></b> wirklich löschen?
<div id="connectedStandards"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal" onclick="javascript:doDelDataFile()">Löschen</button>&nbsp;&nbsp;
@ -268,6 +290,47 @@ a.disabled {
</div>
</div>
<!-- CONFIRMA REPLACE FILE -->
<div class="modal fade" id="replaceFileModal" tabindex="-1" role="dialog" data-backdrop="static" aria-labelledby="groupDelFunction" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Datei ersetzen</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Schließen">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Datei <b><span id="filenametodel"></span></b> ersetzen mit:
<div class="input-group mb-3">
<input class="form-control searchuserfieldstask" list="possfiles" id="searchfiles" type="text" onkeyup="javascript:updateLinkedFiles()" >
<div class="input-group-append">
<button type="button" onclick="javascript:clearSearchfieldAddFile()" class="btn btn-secondary" ><i class="fas fa-times"></i></button>
</div>
<datalist id="possfiles">
{% for f in files %}
<option id="file_{{f.pk}}" value="{{f.name}}">{{f.name}}</option>
{% endfor %}
</datalist>
</div>
<div><span id="choosenfilename"></span></div>
<div id="connectedStandardsReplace"></div>
<hr>
<button id="btnDoReplaceFile" type="button" style="float: right" class="btn btn-secondary mt-1 " data-dismiss="modal" onclick="javascript:doreplaceFile(1)" disabled="true">Ersetzen, Alte Datei löschen!</button>
</div>
<div class="modal-footer" >
&nbsp;&nbsp;
<button id="btnDoReplaceFileSnd" type="button" class="btn btn-danger" data-dismiss="modal" onclick="javascript:doreplaceFile(0)" disabled="true">Ersetzen, Alte Datei <u>nicht</u> löschen!</button>&nbsp;&nbsp;
<button type="button" class="btn btn-success" data-dismiss="modal">Abbrechen</button>
</div>
</div>
</div>
</div>
</div>
<!-- CONFIRMA MOVE/DIR -->
<div class="modal fade" id="moveDataModal" tabindex="-1" role="dialog" data-backdrop="static" aria-labelledby="groupDelFunction" aria-hidden="true">
<div class="modal-dialog " role="document">
@ -377,9 +440,26 @@ a.disabled {
<script>
var actquotasize = {{actquota}};
var ua = window.navigator.userAgent;
var isIE = /MSIE|Trident/.test(ua);
if ( isIE ) {
//IE specific code goes here
setInterval(function()
{
if($('#replaceFileModal').is(':visible')){
console.log("HI!");
updateLinkedFiles();
}
},400);
}
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
$(".toast").toast({
@ -388,6 +468,28 @@ var actquotasize = {{actquota}};
});
});
function clearSearchfieldAddFile(){
$("#searchfiles").val("");
}
var replace_file_id = "";
$("#choosenfilename").html("");
function updateLinkedFiles(){
var g = $('#searchfiles').val();
var id = $('#possfiles').find('option[value="' + g + '"]').attr('id');
if(id != undefined && id.length > 0){
replace_file_id = id.split("_")[1];
console.log(replace_file_id);
clearSearchfieldAddFile();
$("#choosenfilename").html("<b>Neue Datei:&nbsp;</b>" + g);
$("#btnDoReplaceFile").prop("disabled", false);
$("#btnDoReplaceFileSnd").prop("disabled", false);
}
}
//GROUPS
function showGroupChangeModal(tochangeid){
@ -427,9 +529,7 @@ function changeGroup(groupid, value){
dirid : workingdirid,
value : value
},
success: function( data )
{
}
success: function( data ) {}
});
}
@ -454,11 +554,75 @@ function moveFile(fileid)
html = ['<ul id="simple_list"><li><i class="fa fa-folder"></i>&nbsp;<a href="javascript:targetParentToMove({{rootid}})"><b><u>Heimverzeichnis<u></b></a>'];
createList(data["data"]["agencydirlist"], l);
$("#agencydirlist").html(html);
}
});
}
function doreplaceFile(dodel){
$.ajax(
{
type: "GET",
url: "{% url 'cloud-adddir' parentid %}",
data:{
action : "replacefile",
oldid : workingfileid,
newid : replace_file_id,
delold : dodel
},
success: function( data )
{
if(data["data"]["success"]){
location.href = location.href;
}
else{
$("#replaceFileModal").modal("toggle");
$('#replaceFileModal').on('hidden.bs.modal', function (e) {
$("#replaceerrModal").modal("toggle");
})
}
}
});
}
//MOVING OPERATIONS
function replaceFile(fileid)
{
workingfileid = fileid;
workingdirid = false;
replace_file_id = "";
$("#choosenfilename").html("");
$("#btnDoReplaceFile").prop("disabled", true);
$("#btnDoReplaceFileSnd").prop("disabled", true);
$("#replaceFileModal").modal("toggle");
$.ajax(
{
type: "GET",
url: "{% url 'cloud-adddir' parentid %}",
data:{
action : "getname_file",
id : workingfileid
},
success: function( data )
{
standardstring = "";
if(data["data"]["linked_standards"] != undefined && data["data"]["linked_standards"].length > 0){
standardstring = "<hr><b>Achtung!</b> Datei ist mit folgenden Standards verlinkt:<br />";
}
for(i = 0; i < data["data"]["linked_standards"].length; i++){
standardstring += (i+1) + ". " + data["data"]["linked_standards"][i]['name'];
if((i+1)< data["data"]["linked_standards"].length){
standardstring += "<br />";
}
}
$("#connectedStandardsReplace").html(standardstring);
}
});
}
var html = ['<ul id="simple_list"><li><i class="fa fa-folder"></i>&nbsp;<a href="javascript:targetParentToMove({{rootid}})"><b><u>Heimverzeichnis<u></b></a>'];
@ -648,6 +812,17 @@ function delDataFileObje(fileid){
},
success: function( data )
{
standardstring = "";
if(data["data"]["linked_standards"] != undefined && data["data"]["linked_standards"].length > 0){
standardstring = "<hr><b>Achtung!</b> Datei ist mit folgenden Standards verlinkt:<br />";
}
for(i = 0; i < data["data"]["linked_standards"].length; i++){
standardstring += (i+1) + ". " + data["data"]["linked_standards"][i]['name'];
if((i+1)< data["data"]["linked_standards"].length){
standardstring += "<br />";
}
}
$("#connectedStandards").html(standardstring);
$("#filenametodel").html("");
$("#filenametodel").html(data["data"]["filename"]);
}

View File

@ -17,7 +17,8 @@ from datetime import datetime
from users.models import AgencyGroup
from django.conf import settings
from django.http import FileResponse
from standards.models import Standards
from django.contrib import messages
'''
Prüft, ob ein Nutzer in diesen Ordner Zugriffsrechte hat. Läuft den gesamten Strang bis nach oben,
@ -150,7 +151,14 @@ def adddirbyajax(request, parent):
# RETURN FILENAME
elif(request.GET.get("action") == "getname_file"):
fileobj = DataFile.objects.get(pk=request.GET.get('id'), agency=request.user.profile.agency)
data = {'filename' : fileobj.name}
linked_standards = Standards.objects.filter(agency=request.user.profile.agency);
linked_standards_final = []
for ls in linked_standards:
if(fileobj in ls.addedfiles.all()):
linked_standards_final.append({ "id" : ls.pk, "name" : ls.name });
data = {'filename' : fileobj.name, 'linked_standards' : linked_standards_final}
# DELETE FILE
elif(request.GET.get("action") == "del_file"):
DataFile.objects.filter(pk=request.GET.get('id'), agency=request.user.profile.agency).delete()
@ -189,13 +197,38 @@ def adddirbyajax(request, parent):
elif(request.GET.get("action") == "getgroupsofdir"):
dirid = request.GET.get('dirid')
allgroupsofdir = DataDir.objects.get(pk=dirid, agency=request.user.profile.agency).visibleby.all()
grouopsid = []
for ag in allgroupsofdir:
grouopsid.append({"id" : ag.pk})
data = {"gdir" : grouopsid}
# REPLACE FILE
elif(request.GET.get("action") == "replacefile"):
oldid = DataFile.objects.get(pk=request.GET.get('oldid'), agency=request.user.profile.agency)
newid = DataFile.objects.get(pk=request.GET.get('newid'), agency=request.user.profile.agency)
if(oldid != None and newid != None and oldid != newid):
linked_standards = Standards.objects.filter(agency=request.user.profile.agency);
replacecounter = 0
for standard in linked_standards:
if(oldid in standard.addedfiles.all()):
standard.addedfiles.remove(oldid)
standard.addedfiles.add(newid)
standard.save()
replacecounter += 1
if(request.GET.get('delold') == "1"):
oldid.delete()
data = {"success" : True}
if(replacecounter > 0):
if(replacecounter == 1):
messages.success(request, f'Datei wurde in einem Standard ersetzt.')
else:
messages.success(request, f'Datei wurde in '+str(replacecounter)+' Standards ersetzt.')
else:
data = {"success" : False}
elif request.method == 'POST':
tempdir = False
tempdir = DataDir.objects.get(pk=parent)

View File

@ -327,6 +327,8 @@ if ( isIE ) {
{
alluserfields = $(".searchuserfieldstask").each(function(key, value){
specific_userfield_id = value['id'].split("_")[1];
updateLinkedStandards();
updateLinkedFiles();
checkUserVerant();
checkUserEx();
checkUserVer();
@ -334,20 +336,6 @@ if ( isIE ) {
},400);
}
var ua = window.navigator.userAgent;
var isIE = /MSIE|Trident/.test(ua);
if ( isIE ) {
//IE specific code goes here
setInterval(function()
{
alluserfields = $(".searchuserfieldstask").each(function(key, value){
specific_userfield_id = value['id'].split("_")[1];
updateLinkedStandards();
updateLinkedFiles();
});
},400);
}
//USERSTOSTANDARDS
//Verantwortlicher
act_verant = [];