Skip to content

Commit

Permalink
New feature: admin themes list in a tab next to survey themes
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Nov 22, 2017
1 parent dbbb082 commit eca1b91
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 113 deletions.
17 changes: 15 additions & 2 deletions application/controllers/admin/themeoptions.php
Expand Up @@ -148,15 +148,28 @@ public function updatesurveygroup($id = null, $gsid)
}
}

public function setAdminTheme($sAdminThemeName)
{
if (!Permission::model()->hasGlobalPermission('settings', 'update')) {
Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error');
$this->getController()->redirect(array('/admin'));
}

$sAdmintheme = sanitize_paranoid_string($sAdminThemeName);
setGlobalSetting('admintheme', $sAdmintheme);
$this->getController()->redirect(Yii::app()->getController()->createUrl("admin/themeoptions#adminthemes"));
}

/**
* Lists all models.
*/
public function index()
{
if (Permission::model()->hasGlobalPermission('templates', 'read')) {
$model = new TemplateConfiguration();
$aData = array();
$aData['model'] = $model;
$aData['oSurveyTheme'] = new TemplateConfiguration();
$aData['oAdminTheme'] = new AdminTheme();

$this->_renderWrappedTemplate('themeoptions', 'index', $aData);
} else {
Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error');
Expand Down
7 changes: 5 additions & 2 deletions application/models/AdminTheme.php
Expand Up @@ -147,7 +147,7 @@ public function registerStylesAndScripts()
App()->getClientScript()->registerPackage('bootstrap-switch');
App()->getClientScript()->registerPackage('bootstrap-select2');
App()->getClientScript()->registerPackage('bootstrap-datetimepicker');
App()->getClientScript()->registerPackage('adminbasics'); // Combined scripts and style
App()->getClientScript()->registerPackage('adminbasics'); // Combined scripts and style
App()->getClientScript()->registerPackage('adminpanel'); // The new admin panel
App()->getClientScript()->registerPackage('lstutorial'); // Tutorial scripts
App()->getClientScript()->registerPackage('ckeditor'); //
Expand Down Expand Up @@ -341,7 +341,9 @@ static private function getThemeList($sDir)
// Simple Xml is buggy on PHP < 5.4. The [ array -> json_encode -> json_decode ] workaround seems to be the most used one.
// @see: http://php.net/manual/de/book.simplexml.php#105330 (top comment on PHP doc for simplexml)
$oTemplateConfig = json_decode(json_encode((array) simplexml_load_string($sXMLConfigFile), 1));

$previewUrl = Yii::app()->getConfig('styleurl').$file; // NOTE: will not work with uploaded themes for now
$oTemplateConfig->path = $file;
$oTemplateConfig->preview = '<img src="'.$previewUrl.'/preview.png" alt="admin theme preview" height="200" class="img-thumbnail" />';
$aListOfFiles[$file] = $oTemplateConfig;
}
}
Expand All @@ -351,6 +353,7 @@ static private function getThemeList($sDir)
return $aListOfFiles;
}


/**
* Few constants depending on Template
*/
Expand Down
284 changes: 175 additions & 109 deletions application/views/admin/themeoptions/index.php
Expand Up @@ -9,118 +9,184 @@

?>

<?php
//$bFromSurveyGroup = (isset($bFromSurveyGroup))?$bFromSurveyGroup:false;
$bFromSurveyGroup = ($model->scenario == 'surveygroup')?true:false;
?>

<div class="col-lg-12 list-surveys">

<?php
if (!$bFromSurveyGroup){
$this->renderPartial('super/fullpagebar_view', array(
'fullpagebar' => array(
'returnbutton'=>array(
'url'=>'index',
'text'=>gT('Close'),
),
)
));
echo '<h3>'.gT('Installed survey themes:').'</h3>';
}


?>

<div class="row">
<div class="col-sm-12 content-right">

<?php $this->widget('bootstrap.widgets.TbGridView', array(
'dataProvider' => $model->search(),
'columns' => array(
array(
'header' => gT('Preview'),
'name' => 'preview',
'value'=> '$data->preview',
'type'=>'raw',
'htmlOptions' => array('class' => 'col-md-1'),
),

array(
'header' => gT('Name'),
'name' => 'template_name',
'value'=>'$data->template_name',
'htmlOptions' => array('class' => 'col-md-2'),
),

array(
'header' => gT('Description'),
'name' => 'template_name',
'value'=>'$data->template->description',
'htmlOptions' => array('class' => 'col-md-3'),
'type'=>'raw',
),

array(
'header' => gT('Type'),
'name' => 'templates_type',
'value'=>'$data->typeIcon',
'type' => 'raw',
'htmlOptions' => array('class' => 'col-md-2'),
),

array(
'header' => gT('Extends'),
'name' => 'templates_extends',
'value'=>'$data->template->extends',
'htmlOptions' => array('class' => 'col-md-2'),
),

array(
'header' => '',
'name' => 'actions',
'value'=>'$data->buttons',
'type'=>'raw',
'htmlOptions' => array('class' => 'col-md-1'),
),

)));
?>
<?php $bFromSurveyGroup = ($oSurveyTheme->scenario == 'surveygroup')?true:false; ?>
<div class="ls-space margin left-15 right-15 row list-themes">
<ul class="nav nav-tabs" id="themelist" role="tablist">
<li class="active"><a href="#surveythemes"><?php eT('Survey themes'); ?></a></li>
<li><a href="#adminthemes"><?php eT('Admin themes'); ?></a></li>
<li><a href="#questionthemes"><?php eT('Question themes'); ?></a></li>
</ul>
<div class="tab-content">
<div id="surveythemes" class="tab-pane active">
<div class="col-lg-12 list-surveys">

<?php
if (!$bFromSurveyGroup){
$this->renderPartial('super/fullpagebar_view', array(
'fullpagebar' => array(
'returnbutton'=>array(
'url'=>'index',
'text'=>gT('Close'),
),
)
));
echo '<h3>'.gT('Installed survey themes:').'</h3>';
}


?>

<div class="row">
<div class="col-sm-12 content-right">

<?php $this->widget('bootstrap.widgets.TbGridView', array(
'dataProvider' => $oSurveyTheme->search(),
'columns' => array(
array(
'header' => gT('Preview'),
'name' => 'preview',
'value'=> '$data->preview',
'type'=>'raw',
'htmlOptions' => array('class' => 'col-md-1'),
),

array(
'header' => gT('Name'),
'name' => 'template_name',
'value'=>'$data->template_name',
'htmlOptions' => array('class' => 'col-md-2'),
),

array(
'header' => gT('Description'),
'name' => 'template_name',
'value'=>'$data->template->description',
'htmlOptions' => array('class' => 'col-md-3'),
'type'=>'raw',
),

array(
'header' => gT('Type'),
'name' => 'templates_type',
'value'=>'$data->typeIcon',
'type' => 'raw',
'htmlOptions' => array('class' => 'col-md-2'),
),

array(
'header' => gT('Extends'),
'name' => 'templates_extends',
'value'=>'$data->template->extends',
'htmlOptions' => array('class' => 'col-md-2'),
),

array(
'header' => '',
'name' => 'actions',
'value'=>'$data->buttons',
'type'=>'raw',
'htmlOptions' => array('class' => 'col-md-1'),
),

)));
?>

</div>
</div>

<?php if (count($oSurveyTheme->templatesWithNoDb) > 0 && !$bFromSurveyGroup):?>
<h3><?php eT('Available survey themes:'); ?></h3>
<div class="row">
<div class="col-sm-12 content-right">

<div id="templates_no_db" class="grid-view">
<table class="items table">
<thead>
<tr>
<th><?php eT('Preview'); ?></th><th><?php eT('Folder'); ?></th><th><?php eT('Description'); ?></th><th><?php eT('Type'); ?></th><th><?php eT('Extends'); ?></th><th></th>
</tr>
</thead>

