mardi 10 mai 2016

Logging a checkbox's state in Velocity

I am attempting to write a custom macro within Confluence that would create a custom table and I was hoping that I would be able to provide a date as to when tasks are marked started and completed. I have included the code below. I am also having trouble saving the "state" of the checkboxes, ie when the page reloads they are no longer checked.

Any help would be greatly appreciated.

## @noparams

## Defining variables:
#set ($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set ($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set ($containerManager = $getInstanceMethod.invoke(null,null))
#set ($containerContext = $containerManager.containerContext)
#set ($contentPropertyManager=$containerContext.getComponent('contentPropertyManager'))
#set ($d = '$')
#set ($users = $userAccessor.getUsers())
#set ($t1 = $content.currentDate)

#set($taskList = ["Task1", "Task2", "Task3", "Task4"])

<table class="confluenceTable">

    <tr>
        <td> Started </td>
        <td> Completed </td>
        <td> Task </td>
        <td> User ID </td>
    </tr>

    #if ($body != "")
        <form class = "aui" id="dynCheckboxForm">

        #foreach ($box in $taskList)
            #if($contentPropertyManager.getStringProperty($content, "dynCheckbox$box") == "checked")
                #set($checked = 'checked="checked"')
            #else
                #set($checked = '')
            #end

            <tr>
                <td>
                    <div class="checkbox">
                        <input class="checkbox dynCheckbox" type="checkbox" name="dynCheckbox$box" id="dynCheckbox$box" $checked value="checked"/>
                        <label for="dynCheckbox$box"></label>
                    </div> 
                </td>
                <td>
                    <div class="checkbox">
                        <input class="checkbox dynCheckbox" type="checkbox" name="dynCheckbox$box" id="dynCheckbox2$box" $checked value="checked"/>
                        <label for="dynCheckbox$box"></label>
                    </div> 
                </td>           
                <td><b>$box</b></td>
                <td>userID</td>
            </tr>
        #end
        </form>
    #end
</table>

<script type="text/javascript">

var checkBoxFlag = document.getElementById("dynCheckboxAlpha").checked;
if(checkBoxFlag){
    document.getElementById("dynCheckboxAlpha").innerHTML = "testing";
}

AJS.toInit(function(){
    AJS.$('.dynCheckbox').click(function(){
        AJS.${d}.ajax({
            type: 'GET',
            data: {
                submit: 'true',
                checkbox: AJS.$(this).attr('id'),
                value: AJS.$(this).is(':checked') ? 'checked' : ''
            },
            url: "$content.getUrlPath()",
            success: function(data) {
            },
            error: function() {
            }
        });
    });
});
</script>

Aucun commentaire:

Enregistrer un commentaire