###
### Copyright (C) Infopark AG.
###

if {[app get appName] != "CM"} {
    return
}

namespace eval changeSortOrder {
    source [file join [app get shareScriptDir] serverCmds wizards lib\
            wizardController.tcl]

    proc handleInitPage {button} {
        variable objIds
        set objId1 [getParam "wizard.objid1"]
        set objId2 [getParam "wizard.objid2"]

        catch {obj withId $objId1 edit}
        catch {obj withId $objId2 edit}
        catch {obj withId $objId1 take}
        catch {obj withId $objId2 take}
        set sortKey [obj withId [obj withId $objId1 get parent] get sortKey1]
        set tmpSortValue [obj withId $objId1 editedContent get $sortKey]
        obj withId $objId1 editedContent set $sortKey\
                [obj withId $objId2 editedContent get $sortKey]
        obj withId $objId2 editedContent set $sortKey $tmpSortValue
        #addNpsRefresh [lindex $objIds 0] subtree
        addNpsRefresh $objId1
        addNpsRefresh $objId2
        return ""
    }
}
