Skip to content

Commit

Permalink
Dev: check if called via ajax before including jQuery (custom url param)
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jul 27, 2016
1 parent cf0c793 commit a10bd8b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions application/models/AdminTheme.php
Expand Up @@ -133,15 +133,15 @@ public function registerStylesAndScripts()
// and move the rest to the bootstrap package.
// NB: registerAllScripts could be replaced by js definition in package. If needed: not a problem to do it

if (!Yii::app()->request->isAjaxRequest)
if (!Yii::app()->request->getQuery('isAjax', false))
{
Yii::app()->getClientScript()->registerMetaTag('width=device-width, initial-scale=1.0', 'viewport'); // See: https://github.com/LimeSurvey/LimeSurvey/blob/master/application/extensions/bootstrap/components/TbApi.php#l108-l115
App()->bootstrap->registerAllScripts(); // See : https://github.com/LimeSurvey/LimeSurvey/blob/master/application/extensions/bootstrap/components/TbApi.php#l153-l160

App()->getClientScript()->registerPackage('jqueryui'); // jqueryui
App()->getClientScript()->registerPackage('jquery-cookie'); // jquery-cookie
App()->getClientScript()->registerPackage('fontawesome'); // fontawesome ??? TODO: check if needed

}

$aCssFiles = array();
Expand Down

5 comments on commit a10bd8b

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extend https://github.com/LimeSurvey/LimeSurvey/blob/master/framework/web/CHttpRequest.php#L677 is better. Because , actually : cqgrid with $_GET seems to return whole html
capture du 2016-07-28 09-27-56

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And : maybe it's better to leave whole system, and only fix render function (via extend)
https://github.com/LimeSurvey/LimeSurvey/blob/master/framework/web/CClientScript.php#L203
Here : only include script and meta if needed.

But : did this not linked with layout ? What is the layout actually ?

@Shnoulle
Copy link
Collaborator

@Shnoulle Shnoulle commented on a10bd8b Jul 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups, sorry again.

We don't have to extend Yii, because Yii is not used actually ....

We must fix : https://github.com/LimeSurvey/LimeSurvey/blob/master/application/core/Survey_Common_Action.php#L241
And add header/footer only if we are not in ajax (using $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest' ? )

@LouisGac
Copy link
Contributor

@LouisGac LouisGac commented on a10bd8b Jul 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Denis,

Basically, the Yii method : Yii::app()->request->isAjaxRequest is doing what you say (testing the headers). Problem is that headers depend highly on server configuration, and can retrieves unexpected results. The problem is well known, and adding a param in the ajax request seems to be the most used solution:

http://www.yiiframework.com/wiki/251/reliable-alternative-for-yii-app-request-isajaxrequest-and-adding-data-to-ajax-form-with-js/

I also like the idea of extending the render function.

@Shnoulle
Copy link
Collaborator

@Shnoulle Shnoulle commented on a10bd8b Jul 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK :) seems CGgrid add ajax to GET parameters : then :

isAjaxRequest =($_REQUEST['ajax'] || $_REQUEST['isAjax'] || $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest'])

Making a grep on framework seems to show test on $_POST['ajax'] only.

Please sign in to comment.