Squiz Matrix Asset Map Sort Order Using Javascript
Wed, Sep. 21, 2011In a past project I needed a way to change the asset map sort order by dragging items in an asset listing. I figured that it had to be possible, so with a little bit of javascript I wrote up the following function.
Hope it helps someone out!
/** /** * Changes the sort order of assets in Squiz 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 = '<command action="get assets"><asset assetid="'+parent+'" start="0" limit="150" linkid="10" /></command>'; $.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: '<command action="move asset" to_parent_assetid="'+parent+'" to_parent_pos="'+new_position+'"><asset assetid="'+id+'" linkid="'+link_id+'" parentid="'+parent+'" /></command>', contentType: "text/xml", dataType: 'xml', success: function(xml) { //alert(xml); } });//end ajax }//end if });//end each }//end success });//end ajax }//end changeSort()
Remember, this function requires jQuery.
Comments