Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JavaScript Snippets for Squiz / MySource Matrix
/**
/**
* Changes the sort order of assets in Squiz Matrix
* Author: Nicholas Hubbard (http://www.zedsaid.com/blog/change-the-asset-map-sort-order-using-javascript-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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment