Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The two select dialogs above can either merely 'select' elements which then need to be saved in the page below, or they may 'select and save'. The page below will is the important interface in terms of indicating saved or 'yet to be saved' nature of the selected element(s). For look and feel definitions of the select dialogs see selecting elements.

Front end (Javascript)

  • Uses the JQuery dialog Javascript, extended in the file local/js/lib/dialogs.js.php
  • Javascript files should be loaded using the function local_js() in local/js/lib/setup.php
  • Two main classes, totaraDialog and totaraDialog_handler()
  • totaraDialog is the class that handles the dialog frame, opening/closing the dialog, the buttons, and also loading content.
  • totaraDialog_handler() is the function that handles all the logic and the button actions. This is the class you need to extend if you want to customize the Javascript side of the dialog.
  • New dialogs can be generated quickly using the functions at the bottom of the file

Setting up a custom dialog

  • All dialog objects are added to the global array totaraDialogs (indexed by their unique name)
  • Dialogs are only created once per page load, and are simply opened/closed (not recreated)
  • JS should be put inside .php files so you have access to things like optional_param(), $CFG, and get_string()
Code Block
themeEmacs
<nowiki>
  (function() {
      /**
       * Wrapping the code in a function block means variables created inside this scope are cleaned up once the block has executed
       */
  
      // Choose a dialog name unique to this page
      var name = 'addremove';
  
      // Setup the handler class
      var handler = new totaraDialog_handler();
  
      totaraDialogs[name] =  new totaraDialog(
          'name',                   // used for CSS, ID's etc
          /*
            ID of an element on the page to bind to. the dialog's open() function will be called via the "click" handler.
            If you would like to set up this functionality yourself (e.g. want to trigger via something other than
            "click", set this parameter to default)
          */
          'show-'+name+'-dialog',
          {
              buttons: {                                         // Buttons to appear at base of dialog
                    '<?php echo get_string('cancel') ?>': function() { handler._cancel(); },
                    // Add more dialogs here, NOTE: they appear in the opposite order due to floating
              },
              title: '<h2><?php echo get_string('addremove'); ?></h2>',   // Title of dialog (remember the H2 tags!)
          },
          'http://example.com/dialog.php',           // Default URL to load
          handler                                    // Assign the handler
      );
  })();
</nowiki>

Back end (PHP)

Content classes can be used to speed up development of new dialogs very quickly. A number exist already. See local/dialogs/

...