Skip to content

Commit

Permalink
New feature #09442: Allow to save (not save and quit) in Plugin setti…
Browse files Browse the repository at this point in the history
…ngs and global settings

Dev: Add actual tab to url in #tabs
Dev: Fix an notice in settingsWidget buttons
Dev: TODO : same for survey settings
  • Loading branch information
Shnoulle committed Jan 8, 2015
1 parent bbf129d commit 653ce2a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
5 changes: 2 additions & 3 deletions application/controllers/PluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ public function actionConfigure($id)
$aSave[$name] = App()->request->getPost($name, null);
}
$oPluginObject->saveSettings($aSave);

if(App()->request->getPost('redirect'))
Yii::app()->user->setFlash('pluginmanager', 'Settings saved');
if(!is_null(App()->request->getPost('redirect')))
{
Yii::app()->user->setFlash('pluginmanager', 'Settings saved');
$this->forward('plugins/index', true);
}
}
Expand Down
21 changes: 15 additions & 6 deletions application/controllers/admin/globalsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ private function _displaySettings()
'admin/user/setusertemplates'=>'admin/user/sa/index'
);
$refurl= str_replace(array_keys($aReplacements),array_values($aReplacements),$refurl);
Yii::app()->session['refurl'] = htmlspecialchars($refurl); //just to be safe!
// Don't update refurl is it's globalsetting
if(strpos($refurl,'globalsettings')===false)
Yii::app()->session['refurl'] = htmlspecialchars($refurl); //just to be safe!

$data['title'] = "hi";
$data['message'] = "message";
Expand Down Expand Up @@ -110,11 +112,13 @@ private function _displaySettings()

private function _saveSettings()
{
if (App()->request->getPost('action') !== "globalsettingssave") {
if (App()->request->getPost('action') !== "save" && App()->request->getPost('action') !== "savequit") // Why not use App()->request->isPostRequest ?
{
return;
}

if (!Permission::model()->hasGlobalPermission('settings','update')) {
if (!Permission::model()->hasGlobalPermission('settings','update'))
{
$this->getController()->redirect(array('/admin'));
}
Yii::app()->loadHelper('surveytranslator');
Expand Down Expand Up @@ -226,9 +230,14 @@ private function _saveSettings()
setGlobalSetting('usercontrolSameGroupPolicy', strip_tags(App()->request->getPost('usercontrolSameGroupPolicy')));

Yii::app()->setFlashMessage(gT("Global settings were saved."));

$url = htmlspecialchars_decode(Yii::app()->session['refurl']);
if($url){Yii::app()->getController()->redirect($url);}
if(App()->request->getPost('action') == "savequit")
{
$url = htmlspecialchars_decode(Yii::app()->session['refurl']);
if($url)
{
Yii::app()->getController()->redirect($url);
}
}
}

private function _checkSettings()
Expand Down
11 changes: 8 additions & 3 deletions application/extensions/SettingsWidget/SettingsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ protected function renderButton($label, $htmlOptions)
$htmlOptions['class'] = isset($htmlOptions['class']) ? $htmlOptions['class'] . " btn" : 'btn';
if (isset($htmlOptions['type']) && $htmlOptions['type'] == 'link')
{
$htmlOptions['class'] = isset($htmlOptions['class']) ? $htmlOptions['class'] . " btn-link button" : 'btn-link button';
//echo CHtml::link($label,$htmlOptions['href'],$htmlOptions); // This allow cancel without js
echo CHtml::linkButton($label,$htmlOptions);
$htmlOptions['class'] = $htmlOptions['class'] . " btn-link button";
echo CHtml::link($label,$htmlOptions['href'],$htmlOptions); // This allow cancel without js
//echo CHtml::linkButton($label,$htmlOptions);
}
elseif(isset($htmlOptions['type']))
{
Expand All @@ -96,6 +96,11 @@ protected function renderButtons()
echo CHtml::openTag('div', array('class' => 'buttons control-group'));
foreach ($this->buttons as $label => $htmlOptions)
{
if (is_string($htmlOptions))
{
$label = $htmlOptions;
$htmlOptions = array();
}
$htmlOptions['class'] = isset($htmlOptions['class']) ? $htmlOptions['class'] . " inline" : 'inline';
$this->renderButton($label, $htmlOptions);
}
Expand Down
7 changes: 6 additions & 1 deletion application/views/admin/globalSettings_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,12 @@
</div>
<input type='hidden' name='restrictToLanguages' id='restrictToLanguages' value='<?php implode(' ',$restrictToLanguages); ?>'/>
<div class="hidden hide" id="submitglobalbutton">
<p><button type="submit" name="action" value='globalsettingssave'><?php eT("Save"); ?></button></p>
<p>
<?php if(Yii::app()->session['refurl']) { ?>
<button type="submit" name="action" value='savequit'><?php eT("Save and quit"); ?></button>
<?php } ?>
<button type="submit" name="action" value='save'><?php eT("Save"); ?></button>
</p>
</div>
</form>

Expand Down
5 changes: 5 additions & 0 deletions application/views/plugins/configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
'method' => 'post',
'buttons' => array(
gT('Save plugin settings'),
gT('Save and return to plugins list')=>array(
'type'=>'submit',
'name'=>'redirect',
'value'=>App()->createUrl('plugins/index'), // This allow to use App()->request->getPost('redirect')) for forward (not used actually)
),
gT('Cancel') => array(
'type' => 'link',
'href' => App()->createUrl('plugins/index')
Expand Down
11 changes: 10 additions & 1 deletion scripts/admin/admin_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ $(document).ready(function(){
$('#MaximizeGroupWindow').click(function(){
$('#groupdetails').show();
});
$('#tabs').tabs();
$('#tabs').tabs({
activate: function(event, ui) {
if(history.pushState) {
history.pushState(null, null, '#'+ui.newPanel.attr('id'));
}
else {
location.hash = ui.newPanel.attr('id');
}
}
});
$('.tab-nav').tabs();
$(".flashmessage").each(function() {
$(this).notify().notify('create','themeroller',{},{custom:true,
Expand Down
3 changes: 3 additions & 0 deletions scripts/admin/globalsettings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
$(document).on('click',"[data-copy] :submit",function(){
$("form :input[value='"+$(this).val()+"']").click();
});
$(document).on('submit',"#frmglobalsettings",function(){
$('#frmglobalsettings').attr('action',$('#frmglobalsettings').attr('action')+location.hash);// Maybe validate before ?
});
$(document).ready(function(){
$("[data-copy]").each(function(){
$(this).html($("#"+$(this).data('copy')).html());
Expand Down

0 comments on commit 653ce2a

Please sign in to comment.