Datepicker error when adding custom hooks?

Please report bugs and any annoyances here. Kindly include all possible details: steps to reproduce, expected result, actual result, screenshots, ... etc.
Post Reply
peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Datepicker error when adding custom hooks?

Post by peebee » 2016-08-29 23:28

As pointed out by grimblefitz here: http://forums.appgini.com/phpbb/viewtop ... 1991#p6063

I too am seeing exactly the same error in the console:

Code: Select all

datepicker.packed.js:38
GET http://domain.com/hooks/resources/datepicker/js/lang/en.js
(anonymous function) @ datepicker.packed.js:38
(anonymous function) @ datepicker.packed.js:167
Of course the file hooks/resources/datepicker/js/lang/en.js doesn't exist in the hooks folder. Correct path should be resources/datepicker/js/lang/en.js

I tried to find where that file was being called from to cause the error but I think it must be hidden deep somewhere and appears to comes about when you add custom files in the hooks folder that include:

Code: Select all

$currDir=dirname(__FILE__);
include("$currDir/../defaultLang.php");
include("$currDir/../language.php");
include("$currDir/../lib.php");
Easy to get rid of the error by simply adding the language file to hooks folder but hardly correct/elegant and a little bit annoying too.

Any other suggestions?

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Datepicker error when adding custom hooks?

Post by grimblefritz » 2016-08-30 09:29

peebee,

You are correct. In my case, it stems from an ajax provider script in hooks that necessarily includes the AppGini files.

The error is triggered by datepicker.js (well, the packed version) starting at at line 35:

Code: Select all

// Load the appropriate language file
var scriptFiles = document.getElementsByTagName('head')[0].getElementsByTagName('script');
var loc = scriptFiles[scriptFiles.length - 1].src.substr(0, scriptFiles[scriptFiles.length - 1].src.lastIndexOf("/")) + "/resources/datepicker/js/lang/" + datePicker.languageinfo + ".js";

var script  = document.createElement('script');
script.type = "text/javascript";
script.src  = loc;
The way var loc is created, it references the folder where the parent (the php script) runs from. As you note, the resources folder is in the parent of hooks, so if you're loading AppGini files from hooks there is an uncaught variation in the path.

I suppose the datepicker code could be modified to check the last element of the derived path, and if it is hooks, then alter the path. Or, walk up the path until it finds the parent of 'resources/datepicker'. Either of those is probably the best long-term solution, and something for Ahmad to implement in the core package.

Meanwhile, if you're running a linux/unix host, there is a code-free solution. I have not tested this, but it should work.

Code: Select all

cd {app_root}/hooks
ln -s ../resources resources
You can also do this on a Windows host that supports mklink.

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: Datepicker error when adding custom hooks?

Post by peebee » 2016-08-30 23:29

Thanks grimblefitz. Yes, I did find the trigger for the language file in datepicker.js but I was wondering if I could stop it somehow before it was even called by the hooks folder. The default lang for the datepicker is English if not specified, which fortunately suits me just fine.

For the moment, I've just created a new folder and loaded the file to hooks/resources/datepicker/js/lang/en.js which fixes the error immediately. Nobody knows - except me, no errors and all is good. It just annoys me a little bit like when you buy something brand new, it's perfect and then you put a tiny scratch in it that nobody else would even notice - except you. :cry:

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Datepicker error when adding custom hooks?

Post by grimblefritz » 2016-08-30 23:38

Understand. A new car is only new until it gets its first nick or scratch.

A symlink would be better than copying the directory tree. It will work automagically with an AppGini upgrade, whereas it's on you to remember to re-copy the resources directory.

A small thing, but one less opportunity to ding that car :)

Post Reply