Skip to content

Commit

Permalink
Dev: Add button to uninstall plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 28, 2018
1 parent 19189d7 commit cdd9420
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 7 deletions.
55 changes: 55 additions & 0 deletions application/controllers/admin/PluginManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function index()

$oPluginManager->scanPlugins();

$jsFile = App()->getConfig('adminscripts') . 'plugin_manager.js';
App()->getClientScript()->registerScriptFile($jsFile);

// Scan the plugins folder.
/*
$aDiscoveredPlugins = $oPluginManager->scanPlugins();
Expand Down Expand Up @@ -320,6 +323,58 @@ public function resetLoadError($pluginId)
}
}

/**
* Run when user click button to uninstall plugin.
* @return void
*/
public function uninstallPlugin()
{
// Check permissions.
if (!Permission::model()->hasGlobalPermission('settings', 'update')) {
Yii::app()->setFlashMessage(gT('No permission'), 'error');
$this->getController()->redirect($this->getPluginManagerUrl());
}

// Get plugin id from post.
$request = Yii::app()->request;
$pluginId = (int) $request->getPost('pluginId');

$plugin = Plugin::model()->find('id = :id', [':id' => $pluginId]);

// Check if plugin exists.
if (empty($plugin)) {
Yii::app()->setFlashMessage(
sprintf(
gT('Found no plugin with id %d.'),
$pluginId
),
'error'
);
$this->getController()->redirect($this->getPluginManagerUrl());
} else {
if ($plugin->delete()) {
Yii::app()->setFlashMessage(gT('Plugin uninstalled.'), 'success');
} else {
Yii::app()->setFlashMessage(gT('Could not uninstall plugin.'), 'error');
}
$this->getController()->redirect($this->getPluginManagerUrl());
}
}

/**
* Return URL to plugin manager index..
* @return string
*/
protected function getPluginManagerUrl()
{
return $this->getController()->createUrl(
'/admin/pluginmanager',
[
'sa' => 'index'
]
);
}

/**
* Renders template(s) wrapped in header and footer
*
Expand Down
34 changes: 27 additions & 7 deletions application/views/admin/pluginmanager/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>

<?php
echo CHtml::beginForm(Yii::app()->createUrl('/admin/pluginmanager/sa/changestate'),'POST', array('id' => 'ls_action_changestate_form'));
//echo CHtml::beginForm(Yii::app()->createUrl('/admin/pluginmanager/sa/changestate'),'POST', array('id' => 'ls_action_changestate_form'));
/* @var $this ConfigController */
/* @var $dataProvider CActiveDataProvider */

Expand Down Expand Up @@ -108,11 +108,11 @@
'name' => 'description'
),
array(// display the activation link
'type' => 'html',
'type' => 'raw',
'header' => gT('Action'),
'name' => 'action',
'htmlOptions' => array(
'style' => 'white-space: nowrap;',
//'style' => 'white-space: nowrap;',
),
'value' => function($data) {

Expand All @@ -139,9 +139,29 @@
."</a>";
}

$output .= "
<a href='' data-toggle='tooltip' title='" . gT('Uninstall plugin') . "' class='btntooltip btn btn-danger btn-xs'><i class='fa fa-times-circle'></i></a>
";
// TODO: Don't use JS native confirm.
if ($data['active'] == 0) {
$uninstallUrl = App()->getController()->createUrl(
'/admin/pluginmanager',
[
'sa' => 'uninstallPlugin'
]
);
$output .= '&nbsp;' . CHtml::beginForm(
$uninstallUrl,
'post',
[
'style' => 'display: inline-block'
]
);
$output .= "
<input type='hidden' name='pluginId' value='" . $data['id'] . "' />
<button data-toggle='tooltip' onclick='return confirm(\"" . gT('Are you sure you want to uninstall this plugin?') . "\");' title='" . gT('Uninstall plugin') . "' class='btntooltip btn btn-danger btn-xs'>
<i class='fa fa-times-circle'></i>
</button>
</form>
";
}
}

return $output;
Expand All @@ -168,7 +188,7 @@

<input id="ls_action_changestate_type" type="hidden" name="type" value="" />
<input id="ls_action_changestate_id" type="hidden" name="id" value="" />
<?php echo CHtml::endForm(); ?>
<?php //echo CHtml::endForm(); ?>
<script type="text/javascript">
var bindActionButtons = function(){
$('#ls_action_changestate_form').on('click','.ls_action_changestate', function(e){
Expand Down
35 changes: 35 additions & 0 deletions assets/scripts/admin/plugin_manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* All JS related to plugin manager.
*/

// Namespace
var LS = LS || {
onDocumentReady: {}
};

LS.pluginManager = (function() {
var module = {};

/**
* Not used.
* @param {string} msg
* @return {boolean}
*/
module.confirm = function(msg) {
// TODO: Possible to return boolean from bootstrap modal?
$('#confirmation-modal').data('href', 'blablabla').modal('show');
return false;
};

/**
* Init this module.
*/
module.init = function() {
// Bound event to uninstall plugin button (plugin list).
//$('.ls-pm-uninstall-plugin').on('click', module.uninstallPlugin);
};

return module;
})();

$(document).on('ready pjax:scriptcomplete', LS.pluginManager.init);

0 comments on commit cdd9420

Please sign in to comment.