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)
|
||||
{
|
||||
$recordList = $this->getPOSTRecordList($request);
|
||||
$original = $this->gridField->list->count();
|
||||
|
||||
$this->gridField->list->removeMany($recordList);
|
||||
|
||||
$response = new SS_HTTPResponse(Convert::raw2json(array($recordList)));
|
||||
$response->addHeader('Content-Type', 'text/plain');
|
||||
return $response;
|
||||
|
||||
$count = count($recordList) - ($original - $this->gridField->list->count());
|
||||
|
||||
return $this->completeAction($recordList, 'Unlinked {count} items', $count);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,10 +245,8 @@ class GridFieldBulkManager_Request extends RequestHandler {
|
||||
$res = DataObject::delete_by_id($recordClass, $id);
|
||||
array_push($result, array($id => $res));
|
||||
}
|
||||
|
||||
$response = new SS_HTTPResponse(Convert::raw2json(array($result)));
|
||||
$response->addHeader('Content-Type', 'text/plain');
|
||||
return $response;
|
||||
|
||||
return $this->completeAction($result, 'Deleted {count} items');
|
||||
}
|
||||
|
||||
|
||||
@ -279,4 +279,17 @@ class GridFieldBulkManager_Request extends RequestHandler {
|
||||
)));
|
||||
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) {
|
||||
@ -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) {
|
||||
@ -86,10 +86,4 @@ class VersionedGridFieldBulkManager_Request extends GridFieldBulkManager_Request
|
||||
|
||||
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,
|
||||
type: "POST",
|
||||
context: $(this)
|
||||
}).done(function() {
|
||||
$(this).parents('.ss-gridfield').entwine('.').entwine('ss').reload();
|
||||
});
|
||||
}).done(function(r) {
|
||||
// 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