|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* A form field that allows workflow actions and transitions to be edited, |
|
4
|
|
|
* while showing a visual overview of the flow. |
|
5
|
|
|
* |
|
6
|
|
|
* @package advancedworkflow |
|
7
|
|
|
*/ |
|
8
|
|
|
class WorkflowField extends FormField |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
public static $allowed_actions = array( |
|
12
|
|
|
'action', |
|
13
|
|
|
'transition', |
|
14
|
|
|
'sort' |
|
15
|
|
|
); |
|
16
|
|
|
|
|
17
|
|
|
protected $definition; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct($name, $title, WorkflowDefinition $definition) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->definition = $definition; |
|
22
|
|
|
$this->addExtraClass('workflow-field'); |
|
23
|
|
|
|
|
24
|
|
|
parent::__construct($name, $title); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function action() |
|
28
|
|
|
{ |
|
29
|
|
|
return new WorkflowFieldActionController($this, 'action'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function transition() |
|
33
|
|
|
{ |
|
34
|
|
|
return new WorkflowFieldTransitionController($this, 'transition'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function sort($request) |
|
38
|
|
|
{ |
|
39
|
|
|
if (!SecurityToken::inst()->checkRequest($request)) { |
|
40
|
|
|
$this->httpError(404); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$class = $request->postVar('class'); |
|
44
|
|
|
$ids = $request->postVar('id'); |
|
45
|
|
|
|
|
46
|
|
|
if ($class == 'WorkflowAction') { |
|
47
|
|
|
$objects = $this->Definition()->Actions(); |
|
|
|
|
|
|
48
|
|
|
} elseif ($class == 'WorkflowTransition') { |
|
49
|
|
|
$parent = $request->postVar('parent'); |
|
50
|
|
|
$action = $this->Definition()->Actions()->byID($parent); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
if (!$action) { |
|
53
|
|
|
$this->httpError(400, _t('AdvancedWorkflowAdmin.INVALIDPARENTID', 'An invalid parent ID was specified.')); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$objects = $action->Transitions(); |
|
57
|
|
|
} else { |
|
58
|
|
|
$this->httpError(400, _t('AdvancedWorkflowAdmin.INVALIDCLASSTOORDER', 'An invalid class to order was specified.')); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (array_diff($ids, $objects->column('ID'))) { |
|
|
|
|
|
|
62
|
|
|
$this->httpError(400, _t('AdvancedWorkflowAdmin.INVALIDIDLIST', 'An invalid list of IDs was provided.')); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
singleton('WorkflowService')->reorder($objects, $ids); |
|
66
|
|
|
|
|
67
|
|
|
return new SS_HTTPResponse( |
|
68
|
|
|
null, 200, _t('AdvancedWorkflowAdmin.SORTORDERSAVED', 'The sort order has been saved.') |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function getTemplate() |
|
73
|
|
|
{ |
|
74
|
|
|
return 'WorkflowField'; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function FieldHolder($properties = array()) |
|
78
|
|
|
{ |
|
79
|
|
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); |
|
80
|
|
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); |
|
81
|
|
|
Requirements::javascript(ADVANCED_WORKFLOW_DIR . '/javascript/WorkflowField.js'); |
|
82
|
|
|
Requirements::css(ADVANCED_WORKFLOW_DIR . '/css/WorkflowField.css'); |
|
83
|
|
|
|
|
84
|
|
|
return $this->Field($properties); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function Definition() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->definition; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function ActionLink() |
|
93
|
|
|
{ |
|
94
|
|
|
$parts = func_get_args(); |
|
95
|
|
|
array_unshift($parts, 'action'); |
|
96
|
|
|
|
|
97
|
|
|
return $this->Link(implode('/', $parts)); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function TransitionLink() |
|
101
|
|
|
{ |
|
102
|
|
|
$parts = func_get_args(); |
|
103
|
|
|
array_unshift($parts, 'transition'); |
|
104
|
|
|
|
|
105
|
|
|
return $this->Link(implode('/', $parts)); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function CreateableActions() |
|
109
|
|
|
{ |
|
110
|
|
|
$list = new ArrayList(); |
|
111
|
|
|
$classes = ClassInfo::subclassesFor('WorkflowAction'); |
|
112
|
|
|
|
|
113
|
|
|
array_shift($classes); |
|
114
|
|
|
sort($classes); |
|
115
|
|
|
|
|
116
|
|
|
foreach ($classes as $class) { |
|
117
|
|
|
$reflect = new ReflectionClass($class); |
|
118
|
|
|
$can = singleton($class)->canCreate() && !$reflect->isAbstract(); |
|
119
|
|
|
|
|
120
|
|
|
if ($can) { |
|
121
|
|
|
$list->push(new ArrayData(array( |
|
122
|
|
|
'Title' => singleton($class)->singular_name(), |
|
123
|
|
|
'Class' => $class |
|
124
|
|
|
))); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $list; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.