jQuery(document).ready( function() { var helper=BpGalleryHelper; var j = jQuery; /** * TODO: Minimize dependency of Dom elements by Id, as much as possible */ //basic setup //if the file element exists activate swf uploader if(j("#file").get(0)&&helper.is_flash_enabled())//just to avoid the conflict swfuplod_init_for_media("file"); //see above line, activate swf upload for cover upload in case we are opening directly the cover upload page for gallery if(j("#cover_file").get(0)&&helper.is_flash_enabled()) swfuplod_init_for_gallery("cover_file"); //global variables,bad thing but required gallery_upload_error=false;//handling upload errors gallery_upload_error_message='';//in next version, we will use it as an array of errors /* *--------------------------- File Upload functions for swf upload ------------------------------------* *-----------------------------------------------------------------------------------------------------* **/ /*************************************************************** SWF Upload Helper Functions *************************************/ /* Generic functions like queueing, handling queue error etc*/ // Handles Listing of files, just a UI function, It lists the file when file is selected in the DOM function file_queued(event, file){ var listitem='
  • '+ 'File: '+file.name+' ('+Math.round(file.size/1024)+' KB) '+ '
    '+ '

    Pending

    '+ ' '+ '
  • '; j('#log').append(listitem); j('li#'+file.id+' .cancel').bind('click', function(){ var swfu = j.swfupload.getInstance('#swfupload-control'); swfu.cancelUpload(file.id); j('li#'+file.id).slideUp('fast'); }); } //Handle the uploading error, i.e basic client side error handing by swf function file_queue_error( file, errorCode, message){ helper.show_message('Size of the file '+file.name+' is greater than limit'+message,1);//notify the error to the user } //Update the Number of file selected etc when File dialog is complete/closed function file_dialog_complete(event, numFilesSelected, numFilesQueued){ j('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued); } // helper function, called when swfupload starts uploading function upload_start(event, file){ j('#log li#'+file.id).find('p.status').text('Uploading...'); j('#log li#'+file.id).find('span.progressvalue').text('0%'); j('#log li#'+file.id).find('span.cancel').hide(); j(".guploading").show();//show the progress icon } //Helper function to handle the upload progress and show user the progress function upload_progress(event, file, bytesLoaded){ //Show Progress var percentage=Math.round((bytesLoaded/file.size)*100); j('#log li#'+file.id).find('div.progress').css('width', percentage+'%'); j('#log li#'+file.id).find('span.progressvalue').text(percentage+'%'); } /** * @desc helper function used to remove file from the list of selectd files on error/success */ function remove_file_from_list(file){ var item=j('#log li#'+file.id); item.find('div.progress').css('width', '100%'); item.find('span.progressvalue').text('100%'); item.addClass('success').find('p.status').html('Done!!!'); j(item).remove();//remove the file listing from dom } /** * Helper function for gallery cover upload complete * * */ function gallery_upload_complete(event, file){ var swfu = j.swfupload.getInstance('#swfupload-control'); j('li#'+file.id).slideUp('fast'); j(".guploading").hide(); } /** * @desc Helper functuion, used when a gallery save is clicked and response is recieved from server */ function gallery_upload_success(event, file, serverData){ //alert(serverData) var resp=JSON.parse( serverData); if(resp.data) helper.show_message(resp.data.msg);// show update else helper.show_message(resp.error.msg,1); remove_file_from_list(file); } //For Media //Helper function for swfupload, called when a file upload is complete function media_upload_complete(event, file){ var swfu = j.swfupload.getInstance('#swfupload-control'); j('li#'+file.id).slideUp('fast'); // upload has completed, try the next one in the queue var stats=swfu.getStats(); if(stats.files_queued!=0) j(this).swfupload('startUpload'); else{ j(".guploading").hide();//show the progress icon //simulate a click on the other tab //check for upload errors , if none if(!gallery_upload_error) j("#gallery-media-edit").click();//simulate click, let us see else { helper.show_message(gallery_upload_error_message,1); //reset error message gallery_upload_error_message=''; gallery_upload_error=false; } } } //Helper function, used when a media is uploaded and saved function media_upload_success(event, file, serverData){ //alert(serverData); //alert(serverData); resp=JSON.parse(serverData); if(resp.data) j("#update_media_upload").prepend(helper.build_media_html(resp.data)); else{ helper.show_message(resp.error.msg,1);//notify the error gallery_upload_error=true; gallery_upload_error_message=resp.error.msg; } remove_file_from_list(file); } function activity_upload_success(event, file, response){ //alert(serverData); //it should be simply activity update function var form=j("#whats-new-form"); j( 'form#' + form.attr('id') + ' span.ajax-loader' ).hide(); /* Check for errors and append if found. */ if ( response[0] + response[1] == '-1' ) { form.prepend( response.substr( 2, response.length ) ); jq( 'form#' + form.attr('id') + ' div.error').hide().fadeIn( 200 ); button.attr("disabled", ''); } else { if ( 0 == j("ul.activity-list").length ) { j("div.error").slideUp(100).remove(); j("div#message").slideUp(100).remove(); j("div.activity").append( '