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, Ed, biapar, Willr, Ingo, swaiba

How to override admin javascript functionalities?


Go to End
Reply


2 Posts   1430 Views

Avatar
ordinarywebguy

Community Member, 13 Posts

2 August 2010 at 7:45pm

As oppose with this solution http://silverstripe.org/dataobjectmanager-module-forum/show/268741#post268741, I don't wan't to mess-up with core javascript. What's the best workaround to customize javascript functionalities specifically on admin and this script dataobject_manager/javascript/dataobject_manager.js ?

Avatar
ordinarywebguy

Community Member, 13 Posts

4 August 2010 at 11:55pm

Edited: 04/08/2010 11:57pm

After couple of hours solving the scenario, I was able to find a solution. Though it's kinda ugly combining prototype js and jquery co'z jQuery.ajax wasn't executing within Behaviour.register. See code below.

                // Customize admin comment delete behavior
	// Added delete confirmation
	// @see dataobject_manager/javascript/dataobject_manager.js
	Behaviour.register({
		'#Form_EditForm_Comments a.delete-link': {
			initialize: function() {
				jQuery(this).unbind('click'); //unbind default behavior
			},
			onclick : function(event) {
				Event.stop(event);
				// Now show up confirmation message
				deleteIt = confirm('Are you sure you want to delete this comment?');
				if( deleteIt ) {
					target = jQuery(this);
					params = $('SecurityID') ? {'forceajax' : '1', 'SecurityID' : $('SecurityID').value} : {'forceajax' : '1'};

					var options = {
						method: 'post',
						parameters : params,
						onSuccess: function() {
							jQuery(target).parents('li:first').fadeOut();
							jQuery('.ajax-loader').fadeOut('fast');
						}
					};
					// Execute deletion
					new Ajax.Request(target.attr('href'), options);
				}
			}
		}
	});

Hope it'll be a help!