Menu

iTop 3 Alert-Banner

Nico
2023-10-12
2023-10-13
  • Nico

    Nico - 2023-10-12

    Hi,
    I started to migrate our custom extensions to iTop 3.
    In iTop 2.x I used a lot of message banners (like the success banner when creating an object).
    In iTop 3 I now want to use the functions that are already implemented but I only get the banner appended to the site (as seen in the screenshot).
    I use this class and function to place the banner:

    class NM_adds implements iApplicationUIExtension
    {
      public function OnDisplayProperties($oObject, $oPage, $bEditMode = false)
      {
        $oFailAlertBlock = AlertUIBlockFactory::MakeForDanger('Test-Title', "Test-content");
        $oPage->AddUiBlock($oFailAlertBlock);
    ...
    ...
    ...
    

    How can I place to banner to the top or the header of the page?
    I already tried to use "iPageUIBlockExtension" but with that I cannot get any dependencies to my own functions I think.
    Thanks,
    Nico

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2023-10-12

    When exactly do you show this banner?

    Now, you're appending it to the HTML of the page at a seemingly random point.

     
    • Nico

      Nico - 2023-10-12

      Hi Jeffrey,
      this code snippet is just for testing. Using it the banner appears on any object that is shown.
      Just imagine for an example a banner should appear on every UserRequest or Incident, like this:

          $sClass = get_class($oObject);
          $sClasses = array('Incident', 'UserRequest');
          if (in_array($sClass, $sClasses))
          {
              $oFailAlertBlock = AlertUIBlockFactory::MakeForDanger('Ticket-Type', 'Request or Incident');
              $oPage->AddUiBlock($oFailAlertBlock);
          }
      

      This really makes no sense but I just want to figure out how to place the banner to the top of the page/top of object details.

       
      • Jeffrey Bostoen

        Jeffrey Bostoen - 2023-10-12

        I haven't tested it, but I'd check out how Combodo does it for their "Communications to customers" extension.

        See https://github.com/Combodo/itop-communications/blob/master/src/Hook/CommunicationPageUIBlockExtension.php ( the header block )

         
        • Nico

          Nico - 2023-10-12

          That's a good hint, I just checked it. They're using the interface "iPageUIBlockExtension".
          That is okay for the communications because the queries are made directly in the function "GetHeaderBlock". Defining a static banner like that is working for me too.
          But I want to have dependencies with different functions I defined, e.g., in "public function OnDisplayProperties".
          I dont know how to combine those classes.
          Maybe I should just code the banner directly in HTML or just move it from the bottom to the top using Javascript...

           
        • Nico

          Nico - 2023-10-12

          Like this:

            public function OnDisplayProperties($oObject, $oPage, $bEditMode = false)
            {
              $oFailAlertBlock = AlertUIBlockFactory::MakeForDanger('Test-Title', "Test-content", 1313);
              $oPage->AddUiBlock($oFailAlertBlock);
              $oPage->add_ready_script(
          <<<JS
                $('#1313').appendTo($('#ibo-page-header'));
          
          JS);
          ...
          
           
  • Guillaume Lajarige

    Hello Nico,

    Actually I think this is a missing API; we have the same issue internally when we want to display a message on top of an object when it matches some conditions (eg; when a Bug object needs to be retrofitted in a support branch).

    I don't think this can be addressed nicely yet 😕

    The workaround I can see, is to:
    * Use the \AbstractPageUIBlockExtension::GetHeaderBlock() API
    * Read the request (URL) params to see if you are displaying an object
    * Retrieve the object data if necessary to see if it matches conditions
    * Display the AlertBlock if necessary

    Example (not tested, code might not be correct):

    class Foo extends AbstractPageUIBlockExtension {
        public function GetHeaderBlock()
        {
            $sOperation = utils::ReadParam('operation', '', false, utils::ENUM_SANITIZATION_FILTER_PARAMETER);
            $sObjClass = utils::ReadParam('class', '', false, utils::ENUM_SANITIZATION_FILTER_CLASS);
            $sObjKey = utils::ReadParam('operation', '', false, utils::ENUM_SANITIZATION_FILTER_PARAMETER);
    
            // Not displaying an object
            if ($sOperation !== 'detail') {
                return null;
            }
    
            // Missing object params
            if (utils::IsNullOrEmptyString($sObjClass) || utils::IsNullOrEmptyString($sObjKey)) {
                return null;
            }
    
            // TODO: Check if object class matches what you need
    
            // Try to retrieve object
            $oObject = MetaModel::GetObject($sObjClass, $sObjKey, false);
            if (is_null($oObject)) {
                return null;
            }
    
            // TODO: Check if object attributes match what you need
    
            return AlertUIBlockFactory::MakeForDanger('Test-Title', "Test-content", 1313);
        }
    }
    

    I think I'll try this on our iTop to workaround the same issue! 😁

    Hope it helps,
    Guillaume

     

Log in to post a comment.