1: <?php if(!defined('APPLICATION')) exit();
2:
3: 4: 5: 6: 7: 8: 9:
10: class ActionController extends DashboardController {
11:
12: 13: 14: 15:
16: public $Uses = array('Form', 'ActionModel');
17:
18: 19: 20: 21: 22: 23:
24: public function Initialize() {
25: parent::Initialize();
26: $this->Application = 'Yaga';
27: Gdn_Theme::Section('Dashboard');
28: if($this->Menu) {
29: $this->Menu->HighlightRoute('/action');
30: }
31: $this->AddJsFile('jquery-ui-1.10.0.custom.min.js');
32: $this->AddJsFile('admin.actions.js');
33: $this->AddCssFile('reactions.css');
34: }
35:
36: 37: 38: 39: 40:
41: public function Settings($Page = '') {
42: $this->Permission('Yaga.Reactions.Manage');
43: $this->AddSideMenu('action/settings');
44:
45: $this->Title(T('Yaga.ManageReactions'));
46:
47:
48: $this->SetData('Actions', $this->ActionModel->Get());
49:
50: $this->Render();
51: }
52:
53: 54: 55: 56: 57:
58: public function Edit($ActionID = NULL) {
59: $this->Permission('Yaga.Reactions.Manage');
60: $this->AddSideMenu('action/settings');
61: $this->Form->SetModel($this->ActionModel);
62:
63: $Edit = FALSE;
64: $this->Title(T('Yaga.AddAction'));
65: if($ActionID) {
66: $this->Action = $this->ActionModel->GetByID($ActionID);
67: $this->Form->AddHidden('ActionID', $ActionID);
68: $Edit = TRUE;
69: $this->Title(T('Yaga.EditAction'));
70: }
71:
72:
73: $this->SetData('Icons', array('Happy', 'Happy2', 'Smiley', 'Smiley2', 'Tongue', 'Tongue2', 'Sad', 'Sad2', 'Wink', 'Wink2', 'Grin', 'Shocked', 'Confused', 'Confused2', 'Neutral', 'Neutral2', 'Wondering', 'Wondering2', 'PointUp', 'PointRight', 'PointDown', 'PointLeft', 'ThumbsUp', 'ThumbsUp2', 'Shocked2', 'Evil', 'Evil2', 'Angry', 'Angry2', 'Heart', 'Heart2', 'HeartBroken', 'Star', 'Star2', 'Grin2', 'Cool', 'Cool2', 'Question', 'Notification', 'Warning', 'Spam', 'Blocked', 'Eye', 'Eye2', 'EyeBlocked', 'Flag', 'BrightnessMedium', 'QuotesLeft', 'Music', 'Pacman', 'Bullhorn', 'Rocket', 'Fire', 'Hammer', 'Target', 'Lightning', 'Shield', 'CheckmarkCircle', 'Lab', 'Leaf', 'Dashboard', 'Droplet', 'Feed', 'Support', 'Hammer2', 'Wand', 'Cog', 'Gift', 'Trophy', 'Magnet', 'Switch', 'Globe', 'Bookmark', 'Bookmarks', 'Star3', 'Info', 'Info2', 'CancelCircle', 'Checkmark', 'Close'));
74:
75:
76: $PermissionModel = new PermissionModel();
77: $Permissions = $PermissionModel->PermissionColumns();
78: unset($Permissions['PermissionID']);
79: $PermissionKeys = array_keys($Permissions);
80: $PermissionList = array_combine($PermissionKeys, $PermissionKeys);
81: $this->SetData('Permissions', $PermissionList);
82:
83: if($this->Form->IsPostBack() == FALSE) {
84: if(property_exists($this, 'Action')) {
85: $this->Form->SetData($this->Action);
86: }
87: else {
88: $this->Form->SetData(array('Permission' => 'Yaga.Reactions.Add'));
89: }
90: }
91: else {
92: if($this->Form->Save()) {
93: if($Edit) {
94: $Action = $this->ActionModel->GetByID($this->Form->GetFormValue('ActionID'));
95: }
96: else {
97: $Action = $this->ActionModel->GetNewestAction();
98: }
99:
100: $NewActionRow = ActionRow($Action);
101:
102: if($Edit) {
103: $this->JsonTarget('#Action_' . $this->Action->ActionID, $NewActionRow, 'ReplaceWith');
104: $this->InformMessage(T('Yaga.ActionUpdated'));
105: }
106: else {
107: $this->JsonTarget('#Actions', $NewActionRow, 'Append');
108: $this->InformMessage(T('Yaga.ActionAdded'));
109: }
110: }
111: }
112:
113: $this->Render('edit');
114: }
115:
116: 117: 118:
119: public function Add() {
120: $this->Edit();
121: }
122:
123: 124: 125: 126: 127: 128:
129: public function Delete($ActionID) {
130: $Action = $this->ActionModel->GetID($ActionID);
131:
132: if(!$Action) {
133: throw NotFoundException(T('Yaga.Action'));
134: }
135:
136: $this->Permission('Yaga.Reactions.Manage');
137:
138: $Actions = $this->ActionModel->Get();
139:
140: foreach($Actions as $Index => $ActionObject) {
141: $Actions[$Index] = (array)$ActionObject;
142: }
143:
144: $Actions = ConsolidateArrayValuesByKey($Actions, 'ActionID', 'Name');
145: unset($Actions[$ActionID]);
146:
147: $this->SetData('OtherActions', $Actions);
148: $this->SetData('ActionName', $Action->Name);
149:
150: if($this->Form->IsPostBack()) {
151: $FormValues = $this->Form->FormValues();
152: $ReplacementID = $FormValues['Move'] ? $FormValues['ReplacementID'] : NULL;
153:
154:
155: if(!$this->ActionModel->Delete($ActionID, $ReplacementID)) {
156: $this->Form->AddError(sprintf(T('Yaga.Error.DeleteFailed'), T('Yaga.Action')));
157: }
158:
159: if($this->Form->ErrorCount() == 0) {
160: if($this->_DeliveryType === DELIVERY_TYPE_ALL) {
161: Redirect('action/settings');
162: }
163:
164: $this->JsonTarget('#ActionID_' . $ActionID, NULL, 'SlideUp');
165: }
166: }
167:
168: $this->AddSideMenu('action/settings');
169: $this->SetData('Title', T('Yaga.Action.Delete'));
170: $this->Render();
171: }
172:
173: 174: 175: 176: 177:
178: public function Sort() {
179:
180: $this->Permission('Yaga.Reactions.Manage');
181:
182: $Request = Gdn::Request();
183: if($Request->IsPostBack()) {
184: $SortArray = $Request->GetValue('SortArray', NULL);
185: $Saves = $this->ActionModel->SaveSort($SortArray);
186: $this->SetData('Result', TRUE);
187: $this->SetData('Saves', $Saves);
188: }
189: else {
190: $this->SetData('Result', FALSE);
191: }
192:
193: $this->RenderData();
194: }
195: }
196: