If using multiple instances of uploadify within silverstripe cms, the import list is not populated.
If the uploadify field was loaded with ajax the import list also did not work.
I changed uploadify_init to fix this.
Now on tabchange the list is updated. I also added 'var' to all variables defined within functions (line 129).
For us this works better.
$.ajax({
url: $e.metadata().refreshlink,
data: {'FileIDs' : ids.join(",")},
async: false,
dataType: "json",
success: function(data) {
$preview.html(data.html);
}
});
}
}
},
onAllComplete : function(event) {
var $e = $(event.currentTarget);
$e.data('active',false);
$e.parents('form').find(':submit').attr('disabled',false).removeClass('disabled');
$container = $e.parents('.UploadifyField:first');
$('.preview',$container).show();
if($e.metadata().upload_on_submit) {
$e.parents('form').submit();
}
},
onSelectOnce: function(event, queueID, fileObj) {
var $e = $(event.currentTarget);
if($('#folder_select_'+$e.attr('id')).length) {
folder_id = $('#folder_select_'+$e.attr('id')).find('select:first').val();
}
else if($('#folder_hidden_'+$e.attr('id')).length) {
folder_id = $('#folder_hidden_'+$e.attr('id')).val();
}
var data = $e.uploadifySettings('scriptData');
$.extend(data, {
FolderID : folder_id
});
$e.uploadifySettings('scriptData', data, true);
$e.data('active',true);
if(!$e.metadata().upload_on_submit) {
$e.parents('form').find(':submit').attr('disabled',true).addClass('disabled');
}
},
onCancel: function(event, queueID, fileObj, data) {
var $e = $(event.currentTarget);
if (data.fileCount == 0) {
$e.closest('.UploadifyField').find('.preview').show().html('<div class="no_files"></div>');
if (!$e.metadata().auto && !$e.metadata().upload_on_submit) {
$('.uploadifyfield_queue_actions').show();
}
}
}
});
// Handle form submission if the upload happens on submit
if($uploader.metadata().upload_on_submit) {
$(this).parents('form:first').submit(function(e) {
cansubmit = true;
$('input.uploadify').each(function() {
if($(this).data('active')) {
cansubmit = false;
$(this).uploadifyUpload();
}
});
return cansubmit;
});
}
$uploader.uploadify(opts);
// Build the "fake" CSS button
var $buttonWrapper = $('.button_wrapper', $t);
var $fakeButton = $(".button_wrapper a",$t);
var width = $fakeButton.outerWidth();
var height = $fakeButton.outerHeight();
opts.width = width;
opts.height = height;
$buttonWrapper.css("width", width + "px").css("height", height + "px")
// Activate uploadify
// Tabs for the backend
if($t.find('.horizontal_tab_wrap').length) {
$tabSet = $t.find('.horizontal_tab_wrap');
var tabContainers = $('div.horizontal_tabs > div', $tabSet);
tabContainers.hide().filter(':last').show();
$('div.tabNavigation ul.navigation a', $tabSet).live("click",function () {
// trigger reload on tab change added XD
if( $(this).parent().attr('class')=='first' ){
$t.find('.import_dropdown select').trigger("change");
}
tabContainers.hide();
tabContainers.filter(this.hash).show();
$(this).parents('ul:first').find('.selected').removeClass('selected');
$(this).addClass('selected');
return false;
});
$('div.tabNavigation ul.navigation a:last', $tabSet).click();
}
});
});
/**
Attach behaviours external to the uploader, e.g. queue functions
**/
// Delete buttons for the queue items
$('.upload_previews li .delete a').live("click", function() {
var $t = $(this);
$.post(
$t.attr('href'),
{'FileID' : $t.attr('rel')},
function() {
$t.parents("li:first").fadeOut(function() {
$(this).remove();
$('.inputs input[value='+$t.attr('rel')+']').remove();
});
}
);
return false;
});
// Change folder ajax post
$('.folder_select').find(':submit').live("click", function() {
var $t = $(this);
var $target = $(this).parents('.UploadifyField').find('.uploadify');
var $folderSelect = $('#folder_select_'+$target.attr('id'));
var folder_id = $('select:first', $folderSelect).val();
var new_folder = $('input:first', $folderSelect).val();
$folderSelect.parents('.folder_select_wrap').load(
$t.metadata().url,
{ FolderID : folder_id, NewFolder : new_folder}
);
return false;
});
$('.folder_select :submit').livequery(function() {
$(this).siblings('label').hide();
});
// Attach sorting, if multiple uploads
$('.upload_previews ul.sortable').livequery(function() {
var $list = $(this);
var meta = $list.metadata();
$list.sortable({
update: function(e) {
$.post(meta.url, $list.sortable("serialize"));
},
containment : 'document',
tolerance : 'intersect'
});
});
$('.import_dropdown select').livequery("change", function() {
var uplField = $(this).parents('.UploadifyField').find('.uploadify').metadata();
var fileExt = uplField.fileExt;
var $t = $(this);
var $target = $t.parents('.import_dropdown').find('.import_list');
$t.parents('.import_dropdown').find('button').hide();
$target.html('').addClass('loading').show().css('height','50px');
var data = (fileExt != "*.*") ? { FolderID : $t.val(), 'FileExt' : fileExt } : {FolderID : $t.val()};
$.ajax({
url : $t.metadata().url,
data : data,
success : function(data) {
$target.slideUp(function() {
$(this).removeClass('loading').css({'height' : 'auto', 'max-height' : '150px','overflow' : 'auto'});
$(this).html(data);
if($('input', $(this)).length) {
$t.parents('.import_dropdown').find('button').show();
}
$(this).slideDown();
});
}
});
}).change();
$('.import_dropdown button').live("click", function() {
var url = $(this).metadata().url;
var $target = $(this).parents('.UploadifyField').find('.preview');
var $uploader = $(this).parents('.UploadifyField').find('.uploadify');
var $list = $(this).parents('.import_dropdown');
var ids = new Array();
$target.find('input').each(function() {
if($(this).val().length) {
ids.push($(this).val());
}
});
$list.find(':checked').each(function() {
ids.push($(this).val());
});
$.ajax({
url: $uploader.metadata().refreshlink,
data: {'FileIDs' : ids.join(",")},
dataType : "json",
success: function(data) {
$target.html(data.html);
$msg = $list.find('.import_message');
$msg.html(data.success).fadeIn();
setTimeout(function() {
$msg.fadeOut()
},5000);
$list.find('select').val('');
$list.find('button').hide();
$list.find('.import_list').slideUp();
}
});
return false;
});
$('.import_list_search_field').live('keyup',function(){
var searchTxt = $(this).val().toLowerCase();
$(this).parent().find('.import_list').find('li').each(function(x){
var v = $(this).find('label').text().toLowerCase();
if(v.indexOf(searchTxt) != -1){
$(this).removeClass().addClass(function(){return (x%2==0) ? 'odd' : 'even';}).show();
} else {
$(this).hide();
}
});
});
If using multiple instances of uploadify within silverstripe cms, the import list is not populated.
If the uploadify field was loaded with ajax the import list also did not work.
I changed uploadify_init to fix this.
Now on tabchange the list is updated. I also added 'var' to all variables defined within functions (line 129).
For us this works better.
if( $(this).parent().attr('class')=='first' ){
$t.find('.import_dropdown select').trigger("change");
}
Altered code for uploadify_init.js:
jQuery.noConflict();$t = $ (this);$input = $ ('input.uploadify',$t);$uploader = $ ('');
$uploader = $ ('input.uploadify', $t);$e = $ (event.currentTarget);
$e = $ (event.currentTarget);$preview = $ ('#upload_preview_'+$e.attr('id'));$inputs = $ ('.inputs input', $preview);
(function($) {
$(function() {
$('.UploadifyField').livequery(function() {
$(this).each(function() {
var
if(!$t.hasClass('backend')) {
var
var name = $input.attr('name');
var id = $input.attr('id');
var klass = $input.attr('class');
var
$input.replaceWith($uploader);
}
else {
}
/**
Build a set of options to pass to the uploadify object
**/
var opts = $uploader.metadata();
$.extend(opts, {
onComplete: function(event, queueID, fileObj, response, data) {
var
var $container = $e.parents('.UploadifyField:first');
if(isNaN(response)) {
alert(response);
}
if($e.metadata().refreshlink) {
var
var
if($preview.length) {
var ids = new Array();
$inputs.each(function() {
if($(this).val().length) {
ids.push($(this).val());
}
});
ids.push(response);
});
})(jQuery);