[Intermediate] Change asset map sort order using jQuery


(Nic Hubbard) #1

I had a need a few time, to allow the user to dynamically change the sort order of the asset map, using JS. So, if I had an asset listing of items, they could drag the times to change the order, and my ajax function would call the asset map to update. I put that all into a useful jQuery function, and thought you guys might like to use it as well.


The function requires the id to sort, parent id that the sorting id is under, and the new position to set (0 being the first in the sort order).



Let me know if you have any questions.



Enjoy!


    /**
    /**
    * Changes the sort order of assets in MySource Matrix
    *
    * @param number		id				ID of the asset to move
    * @param number		parent			ID of the parent that the asset is under
    * @param number		new_position	New position of asset (0 is first in the sort order)
    *
    * @return string
    * @access public
    */
    function changeSort(id, parent, new_position) {
    	var host_url = location.protocol+'//'+location.host+'?SQ_ACTION=asset_map_request';
    	var link_id;
    	
    	// Construct our XML to send
    	var xml_get = '';
    	
    	$.ajax({
    		url: host_url,
    		type: 'POST',
    		processData: false,
    		data: xml_get,
    		contentType: "text/xml",
    		dataType: 'xml',
    		success: function(xml) {
    			$(xml).find('asset').each(function() {
    				if ($(this).attr('assetid') == id) {
    					link_id = $(this).attr('linkid');
    					$.ajax({
    						url: host_url,
    						type: 'POST',
    						processData: false,
    						data: '',
    						contentType: "text/xml",
    						dataType: 'xml',
    						success: function(xml) {
    							//alert(xml);
    						}
    					});//end ajax
    					
    				}//end if
    				
    			});//end each
    			
    		}//end success
    		
    	});//end ajax
    	
    }//end changeSort()	  
     


Edit: Cleaned up the function just a bit.

(Steve Brown) #2

This is niceā€¦


Will be using this at some stage in the near future.



Thanks Nick for continuing to push the boundaries of the product for us.