Skip to content

Commit

Permalink
New feature: Templates can now overwrite the question views
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed May 3, 2016
1 parent 29c2c6a commit 74fca96
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 185 deletions.
2 changes: 1 addition & 1 deletion application/core/Survey_Common_Action.php
Expand Up @@ -1350,7 +1350,7 @@ public function registerCssFile( $sPath, $sFile )
{
$url = ($sPath == 'PUBLIC')?Yii::app()->getConfig('publicstyleurl'):Yii::app()->getConfig('adminstyleurl').'/css/'; // We get the wanted url defined in config
App()->getClientScript()->registerCssFile( $url.$sFile ); // We publish the css file

}
}

Expand Down
364 changes: 197 additions & 167 deletions application/helpers/qanda_helper.php

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions application/models/TemplateConfiguration.php
Expand Up @@ -41,6 +41,8 @@ class TemplateConfiguration extends CFormModel
public $hasConfigFile='';
public $isOldTemplate;

public $overwrite_question_views=false;

public $xmlFile;

/**
Expand Down Expand Up @@ -84,8 +86,6 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')
}




// If the template don't have a config file (maybe it has been deleted, or whatever),
// then, we load the default template
$this->hasConfigFile = is_file($this->path.DIRECTORY_SEPARATOR.'config.xml');
Expand Down Expand Up @@ -118,6 +118,9 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')

// condition for user's template prior to 160219
$this->filesPath = (isset($this->config->engine->filesdirectory))? $this->path.DIRECTORY_SEPARATOR.$this->config->engine->filesdirectory.DIRECTORY_SEPARATOR : $this->path . '/files/';
// condition for user's template prior to 160504
$this->overwrite_question_views = (isset($this->config->engine->overwrite_question_views))? $this->config->engine->overwrite_question_views=='true' : false;

$this->cssFramework = $this->config->engine->cssframework;
$this->packages = (array) $this->config->engine->packages->package;
$this->otherFiles = $this->setOtherFiles();
Expand Down Expand Up @@ -173,6 +176,7 @@ public function actualizeLastUpdate()
private function createTemplatePackage()
{
Yii::setPathOfAlias('survey.template.path', $this->path); // The package creation/publication need an alias
Yii::setPathOfAlias('survey.template.viewpath', $this->viewPath); //

$aCssFiles = (array) $this->config->files->css->filename; // The CSS files of this template
$aJsFiles = (array) $this->config->files->js->filename; // The JS files of this template
Expand Down
20 changes: 11 additions & 9 deletions templates/default/config.xml
Expand Up @@ -17,18 +17,14 @@
<license>GNU General Public License version 2 or later</license>
<version>1.0</version>
<description>Default LimeSurvey Template.</description>
<!--
The last_update field must be updated before each release,
to be sure that the asset manager will publish new assets and make visible CSS changes for final users (without browser cache refresh)
-->
<last_update>2016-04-12 19:46:00</last_update>
<last_update>2016-05-13 10:46:00</last_update>
</metadatas>

<!--
Here the list of the css/js files to load.
Any file here will be loaded via the asset manager
-->
<files>
<!--
Here the list of the css/js files to load.
Any file here will be loaded via the asset manager
-->
<css>
<filename>css/jquery-ui-custom.css</filename>
<filename>css/bootstrap-slider.css</filename>
Expand Down Expand Up @@ -93,6 +89,12 @@
<!-- Path of the pstpl files -->
<pstpldirectory>views</pstpldirectory>

<!--
Set to yes to overwrite the question views,
then, just copy application/views/survey/* to template/{your_view_directory}/survey/
-->
<overwrite_question_views>false</overwrite_question_views>

<!-- Asset manager will copy the whole template directory to tmp. So it's possible to refer any file in the files directory in CSS via relative path (e.g: '../files/foo.jpg') -->
<filesdirectory>files</filesdirectory>

Expand Down
22 changes: 17 additions & 5 deletions templates/news_paper/config.xml
Expand Up @@ -4,6 +4,7 @@
In future versions of LimeSurvey, it will be used to fill a template table,
and to give user control on template configuration (like variables to use to render the questions, banners, background, etc.)
-->

<config>
<!-- Those metadatas will be display in the template configuration page. They are not used for now. -->
<metadatas>
Expand All @@ -16,7 +17,7 @@
<license>GNU General Public License version 2 or later</license>
<version>1.0</version>
<description>News paper LimeSurvey Template.</description>
<last_update>2016-04-12 19:46:00</last_update>
<last_update>2016-05-13 10:46:00</last_update>
</metadatas>

<!--
Expand All @@ -38,6 +39,14 @@
<print_css>
<filename>css/print_template.css</filename>
</print_css>

<!--
Those files will be loaded for right to left languages only
NOTE 1: If for any reason, you need to edit the RTL behaviors, feel free to contact the LimeSurvey team about it.
We'll be always pleased to make better the right to left display
NOTE 2: those files are generated with the script R2. See: https://github.com/ded/R2
-->
<rtl>
<css>
<filename>css/template-rtl.css</filename>
Expand Down Expand Up @@ -74,15 +83,18 @@
<cssframework>bootstrap</cssframework>
<!-- Path of the pstpl files -->
<pstpldirectory>views</pstpldirectory>

<!--
Where the files of the template will be uploaded
Warning : if the template contain files, the whole directory template will published via the Asset Manager,
and not the files one by one. It change the update strategy, and a single change to a css file will not change the asset tmp directory
Overwriting the Asset Manager will be necessary to resolve this problem.
Set to yes to overwrite the question views,
then, just copy application/views/survey/* to template/{your_view_directory}/survey/
-->
<overwrite_question_views>true</overwrite_question_views>

<!-- Asset manager will copy the whole template directory to tmp. So it's possible to refer any file in the files directory in CSS via relative path (e.g: '../files/foo.jpg') -->
<filesdirectory>files</filesdirectory>

<!-- Here, you can publish packages set as third party extensions in application/config/third_party -->
<!-- If bootstrap is registred as a css framework, it will be loaded first -->
<packages>
<package>jqueryui</package>
<package>jquery-touch-punch</package>
Expand Down
21 changes: 20 additions & 1 deletion templates/ubuntu_orange/config.xml
Expand Up @@ -10,9 +10,13 @@
<license>GNU General Public License version 2 or later</license>
<version>1.0</version>
<description>LimeSurvey Template.</description>
<last_update>2016-04-12 19:57:00</last_update>
<last_update>2016-05-13 10:46:00</last_update>
</metadatas>

<!--
Here the list of the css/js files to load.
Any file here will be loaded via the asset manager
-->
<files>
<css>
<filename>css/jquery-ui-custom.css</filename>
Expand All @@ -28,6 +32,14 @@
<print_css>
<filename>css/print_template.css</filename>
</print_css>

<!--
Those files will be loaded for right to left languages only
NOTE 1: If for any reason, you need to edit the RTL behaviors, feel free to contact the LimeSurvey team about it.
We'll be always pleased to make better the right to left display
NOTE 2: those files are generated with the script R2. See: https://github.com/ded/R2

This comment has been minimized.

Copy link
@SamMousa

SamMousa May 3, 2016

Contributor

Is that library still alive?
And do we require node JS on the server now?
Or do you mean that RTL files "could" be created using a script like that one?

This comment has been minimized.

Copy link
@olleharstedt

olleharstedt May 3, 2016

Contributor

We use R2 at the office to generate RTL files.

This comment has been minimized.

Copy link
@SamMousa

SamMousa May 3, 2016

Contributor

Ok.

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle May 3, 2016

Collaborator

RTL files "could" be created using a script like that one

Bu any other script/method can do the trick :)

-->
<rtl>
<css>
<filename>css/template-rtl.css</filename>
Expand Down Expand Up @@ -56,6 +68,13 @@
<engine>
<cssframework>bootstrap</cssframework>
<pstpldirectory>views</pstpldirectory>

<!--
Set to yes to overwrite the question views,
then, just copy application/views/survey/* to template/{your_view_directory}/survey/
-->
<overwrite_question_views>false</overwrite_question_views>

This comment has been minimized.

Copy link
@SamMousa

SamMousa May 3, 2016

Contributor

Can I overwrite a view for a single question or must I do it for all questions?

This comment has been minimized.

Copy link
@LouisGac

LouisGac May 3, 2016

Contributor

you can overwrite a single question

This comment has been minimized.

Copy link
@SamMousa

SamMousa May 3, 2016

Contributor

Nice! Why not omit the configuration then? Wouldn't the presence or absence of the appropriate view indicate you want to or don't want to overwrite question views?

This comment has been minimized.

Copy link
@LouisGac

LouisGac May 3, 2016

Contributor

to avoid useless test on file system

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle May 3, 2016

Collaborator

You mean : single Question type ? Right ?

This comment has been minimized.

Copy link
@LouisGac

LouisGac May 3, 2016

Contributor

yep, or a single question type view (like a td inside a table).

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle May 3, 2016

Collaborator

Or help part or ... etc ... it's just for precision. Then for single question : beforeQuestionRender ;)

This comment has been minimized.

Copy link
@LouisGac

LouisGac May 3, 2016

Contributor

you can add the event beforeDoRender in the function if you want, no problem for me

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle May 3, 2016

Collaborator

No, we already have beforeQuestionRender : https://manual.limesurvey.org/BeforeQuestionRender in 2.05 who can already do this in another way. Don't need (and don't want) a new event here :)

This comment has been minimized.

Copy link
@LouisGac

LouisGac May 3, 2016

Contributor

Tammo couldn't use this one. Only people able to create plugins could use this one.
The goal of this feature is to provide the possibility to template creators who only handle HTML,CSS and JS to modify the question rendering.
You've yet shown me that your templates are doing it a lot using plugins, so I guess you understand that other template creators want to be able to do it, in a easier way.

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle May 3, 2016

Collaborator

Oh yes, i understand . But i'm afraid of broken survey due to broken template.

PS : in 2.X/3.X release : we need a cache system to don't test file existence again and again ....

This comment has been minimized.

Copy link
@LouisGac

LouisGac May 3, 2016

Contributor

the file system is not tested if the setting is set to off in the config file ;-)
About broken templates : this feature is for advanced LimeSurvey users, like you or tammo, who use to develop specific templates for their clients. Basic LimeSurvey users should only use the official templates.


<packages>
<package>jqueryui</package>
<package>jquery-touch-punch</package>
Expand Down

2 comments on commit 74fca96

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems very difficult for me : to have a "own HTML system" : what do be used in future ?

  • QuestionObject
  • beforeQuestionRender event
  • template

And when a user have issue with one of is question : we must ask hime

  • What is the question object
  • What plugin is active
  • What template used : please send whomle template zip.

@olleharstedt
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Please sign in to comment.