vanilla-application-yaga/controllers/class.actioncontroller.php

124 lines
3.5 KiB
PHP
Raw Normal View History

2013-10-25 17:05:01 -05:00
<?php if(!defined('APPLICATION')) exit();
/* Copyright 2013 Zachary Doll */
/**
* Manage actions that are available for reactions
2013-10-25 17:05:01 -05:00
*
* @since 1.0
* @package Yaga
*/
class ActionController extends DashboardController {
2013-10-25 17:05:01 -05:00
/**
2013-11-12 10:59:14 -06:00
* @var array These objects will be created on instantiation and available via
* $this->ObjectName
2013-10-25 17:05:01 -05:00
*/
2013-11-12 10:59:14 -06:00
public $Uses = array('Form', 'ActionModel');
2013-10-25 17:05:01 -05:00
/**
2013-11-12 10:59:14 -06:00
* Make this look like a dashboard page and add the resources
2013-10-25 17:05:01 -05:00
*
* @since 1.0
* @access public
*/
public function Initialize() {
parent::Initialize();
Gdn_Theme::Section('Dashboard');
if($this->Menu) {
2013-11-12 10:19:21 -06:00
$this->Menu->HighlightRoute('/action');
2013-10-25 17:05:01 -05:00
}
$this->AddJsFile('admin.actions.js');
$this->AddCssFile('reactions.css');
2013-10-25 17:05:01 -05:00
}
2013-11-12 10:59:14 -06:00
/**
* Manage the available actions for reactions
*
* @param int $Page
*/
2013-10-25 17:05:01 -05:00
public function Settings($Page = '') {
$this->Permission('Yaga.Reactions.Manage');
$this->AddSideMenu('action/settings');
2013-10-25 17:05:01 -05:00
$this->Title('Manage Reactions');
// Get list of actions from the model and pass to the view
$this->SetData('Actions', $this->ActionModel->GetActions());
$this->Render();
}
2013-11-12 10:59:14 -06:00
/**
* Edit an existing action or add a new one
*
* @param int $ActionID
*/
2013-10-25 17:05:01 -05:00
public function Edit($ActionID = NULL) {
$this->Permission('Yaga.Reactions.Manage');
$this->AddSideMenu('action/settings');
2013-10-25 17:05:01 -05:00
$this->Form->SetModel($this->ActionModel);
$Edit = FALSE;
2013-10-25 17:05:01 -05:00
if($ActionID) {
$this->Action = $this->ActionModel->GetAction($ActionID);
$this->Form->AddHidden('ActionID', $ActionID);
$Edit = TRUE;
2013-10-25 17:05:01 -05:00
}
if($this->Form->IsPostBack() == FALSE) {
if(property_exists($this, 'Action')) {
$this->Form->SetData($this->Action);
}
2013-10-25 17:05:01 -05:00
}
else {
if($this->Form->Save()) {
if($Edit) {
$Action = $this->ActionModel->GetAction($this->Form->GetFormValue('ActionID'));
}
else {
$Action = $this->ActionModel->GetNewestAction();
}
2013-10-25 17:05:01 -05:00
$NewActionRow = '<tr id="ActionID_' . $Action->ActionID . '" data-actionid="'. $Action->ActionID . '">';
$NewActionRow .= "<td>$Action->Name</td>";
$NewActionRow .= '<td><span class="ReactSprite ' . $Action->CssClass . '"> </span></td>';
2013-10-25 17:05:01 -05:00
$NewActionRow .= "<td>$Action->Description</td>";
$NewActionRow .= "<td>$Action->Tooltip</td>";
$NewActionRow .= "<td>$Action->AwardValue</td>";
$NewActionRow .= '<td>' . Anchor(T('Edit'), 'yaga/action/edit/' . $Action->ActionID, array('class' => 'Popup SmallButton')) . Anchor(T('Delete'), 'yaga/action/delete/' . $Action->ActionID, array('class' => 'Hijack SmallButton')) . '</td>';
2013-10-25 17:05:01 -05:00
$NewActionRow .= '</tr>';
if($Edit) {
$this->JsonTarget('#ActionID_' . $this->Action->ActionID, $NewActionRow, 'ReplaceWith');
$this->InformMessage('Action updated successfully!');
}
else {
$this->JsonTarget('#Actions tbody', $NewActionRow, 'Append');
$this->InformMessage('Action added successfully!');
}
2013-10-25 17:05:01 -05:00
}
}
$this->Render('add');
}
2013-11-12 10:59:14 -06:00
/**
* Convenience function for nice URLs
*/
2013-10-25 17:05:01 -05:00
public function Add() {
$this->Edit();
}
2013-11-12 10:59:14 -06:00
/**
* Remove the action via model.
*
* @todo Consider adding a confirmation page when not using JS
* @param int $ActionID
*/
2013-10-25 17:05:01 -05:00
public function Delete($ActionID) {
$this->Permission('Yaga.Reactions.Manage');
$this->ActionModel->DeleteAction($ActionID);
2013-11-12 10:59:14 -06:00
redirect('action/settings');
2013-10-25 17:05:01 -05:00
}
}