Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Move Folder page contents from one page to another easily?  (Read 6045 times)
Jeff M.
Posts: 38


« on: August 28, 2019, 01:01:09 pm »

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.
Jeff M.
Posts: 38


« Reply #1 on: August 28, 2019, 03:15:10 pm »

Don't worry, it was simple enough to write a function to do it.

Incase anyone ever needs to:

Code
  1. # Will swap the SINGLE child of page 1 and the single child of page 2 with each other
  2. #
  3. FUNCTION swap_page_contents(f_page_from, f_page_to)
  4.  
  5.    DEFINE f_page_from, f_page_to           STRING
  6.  
  7.    DEFINE fw_window                        ui.Window       -- Your window
  8.  
  9.    DEFINE fd_page_from, fd_page_to         om.DomNode      -- The pages
  10.    DEFINE fd_cont_from, fd_cont_to         om.DomNode      -- The content
  11.  
  12.    LET fw_window       = ui.Window.getCurrent()
  13.  
  14.    LET fd_page_from    = fw_window.findNode("Page", f_page_from)
  15.    IF ( fd_page_from IS NULL )
  16.    THEN
  17.        ERROR SFMT("Page '%1' could not be got", f_page_from CLIPPED)
  18.        RETURN FALSE
  19.    END IF
  20.    IF ( fd_page_from.getChildCount() != 1 )        -- For simplicity we want to move one big block, not several
  21.    THEN
  22.        ERROR SFMT("Page '%1' has too many children to move", f_page_from CLIPPED)
  23.        RETURN FALSE
  24.    END IF
  25.  
  26.    LET fd_page_to      = fw_window.findNode("Page", f_page_to  )
  27.    IF ( fd_page_to   IS NULL )
  28.    THEN
  29.        ERROR SFMT("Page '%1' could not be got", f_page_to   CLIPPED)
  30.        RETURN FALSE
  31.    END IF
  32.    IF ( fd_page_to.getChildCount() != 1 )        -- For simplicity we want to move one big block, not several
  33.    THEN
  34.        ERROR SFMT("Page '%1' has too many children to move", f_page_to CLIPPED)
  35.        RETURN FALSE
  36.    END IF
  37.  
  38.    LET fd_cont_from    =   fd_page_from.getFirstChild()
  39.    LET fd_cont_to      =   fd_page_to.getFirstChild()
  40.  
  41.    CALL fd_page_from.removeChild(fd_cont_from)     -- Will orphan fd_cont_from
  42.    CALL fd_page_to.removeChild(fd_cont_to)         -- Will orphan fd_cont_to
  43.  
  44.    CALL fd_page_to.appendChild(fd_cont_from)       -- Now attaches fd_cont_from to page fd_page_to
  45.    CALL fd_page_from.appendChild(fd_cont_to)       -- Now attaches fd_cont_to to page fd_page_from
  46.  
  47.    RETURN TRUE
  48.  
  49. END FUNCTION
and then:
Code
  1.        ON ACTION fcf_1401reqsl
  2.            IF ( m_has_content != "fcf_1401reqsl" )    -- m_has_content defaulted to fcf_1401reqsl earlier
  3.            THEN
  4.                IF ( swap_page_contents("fcf_1401reqmc", "fcf_1401reqsl") = TRUE )
  5.                THEN
  6.                    LET m_has_content = "fcf_1401reqsl"
  7.                END IF
  8.            END IF
  9.  
  10.        ON ACTION fcf_1401reqmc
  11.            IF ( m_has_content != "fcf_1401reqmc" )
  12.            THEN
  13.                IF ( swap_page_contents("fcf_1401reqsl", "fcf_1401reqmc") = TRUE )
  14.                THEN
  15.                    LET m_has_content = "fcf_1401reqmc"
  16.                END IF
  17.            END IF
  18.  
  19.  
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines