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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Nested DataObjects with DOM


Go to End
Reply

16 Posts   2277 Views

Avatar
CraftsMan

16 December 2010 at 5:57pm Community Member, 35 Posts

Hi UncleCheese

Fairly new comer to the SS arena but DataObjectManager was one of the key reason I geared in this direction. Fantastic module!

I have holder pages for multiple categories ( type Page ) which has attached DO via DOM. Those DO contains more sub articles (has_many)- again DO via DOM. These sub article can now contain file, images, galleries etc.

My first problem is:
When I load the first DOM from the page alls fine. When I save and add a sub article it loads and overlays the previous window which when I close rather than going back to the previous overlay it goes back to the main page.

Secondly:
When I upload an image and click attach the attachment area shows up with a preview of the site inside the frame. This only seems to happen on Mac and FF. All other platform and browsers I have tested are ok so far.

3rd Q;
- Can pages be attached to DataObject via DataObjectManager? These pages already contains existing DataObjects via DataObjectManager.

Avatar
UncleCheese

16 December 2010 at 6:57pm 4085 Posts

Hi, CraftsMan,

Thanks for the kind words..

1) I'm not sure what might be going on here. If you can, please replicate the issue on my demo site http://dataobjectmanager.carlinowebdesign.com/admin (admin/password) so I can test it. There should be an entry in the sitetree for "Nested DOM test"

2) I'm not sure what you mean, here. What do you mean "click attach?" Are you using an Uploadify field?

3) I'm not sure what you mean by "attaching" a page to a DataObject. Do you just mean creating a $has_one relation to a SiteTree object? If so, that's pretty trivial..

static $has_one = array (
'LinkedPage' => 'SiteTree'
);

... new SimpleTreeDropdownField('LinkedPageID','Linked page');

Avatar
CraftsMan

16 December 2010 at 7:07pm Community Member, 35 Posts

Thanks for your reply.

On your site it seems to work as expected :-)

My code is below for one of the category page. I am guessing I have done something wrong.

class AboutUsHolder extends Page {

   static $add_action = 'AboutUsHolder';
static $allowed_children = array();

   static $has_many = array (
      'AboutUsPages' => 'AboutUsPage',
   );

function getCMSFields() {
      $fields = parent::getCMSFields();

      $item = new DataObjectManager( $this, 'AboutUsPages', 'AboutUsPage');
      $fields->addFieldToTab('Root.Content.Main', $item);

      return $fields;
   }

}

class AboutUsPage extends ItemBase {

static $has_one = array (
'Picture' => 'Image',
'AboutUsHolder' => 'AboutUsHolder'
);

   static $has_many = array (
      'AboutUsItems' => 'AboutUsItem',
   );

   function getCMSFields() {

      $fields = new FieldSet();

      $item = new DataObjectManager( $this, 'AboutUsItems', 'AboutUsItem');
      $item->setAddTitle('About Us sub article page');
      $fields->push($item);

      $fields->push(new ImageField('Picture', 'Main Image'));

return $fields;
   }

}

class AboutUsItem extends ItemBase {

   static $has_one = array(
    'AboutUsPage' => 'AboutUsPage',
      'Picture' => 'Image'
   );
   static $has_many = array (
      'Images' => 'ItemImageResource'
   );

   function getCMSFields() {
      $fields = new FieldSet();

      $fields->push(new ImageField('Picture', 'Picture'));

$manager = new ImageDataObjectManager(
$this, // Controller
'SliderImages', // Source name
'ItemImageResource', // Source class
'Attachment', // File name on DataObject
array(
'Url' => 'Url'
), // Headings
'getCMSFields_forPopup' // Detail fields
// Filter clause
// Sort clause
// Join clause
);
$manager->setParentClass("ItemBase");
$fields->push($manager);

return $fields;
   }
}

class ItemImageResource extends DataObject {

static $db = array (
'Url' => 'Text'
);

static $has_one = array (
'Attachment' => 'Image', //Needs to be an image
'ItemBase' => 'ItemBase'
);

public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Url'),
new FileIFrameField('Attachment')
);
}

public function canCreate(){
return false;
}
}

Avatar
CraftsMan

16 December 2010 at 7:10pm Community Member, 35 Posts

sorry I shoudl have elaborated a bit more - so when I click on add AboutUsPage my pop up window comes up for the DOM, and when I click to add a sub article ( AboutUsItem ) and save and close - it closes both windows.

Avatar
CraftsMan

16 December 2010 at 8:23pm Community Member, 35 Posts

Hi UC

I have realised whats happening here is that when I close the DOM window after adding or updating AboutUsItem, the window does close properly and revert to the previous DOM window ( AboutUsHolder ) but the window now contains all the field for the most recent window viewed DOM ( i.e AboutUsItem ) displayed - on close it does not refresh/revert back to AboutUsHolder DOM.

Originally I had used Page type for the for the AboutUsHolder rahter than DO but realised this will fill up quickly and there are 4 otehr similar categories - so the sitetree would fill up quickly.

Is there a better of utelising DOM to do this than the way I have done as overlay windo on top of another doesnt seem to be very user friendly at the moment.

Avatar
UncleCheese

17 December 2010 at 3:53am 4085 Posts

Trust me, that UI has been the bane of my existence. I agree, it's pretty ugly. But a lot of people were asking for nested DOM, and it was the only solution that made sense given the existing codebase, so I went with it. Fundamentally, the popup window convention of adding and editing records is flawed. When I redo DOM, it won't use popup windows. They're a UI nightmare for this kind of stuff.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
CraftsMan

17 December 2010 at 8:28am Community Member, 35 Posts

May I pick your brain as to what the schedule is on re-doing the DOM?

It might still be a good idea to keep the pop up window as an "option" ( just my 2 cents on it ). In my particular example it would be good if I could have the regular cms edit style for the AboutUsHolder and then pop up for AboutUsItem ( is actually client feedback ).

To clarify further on my other quereis:
2) My articles have a has_one 'Picture' => 'Image' object, which I can use to browse and select the file but when I click to Attach the file, instead of seeing a preview I am seeing the full rendered homepage inside the upload area. The upload however seems to have completed successfully because if I refresh the page it show up - as mentioned this only happens on mac with FF

3) Please ignore this Q as what I had in mind is not logical :-)

Two more quick Qs to added:
1) Is it possible for me to assign icons for a column based on the value ( as in can I decorate them in anyway ? )
2) Can I attach a "lookup" feature so that I can show different value in the listview based on the field value - eg in my instance I have:

protected $columnPriority = array(
1 => '1st item',
2 => '2nd item',
3 => '3rd item',
4 => '4th item',
5 => '5th item',
6 => '6th item'
);

DataObject stores the array keys but I would like to show the array value in the summary listings.

Thanks in advance for your valuable time.

Avatar
UncleCheese

17 December 2010 at 9:03am 4085 Posts

I'm not sure what's going on with your image upload. I don't use those iframe fields. I would switch to Uploadify. http://www.leftandmain.com/silverstripe-modules/2010/08/26/uploadify/

You don't have to render only native fields in the table -- you can use functions, too.

public function getPriorityLabel() {
return self::$columnPriority[$this->Priority];
}

and in your headings array:

'PriorityLabel' => 'Priority'

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Go to Top