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.

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

DOM and ModelAdmin


Go to End


29 Posts   6785 Views

Avatar
Hamish

Community Member, 712 Posts

18 August 2009 at 3:31pm

Hey all,

Firstly, awesome module.

Secondly, I'm using it with ModelAdmin. Seems to work ok, except for some javascript behavour that needs modification.

See the attached diff for dataobject_manager.js - this is purely to help upgrade the module to work well with ModelAdmin. It probably breaks nested or multiple instance pages.

Basically, the way the DOM is initiated means that the html is not yet prepared (i think), whereas the Behavior method handles this better. Note that the javascript is a bit mixed up - seems to be mixing prototype and jQuery. Might be worth cleaning this up.

Regards,
Hamish

Avatar
Hamish

Community Member, 712 Posts

18 August 2009 at 3:31pm

oh, that's odd - can't add files to this thread.

Diff as below:

Index: dataobject_manager.js
===================================================================
--- dataobject_manager.js	(revision 227)
+++ dataobject_manager.js	(working copy)
@@ -259,16 +259,16 @@
 $().ajaxStop(function(r,s){  
   $(".ajax-loader").fadeOut("fast");  
 });  
-if(!nested && $(this).attr('id')) {
+//if(!nested && $(this).attr('id')) {
   Behaviour.register({
   	'.DataObjectManager' : {
   		initialize : function() {$(this).DataObjectManager();}
   	}
   });
-}
-else {
-  $(function() {$('.DataObjectManager').DataObjectManager();});
-}
+//}
+//else {
+//  $(function() {$('.DataObjectManager').DataObjectManager();});
+//}
 
 })(jQuery);
 

Avatar
UncleCheese

Forum Moderator, 4102 Posts

18 August 2009 at 3:47pm

Well that will break nested dataobjectmanager now, so that isn't exactly an air-tight fix.

I avoid the behavior object at all costs and do everything with jQuery. Behavior and Prototype are such hogs, and they slow everything down. In CMSMain, you have to use the Behavior object because it's tied in so closely with the site tree, but in ModelAdmin you shouldn't need it.

I have a feeling your DOM is getting flagged as nested because it's a component of a DataObject, and not a page. I'll have to do some testing.

Avatar
Hamish

Community Member, 712 Posts

18 August 2009 at 3:55pm

Thanks.

Yeah, I noted from other posts that you hadn't had a look at this yet, so hopefully this helps. That seems to be the only issue with ModelAdmin - although I have only just started using it.

Some other minor feedback that might help others not to make a silly mistake: don't forget to allow .swf through your htaccess rules :P

Avatar
UncleCheese

Forum Moderator, 4102 Posts

19 August 2009 at 5:27am

I'm not noticing this bug with ModelAdmin. Please check the dataobjectmanager test site and make sure I've set everything up right.

http://dataobjectmanager.carlinowebdesign.com
user:admin
pass:password

"My Test Admin" tab.

Avatar
Hamish

Community Member, 712 Posts

19 August 2009 at 9:20am

Edited: 19/08/2009 9:21am

Yep, it's happening on the test site too.

On loading the Employee Object, I get the JavaScript error:

TypeError: Object [object global] has no method 'getAttribute'

This is them same error I was having, and it prevents the DataObjectManager being applied to the div. This means that pressing 'add xxxxxx' redirects you to the form, rather than loading it in the popup. Tested XP with IE8, Chrome and FF3.5

This seems to be thrown by:

if(!nested && $(this).attr('id')) {

"this" will refer to the window, which doesn't make sense. I suspect this block of code is supposed to be:

if(!nested && $('.DataObjectManager').attr('id')) {
  Behaviour.register({
  	'.DataObjectManager' : {
  		initialize : function() {$(this).DataObjectManager();}
  	}
  });
}
else {
  $(function() {$('.DataObjectManager').DataObjectManager();});
}

However there is still the problem that when this is executed the DOM (document object model) has not yet been updated. You can prove this by adding "alert(this.length);" to the DataObjectManager function - it will return 0.

This is why I forced using Behavior - it delays execution until the response has been injected into the object model.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

19 August 2009 at 10:49am

AFAIK, the command:

$(function() {$('.DataObjectManager').DataObjectManager();});

Is using the jQuery syntax to run on document ready. If you put alert('hello') in that function, you'll see it happens once the page is loaded.

You were right, the fix was this:

if(!nested && $('.DataObjectManager').length) {

testing for .attr('id') would have effectively done the same thing, but it's a little less clear. I had to figure out why I even had that there. The second condition is to test for the case that a DOM is in the fieldset, but is not displaying because the controller has no ID, e.g. it is displaying the place holder "You may add xxxx when you have saved for the first time..", and therefore there is no DOM holder div.

Thanks for the heads up. Run an update and test if you will.

Avatar
Hamish

Community Member, 712 Posts

19 August 2009 at 11:19am

Edited: 19/08/2009 1:22pm

"AFAIK, the command:

$(function() {$('.DataObjectManager').DataObjectManager();});

Is using the jQuery syntax to run on document ready. If you put alert('hello') in that function, you'll see it happens once the page is loaded."

No, This will execute in-line.

Edit: See later posts - the above was incorrect. :)

However, this doesn't fix the problem. $('.DataObjectManager').length still returns 0. This happens whether it is loaded from within the onready handler or not. On your test site (and mine) I still get diverted instead of the popup when clicking "Add xxxxxx".

An alternative fix is to use this:

$('.DataObjectManager').livequery(function(){
	$(this).DataObjectManager();									   
});

This will initialize it correctly, after the object model has been updated.

By the way, I don't understand the nested check. Why do you use Behavior.register if it is nested? $('.DataObjectManager') will return the same objects regardless of the check anyway, so the two methods should be functionally identical.

Go to Top