Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Show has_one dataobject in CMS with popup details


Reply


6 Posts   1807 Views

Avatar
pingu

Community Member, 75 Posts

28 June 2010 at 2:11am

I'm using dataobjects & ModelAdmin to store customers and details for a retail store.

Order has_one customer, and customer has_many orders.

When you look at the "order" tab of Modeladmin, the customer is displayed (selected by default) in a dropdown list.

Instead of this, I'd like the customers name to be displayed with the option to view their details, like in a ComplexTableField - however I ONLY want the customer who owns the current order to be displayed, not all customers. Could someone please advise (with an example code snippet) how I could achieve this?

Avatar
pingu

Community Member, 75 Posts

30 June 2010 at 1:30pm

Anyone with any suggestions on how I can achieve this??

Avatar
pingu

Community Member, 75 Posts

2 November 2010 at 1:01am

Anyone with any ideas on this one??

Avatar
swaiba

Forum Moderator, 1799 Posts

2 November 2010 at 2:00am

Edited: 02/11/2010 2:01am

This will replace the filed with a read only field...

$fields->insertBefore(new ReadonlyField('NEWFIELDNAMEUNIQUE','FIELDNAME','DATATOSHOW'),'FIELDNAME TOBEINSERTEDBEFORE');
$fields->removeByName('FIELDNAME TO REMOVE');

this is what probably will take you to editing the required item, but that will be in the normal way and lose your "context" of the record you are editing... but it is untested...

$fields->insertBefore(new LiteralField('FIELDNAME LINK',"<button onClick=\"adminurl/DataObject/<id>/edit\">Edit</button>"),'FIELDNAME TOBEINSERTEDBEFORE');

This is my code that places some data from a url into a face box popup, if this helps...

<button onClick=\"jQuery.facebox(function() {jQuery.get('myurl',function(data){jQuery.facebox(data)})})\">

I use a combination of the above to allow editing of records in custom ways, while still using all of the model admin. I hope this helps and look forward to see a full solution if you get one!

Barry

Avatar
swaiba

Forum Moderator, 1799 Posts

2 November 2010 at 9:52am

I should have mentioned the about goes in getCMSFields in the DataObject. And as it happens I grow curious for this as well, but I'll settle for being able to edit the has_one in any fashion, e.g. findOrMakeTab, fill it with the $this->HasOneObject()->getCMSFields(), but then how to add it to the save of the object under edit already? I'm going to prepare an example and hopefully, with the help of the excellent silverstripe community we can get this solved :)

Avatar
swaiba

Forum Moderator, 1799 Posts

19 November 2010 at 3:00am

Edited: 19/11/2010 4:59am

Well - it's not quite the solution I was after, but this works functionally and is very simple to implement...

function getCMSFields() {
...
      $hasOneCTF = new HasOneComplexTableField($this,'DATAOBJECT','DATAOBJECT',null,null,'ID='.$this->DATAOBJECTID);
      $hasOneCTF->setPermissions(array('edit','show'));
      $hasOneCTF->Markable = false;
      $fields->addFieldToTab("Root.DATAOBJECT", $hasOneCTF);
...
}