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

Support proper editor use in mod_database template editing

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.1
    • MOODLE_401_STABLE

      The database activity has a weird way of editing templates:

      • you can enable or disable an HTML editor via a checkbox
      • one of the templates is broken down into a header, repeating element, and footer (The list template - arguably the most important)

      The reason this is the case is that many of the templates consist of a section that is repeated and it is often desirable to have them in something like a table. To achieve this you need to precede the starting elements with the relevant table tags.

      The result of this is that sometimes you are able to use a WYSIWYG editor, and sometimes you are not.

      To expand upon this problem, the idea is that you might want something like a table. To do that you would need:

      A header:

      <table>
        <thead>
          <tr>
            <th>id</th>
            <th>Name</th>
            <th>Colour</th>
            <th>Actions</th>
          </tr>
        </thead>
        <tbody>
      

      A repeated section like:

          <tr>
            <td>[[id]]</td>
            <td>[[name]]</td>
            <td>[[colour]]</td>
            <td>##edit## ##more## ##delete## ##approve## ##disapprove## ##export##</td>
          </tr>
      

      And a footer:

        </tbody>
      </table>
      

      The combination of these gives you valid HTML, but individually they are totally invalid. The problem comes when you try to create any reasonable HTML editor to create these sections because they will not let you create invalid HTML - such as a table with some opening tags which don't close, or closing tags which were never opened, or a table row not a part of a table. Most WYSIWYG editors will fix this HTML because it is non-sensical on its own as content.

      Essentially we have a couple of potential solutions to this problem:

      1. we 'fix' editors to allow partial HTML
      2. we make it possible to more easily switch between WYSIWYG and plain text
      3. we combine the templates so that there is always valid HTML, but a placeholder is used to indicate the location of the repeating elements

      Fixing editors

      Yeah nah. This would be a bad idea even if it were an easy one. Most editors rely on the DOM being correct and valid to work, and most also use underlying browser APIs to generate that DOM, and they don't support invalid markup either.

      Let's not pretend this is a good iea. It simply is not.

      Make it possible to switch between editors and plain text more easily

      At the moment this is handled by a checkbox. That checkbox value is persisted to the database and restored when viewing the form. That's important because if you have written 'invalid' HTML, and then save it, and when you view it again you get the HTML editor, the editor will 'fix' the 'bad' HTML when the form is saved. Even if you aren't intentionally changing that template (i.e. you want to change the repeating template, and it 'fixes' all three).

      Making it easier to switch between editors is not a good solution to this problem and will likely introduce more issues.

      Merge the templates and use some form of placeholder to indicate the repeating section

      We can try to create a template which combines both the header and footer into a single template, or possibly even all three, but it may still not be easy...

      Again, imagine the same scenario, so you create your header+footer template:

      <table>
        <thead>
          <tr>
            <th>id</th>
            <th>Name</th>
            <th>Colour</th>
            <th>Actions</th>
          </tr>
        </thead>
        <tbody>
       
       
        </tbody>
      </table>
      

      But you need to signify that the repeating element goes in that tbody section. It would be invalid HTML to put something like ##CONTENT## in so that won't work.
      You could use an HTML comment:

      <!-- ##content -->
      

      That would work, but you would have to find some way to make that happen as a part of the HTML editor because it doesn't (typically) show HTML comment.

      You also still have the same issue of invalid HTML in the content section because it's table content not part of a table.

      So you could instead combine everything into a single template:

      <table>
        <thead>
          <tr>
            <th>id</th>
            <th>Name</th>
            <th>Colour</th>
            <th>Actions</th>
          </tr>
        </thead>
        <tbody>
       
      <!-- ##repeatstart## -->
          <tr>
            <td>[[id]]</td>
            <td>[[name]]</td>
            <td>[[colour]]</td>
            <td>##edit## ##more## ##delete## ##approve## ##disapprove## ##export##</td>
          </tr>
      <!-- ##repeatend## -->
       
        </tbody>
      </table>
      

      This would solve the problem of invalid content in the content section, but you still have to identify the repeating element.

      Again, you could do so with something like an HTML attribute, or an HTML comment (as above). That would work, but there's no nice way of managing that in the editor.

      Our Editor API doesn't allow individual activities to add/enable a plugin for a specific editor, so it would be hard to add anything to either Atto, or Tiny (or any other editor) to help you either.

      Either way you're then stuck doing this by giving directions to add some magic code to the HTML source view of the content, so that sucks.

      Summary

      I'm of the opinion that we are already possibly in the least-bad position, but its a close tie wtih merging the templates and using the HTML comment approach.

            Unassigned Unassigned
            dobedobedoh Andrew Lyons
            Votes:
            3 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:

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