Skip to content

Commit

Permalink
Dev: Move plugin action buttons to model
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 29, 2018
1 parent 6f897ac commit 7e30e3f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 53 deletions.
1 change: 1 addition & 0 deletions application/controllers/admin/PluginManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function ($installedPlugin) {
$aData['fullpagebar']['returnbutton']['url'] = 'index';
$aData['fullpagebar']['returnbutton']['text'] = gT('Return to admin home');
$aData['data'] = $data;
$aData['plugins'] = $aoPlugins;
$aData['scanFilesUrl'] = $this->getController()->createUrl(
'/admin/pluginmanager',
[
Expand Down
1 change: 1 addition & 0 deletions application/libraries/PluginManager/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public function dispatchEvent(PluginEvent $event, $target = array())
* that specifically deals with enabling / disabling plugins.
* @param boolean $includeInstalledPlugins If set, also return plugins even if already installed in database.
* @return array
* @todo Factor out
*/
public function scanPlugins($includeInstalledPlugins = false)
{
Expand Down
56 changes: 56 additions & 0 deletions application/models/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function isCompatible()

/**
* @return xml
* @todo Use PluginConfiguration.
* @throws Exception if file does not exist.
*/
public function getConfig()
Expand All @@ -86,6 +87,61 @@ public function getConfig()
}
}

/**
* Action buttons in plugin list.
* @return string HTML
*/
public function getActionButtons()
{
$output='';
if (Permission::model()->hasGlobalPermission('settings','update')) {
if ($this->load_error == 1) {
$reloadUrl = Yii::app()->createUrl(
'admin/pluginmanager',
[
'sa' => 'resetLoadError',
'pluginId' => $this->id
]
);
$output = "<a href='" . $reloadUrl . "' data-toggle='tooltip' title='" . gT('Attempt plugin reload') ."' class='btn btn-default btn-xs btntooltip'><span class='fa fa-refresh'></span></a>";
} elseif ($this->active == 0) {
$output = "<a data-toggle='tooltip' title='" . gT('Activate'). "' href='#activate' data-action='activate' data-id='".$this->id . "' class='ls_action_changestate btn btn-default btn-xs btntooltip'>"
. "<span class='fa fa-power-off'></span>"
."</a>";
} else {
$output = "<a data-toggle='tooltip' title='" . gT('Deactivate') . "' href='#deactivate' data-action='deactivate' data-id='".$this->id."' class='ls_action_changestate btn btn-warning btn-xs btntooltip'>"
. "<span class='fa fa-power-off'></span>"
."</a>";
}

// TODO: Don't use JS native confirm.
if ($this->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='" . $this->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;
}

/**
* @param Plugin|null $plugin
* @param string $pluginName
Expand Down
55 changes: 2 additions & 53 deletions application/views/admin/pluginmanager/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
'caseSensitiveSort'=> false,
);

$dataProvider = new CArrayDataProvider($data, $providerOptions);
$dataProvider = new CArrayDataProvider($plugins, $providerOptions);

$gridColumns = array(
array(// display the status
Expand Down Expand Up @@ -114,58 +114,7 @@
'htmlOptions' => array(
//'style' => 'white-space: nowrap;',
),
'value' => function($data) {

$output='';
if(Permission::model()->hasGlobalPermission('settings','update'))
{
if ($data['load_error'] == 1) {
$reloadUrl = Yii::app()->createUrl(
'admin/pluginmanager',
[
'sa' => 'resetLoadError',
'pluginId' => $data['id']
]
);
$output = "<a href='" . $reloadUrl . "' data-toggle='tooltip' title='" . gT('Attempt plugin reload') ."' class='btn btn-default btn-xs btntooltip'><span class='fa fa-refresh'></span></a>";
} elseif ($data['active'] == 0)
{
$output = "<a data-toggle='tooltip' title='" . gT('Activate'). "' href='#activate' data-action='activate' data-id='".$data['id']."' class='ls_action_changestate btn btn-default btn-xs btntooltip'>"
. "<span class='fa fa-power-off'></span>"
."</a>";
} else {
$output = "<a data-toggle='tooltip' title='" . gT('Deactivate') . "' href='#deactivate' data-action='deactivate' data-id='".$data['id']."' class='ls_action_changestate btn btn-warning btn-xs btntooltip'>"
. "<span class='fa fa-power-off'></span>"
."</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;
}
'value' => '$data->getActionButtons()'
),
);

Expand Down

0 comments on commit 7e30e3f

Please sign in to comment.