Uploaded image for project: 'Moodle app'
  1. Moodle app
  2. MOBILE-3457

Mobile init function return does not get passed to other handlers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • 3.9.0
    • Remote addons
    • Hide

      You can just save the data in a global variable (window.whatever), although this probably isn't ideal if the user might have multiple sites.

      Show
      You can just save the data in a global variable (window.whatever), although this probably isn't ideal if the user might have multiple sites.
    • MOODLE_39_STABLE
    • Moodle App 3.9.3

      Documentation https://docs.moodle.org/dev/Mobile_support_for_plugins#Initialization says you can do this in a plugin init function:

      (begin paste)

      Finally, if you return an object in this init Javascript code, all the properties of that object will be passed to all the Javascript code of that handler so you can use them when the code is run. For example, if your init Javascript code does something like this:

      var result = {
          MyAddonClass: new MyAddonClass()
      };
      result;
      

      Then, for the rest of Javascript code of your handler (e.g. for the “main” method) you can use this variable like this:

      this.MyAddonClass
      

      (end paste)

      This does not appear to actually work. Here is examples from my code, running in a main menu handler.

      End of init.js:

      console.log('---Ran TEST code--');
      var result = {
          MyAddonClass: "TESTING"
      };
      result;
      

      Start of page .js:

      console.log('Test input values');
      console.log(this.MyAddonClass);
      console.log('DONE');
      

      Excerpts from console:

      Running against app tag v3.9.0:

      ---Ran TEST code--
      

      [...and when the page loads...]

      Test input values
       undefined
       DONE
      

            jleyva Juan Leyva
            quen Sam Marshall
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.