Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SS3 Data Grid. When adding item and clicking back Page must be refreshed

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

Page: 1
Go to End
Author Topic: 481 Views
  • Fraser
    Avatar
    Community Member
    46 Posts

    SS3 Data Grid. When adding item and clicking back Page must be refreshed Link to this post

    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
    481 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.