$(document).ready(function() {
    $('#triggers-list').children('tbody').sortable({
        helper : fixHelper,
        handle : '.js-drag-handle',
        items : 'tr',
        stop : function(event, ui) {
            var triggers = [];
            var project_id;

            _.each($('#triggers-list tbody').children('tr'), function(row) {
                project_id = project_id || $(row).data('project-id');
                triggers.push($(row).data('trigger-id'));
            });
            xajax_update_position(project_id, triggers);
        }
    });
});

var fixHelper = function(event, el) {
    el.children().each(function() {
        $(this).width($(this).width());
    });
    return el;
};
