Organigramm double-id-bug bei agency und user gelöst
This commit is contained in:
parent
37887f153c
commit
909db14c75
|
|
@ -26,29 +26,28 @@ margin-right:auto;">
|
|||
|
||||
|
||||
var data = [
|
||||
{ 'id' : '{{request.user.profile.agency.pk}}', 'parent' : "", 'role': "", 'name': '{{request.user.profile.agency.name}}', 'color': '#71AF17', "imageUrl": ""},
|
||||
{ 'id' : '{{request.user.profile.agency.pk}}', 'parent' : "", 'role': "", 'name': '{{request.user.profile.agency.name}}', 'color': '#71AF17', "imageUrl": "", 'children' : []},
|
||||
{% for u in agencyuser %}
|
||||
{% if u.profile.parent == u %}
|
||||
{ 'id': '{{u.pk}}' , 'name': "{{u.first_name}} {{u.last_name}}",'role': '<b>{{u.profile.get_func_display}}</b></br >{{u.profile.compfunc}}', 'parent': "{{request.user.profile.agency.pk}}", 'color': '#1859B7', "imageUrl": "{{u.profile.get_photo_url}}", 'userid' : '{{u.pk}}' },
|
||||
{ 'id': '{{u.pk}}' , 'name': "{{u.first_name}} {{u.last_name}}",'role': '<b>{{u.profile.get_func_display}}</b></br >{{u.profile.compfunc}}', 'parent': "{{request.user.profile.agency.pk}}", 'color': '#1859B7', "imageUrl": "{{u.profile.get_photo_url}}", 'userid' : '{{u.pk}}', 'children' : [] },
|
||||
{% else %}
|
||||
{ 'id': '{{u.pk}}', 'name': "{{u.first_name}} {{u.last_name}}", 'role': '<b>{{u.profile.get_func_display}}</b></br >{{u.profile.compfunc}}', 'parent': '{{u.profile.parent.pk}}', 'color': '#1859B7', "imageUrl": "{{u.profile.get_photo_url }}", 'userid' : '{{u.pk}}'},
|
||||
{ 'id': '{{u.pk}}', 'name': "{{u.first_name}} {{u.last_name}}", 'role': '<b>{{u.profile.get_func_display}}</b></br >{{u.profile.compfunc}}', 'parent': '{{u.profile.parent.pk}}', 'color': '#1859B7', "imageUrl": "{{u.profile.get_photo_url }}", 'userid' : '{{u.pk}}', 'children' : []},
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
];
|
||||
|
||||
/*
|
||||
var data = [
|
||||
{'id' : 11, 'name' : 'AGENCY', 'parent' : "", 'children': []},
|
||||
{'id' : 2, 'name' : 'Holger', 'parent' : 11, 'children' : []},
|
||||
{'id' : 9, 'name' : 'Felix', 'parent' : 11, 'children' : []},
|
||||
{'id' : 1, 'name' : 'Marko', 'parent' : 2, 'children' : []},
|
||||
{'id' : 23, 'name' : 'Janina', 'parent' : 1, 'children' : []},
|
||||
{'id' : 6, 'name' : 'Franziska', 'parent' : 1, 'children' : []},
|
||||
{'id' : 12, 'name' : 'Berthold', 'parent' : 6, 'children' : []},
|
||||
{'id' : 7, 'name' : 'Jürgen', 'parent' : 23, 'children' : []}
|
||||
];
|
||||
//Check for Agency and User-IDs - dont touch the userid for URLs!
|
||||
for(i = 0; i < data.length; i++){
|
||||
for(k = 0; k < data.length; k++){
|
||||
if(k != i){
|
||||
if(data[i]['id'] == data[k]['id']){
|
||||
data[k]['id'] = data[k]['id']*10;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
//Creates nested array from data
|
||||
function unflatten(arr) {
|
||||
var tree = [],
|
||||
mappedArr = {},
|
||||
|
|
@ -78,37 +77,9 @@ function unflatten(arr) {
|
|||
return tree;
|
||||
}
|
||||
|
||||
function unflattenList(arr) {
|
||||
var tree = [],
|
||||
mappedArr = {},
|
||||
arrElem,
|
||||
mappedElem;
|
||||
|
||||
// First map the nodes of the array to an object -> create a hash table.
|
||||
for(var i = 0, len = arr.length; i < len; i++) {
|
||||
arrElem = arr[i];
|
||||
mappedArr[arrElem.id] = arrElem;
|
||||
mappedArr[arrElem.id]['children'] = [];
|
||||
}
|
||||
|
||||
for (var id in mappedArr) {
|
||||
if (mappedArr.hasOwnProperty(id)) {
|
||||
mappedElem = mappedArr[id];
|
||||
// If the element is not at the root level, add it to its parent array of children.
|
||||
if (mappedElem.parent) {
|
||||
mappedArr[mappedElem['parent']]['children'].push(mappedElem);
|
||||
}
|
||||
// If the element is at the root level, add it to first level elements array.
|
||||
else {
|
||||
tree.push(mappedElem);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
var html = ['<ul class="tree">'];
|
||||
|
||||
//Create UL-LI-List for tree
|
||||
function createList(arr) {
|
||||
html.push('<ul>');
|
||||
$.each(arr, function(i, val) {
|
||||
|
|
@ -116,7 +87,7 @@ function createList(arr) {
|
|||
html.push('<li><a href="#"><h4>' + val.name + "</h4></a>");
|
||||
}
|
||||
else {
|
||||
html.push('<li><a href="#" onclick="goToUser('+ val.id +')"><img src="'+val.imageUrl+'" width="125px"><h5>' + val.name + "</h5></ br><small>"+val.role+"</small></a>");
|
||||
html.push('<li><a href="#" onclick="goToUser('+ val.userid +')"><img src="'+val.imageUrl+'" width="125px"><h5>' + val.name + "</h5></ br><small>"+val.role+"</small></a>");
|
||||
}
|
||||
if (val.children) {
|
||||
createList(val.children)
|
||||
|
|
@ -128,6 +99,7 @@ function createList(arr) {
|
|||
|
||||
createList(unflatten(data));
|
||||
|
||||
//Remove double ul/ul-Elements at the End
|
||||
for(i = 0; i < html.length; i++){
|
||||
if(html[i+1] != undefined){
|
||||
if(html[i] == "<ul>" && html[i+1] == "</ul>"){
|
||||
|
|
@ -141,86 +113,5 @@ function goToUser(id){
|
|||
}
|
||||
|
||||
$('#diagram').append(html.join(''));
|
||||
//html = addLiEle(data[0]['children'], "<ul class='tree'><li>" + data[0]['name'] + "</li><ul>");
|
||||
|
||||
//$("#diagram").html(html);
|
||||
|
||||
|
||||
/*
|
||||
function createList(parent, array) {
|
||||
console.log(parent);
|
||||
|
||||
for(i = 0; i < array.length; i++){
|
||||
|
||||
var li = document.createElement("li"),
|
||||
ul;
|
||||
|
||||
li.textContent = array[i].name;
|
||||
parent.appendChild(li);
|
||||
if (array[i].children) {
|
||||
ul = document.createElement("ul");
|
||||
|
||||
li.appendChild(ul);
|
||||
//createList(ul, array[i].id);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
/*
|
||||
var obj = data;
|
||||
var x = "";
|
||||
$.each(obj, function(index, value) {
|
||||
x += '<li>'+value.parent+'</li>';
|
||||
if(value.children[0]){
|
||||
var s = '<ul>';
|
||||
$.each(value.children, function(i, v) {
|
||||
s += "<li>"+v.name+"</li>";
|
||||
});
|
||||
s += '</ul>'
|
||||
x += s;
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
for(i = 0; i < agdata.length; i++){
|
||||
//Wenn ID und PARENT gleich sind, wrid nichts gemacht
|
||||
for(k = i+1; k < agdata.length; k++){
|
||||
if(agdata[i]['id'] == agdata[k]['parent']){
|
||||
agdata[i]['children'].push(agdata[k]);
|
||||
agdata.splice(k, 1);
|
||||
k = k - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < agdata.length; i++){
|
||||
if(agdata[i]['children'].length > 0){
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
function goToUser(){
|
||||
if(diagram.selectedItems['nodes'][0] != undefined){
|
||||
selected_id = diagram.selectedItems['nodes'][0]['properties']['data']['id'];
|
||||
if(selected_id != 'parent'){
|
||||
$("#diagram").hide();
|
||||
$("#spinner").show();
|
||||
window.location.href = "/orga/single/"+selected_id;
|
||||
}
|
||||
else{
|
||||
$("#diagram").hide();
|
||||
$("#spinner").show();
|
||||
window.location.href = "/orga/";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
</script>
|
||||
{% endblock content %}
|
||||
Loading…
Reference in New Issue