Hi All,
I have a situation where I need 2 pages in a folder that are identical (almost) but serve different purposes. What I don't want to do is write two different dialog blocks to handle them.
Normally I would probably have them in one page with a toggle but that isn't clear enough on this application so I definitely need two pages in the folder.
My question - is there an easy was to move the dom contents of a page to another page (and back) according to which page has been clicked? Effectively changing the parent id of the a dom container object in the page 1 to page 2.
I would expect I would need another container object to keep each page valid, eg:
FOLDER myfolder
PAGE page1
VBOX page1_root
VBOX page_contents
-- all the stuff I want
END -- VBOX page_contents
END -- VBOX page1_root
END -- PAGE page1
PAGE page2
VBOX page2_root
END -- VBOX page2_root
END -- PAGE page2
END -- FOLDER
So attach the node page_contents (or all the children of page1_root) to page2_root.
I would appreciate any help on this as it is a very large dialog block I would need to duplicate just to make it look better.
Don't worry, it was simple enough to write a function to do it.
Incase anyone ever needs to:
# Will swap the SINGLE child of page 1 and the single child of page 2 with each other
#
FUNCTION swap_page_contents(f_page_from, f_page_to)
DEFINE f_page_from, f_page_to STRING
DEFINE fw_window ui.Window -- Your window
DEFINE fd_page_from, fd_page_to om.DomNode -- The pages
DEFINE fd_cont_from, fd_cont_to om.DomNode -- The content
LET fw_window = ui.Window.getCurrent()
LET fd_page_from = fw_window.findNode("Page", f_page_from)
IF ( fd_page_from IS NULL )
THEN
ERROR SFMT("Page '%1' could not be got", f_page_from CLIPPED)
RETURN FALSE
END IF
IF ( fd_page_from.getChildCount() != 1 ) -- For simplicity we want to move one big block, not several
THEN
ERROR SFMT("Page '%1' has too many children to move", f_page_from CLIPPED)
RETURN FALSE
END IF
LET fd_page_to = fw_window.findNode("Page", f_page_to )
IF ( fd_page_to IS NULL )
THEN
ERROR SFMT("Page '%1' could not be got", f_page_to CLIPPED)
RETURN FALSE
END IF
IF ( fd_page_to.getChildCount() != 1 ) -- For simplicity we want to move one big block, not several
THEN
ERROR SFMT("Page '%1' has too many children to move", f_page_to CLIPPED)
RETURN FALSE
END IF
LET fd_cont_from = fd_page_from.getFirstChild()
LET fd_cont_to = fd_page_to.getFirstChild()
CALL fd_page_from.removeChild(fd_cont_from) -- Will orphan fd_cont_from
CALL fd_page_to.removeChild(fd_cont_to) -- Will orphan fd_cont_to
CALL fd_page_to.appendChild(fd_cont_from) -- Now attaches fd_cont_from to page fd_page_to
CALL fd_page_from.appendChild(fd_cont_to) -- Now attaches fd_cont_to to page fd_page_from
RETURN TRUE
END FUNCTION
and then:
ON ACTION fcf_1401reqsl
IF ( m_has_content != "fcf_1401reqsl" ) -- m_has_content defaulted to fcf_1401reqsl earlier
THEN
IF ( swap_page_contents("fcf_1401reqmc", "fcf_1401reqsl") = TRUE )
THEN
LET m_has_content = "fcf_1401reqsl"
END IF
END IF
ON ACTION fcf_1401reqmc
IF ( m_has_content != "fcf_1401reqmc" )
THEN
IF ( swap_page_contents("fcf_1401reqsl", "fcf_1401reqmc") = TRUE )
THEN
LET m_has_content = "fcf_1401reqmc"
END IF
END IF