Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-54034

Filters not applied by default in ajax calls

XMLWordPrintable

    • MOODLE_31_STABLE
    • MOODLE_30_STABLE
    • MDL-54034-master
    • Hide

      Test pre-requisites

      • The filter 'Multi-Language Content' is enabled on 'Content and headings'

      Test for 3.0 onwards

      1. Create a new survey module on the front page
      2. Set its name to:

        Survey title: <span class="multilang" lang="en">EN</span><span class="multilang" lang="fr">FR</span>
        

      3. Add an image to the description
      4. Switch to the HTML view of Atto, and add the following:

        <p>Filters: <span class="multilang" lang="en">EN</span><span class="multilang" lang="fr">FR</span></p>
        

      5. View the survey and confirm that:
        • The title is 'Survey title: EN' (in the breadcrumb, see MDL-54045 for the heading)
        • You can see the picture, and 'Filters: EN'. You cannot see 'FR'.
      6. Edit the file mod/survey/db/services.php to add ajax => true to get_surveys_in_courses:

            'mod_survey_get_surveys_by_courses' => array(
                ...
                'ajax' => true
            )
        

      7. Open your JS console and run the following snippet:

        var SITEID = 1;
        require(['jquery', 'core/ajax'], function($, Ajax) {
          Ajax.call([{
            methodname: 'mod_survey_get_surveys_by_courses',
            args: {
              courseids: [SITEID]
            }
          }])[0].then(function(surveys) {
            var survey = surveys.surveys.pop();
            $('body').empty();
            $('body').append($('<h1>').html(survey.name));
            $('body').append($('<div>').html(survey.intro));
          }).fail(function() {
            alert('Error!');
            console.log(arguments);
          });
        });
        

      8. Confirm that the page displays the survey title and description.
        • The title is 'Survey title: EN'
        • The image from the description is displayed
        • The description reads 'Filters: EN'

      Test for 2.9

      We're only testing external_format_text here. Its string equivalent did not exist.

      1. Login as admin and edit your profile
      2. Add an image to your profile description
      3. Switch to the HTML view of Atto, and add the following:

        <p>Filters: <span class="multilang" lang="en">EN</span><span class="multilang" lang="fr">FR</span></p>
        

      4. View your profile and confirm that you can see the picture, and 'Filters: EN'. You cannot see 'FR'.
      5. Edit the file user/externallib.php to add the following:

            public static function get_users_is_allowed_from_ajax() {
                return true;
            }
        

      6. Open your JS console and run the following snippet:

        require(['jquery', 'core/ajax'], function($, Ajax) {
          Ajax.call([{
            methodname: 'core_user_get_users',
            args: {
              criteria: [
                {key: 'id', value: 2}
              ]
            }
          }])[0].then(function(users) {
            var user = users.users.pop();
            $('body').empty();
            $('body').append($('<div>').html(user.description));
          }).fail(function() {
            alert('Error!');
            console.log(arguments);
          });
        });
        

      7. Confirm that the page displays your profile description.
        • The image is visible
        • The text reads 'Filters: EN'
      Show
      Test pre-requisites The filter 'Multi-Language Content' is enabled on 'Content and headings' Test for 3.0 onwards Create a new survey module on the front page Set its name to: Survey title: <span class="multilang" lang="en">EN</span><span class="multilang" lang="fr">FR</span> Add an image to the description Switch to the HTML view of Atto, and add the following: <p>Filters: <span class="multilang" lang="en">EN</span><span class="multilang" lang="fr">FR</span></p> View the survey and confirm that: The title is 'Survey title: EN' (in the breadcrumb, see MDL-54045 for the heading) You can see the picture, and 'Filters: EN'. You cannot see 'FR'. Edit the file mod/survey/db/services.php to add ajax => true to get_surveys_in_courses : 'mod_survey_get_surveys_by_courses' => array ( ... 'ajax' => true ) Open your JS console and run the following snippet: var SITEID = 1; require([ 'jquery' , 'core/ajax' ], function ($, Ajax) { Ajax.call([{ methodname: 'mod_survey_get_surveys_by_courses' , args: { courseids: [SITEID] } }])[0].then( function (surveys) { var survey = surveys.surveys.pop(); $( 'body' ).empty(); $( 'body' ).append($( '<h1>' ).html(survey.name)); $( 'body' ).append($( '<div>' ).html(survey.intro)); }).fail( function () { alert( 'Error!' ); console.log(arguments); }); }); Confirm that the page displays the survey title and description. The title is 'Survey title: EN' The image from the description is displayed The description reads 'Filters: EN' Test for 2.9 We're only testing external_format_text here. Its string equivalent did not exist. Login as admin and edit your profile Add an image to your profile description Switch to the HTML view of Atto, and add the following: <p>Filters: <span class="multilang" lang="en">EN</span><span class="multilang" lang="fr">FR</span></p> View your profile and confirm that you can see the picture, and 'Filters: EN'. You cannot see 'FR'. Edit the file user/externallib.php to add the following: public static function get_users_is_allowed_from_ajax() { return true; } Open your JS console and run the following snippet: require([ 'jquery' , 'core/ajax' ], function ($, Ajax) { Ajax.call([{ methodname: 'core_user_get_users' , args: { criteria: [ {key: 'id' , value: 2} ] } }])[0].then( function (users) { var user = users.users.pop(); $( 'body' ).empty(); $( 'body' ).append($( '<div>' ).html(user.description)); }).fail( function () { alert( 'Error!' ); console.log(arguments); }); }); Confirm that the page displays your profile description. The image is visible The text reads 'Filters: EN'

      Also, I don't think it is possible to apply them altogether. I would apply them by default as it's the most sensible use for frontends.

        1. atto.png
          36 kB
          Jun Pataleta
        2. heading.png
          9 kB
          Jun Pataleta

            fred Frédéric Massart
            fred Frédéric Massart
            Adrian Greeve Adrian Greeve
            David Monllaó David Monllaó
            Jun Pataleta Jun Pataleta
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

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