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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SS3 Data Grid. When adding item and clicking back Page must be refreshed


Reply


531 Views

Avatar
Fraser

Community Member, 47 Posts

1 August 2012 at 2:26pm

I have put together a couple of Data Grids to allow users to upload images and videos into a gallery system. It all works fine for adding items, however once you enter that "add new xxx" section and try to come back out of it with the back button, 2 throbbers appear rather than 1 and then main page area goes blank requiring a page refresh to view anything.

Does anyone have any ideas what could be happening here?

GalleryImage.php

<?php

class GalleryImage extends DataObject {

   static $db = array (
      'Title' => 'Varchar',
      'Description' => 'Text'
   );

   static $has_one = array (
      'Gallery' => 'Gallery',
       'GalleryImage' => 'Image'
   );

   public static $summary_fields = array(
   'Title' => 'Image Title',
   'Description' => 'Image Description'
   );

   public function getCMSFields_forPopup() {

    $imageField = new UploadField('GalleryImage', 'Image');
    $imageField->allowedExtensions = array('jpg', 'png', 'gif');
   
    // Name, Description and Website fields
    return new FieldList(
       new TextField('Title', 'Title'),
       new TextareaField('Description', 'Image Description'),
       $imageField
    );
   }
}

LinkedVideo.php

<?php

class LinkedVideo extends DataObject {

   static $db = array (
      'URL' => 'Varchar',
      'Title' => 'Varchar',
      'Description' => 'Text'
   );

   static $has_one = array (
      'Gallery' => 'Gallery'
   );

   public static $summary_fields = array(
   'URL' => 'Video URL (Youtube or Vimeo)',
   'Title' => 'Image Title',
   'Description' => 'Image Description'
   );

   public function getCMSFields_forPopup() {
    return new FieldList(
       new TextField('URL', 'URL (Youtube or Vimeo)'),
       new TextField('Title', 'Title'),
       new TextareaField('Description', 'Image Description')
    );
   }
}

Gallery.php

.....
public static $has_many = array(
      'GalleryImages' => 'GalleryImage',
      'LinkedVideos' => 'LinkedVideo'
   );
   
   function getCMSFields() {
      $fields = parent::getCMSFields();
      $gridFieldConfig = GridFieldConfig::create()->addComponents(
    new GridFieldToolbarHeader(),
    new GridFieldAddNewButton('toolbar-header-right'),
    new GridFieldSortableHeader(),
    new GridFieldDataColumns(),
    new GridFieldPaginator(10),
    new GridFieldEditButton(),
    new GridFieldDeleteAction(),
    new GridFieldDetailForm()
    );
   
    $gridField = new GridField("GalleryImages", "Images:", $this->GalleryImages(), $gridFieldConfig);
    $fields->addFieldToTab("Root.Images", $gridField);
   
    $gridFieldConfig = GridFieldConfig::create()->addComponents(
    new GridFieldToolbarHeader(),
    new GridFieldAddNewButton('toolbar-header-right'),
    new GridFieldSortableHeader(),
    new GridFieldDataColumns(),
    new GridFieldPaginator(10),
    new GridFieldEditButton(),
    new GridFieldDeleteAction(),
    new GridFieldDetailForm()
    );
   
    $gridField = new GridField("LinkedVideos", "Videos:", $this->LinkedVideos(), $gridFieldConfig);
    $fields->addFieldToTab("Root.Videos", $gridField);
      
      return $fields;
   }

}
.....

Attached Files