Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Show has_one dataobject in CMS with popup details

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1777 Views
  • pingu
    Avatar
    Community Member
    75 Posts

    Show has_one dataobject in CMS with popup details Link to this post

    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?

  • pingu
    Avatar
    Community Member
    75 Posts

    Re: Show has_one dataobject in CMS with popup details Link to this post

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

  • pingu
    Avatar
    Community Member
    75 Posts

    Re: Show has_one dataobject in CMS with popup details Link to this post

    Anyone with any ideas on this one??

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Show has_one dataobject in CMS with popup details Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Show has_one dataobject in CMS with popup details Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Show has_one dataobject in CMS with popup details Link to this post

    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);
    ...
    }

    1777 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.