Last active
May 2, 2018 12:01
-
-
Save thaim/da63951c585bfd5c66905cdcd12457b7 to your computer and use it in GitHub Desktop.
redmine 'view customize plugin' script to show subprojects in table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Path pattern: /projects/[a-z0-9\-_]+$ | |
// Type : JavaScript | |
$(function() { | |
var box = document.getElementsByClassName('projects box')[0] | |
var leaf = $(box).children('a'); | |
var rows = []; | |
for (var i=0; i<leaf.length; i++) { | |
rows.push(createRow(leaf.eq(i))); | |
} | |
rows.sort(function(a, b){ | |
return a.text() <= b.text() ? -1:1; | |
}); | |
var table = $('<table class="list"></table>'); | |
for (var i=0; i<rows.length; i++) { | |
table.append(rows[i].addClass((i % 2 == 0) ? 'odd' : 'even')); | |
} | |
var dataNodes = Array.prototype.slice.call($(box)[0].childNodes); | |
for (var i=0; i<dataNodes.length; i++) { | |
if (dataNodes[i].nodeType == 3) { | |
dataNodes[i].parentNode.removeChild(dataNodes[i]); | |
} | |
} | |
$(box).append(table); | |
function createRow(target) { | |
var tr = $('<tr>'); | |
tr.addClass('project').addClass('child').addClass('leaf'); | |
tr.append($('<td>').append($('<span>').append(target)).addClass('name')); | |
return tr; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment