1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
*@author nicolaas [at] sunnysideup.co.nz |
4
|
|
|
*@package: dataobjectsorter |
5
|
|
|
*@description: allows you to edit one record |
6
|
|
|
* |
7
|
|
|
**/ |
8
|
|
|
|
9
|
|
|
class DataObjectOneRecordUpdateController extends DataObjectSortBaseClass |
10
|
|
|
{ |
11
|
|
|
private static $allowed_actions = array( |
|
|
|
|
12
|
|
|
"onerecordform" => 'DATA_OBJECT_SORT_AND_EDIT_PERMISSION', |
13
|
|
|
"show" => 'DATA_OBJECT_SORT_AND_EDIT_PERMISSION', |
14
|
|
|
"save" => 'DATA_OBJECT_SORT_AND_EDIT_PERMISSION' |
15
|
|
|
); |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* |
19
|
|
|
* make sure to also change in routes if you change this link |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private static $url_segment = 'dataobjectonerecordupdate'; |
|
|
|
|
23
|
|
|
|
24
|
|
|
public static function popup_link_only($className, $recordID) |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
DataObjectSorterRequirements::popup_link_requirements(); |
27
|
|
|
return Injector::inst()->get('DataObjectOneRecordUpdateController')->Link('show/'.$className."/".$recordID); |
28
|
|
|
} |
29
|
|
View Code Duplication |
public static function popup_link($className, $recordID, $linkText = 'click here to edit') |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$link = DataObjectOneRecordUpdateController::popup_link_only($className, $recordID); |
32
|
|
|
if ($link) { |
33
|
|
|
return ' |
34
|
|
|
<a href="'.$link.'" class="modalPopUp modal-popup" data-width="800" data-height="600" data-rel="window.open(\''.$link.'\', \'sortlistFor'.$className.$recordID.'\',\'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=600,left = 440,top = 200\'); return false;">'.$linkText.'</a>'; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function init() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
//must set this first. |
41
|
|
|
Config::inst()->update('SSViewer', 'theme_enabled', Config::inst()->get('DataObjectSorterRequirements', 'run_through_theme')); |
42
|
|
|
parent::init(); |
43
|
|
|
if (! Director::is_ajax()) { |
44
|
|
|
DataObjectSorterRequirements::popup_requirements('onerecord'); |
45
|
|
|
$url = Director::absoluteURL( |
46
|
|
|
Injector::inst()->get('DataObjectOneRecordUpdateController')->Link('onerecordform') |
47
|
|
|
); |
48
|
|
|
Requirements::customScript( |
49
|
|
|
"var DataObjectOneRecordUpdateURL = '".$url."'", |
50
|
|
|
'DataObjectOneRecordUpdateURL' |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function onerecordform() |
56
|
|
|
{ |
57
|
|
|
Versioned::set_reading_mode('Stage.Stage'); |
58
|
|
|
$table = $this->SecureTableToBeUpdated(); |
59
|
|
|
$record = $this->SecureRecordToBeUpdated(); |
60
|
|
|
$obj = $table::get()->byID($record); |
61
|
|
|
if (!$obj) { |
62
|
|
|
user_error("record could not be found!", E_USER_ERROR); |
63
|
|
|
} |
64
|
|
|
if (! $obj->canEdit()) { |
65
|
|
|
$this->permissionFailureStandard(); |
66
|
|
|
} |
67
|
|
|
$formFields = $this->getFormFields($obj); |
|
|
|
|
68
|
|
|
if (!$formFields) { |
69
|
|
|
user_error("Form Fields could not be Found", E_USER_ERROR); |
70
|
|
|
} |
71
|
|
|
$fields = new FieldList( |
72
|
|
|
new HiddenField("Table", "Table", $table), |
73
|
|
|
new HiddenField("Record", "Record", $record) |
74
|
|
|
); |
75
|
|
|
foreach ($formFields as $f) { |
76
|
|
|
$fields->push($f); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$form = new Form( |
80
|
|
|
$controller = $this, |
81
|
|
|
$name = "OneRecordForm", |
82
|
|
|
$fields, |
83
|
|
|
$actions = new FieldList(new FormAction("save", "save and close")) |
84
|
|
|
); |
85
|
|
|
$form->loadDataFrom($obj); |
86
|
|
|
return $form; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function save($data, $form) |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
$table = $this->SecureTableToBeUpdated(); |
92
|
|
|
$record = $this->SecureRecordToBeUpdated(); |
93
|
|
|
$obj = $table::get()->byID($record); |
94
|
|
|
if ($obj->canEdit()) { |
95
|
|
|
$form->saveInto($obj); |
96
|
|
|
$obj->write(); |
97
|
|
|
return ' |
98
|
|
|
<p>Your changes have been saved, please <a href="#" onclick="self.close(); return false;">close window</a>.</p> |
99
|
|
|
<script type="text/javascript">self.close();</script>'; |
100
|
|
|
} else { |
101
|
|
|
return $this->permissionFailureStandard(); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function show() |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$table = $this->SecureTableToBeUpdated(); |
108
|
|
|
$record = $this->SecureRecordToBeUpdated(); |
109
|
|
|
$obj = $table::get()->byID($record); |
110
|
|
|
if ($obj->canEdit()) { |
111
|
|
|
//.. |
112
|
|
|
} else { |
113
|
|
|
return $this->permissionFailure(); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|