/templates/sitepreferences.tmpl
Type: /type/template
body: value: $def with (permissions)

$var title: Site Preferences

<script src="/static/js/repetition/repetition-model.js"></script>

<form method="POST">

<table>
<tbody>    
<tr id="paths" repeat="template">
    <td>
        <table>
            <tbody>
            <tr>
                <td>Path</td>
                <td>Who</td>
                <td>What</td>
                <td></td>
            </tr>
            <tr>
                <td>
                    <input id="path[paths]_text"type="text" name="path[paths]"/>
                    <input type="hidden" name="order" value="[paths]"/>
                </td>
                <td></td>
                <td></td>
                <td>
                    <button type="remove">Delete Path</button>
                    <button type="move-up">Move Up</button>
                    <button type="move-down">Move Down</button>
                </td>
            </tr>
            </tbody>
            <tbody>
                <tr id="path[paths]" repeat="template">
                    <td></td>
                    <td><input id="who[path[paths]]_[paths]" name="who[path[paths]]_path[paths]"/></td>
                    <td><input id="what[path[paths]]_[paths]" name="what[path[paths]]_path[paths]"/></td>
                    <td><button type="remove">Delete</button></td>
                </tr>
                <tr>
                    <td></td>
                    <td><button id="newperm_[paths]" type="add" template="path[paths]">New Permission</button></td>
                    <td></td>
                    <td></td>
                </tr>
            </tbody>            
        </table>
    </td>
</tr>
</tbody>

<tbody>
<tr>
    <td>
        <table>
            <tr>
                <td><button id="newpath" type="add" template="paths">New Path</button></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </table>
    </td>
</tr>
</tbody>
</table>

<script>
function click_add_button(id) {
    var button = document.getElementById(id);
    //@@ Hack to click add button programatically
    RepetitionElement._addButton_click.apply(button);    
}
function add_newpath(i, path) {
    click_add_button('newpath')
    document.getElementById('path' + i + '_text').value = path;    
}
function add_newperm(i, j, who, what) {
    click_add_button('newperm_' + i)
    document.getElementById('who' + j + '_' + i).value =  who;    
    document.getElementById('what' + j + '_' + i).value =  what;    
}

function setup() {
    $ i = 0
    $for item in permissions:
        $ path = item[0]
        $ perms = item[1]
        add_newpath($i, "$path");
        $ j = 0
        $for perm in perms:
            $ who = perm[0]
            $ what = perm[1]
            add_newperm($i, $j, "$who", "$what")
            $ j = j + 1
        $ i = i + 1
}
window.onload = setup;
</script>

<input type="submit" value="Save"/>
</form>

title: sitepreferences template