5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 514 Views |
-
ModelAdmin: Load next DO with Next Button

3 September 2011 at 12:28am
hi,
with the help of this tutorial:
http://www.ssbits.com/tutorials/2011/add-a-duplicate-button-to-model-admin/I created a "Next" Button at the bottom of model admin.
The button calls the function "nextdataobject".
public function nextdataobject($data, $form, $request) {
$NextRecord = DataObject::get_by_id('SomeDataObject', $this->currentRecord->ID + 1);
$this->currentRecord = $NextRecord;
if(Director::is_ajax()) {
return new SS_HTTPResponse(
Convert::array2json(array(
'html' => $this->EditForm()->forAjaxTemplate(),
'message' => _t('ModelAdmin.PUBLISHED',"Next DataObject was loaded.")
)),
200
);
} else {
Director::redirectBack();
}
}This works only if there are no breaks in the ID's. Because I just do a + 1 on the ID it could
be that one is missing cause of deletion. How to get just the next DO?$this->nextRecord or something else would be great, does anyone have an idea?
But there is one more problem, the DataObject has a "has_one" relationship to an image.
If I click on "Next" it loads everything correct, but not the images ... it loads the images
of the last DataObject. Any idea why and how to solve?Thx
-
Re: ModelAdmin: Load next DO with Next Button

7 September 2011 at 1:10am
best I could recomend is to persist the search query into the session...
class MyAdmin_CollectionController extends ModelAdmin_CollectionController {
function getSearchQuery($searchCriteria){
$query = parent::getSearchQuery($searchCriteria);
Session::set('LastQuery',$query);
return $query;
}
}then modify your code to run this same query and grab the next one in the returned DataObjectSet after the $this->ID
please let me know if you get this running - I'd be interested to add this functionality for some of my users.
-
Re: ModelAdmin: Load next DO with Next Button

8 September 2011 at 3:29am Last edited: 8 September 2011 3:56am
hi swaiba,
is your solution for the "select next ID" problem or for the problem with the relations and images?
at the moment I use this working way for the problem selecting the next ID:
$NextRecord = DataObject::get_one('SomeDataObject', "ID > ".$this->currentRecord->ID, true, "ID ASC");
$this->currentRecord = $NextRecord;I just changed the DataObject::get_by_id to DataObject::get_one. with a filter and ordering.
But still have no idea how to solve the problem with the relations ... if I click "Next" it loads the next row, but without
the correct relations. Each row has_one Image, and if I click "Next" always the image of the previous row shows ...
alse other has_many or many_many relations are no there.I tried to solve this with your idea this way ...
$query = Session::get('LastQuery');
$NextRecord = DataObject::get_one('SomeDataObject', "ID > ".$this->currentRecord->ID, true, "ID ASC");
$query->where = array('SomeDataObjecet.ID = '.$NextRecord->ID);
$result = $query->execute();
$this->currentRecord = singleton('SomeDataObject')->buildDataObjectSet($result)->First();... but with no success in case of the relations.
EDIT: the relations work, only the Images dont ... if I dump the query, the the "logoID" and "screenshotID" are correct (the IDs of the next DO) but the pics of the prv. DO shows ...
-
Re: ModelAdmin: Load next DO with Next Button

8 September 2011 at 4:05am Last edited: 8 September 2011 4:12am
ok ....
the image problem is only when I use uploadify.
If I use standard upload it works
here the complete function which is working:
public function nextdataobject($data, $form, $request) {
$NextRecord = DataObject::get_one('SomeDataObject', "ID > ".$this->currentRecord->ID, true, "ID ASC");
$this->currentRecord = $NextRecord;
if(Director::is_ajax()) {
return new SS_HTTPResponse(
Convert::array2json(array(
'html' => $this->EditForm()->forAjaxTemplate(),
'message' => _t('ModelAdmin.PUBLISHED',"Next DataObject loaded.")
)),
200
);
} else {
Director::redirectBack();
}
}so finaly, changed has onle the $NextRecord = DataObject....... and I switched back from an uploadify field to a normal ImageField.
@unclecheese: andy ideas to get this working with uploadify to?
EDIT: muahaha, what a day :-|
this solution only work if you dont have any search criteria, so let's add the code for the SearchQuery manipulation again ...
-
Re: ModelAdmin: Load next DO with Next Button

28 January 2012 at 5:22am
Hey Danzzz,
Just had a ticket with a client requesting this - did you get any further with your coding than is recorded here?
| 514 Views | ||
|
Page:
1
|
Go to Top |


