mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
(merged from branches/roa. use "svn log -c <changeset> -g <module-svn-path>" for detailed commit message)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@60289 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
574fdb190d
commit
cc0117a307
@ -328,7 +328,7 @@ abstract class ModelAdmin extends LeftAndMain {
|
||||
*
|
||||
*/
|
||||
class ModelAdmin_CollectionController extends Controller {
|
||||
protected $parentController;
|
||||
public $parentController;
|
||||
protected $modelClass;
|
||||
|
||||
static $url_handlers = array(
|
||||
@ -401,12 +401,15 @@ class ModelAdmin_CollectionController extends Controller {
|
||||
$form = new Form($this, "SearchForm",
|
||||
$fields,
|
||||
new FieldSet(
|
||||
new FormAction('search', _t('MemberTableField.SEARCH'))
|
||||
new FormAction('search', _t('MemberTableField.SEARCH')),
|
||||
$clearAction = new ResetFormAction('clearsearch', _t('ModelAdmin.CLEAR_SEARCH','Clear Search'))
|
||||
)
|
||||
);
|
||||
$form->setFormAction(Controller::join_links($this->Link(), "search"));
|
||||
$form->setFormMethod('get');
|
||||
$form->setHTMLID("Form_SearchForm_" . $this->modelClass);
|
||||
$clearAction->useButtonTag = true;
|
||||
$clearAction->addExtraClass('minorAction');
|
||||
return $form;
|
||||
}
|
||||
|
||||
@ -420,10 +423,15 @@ class ModelAdmin_CollectionController extends Controller {
|
||||
foreach ($source as $fieldName => $label){
|
||||
$value[] = $fieldName;
|
||||
}
|
||||
$checkboxes = new CheckboxSetField("ResultAssembly", "Tick the box if you want it to be shown in the results", $source, $value);
|
||||
$checkboxes = new CheckboxSetField("ResultAssembly", false, $source, $value);
|
||||
|
||||
$field = new CompositeField(
|
||||
new LiteralField("ToggleResultAssemblyLink", "<a class=\"form_frontend_function toggle_result_assembly\" href=\"#\">+ choose columns</a>"),
|
||||
new LiteralField(
|
||||
"ToggleResultAssemblyLink",
|
||||
sprintf("<a class=\"form_frontend_function toggle_result_assembly\" href=\"#\">%s</a>",
|
||||
_t('ModelAdmin.CHOOSE_COLUMNS', 'Select result columns...')
|
||||
)
|
||||
),
|
||||
$checkboxesBlock = new CompositeField(
|
||||
$checkboxes,
|
||||
new LiteralField("ClearDiv", "<div class=\"clear\"></div>"),
|
||||
@ -583,7 +591,13 @@ class ModelAdmin_RecordController extends Controller {
|
||||
*/
|
||||
function edit($request) {
|
||||
if ($this->currentRecord) {
|
||||
return $this->EditForm()->forAjaxTemplate();
|
||||
if(Director::is_ajax()) {
|
||||
return $this->EditForm()->forAjaxTemplate();
|
||||
} else {
|
||||
return $this->parentController->parentController->customise(array(
|
||||
'EditForm' => $this->EditForm()
|
||||
))->renderWith('LeftAndMain');
|
||||
}
|
||||
} else {
|
||||
return "I can't find that item";
|
||||
}
|
||||
@ -603,6 +617,11 @@ class ModelAdmin_RecordController extends Controller {
|
||||
new FormAction("doSave", "Save")
|
||||
);
|
||||
|
||||
if($this->currentRecord->canDelete(Member::currentUser())) {
|
||||
$actions->insertFirst($deleteAction = new FormAction('doDelete', 'Delete'));
|
||||
$deleteAction->addExtraClass('delete');
|
||||
}
|
||||
|
||||
$form = new Form($this, "EditForm", $fields, $actions, $validator);
|
||||
$form->loadDataFrom($this->currentRecord);
|
||||
|
||||
@ -628,7 +647,19 @@ class ModelAdmin_RecordController extends Controller {
|
||||
Director::redirectBack();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete the current record
|
||||
*/
|
||||
public function doDelete($data, $form, $request) {
|
||||
if($this->currentRecord->canDelete(Member::currentUser())) {
|
||||
$this->currentRecord->delete();
|
||||
Director::redirect($this->parentController->Link());
|
||||
}
|
||||
else Director::redirectBack();
|
||||
return;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@
|
||||
}
|
||||
|
||||
body.ModelAdmin #left {
|
||||
width: 250px;
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
body.ModelAdmin #Form_AddForm fieldset {
|
||||
@ -32,7 +32,7 @@ body.ModelAdmin #SearchForm_holder {
|
||||
}
|
||||
|
||||
body.ModelAdmin #SearchForm_holder div.ResultAssemblyBlock{
|
||||
margin: 1.5em 0px;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
body.ModelAdmin #SearchForm_holder form div.field.hidden{
|
||||
|
@ -48,6 +48,22 @@ jQuery(document).ready(function() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* POST a hash of form submitted data to the given endpoint
|
||||
*/
|
||||
function deleteRecord(uri, data) {
|
||||
jQuery.post(uri, data, function(result){
|
||||
jQuery('#right #ModelAdminPanel').html(result);
|
||||
|
||||
statusMessage("Deleted");
|
||||
|
||||
// TODO/SAM: It seems a bit of a hack to have to list all the little updaters here.
|
||||
// Is livequery a solution?
|
||||
Behaviour.apply(); // refreshes ComplexTableField
|
||||
jQuery('#right ul.tabstrip').tabs();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a flattened array of data from each field
|
||||
* of the given form
|
||||
@ -75,13 +91,26 @@ jQuery(document).ready(function() {
|
||||
/**
|
||||
* attach generic action handler to all forms displayed in the #right panel
|
||||
*/
|
||||
jQuery('#right #form_actions_right .action').livequery('click', function(){
|
||||
form = jQuery('#right form');
|
||||
jQuery('#right #form_actions_right input[name=action_doSave]').livequery('click', function(){
|
||||
var form = jQuery('#right form');
|
||||
var formAction = form.attr('action') + '?' + jQuery(this).fieldSerialize();
|
||||
saveRecord(formAction, formData(form));
|
||||
return false;
|
||||
});
|
||||
|
||||
/**
|
||||
* attach generic action handler to all forms displayed in the #right panel
|
||||
*/
|
||||
jQuery('#right #form_actions_right input[name=action_doDelete]').livequery('click', function(){
|
||||
var confirmed = confirm("Do you really want to delete?");
|
||||
if(!confirmed) return false;
|
||||
|
||||
var form = jQuery('#right form');
|
||||
var formAction = form.attr('action') + '?' + jQuery(this).fieldSerialize();
|
||||
deleteRecord(formAction, formData(form));
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('#right #ModelAdminPanel tbody td a').livequery('click', function(){
|
||||
var el = jQuery(this);
|
||||
showRecord(el.attr('href'));
|
||||
@ -128,22 +157,14 @@ jQuery(document).ready(function() {
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('a.form_frontend_function.clear_search').click(function(e) {
|
||||
//jQuery('#SearchForm_holder .tab form').clearForm();
|
||||
var searchform = jQuery(this).parent().get(0);
|
||||
jQuery(searchform).clearForm();
|
||||
jQuery('#SearchForm_holder button[name=action_clearsearch]').click(function(e) {
|
||||
jQuery(this.form).clearForm();
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('a.form_frontend_function.toggle_result_assembly').click(function(){
|
||||
var toggleElement = jQuery(this).next();
|
||||
if(toggleElement.css('display') != 'none'){
|
||||
jQuery(this).html('+ choose columns');
|
||||
toggleElement.hide();
|
||||
}else{
|
||||
jQuery(this).html('- hide column choose');
|
||||
toggleElement.show();
|
||||
}
|
||||
toggleElement.toggle();
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
<% control SearchForms %>
|
||||
<div class="tab" id="{$Form.Name}_$ClassName">
|
||||
$Form
|
||||
<a class="form_frontend_function clear_search" href="#">Clear Search</a>
|
||||
</div>
|
||||
<% end_control %>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user