0

In another SO question, this was answered for usage within Blocks (Page selector (block development)). However, how do we apply this within the dashboard for example?

Variable "Concrete" and "ConcreteEvent" seem to be undefined within the admin. What would be the best way to approach this issue?

Example code (using 5.7.x):

Concrete.event.bind('ConcreteSitemap', function(e, instance) {
    Concrete.event.bind('SitemapSelectPage', function(e, data) {
        if (data.instance == instance) {
            Concrete.event.unbind(e);
            alert("You've selected a page! " + data.cID);
        }
    });
});
Community
  • 1
  • 1
  • That didn't work either, so I went looking (as it worked for you). I register&require my JS asset with AssetList::getInstance()->register() & $this->requireAsset(). For some reason, these get registered ABOVE events.js, app.js etc. etc. So what I need to find out is, how to move these down (or the other ones up). I put a $this->requireAsset('core/app') before my own requireAsset, but that's just ugly and not the way. Is there a possibility to require my assets after others? – Ramon Leenders Apr 22 '16 at 11:25
  • That is really strange, cause in my controller I didn't call any assets at all (except my owns) - but it's in a packeage, maybe that is the reason. 1 moment I test that – toesslab Apr 22 '16 at 11:30
  • Ok, you're right: In Single Page it doesn't work, but in a package it does.... sry can't help you – toesslab Apr 22 '16 at 11:37
  • My assets are in a package too. They still get loaded before core assets though. It works with the code I posted in the original post and adding the $this->requireAsset('core/app') before my assets though. A workaround for now, but would be nice if someone has the obvious solution for me here! – Ramon Leenders Apr 22 '16 at 11:37
  • Ok so in a package it works (for me) without `$this->requireAsset('core/app')` & `window.Concrete....` ... really strange – toesslab Apr 22 '16 at 11:40
  • Yes, version 5.7.5.6 indeed. I'm doing this in a single page (Dashboard) controller. I leave "window." off as well, so I use the code from the OP. – Ramon Leenders Apr 22 '16 at 11:50
  • The `concrete/js/events.js` (included by deafult, without having to register it) is loaded after my implementaion of `Concrete.event...` Just to say. Maybe the error is somewhere else – toesslab Apr 23 '16 at 05:52

1 Answers1

1

It looks like Concrete.event is always loaded in dashboard pages. If you're worried about load order you have a few options.

  1. Make an asset group and put the event js asset first. If you then include the group instead of just the asset concrete5 should manage loading event first.
  2. Use an onload event like jquery's $(function() { ... }). This will fire a little later than you expect, but it will always happen after eventing is loaded.
  3. Set the position of the asset to \Concrete\Core\Asset\Asset::ASSET_POSITION_FOOTER. this will cause your JS to be included in the footer instead of the head allowing the event JS to always load in first

Hope that helps ya

Korvin Szanto
  • 4,531
  • 4
  • 19
  • 49