Commit f6616863 authored by Andreas Valder's avatar Andreas Valder
Browse files

redid perm editor. closes #308

parent 0136e164
......@@ -141,121 +141,136 @@ var moderator = {
}
},
init: function () {
$('.modmoderator_permissioneditor').popover(
{
title: "Zugriffsrechte",
html: true,
placement: "left",
trigger: 'click',
container: 'body',
content: function () {
var html = '';
var id = $(this).data('id');
var type = $(this).data('type');
html += '<div width="300px" class="row" data-id="'+id+'" data-type="'+type+'">';
html += '<select onchange="moderator.permissioneditor.selectpermission(this)" size="6" class="col-xs-12 permissionlist">';
var idlist = [];
for (i in moderator.permissioneditor.permissions) {
if ((moderator.permissioneditor.permissions[i][type+'_id'] == id)) {
var perm = {};
perm.type = moderator.permissioneditor.permissions[i]['type'];
perm.param1 = moderator.permissioneditor.permissions[i]['param1'];
perm.param2 = moderator.permissioneditor.permissions[i]['param2'];
perm.id = moderator.permissioneditor.permissions[i]['id'];
idlist[idlist.length] = perm.id;
$('#editperm').on('show.bs.modal', function (e) {
var srcel = e.relatedTarget;
if (!srcel) {
return 0;
}
var id = $(srcel).data('id');
var type = $(srcel).data('type');
$('#editpermdiv').data('id',id);
$('#editpermdiv').data('type',type);
var html = ''
for (i in moderator.permissioneditor.permissions) {
if ((moderator.permissioneditor.permissions[i][type+'_id'] == id)) {
var perm = {};
perm.type = moderator.permissioneditor.permissions[i]['type'];
perm.param1 = moderator.permissioneditor.permissions[i]['param1'];
perm.param2 = moderator.permissioneditor.permissions[i]['param2'];
perm.id = moderator.permissioneditor.permissions[i]['id'];
permstring = '';
switch (perm.type) {
case 'password':
permstring = '("'+perm.param1+'":"'+perm.param2+'")'
break;
case 'public':
permstring = '';
switch (perm.type) {
case 'password':
permstring = '("'+perm.param1+'":"'+perm.param2+'")'
break;
case 'public':
permstring = '';
break;
case 'none':
permstring = '(Kein Zugriff)';
break;
case 'rwth':
permstring = '(RWTH-intern)'
break;
case 'fsmpi':
permstring = '(FS-intern)'
break;
case 'l2p':
permstring = '(' + perm.param1 + ')'
break;
}
html += '<option data-auth_id="'+perm.id+'">#'+perm.id+' '+perm.type+' '+ permstring +'</option>';
}
break;
case 'none':
permstring = '(Kein Zugriff)';
break;
case 'rwth':
permstring = '(RWTH-intern)'
break;
case 'fsmpi':
permstring = '(FS-intern)'
break;
case 'l2p':
permstring = '(' + perm.param1 + ')'
break;
}
html += '</select>';
html += '<select class="col-xs-12 authtype" onchange="moderator.permissioneditor.typechange(this)">';
html += '<option value="public">Öffentlich</option>';
html += '<option selected value="password">Passwort</option>';
html += '<option value="rwth">RWTH intern</option>';
html += '<option value="fsmpi">FSMPI intern</option>';
html += '<option value="l2p">L2P Lernraum</option>';
html += '<option value="none">Kein Zugriff</option>';
html += '</select>';
html += '<input class="col-xs-12 passwordinput authuser" type="text" placeholder="Benutzername">';
html += '<input class="col-xs-10 passwordinput authpassword" type="text" placeholder="Passwort">'
html += '<button class="col-xs-2 passwordinput authpgen" type="button" onclick="$(\'.authpassword\',this.parentNode).val(moderator.permissioneditor.randompw());"><span class="fa fa-plus" aria-hidden="true"></span></button>'
html += '<input class="col-xs-12 authl2p" type="text" placeholder="Lernraum" style="display: none;">';
html += '<button class="col-xs-6" onclick="moderator.permissioneditor.addbtnclick(this)">Add</button>';
//html += '<button class="col-xs-4" onclick="moderator.permissionedior.updatebtnclick(this)">Update</button>';
html += '<button class="col-xs-6" onclick="moderator.permissioneditor.delbtnclick(this)">Delete</button>';
html += '</div>';
return html;
html += '<option data-id="'+perm.id+'" data-type="'+perm.type+'" data-param1="'+perm.param1+'" data-param2="'+perm.param2+'">#'+perm.id+' '+perm.type+' '+ permstring +'</option>';
}
}
);
},
selectpermission: function (element) {
}
$('#permissionlist').html(html);
});
},
delbtnclick: function (element) {
moderator.api.set("perm."+$(".permissionlist option:selected", element.parentElement).data('auth_id')+".deleted",1,true);
},
addbtnclick: function (element) {
var perm = {};
perm.type = $(".authtype", element.parentElement).val();
selectpermission: function (element) {
var perm = $('#permissionlist option:selected').data();
if (!perm) {
return;
}
var container = $('#editpermdiv');
moderator.permissioneditor.typechangehandler(perm.type, container);
switch(perm.type) {
case 'password':
perm.param1 = $(".authuser", element.parentElement).val();
perm.param2 = $(".authpassword", element.parentElement).val();
$(".authuser", container).val(perm.param1);
$(".authpassword", container).val(perm.param2);
break
case 'l2p':
perm.param1 = $(".authl2p", element.parentElement).val();
$(".authl2p", container).val(perm.param1);
break
}
$(".authtype option[value="+perm.type+"]").prop("selected", true);
},
delbtnclick: function (element) {
moderator.api.set("perm."+$("#permissionlist option:selected", element.parentElement).data('id')+".deleted",1,true);
},
addbtnclick: function (element) {
var container = element.parentElement;
var perm = moderator.permissioneditor.getpermform(container);
dict = {}
dict['type'] = perm.type;
dict['param1'] = perm.param1;
dict['param2'] = perm.param2;
dict[$(element.parentElement).data('type')+'_id'] = $(element.parentElement).data('id');
dict[$(container).data('type')+'_id'] = $(container).data('id');
moderator.api.add_new(dict,'perm',true);
var option = $('<option>', {
"text": perm.type+' '+( perm.type == "password" ? ' ("'+perm.param1+'":"'+perm.param2+'")' : '' ) ,
"data-auth": JSON.stringify(perm)
});
$(".permissionlist",element.parentElement).append(option);
$("#permissionlist",element.parentElement).append(option);
},
updatebtnclick: function (element) {
var container = element.parentElement
var perm = moderator.permissioneditor.getpermform(container);
var id = $("#permissionlist option:selected", element.parentElement).data('id');
if (!id) {
return;
}
var dict = {};
for (i in perm) {
dict['perm.'+id+'.'+i] = perm[i];
}
console.log(dict);
moderator.api.set_multi(dict,true)
},
getpermform: function (container) {
var perm = {};
perm.type = $(".authtype", container).val();
switch(perm.type) {
case 'password':
perm.param1 = $(".authuser", container).val();
perm.param2 = $(".authpassword", container).val();
break
case 'l2p':
perm.param1 = $(".authl2p", container).val();
break
}
return perm;
},
typechange: function (element) {
switch ($(element).val()) {
$("#permissionlist option:selected").prop("selected", false);
moderator.permissioneditor.typechangehandler($(element).val(),element.parentElement);
},
typechangehandler: function (type, container) {
$(".authuser", container).val('');
$(".authpassword", container).val('');
$(".authl2p", container).val('');
switch (type) {
case 'password':
$(".passwordinput",element.parentElement).show();
$(".authl2p",element.parentElement).hide();
$(".passwordinput",container).show();
$(".authl2p",container).hide();
break;
case 'l2p':
$(".passwordinput",element.parentElement).hide();
$(".authl2p",element.parentElement).show();
$(".passwordinput",container).hide();
$(".authl2p",container).show();
break;
default:
$(".passwordinput",element.parentElement).hide();
$(".authl2p",element.parentElement).hide();
$(".passwordinput",container).hide();
$(".authl2p",container).hide();
break;
}
},
......@@ -263,8 +278,9 @@ var moderator = {
var array = new Uint8Array(10);
window.crypto.getRandomValues(array);
var result = '';
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
for (var i = 0; i< array.length; i++) {
result += String.fromCharCode(48+ (array[i]/255.0)*74);
result += chars.charAt(array[i] % chars.length);
}
return result;
}
......
......@@ -98,6 +98,42 @@
</ul>
</div>
{% if ismod() %}
<div class="modal fade" id="editperm" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Zugriffsrechte</h4>
</div>
<div class="modal-body">
<div class="row" style="padding-left: 10px; padding-right: 10px;" data-id="-1" data-type="-1" id="editpermdiv">
<span>Es existieren folgende Zugriffsrechte:</span>
<select onchange="moderator.permissioneditor.selectpermission(this)" size="6" class="col-xs-12" id="permissionlist">
</select>
<select class="col-xs-12 authtype" onchange="moderator.permissioneditor.typechange(this)">
<option value="public">Öffentlich</option>
<option selected value="password">Passwort</option>
<option value="rwth">RWTH intern</option>
<option value="fsmpi">FSMPI intern</option>
<option value="l2p">L2P Lernraum</option>
<option value="none">Kein Zugriff</option>
</select>
<input class="col-xs-12 passwordinput authuser" type="text" placeholder="Benutzername">
<input class="col-xs-10 passwordinput authpassword" type="text" placeholder="Passwort">
<button class="col-xs-2 passwordinput authpgen" type="button" onclick="$('.authpassword',this.parentNode).val(moderator.permissioneditor.randompw());"><span class="fa fa-refresh" aria-hidden="true"></span></button>
<input class="col-xs-12 authl2p" type="text" placeholder="Lernraum" style="display: none;">
<button class="col-xs-4" onclick="moderator.permissioneditor.addbtnclick(this)">Add</button>
<button class="col-xs-4" onclick="moderator.permissioneditor.updatebtnclick(this)">Update</button>
<button class="col-xs-4" onclick="moderator.permissioneditor.delbtnclick(this)">Delete</button>
</div>
</div>
</div>
</div>
</div>
<script>
$.ajax({
method: "GET",
......
......@@ -323,12 +323,12 @@ $('#embedcodebtn').popover(
{% endif %}
{% if ismod() %}
<button class="btn btn-default modmoderator_permissioneditor" data-type="{{ type }}" data-id="{{ id }}">
{{ permlogos|safe }}
<button class="btn btn-default" data-toggle="modal" data-target="#editperm" data-type="{{ type }}" data-id="{{ id }}">
{{ permlogos|safe }}
</button>
{% else %}
<span title="{{permdescription[1]}}">
{{ permlogos|safe }}
{{ permlogos|safe }}
</span>
{% endif %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment