I have a custom Action Added to a DataObjectManager, how to I trigger close Pop-Up when it's clicked?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
DataObjectManager Module /
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
Triggering Close Pop-Up
- Page 11(current)
- 2
- Next 10 entries
Hmm, Nothing? Is there no way to force an action to close the DOM popup?
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'));
});");
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
All you should have to do is add the requirements above to your delete method. Have you tried that?
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'));
});");
}
}
?>
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. :)
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
- Page 11(current)
- 2
- Next 10 entries