1. Fabrik 3.8.1 has been released. It is mostly bug fixes and feature enhancements, but does include two new plugins (push notifications, and the sequence element). As usual we strongly recommend testing the new release on a sandbox if your application is mission critical, and always do an Akeeba backup before updating.
    Dismiss Notice

PHP list plugin javascript stopped working

Discussion in 'Community' started by Bauer, Jul 3, 2017.

  1. Bauer

    Bauer Well-Known Member

    Level: Supporter
    I was using some javascript in a php list plugin to prevent the code from running in a certain situation.
    Suddenly (not sure when, but it worked last time I tried a few weeks ago) the code errors out.

    Per the Wiki, I expected to use (was using) the variables rows and ids.
    But now both 'ids' and 'rows' are giving errors and show as undefined or empty when sent to the javascript console.log.

    Please tell me this is not "just me" - and then please fix it so the javascript in a php list plugin will work as expected again.
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Works fine for me.

    We don't define an ids, only rows (an object of row objects). If you need the selected ids, you have to get that yourself (see the php.js for how we do this). Maybe you are thinking of the js list plugin, where we provide both ids and rows? Here's the code for php.js, which hasn't been changed in a long time:

    https://github.com/Fabrik/fabrik/blob/master/plugins/fabrik_list/php/php.js

    As you can see, no 'ids' var, just rows.

    -- hugh
     
  3. Bauer

    Bauer Well-Known Member

    Level: Supporter
    The Wiki for the Javascript List Plugin has these 2 examples...
    Code (Javascript):
    console.log(ids); //outputs an array of the selected row ids
    console.log(rows); // outputs a object key'ed on the selected row ids, each value is an object containing the row data.
     
    So I assumed (and tested/tried using) both.
    ids throws an error and rows is an empty array.

    Anyhow, here is the code I was using...
    Code (Javascript):
    var applied_val = rows[0]['fb_breakouts___applied_raw'];
    var applied = (applied_val=='1') ? true : false ;
    if (applied === false){
      alert("Report cannot be generated until it has been 'Applied'.");
    }
    return applied;
    It doesn't work anymore. The console has error...
    Uncaught TypeError: Cannot read property 'fb_breakouts___applied_raw' of undefined

    Figures it was a "just me". Phil's law strikes again.:mad:
     
  4. Bauer

    Bauer Well-Known Member

    Level: Supporter
    I was trying to think of what I might have changed to break this.
    I add a 'group by' to the list a few days ago.
    That's what breaks it.
    If I disable the groupby - it works fine again.
    But I want to be able to use groupby on this list too!:mad:
     
  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Right. But that's the Javascript List Plugin. According to the thread subject, this thread is about the PHP List Plugin. Which isn't the same. One could argue that it should be, but it isn't. It just has 'rows' which are not indexed by row id.

    -- hugh
     
  6. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I shall take a look.

    -- hugh
     
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    OK, I've modifed the php plugin JS to do the same thing as the js plugin, and create the ids array, and the rows object is now keyed by rowid. And it fixes the group by issue.

    It's possible this may break backward compat for existing PHP plugin code that operates on the sequentially keyed rows object, although most code I can picture in my head wouldn't break, but moving forward it just makes more sense for both plugins to do it the same way.

    https://github.com/Fabrik/fabrik/commit/54bdb83540c617ef17bc15e68614bc2a21cdcd44

    -- hugh
     
  8. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    And I've updated the wiki to document them.

    -- hugh
     
  9. Bauer

    Bauer Well-Known Member

    Level: Supporter
    You've been a busy guy - considering it's supposed to be a holiday.:p (But I'm in the same boat.)
    Thanks a bunch for getting to this.

    Now if you can implement the github pull request changes I made to the list copy plugin that allow you to specify what columns get reset to their default values during copy (or look at my code at github to get the basic idea of how I think it should work - and fix it with any modifications to that you might have) - then I'll be able to just use the list copy plugin rather than the php plugin code I wrote. (I haven't tested your fix for the groupby bug yet - but I'm sure you fixed it.)

    Also, today I changed the Yes/No plugin to allow images for Yes/No - so in a list view you can have an image that better represents what the toggle does (in my case an image of a locked lock or an unlocked lock). My 'client' wanted something a little more professional looking than one-color icons. It's pretty basic - just 3 more variables (optionally) added to the $displayData array used in the layout file from those new configuration parameters - which will display the image instead; and set the width to resize if specified. Do you think other Fabrik users might be interested in that? If so I'll put it at Github in the morning.
     
  10. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I saw the pr, haven't had time to look at it. Sure, add the yesno stuff. If it looks useful I'll merge it.

    Sent from my HTC6545LVW using Tapatalk
     

Share This Page