<tbody>
<?php foreach ($oSurveyTheme->templatesWithNoDb as $oTemplate):?>
<?php // echo $oTemplate; ?>
<tr class="odd">
<td class="col-md-1"><?php echo $oTemplate->preview; ?></td>
<td class="col-md-2"><?php echo $oTemplate->sTemplateName; ?></td>
<td class="col-md-3"><?php echo $oTemplate->config->metadatas->description; ?></td>
<td class="col-md-2"><?php eT('XML themes');?></td>
<td class="col-md-2"><?php echo $oTemplate->config->metadatas->extends; ?></td>
<td class="col-md-1"><?php echo $oTemplate->buttons; ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>

</div>

</div>
</div>
<?php endif;?>
</div>
</div>
</div>

<?php if (count($model->templatesWithNoDb) > 0 && !$bFromSurveyGroup):?>
<h3><?php eT('Available survey themes:'); ?></h3>
<div class="row">
<div class="col-sm-12 content-right">

<div id="templates_no_db" class="grid-view">
<table class="items table">
<thead>
<tr>
<th><?php eT('Preview'); ?></th><th><?php eT('Folder'); ?></th><th><?php eT('Description'); ?></th><th><?php eT('Type'); ?></th><th><?php eT('Extends'); ?></th><th></th>
</tr>
</thead>

<tbody>
<?php foreach ($model->templatesWithNoDb as $oTemplate):?>
<?php // echo $oTemplate; ?>
<tr class="odd">
<td class="col-md-1"><?php echo $oTemplate->preview; ?></td>
<td class="col-md-2"><?php echo $oTemplate->sTemplateName; ?></td>
<td class="col-md-3"><?php echo $oTemplate->config->metadatas->description; ?></td>
<td class="col-md-2"><?php eT('XML themes');?></td>
<td class="col-md-2"><?php echo $oTemplate->config->metadatas->extends; ?></td>
<td class="col-md-1"><?php echo $oTemplate->buttons; ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>

<div id="adminthemes" class="tab-pane">
<div class="col-lg-12 list-surveys">
<h3><?php eT('Available admin themes:'); ?></h3>
<div class="row">
<div class="col-sm-12 content-right">
<div id="templates_no_db" class="grid-view">
<table class="items table">
<thead>
<tr>
<th><?php eT('Preview'); ?></th><th><?php eT('Folder'); ?></th><th><?php eT('Description'); ?></th><th><?php eT('Type'); ?></th><th></th>
</tr>
</thead>

<tbody>
<?php foreach ($oAdminTheme->adminThemeList as $oTheme ):?>
<tr class="odd">
<td class="col-md-1"><?php echo $oTheme->preview; ?></td>
<td class="col-md-2"><?php echo $oTheme->metadatas->name; ?></td>
<td class="col-md-3"><?php echo $oTheme->metadatas->description; ?></td>
<td class="col-md-2"><?php eT('core admin theme');?></td>
<td class="col-md-1">
<?php if ($oTheme->path == getGlobalSetting('admintheme')):?>
<?php eT("Selected")?>
<?php else: ?>
<a href="<?php echo Yii::app()->getController()->createUrl("admin/themeoptions/sa/setAdminTheme/", ['sAdminThemeName'=>$oTheme->path]);?>" class="btn btn-default ">
<?php eT("select");?>
</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>

</div>

</div>
</div>

</div>
</div>
<?php endif;?>
<div id="questionthemes" class="tab-pane">
questions
</div>
</div>
</div>




<script>
$('#themelist a').click(function (e) {
window.location.hash = $(this).attr('href');
e.preventDefault();
$(this).tab('show');
});
$(document).on('ready pjax:complete', function(){
if(window.location.hash){
$('#themelist').find('a[href='+window.location.hash+']').trigger('click');
}
})
</script>
Binary file added themes/admin/Apple_Blossom/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/admin/Bay_of_Many/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/admin/Black_Pearl/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/admin/Dark_Sky/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/admin/Free_Magenta/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/admin/Noto_All_Languages/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/admin/Purple_Tentacle/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/admin/Sea_Green/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/admin/Sunset_Orange/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eca1b91

Please sign in to comment.