Thursday, December 18, 2014

TypeError: detail_handler is undefined

Wow, we had a subtle bug (#34), which took me several hours: when Alicia or Hubert created a notes.Note, then they had strange phenomens happening: Lino failed to close the detail window, asked whether they want to save altough there were no changes, together with a JavaScript run-time error “TypeError: detail_handler is undefined”.

This came because notes.Notes was (1) visible only to admin and (2) used as the model’s default table.

Background: When creating a row, CreateRow (or to be more precise, CreateRow which inherits from it) call ar.goto_instance in order to display the newly created row. And ar.goto_instance needs the model’s default table to specify the detail handler. You might ask why it doesn’t simply take the detail handler defined on the table where it was called. Good question, but we’ll dive into this another time. I think it is because we want it to work transparently also in situations where the calling table is not known…

  • First of all, the detail of a Note should be visible to everybody, not only to Admin. But the table of all notes, available via Explorer ‣ Office ‣ Notes should remain admin-only. Until now we used notes.Notes for this command. Since there is no other candidate for the default table, we define a new table notes.AllNotes with user_level=admin and use this table for the Explorer menu command. And notes.Notes remains there as the mother of all notes tables, but not directly used.

  • And secondly, if we would have wanted an admin-only detail, that’s not a reason for Lino to produce such strange behaviour. ar.goto_instance must test whether the detail_action has view permission before demanding to use it. This test is actually done in the object’s get_detail_action method.

  • And thirdly, I defined a new table about.DetailLayouts and added a section “List of detail layouts” to General overview of Lino Welfare in to make these subtleties visible.

Miscellaneous

  • Updated the docs for initdb

  • Added new application setting keep_erroneous_cache_files. Some time ago I had commented out the call to os.remove because I had that rather rare situation of wanting to see the partly generated chache file, and I forgot to reactivate that line of code after having fixed the problem.

    Now I had this TypeError: Lino.main_menu is undefined again in my JavaScript console, and I remember that we had this message in a beginner session with Steve. Steve, so here is the reason for that irritating behaviour.

  • Added a new role message for marking up the message when writing text as the previous paragraph. (I thought it would be easy to have this message then also appear in the main documentation index so that a future victim of this problem has more chances to find the solution. But after some trying I gave up for this time.)