How to automatically exit out of simple edit on save

Is there a way that I can drop out of edit mode when the user hits the save button ?

The page would need to reload in order for the changes to commit correctly to matrix. You could use some javascript to exit the user out of _edit but you would need a way for it to be able to know that the page is being loaded from a previous commit. You may be able to do this by appending a query string value to the end of the action attribute of the form in the simple edit page (more javascript), but as with all javascript implementations on the simple edit interface you'd have to test it quite thoroughly.

It's true you should test it, but it's easy to add the redirect into an onlick method in your simple edit layout, so after you submit_form(this.form);



    location.href='%asset_url%?exiting=1';

Hey there,


I have had this problem previously and ended up writing a bunch of code for it in jQuery, basically I added the save, save&exit and cancel button using javascript. On click they then do the appropriate action using ajax where possible. These are just excerpts below but it might help you along :slight_smile:



The click functions for the buttons

    
    $('.' + o.seLink).click(function(){ //save and exit
    				$('#'+o.controlId).html('' + $.fn.mse.dialogue.save);
    				$.fn.mse.control('saveexit');
    				return false;
    			})
    			
    			$('.' + o.saveLink).click(function(){ //save
    				$('#'+o.controlId).html('' + $.fn.mse.dialogue.save);
    				$.fn.mse.control('save');
    				return false;
    			})
    			
    			$('.' + o.exitLink).click(function(){ //exit
    				if(confirm($.fn.mse.dialogue.cancel)){
    					$('#'+o.controlId).html('' + $.fn.mse.dialogue.exit);
    					$.fn.mse.control('exit');
    				}
    				return false;
    			})


And then the "handler"
    
    $.fn.mse.control = function(mode, controls) 
    		{
			$('textarea[id*=wysiwyg]').each(function () { //get the wysiwyg areas
				try 
				{
					var i = $(this).attr('id');
					$(this).val(eval('editor_' + i + '.getHTML();'));
				} catch(e){};
				
			});
			var data = form.serialize(); //serialize the form
			
			if (mode == 'exit')  //if we're exiting add this string - WILL NOT SAVE
			{
				data = data + "&sq_lock_release_manual=1"
			}
			
			$.ajax({
				type: "POST",
				url: form.attr('action'),
				data: data,
				success: function(msg)
				{
					if(mode == 'exit')
					{
						top.location = top.location.href.substr(0, (top.location.href.indexOf("?") - 6)) //remove _edit
					} else if (mode == 'saveexit')
					{
						$.fn.mse.control('exit'); //so it's now saved, we can go off and exit
					} else if (mode == 'save') {
						initControls(); //rebind controls again
                                           
					}
				}
			 })
			 
		}// end $.fn.mse.control()




Hope it helps

[quote]
Hey there,



I have had this problem previously and ended up writing a bunch of code for it in jQuery, basically I added the save, save&exit and cancel button using javascript. On click they then do the appropriate action using ajax where possible. These are just excerpts below but it might help you along :slight_smile:



[/quote]



Thanks - yes, that is very helpful.