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

Triggering Close Pop-Up


Go to End
Reply


9 Posts   2830 Views

Avatar
zenmonkey

Community Member, 528 Posts

1 October 2009 at 2:56am

I have a custom Action Added to a DataObjectManager, how to I trigger close Pop-Up when it's clicked?

Avatar
zenmonkey

Community Member, 528 Posts

9 October 2009 at 12:39pm

Hmm, Nothing? Is there no way to force an action to close the DOM popup?

Avatar
UncleCheese

4085 Posts

10 October 2009 at 9:54am

If you look at the closePopup method in FileDOM, there's a good example of how to close a popup.

         Requirements::customScript("
               var container = parent.jQuery('#".$this->id()."');
               parent.jQuery('#facebox').fadeOut(function() {
                  parent.jQuery('#facebox .content').removeClass().addClass('content');
                  parent.jQuery('#facebox_overlay').remove();
                  parent.jQuery('#facebox .loading').remove();
                  parent.refresh(container, container.attr('href'));
               });");

Avatar
vancouverWill

Community Member, 121 Posts

6 November 2009 at 4:32pm

Any luck getting this to work? I have been trying for on and off for a few weeks to add a FormAction to the nested image of imagedataobjectmanager which will let me delete it from the popup. The action works fine and it deletes but then I am left in the empty popup window. Any advice would be much appreciated. I trying calling the function closepopup() by $this->FileDataObjectManager()->closePopup(); and that obviously didn't work. Perhaps I need to create the function in a different place? Currently the function is in my file projectImage file which is a child of project. I know the function is working because it is deleting the image as expected but I can't get the popup to close.

btw.

I realised I could access the page by calling

$this->Project()->ProjectPage;

so I thought then I could maybe call the imagedataobject manager like this

$this->Project()->getProjectCMSFields_forPopup()->ImageDataObjectManager()->closePopup();

but that most definitely did not work. haha. I don't see how I can call the imagedataobjectmanager and if I was to copy the code from there which ID is it using? page id? project id?

Thanks guys

Avatar
UncleCheese

4085 Posts

6 November 2009 at 5:09pm

All you should have to do is add the requirements above to your delete method. Have you tried that?

Avatar
vancouverWill

Community Member, 121 Posts

7 November 2009 at 8:56pm

Thanks for the quick reply.

The problem is if I just paste the code it has the line

var container = parent.jQuery('#".$this->id()."');

as there is no id on my projectimage, or at least I'm not sure how to call it directly. This give me the following error:

[User Error] Uncaught Exception: Object->__call(): the method 'id' does not exist on 'ProjectImage'
GET /admin/?flush=1

Line 551 in C:\xampp\htdocs\xampp\silverstripe\synergy_latest_from_godaddy\sapphire\core\Object.php

I have tried removing the Id and the form is then working but after the object is deleted it tries to go to the same object and it is still in the popup as I get the following error inside the popup

Fatal error: Call to a member function Image() on a non-object in C:\xampp\htdocs\xampp\silverstripe\synergy_latest_from_godaddy\dataobject_manager\code\ImageDataObjectManager.php on line 104

Here is my code perhaps you can point me in the right direction

<?php
class ProjectImage extends DataObject
{
   static $db = array(
   'ImageTitle' => 'Text'
   );

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

   public function getCMSFields()
   {
   
      return new FieldSet(
         new TextField('ImageTitle', 'Image Title'),
         new ConfirmedFormAction(
             $action = $this->deleteImage(),
             $title = "Delete",
             $confirmation = 'Delete this?'
         )
         /*, new ConfirmedFormAction(
             $action = $this->saveImage(),
             $title = "Save",
             $confirmation = 'Save this?'
         )*/
      );
   }
   
   function saveImage()
   {   
      //echo '<h1>in function</h1>';
      $this->write();
   }
   
   function deleteImage()
   {

      //$this->dataObj()->delete();
      
      $this->brokenOnDelete = true;
      $this->onBeforeDelete();
      if($this->brokenOnDelete) {
         user_error("$this->class has a broken onBeforeDelete() function. Make sure that you call parent::onBeforeDelete().", E_USER_ERROR);
      }
      
      foreach($this->getClassAncestry() as $ancestor) {
         if(self::has_own_table($ancestor)) {
            $sql = new SQLQuery();
            $sql->delete = true;
            $sql->from[$ancestor] = "`$ancestor`";
            $sql->where[] = "ID = $this->ID";
            $this->extend('augmentSQL', $sql);
            $sql->execute();
         }
      }
      
      $this->onAfterDelete();

      $this->OldID = $this->ID;
      $this->ID = 0;

      DataObjectLog::deletedObject($this);
      
       Requirements::customScript("
var container = parent.jQuery('#".$this->id."');
parent.jQuery('#facebox').fadeOut(function() {
parent.jQuery('#facebox .content').removeClass().addClass('content');
parent.jQuery('#facebox_overlay').remove();
parent.jQuery('#facebox .loading').remove();
parent.refresh(container, container.attr('href'));
});");
   }
}

?>

Avatar
UncleCheese

4085 Posts

8 November 2009 at 4:51pm

Yeah, that's tricky. What you need is the id of the DataObjectManager that holds that record. I believe the ID of the DOM is based on the has_many relation, so if you have a $has_many 'ProjectImages' => 'ProjectImage' in your Project class, the ID of the DOM should be "ProjectImages"

But if it were my project, I would search the Project class for a has_many relation of $this->class, so that if the name ever changed, I wouldn't have to make two updates. :)

Avatar
vancouverWill

Community Member, 121 Posts

8 November 2009 at 8:13pm

Hmm, yeah perhaps too tricky.

I tried playing around with the variables to see if I could get one to work as per below but maybe I am going in the wrong direction.

echo '<h6>project :'.$this->Project()->Name.'</h6>';
   echo '<h6>project id :'.$this->Project()->ID.'</h6>';
   echo '<h6>projectimages :'.$this->ProjectImages.'</h6>';
   echo '<h6>projectimages ID :'.$this->ID   .'</h6>';

I tried the javascript setup as

Requirements::customScript("
var container = parent.jQuery('#".$this->ID."');
parent.jQuery('#facebox').fadeOut(function() {
parent.jQuery('#facebox .content').removeClass().addClass('content');
parent.jQuery('#facebox_overlay').remove();
parent.jQuery('#facebox .loading').remove();
parent.refresh(container, container.attr('href'));
});");

and

Requirements::customScript("
var container = parent.jQuery('#".$this->Project()->ID."');
parent.jQuery('#facebox').fadeOut(function() {
parent.jQuery('#facebox .content').removeClass().addClass('content');
parent.jQuery('#facebox_overlay').remove();
parent.jQuery('#facebox .loading').remove();
parent.refresh(container, container.attr('href'));
});");

with neither working. The function runs, no crashing but I always end up with an empty popup window on the screen.

Can you recommend any high level object oriented books that would be relevant to silverstripe? I'm thinking maybe I need to know more about OO or maybe it is my JS. Thanks again. Will

Go to Top