mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
Now displays messages when an action is performed
This commit is contained in:
parent
a3e55785ac
commit
a19334c5d7
@ -220,11 +220,13 @@ class GridFieldBulkManager_Request extends RequestHandler {
|
|||||||
public function unlink(SS_HTTPRequest $request)
|
public function unlink(SS_HTTPRequest $request)
|
||||||
{
|
{
|
||||||
$recordList = $this->getPOSTRecordList($request);
|
$recordList = $this->getPOSTRecordList($request);
|
||||||
|
$original = $this->gridField->list->count();
|
||||||
|
|
||||||
$this->gridField->list->removeMany($recordList);
|
$this->gridField->list->removeMany($recordList);
|
||||||
|
|
||||||
$response = new SS_HTTPResponse(Convert::raw2json(array($recordList)));
|
$count = count($recordList) - ($original - $this->gridField->list->count());
|
||||||
$response->addHeader('Content-Type', 'text/plain');
|
|
||||||
return $response;
|
return $this->completeAction($recordList, 'Unlinked {count} items', $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,10 +245,8 @@ class GridFieldBulkManager_Request extends RequestHandler {
|
|||||||
$res = DataObject::delete_by_id($recordClass, $id);
|
$res = DataObject::delete_by_id($recordClass, $id);
|
||||||
array_push($result, array($id => $res));
|
array_push($result, array($id => $res));
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = new SS_HTTPResponse(Convert::raw2json(array($result)));
|
return $this->completeAction($result, 'Deleted {count} items');
|
||||||
$response->addHeader('Content-Type', 'text/plain');
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -279,4 +279,17 @@ class GridFieldBulkManager_Request extends RequestHandler {
|
|||||||
)));
|
)));
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function completeAction($recordList = null, $text = 'No changes', $count = null) {
|
||||||
|
if($recordList && (count($recordList) || $count)) {
|
||||||
|
if(!$count) $count = count($recordList);
|
||||||
|
$text = _t('GridFieldBulkManager.' . strtoupper(str_replace(array('{count}', ' '), '_', $text)), $text, array('count' => $count));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$text = _t('GridFieldBulkManager.NO_CHANGES', 'No changes');
|
||||||
|
|
||||||
|
$response = new SS_HTTPResponse(json_encode(array('records' => $recordList, 'message' => $text)));
|
||||||
|
$response->addHeader('Content-Type', 'text/json');
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
}
|
}
|
@ -35,7 +35,7 @@ class VersionedGridFieldBulkManager_Request extends GridFieldBulkManager_Request
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->completeAction($recordList);
|
return $this->completeAction($recordList, 'Published {count} items');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unpublish(SS_HTTPRequest $request) {
|
public function unpublish(SS_HTTPRequest $request) {
|
||||||
@ -50,7 +50,7 @@ class VersionedGridFieldBulkManager_Request extends GridFieldBulkManager_Request
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->completeAction($recordList);
|
return $this->completeAction($recordList, 'Unpublished {count} items');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function doPublish($record) {
|
protected function doPublish($record) {
|
||||||
@ -86,10 +86,4 @@ class VersionedGridFieldBulkManager_Request extends GridFieldBulkManager_Request
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function completeAction($recordList = null) {
|
|
||||||
$response = new SS_HTTPResponse(Convert::raw2json(array($recordList)));
|
|
||||||
$response->addHeader('Content-Type', 'text/plain');
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -134,9 +134,19 @@
|
|||||||
data: data,
|
data: data,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
context: $(this)
|
context: $(this)
|
||||||
}).done(function() {
|
}).done(function(r) {
|
||||||
$(this).parents('.ss-gridfield').entwine('.').entwine('ss').reload();
|
// A bit hacky, but it checks if the response is json
|
||||||
});
|
try {
|
||||||
|
$.parseJSON(r);
|
||||||
|
|
||||||
|
if(r.message) {
|
||||||
|
var msgType = r.messageType ? r.messageType : 'good';
|
||||||
|
statusMessage(decodeURIComponent(r.message), msgType);
|
||||||
|
}
|
||||||
|
} catch(e) { }
|
||||||
|
|
||||||
|
$(this).parents('.ss-gridfield').entwine('.').entwine('ss').reload();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user