Menu

$oPage->add_ready_script doesnt work in itop3.2.0

2024-10-31
2024-11-06
  • SITEDJEYA FOTSO Brondon Stael

    Hello everyone,

    i am migrating my itop to 2.7 to 3.2 and i am facing one issue with my custom extension,

    it seems like $oPage->add_ready_script() doesnt work anymore, but i havent see a notice about that in changelog.

    this code works well in itop2.7

    class ChangeCustom implements iApplicationUIExtension {
    
    public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false) {
    $oPage->add_ready_script("console.log('Hello, world!');");
    
    }
    }
    

    But in itop3.2 it doesn't work,

    my question is add_ready_script is deprecated? and how to do the same way in the new version

    thank you

     
  • Stephen Abello

    Stephen Abello - 2024-11-04

    Hi,
    This interface should still work in iTop 3.2. Have you tried debugging/adding trace to ensure your code is interpreted ?

    Since iTop 3.0 you can also use this interface to add ready scripts:

    /**
     * Implement this interface to add inline script (JS) to the backoffice pages that will be executed slightly AFTER the DOM is ready (just after the init. scripts).
     *
     * @see \iTopWebPage::$a_ready_scripts
     * @api
     * @package BackofficeUIExtensibilityAPI
     * @since 3.0.0
     */
    interface iBackofficeReadyScriptExtension
    {
        /**
         * @api
         * @see \iTopWebPage::$a_ready_scripts
         * @return string
         */
        public function GetReadyScript(): string;
    }
    

    Hope this helps,
    Stephen

     
  • SITEDJEYA FOTSO Brondon Stael

    Hi,

    Thanks for your reply,

    i will try iBackofficeReadyScriptExtension interface, it looks well 😊

    i have another question about ev_approve stimulus on change class,
    this action leads to a form that can no longer be extended with iApplicationUIExtension::OnDisplayProperties(), is there any change from that too?

    public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false) {
    if ($oObject instanceof Change && $bEditMode == false) {
         if (isset($_GET['stimulus']) && $_GET['stimulus'] == 'ev_approve') {
              $oPage->add_ready_script("console.log('Hello, world!');");
          }
    }
    }
    

    Expected Result: Hello word in the console on the change approval form

    is there anything i missed ?

    I attach the first image (the button for approve change)
    and the second image (the form page which is not extended by OnDisplayProperties)

     
  • Stephen Abello

    Stephen Abello - 2024-11-06

    Ok I think I understand what's going on, OnDisplayProperties is called when the properties are displayed, meaning when the details of an object are displayed.

    In iTop 2.7 you had the details displayed under the transition form.

    Going forward with iTop 3.0 we removed these properties and only displayed the form, so the OnDisplayProperties method is not called anymore on this page.

    We encourage using the iBackofficeXXXExtension as giving direct access to the $oPage element as it allowed developer to do anything on it, which was to complicated for us to maintain and guarantee over time.

    Moreover you'll have access to more meta data in the console starting with iTop 3.0 allowing your scripts to do some checks to, example for transitions:

    <div class="object-transition" data-object-class="UserRequest" data-object-id="4" data-object-mode="stimulus" data-object-current-state="new" data-object-target-state="assigned">
    
     
    ❤️
    1
    • SITEDJEYA FOTSO Brondon Stael

      Hello Stephen,

      Thank you for your reply, i think you understood what is going on 😃

      Please where i could find the documentation of iBackofficeXXXExtension, i couldnt find it to the itop doc. plus

      in the form transition i want to access to objects detail in my script to prefill the start_date and end_date with javascript as image below, the iBackofficeXXXExtension combined to meta-data can do so ?

      thank you.

       
      • Stephen Abello

        Stephen Abello - 2024-11-06

        Our documentation on the developers APIs is not that complete yet, I'd recommend going to this page and if you need check examples on how it can be used

        For your specific case I think using Form Prefill and more specifically Prefill Transition Form would be easier and really suit your needs (and would also work in the Portal/Kanban board/ and transitions in popups if we add it one day 😁)

         
        • SITEDJEYA FOTSO Brondon Stael

          Hello Stephen,

          the iBackOffice interface works well, and the Prefill Transition form also 😃

          thanks you for your help

           
          🎉
          1
          • Stephen Abello

            Stephen Abello - 2024-11-06

            Glad to see it works! :)

             
  • SITEDJEYA FOTSO Brondon Stael

    Okay let's check all of that, get you soon

    thank you Stephen

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.