2010-05-12 00:16:39 +00:00
|
|
|
$(document).ready(function() {
|
2010-07-23 20:20:09 +00:00
|
|
|
|
|
|
|
// automatic slug from collection name
|
|
|
|
$('#asset_collection_name').keypress(function() {
|
|
|
|
var input = $(this);
|
|
|
|
var slug = $('#asset_collection_slug');
|
|
|
|
|
|
|
|
if (!slug.hasClass('filled')) {
|
|
|
|
setTimeout(function() {
|
|
|
|
slug.val(input.val().replace(/\s/g, '_').toLowerCase());
|
|
|
|
}, 50);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#asset_collection_slug').keypress(function() { $(this).addClass('filled'); });
|
|
|
|
|
|
|
|
// sortable assets
|
|
|
|
|
|
|
|
var updateAssetsOrder = function() {
|
|
|
|
var list = $('ul.assets.sortable');
|
|
|
|
var ids = jQuery.map(list.sortable('toArray'), function(e) {
|
|
|
|
return e.match(/asset-(\w+)/)[1];
|
|
|
|
}).join(',');
|
|
|
|
$('#asset_collection_assets_order').val(ids || '');
|
|
|
|
}
|
|
|
|
|
2010-10-29 14:19:41 +00:00
|
|
|
var setLastClassForAssets = function() {
|
|
|
|
$('ul.assets li.last').removeClass('last');
|
|
|
|
var i = parseInt($('ul.assets li.asset').size() / 6);
|
|
|
|
while (i > 0) {
|
|
|
|
$('ul.assets li.asset:eq(' + (i * 6 - 1) + ')').addClass('last');
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 20:20:09 +00:00
|
|
|
$('ul.assets.sortable').sortable({
|
|
|
|
items: 'li.asset',
|
2010-10-29 14:19:41 +00:00
|
|
|
stop: function(event, ui) { updateAssetsOrder(); setLastClassForAssets(); }
|
2010-07-23 20:20:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('ul.assets.sortable li div.actions a.remove').click(function(e) {
|
|
|
|
if (confirm($(this).attr('data-confirm'))) {
|
|
|
|
$(this).parents('li').remove();
|
|
|
|
|
|
|
|
updateAssetsOrder();
|
|
|
|
|
|
|
|
if ($('ul.assets li.asset').size() == 0) $('p.no-items').show();
|
|
|
|
|
2010-10-29 14:19:41 +00:00
|
|
|
setLastClassForAssets();
|
2010-07-23 20:20:09 +00:00
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|