// JavaScript Document var uploadDeleteHandler = function(e) { var id = $(this).parent().attr('id'); if($('#dialog').length){ profile_img_uploader_onFocus($(this).parent()); var t = ''; var confirmBtnTxt = ''; var cancelBtnTxt = ''; var contentTxt = ''; switch($(this).parent().attr('id')){ case 'project_profile': switch(Number(global_js_params.lang)){ default: case 1: cancelBtnTxt = 'Cancel'; confirmBtnTxt = 'Confirm'; contentTxt = 'Are you sure to remove the Project Profile Image ?'; t = 'Delete Profile Image'; break; case 2: cancelBtnTxt = '取消'; confirmBtnTxt = '確定'; contentTxt = '您確定要刪除項目相片?'; t = '刪除項目簡介圖片'; break; case 3: cancelBtnTxt = '取消'; confirmBtnTxt = '确定'; contentTxt = '您确定要删除项目相片?'; t = '删除项目图片'; break; } break; case 'project_highlight': switch(Number(global_js_params.lang)){ default: case 1: cancelBtnTxt = 'Cancel'; confirmBtnTxt = 'Confirm'; contentTxt = 'Are you sure to remove the Project Highlight Image ?'; t = 'Delete Highlight Image'; break; case 2: cancelBtnTxt = '取消'; confirmBtnTxt = '確定'; contentTxt = '您確定要刪除項目顯示圖片?'; t = '刪除顯示圖像'; break; case 3: cancelBtnTxt = '取消'; confirmBtnTxt = '确定'; contentTxt = '您确定要删除项目显示图片?'; t = '删除显示图像'; break; } break; case 'org_profile': switch(Number(global_js_params.lang)){ default: case 1: cancelBtnTxt = 'Cancel'; confirmBtnTxt = 'Confirm'; contentTxt = 'Are you sure to remove Profile Image for your Organization ?'; t = 'Delete Profile Image'; break; case 2: cancelBtnTxt = '取消'; confirmBtnTxt = '確定'; contentTxt = '您確定要刪除主辦方相片?'; t = '刪除主辦方圖片'; break; case 3: cancelBtnTxt = '取消'; confirmBtnTxt = '确定'; contentTxt = '您确定要删除主办方相片?'; t = '删除主办方图片'; break; } break; default: case 'account_profile': switch(Number(global_js_params.lang)){ default: case 1: cancelBtnTxt = 'Cancel'; confirmBtnTxt = 'Confirm'; contentTxt = 'Are you sure to remove User Profile Image for your User Account ?'; t = 'Delete Profile Image'; break; case 2: cancelBtnTxt = '取消'; confirmBtnTxt = '確定'; contentTxt = '您確定要刪除帳戶相片'; t = '刪除帳戶相片'; break; case 3: cancelBtnTxt = '取消'; confirmBtnTxt = '确定'; contentTxt = '您确定要删除帐户相片'; t = '删除帐户相片'; break; } break; } $( "#dialog" ).html(contentTxt); $( "#dialog" ).dialog({ resizable: false, open: function(){ $('.ui-widget-overlay').hide().fadeIn(); $('.ui-widget-overlay').bind('click', function() { ajax_show_loading_mask(false); ajax_submitBtn_setInProgress_withLoadingBar($("#continueSubmitBtn"), payout_bank_registration_handler, false); $('#dialog').dialog('close'); }); }, show: { effect: "clip", duration: 200 }, hide: { effect: "clip", duration: 200 }, autoOpen: true, draggable: false, width: 'auto', modal: true, closeOnEscape: false, title: t, buttons: [ { text: confirmBtnTxt, click: function() { $('#'+id+'_file_delete').submit(); $( this ).dialog( "close" ); } }, { text: cancelBtnTxt, click: function() { $( this ).dialog( "close" ); } } ] }); } // if($('#dialog').length){ } function init_img_uploader(_target, _img_size_MB, _required_upload_boo, _default_img){ // Organizer & User Profile, Project // ------- UPlaod ----------------------------- if(_target.length){ var targetHover = function() { profile_img_uploader_onHover(_target); $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').css("opacity", 0.6); $('#'+_target.attr('id')+' #file_upload_description').stop().css("opacity", 1.0).show(); } var targetHoverOut = function() { $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').css("opacity", 1.0); if(_required_upload_boo) profile_img_uploader_onBlur(_target, _default_img); } var options_delete = { dataType:'json', beforeSend: function() { //$('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').hide(); _target.unbind(); _target.removeAttr('href'); $('#'+_target.attr('id')+' #file_upload_delete').hide(); $('#'+_target.attr('id')+' #file_upload_delete').unbind(); }, success: function(json_data) { if(json_data.status != 1){ } else { if(typeof _default_img === "undefined"){ $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').attr("src", $('#'+_target.attr('id')+'_file_delete #fname').val()); } else { $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').attr("src", local_url+_default_img); } $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').show(); $('#'+_target.attr('id')+' #file_upload_delete').unbind(); $('#'+_target.attr('id')+' #file_upload_delete').hide(); $('#'+_target.attr('id')+' #file_upload_description').show(); $('#'+_target.attr('id')+'_file_upload #file_upload_file').val(''); } }, complete: function(response) { _target.attr("href", "javascript:void(0);"); _target.hover(targetHover, targetHoverOut); }, error: function() { $('#'+_target.attr('id')+' #file_upload_delete').bind("click", uploadDeleteHandler); $('#'+_target.attr('id')+' #file_upload_delete').show(); $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').show(); } }; var options_upload = { dataType:'json', beforeSend: function() { //$('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').hide(); _target.unbind(); _target.removeAttr('href'); $('#'+_target.attr('id')+' #file_upload_description').hide(); $('#'+_target.attr('id')+' #upload_processbox').show(); $('#'+_target.attr('id')+' #upload_processbar').width('0%'); //$('#'+_target.attr('id')+' #upload_processtxt').html("0%"); $('#'+_target.attr('id')+' #file_upload_delete').hide(); $('#'+_target.attr('id')+' #file_upload_delete').unbind(); }, uploadProgress: function(event, position, total, percentComplete) { if(percentComplete >= 80 && percentComplete < 100){ percentComplete = 80; } else if(percentComplete == 100){ percentComplete = 90; } $('#'+_target.attr('id')+' #upload_processbar').width(percentComplete+'%'); }, success: function(json_data) { $('#'+_target.attr('id')+' #upload_processbar').width('100%'); //alert(json_data.status); if(json_data.status != 1){ $('#'+_target.attr('id')+'_file_upload #file_upload_file').val(''); //-52, dimension 400 x 400 if(!$('#'+_target.attr('id')+'_err').length){ _target.after('
'+ajax_showStatusMessage(json_data.status)+'
'); } } else { //$('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').attr("src", local_url+json_data.path); $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').attr("src", json_data.path); $('#'+_target.attr('id')+'-upid').val(json_data.upid); var action_url = $('#'+_target.attr('id')+'_file_upload').attr('action'); var action_url_arr = action_url.split('&upid='); if(action_url_arr.length > 1){ $('#'+_target.attr('id')).attr('action', action_url_arr[0]+'&upid='+json_data.upid); } else { $('#'+_target.attr('id')).attr('action', action_url+'&upid='+json_data.upid); } //alert(json_data.upid); //alert('-upid:'+$('#'+_target.attr('id')+'-upid').val()); //alert(json_data.upid_r); $('#'+_target.attr('id')+' #file_upload_delete').bind("click", uploadDeleteHandler); $('#'+_target.attr('id')+' #file_upload_delete').show(); } $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').show(); $('#'+_target.attr('id')+' #upload_processbar').width('100%'); //$('#'+_target.attr('id')+' #upload_processtxt').html('100%'); $('#'+_target.attr('id')+' #upload_processbox').hide(); }, complete: function(response) { _target.attr("href", "javascript:void(0);"); _target.hover(targetHover, targetHoverOut); }, error: function(xhr, ajaxOptions, thrownError){ //alert('error: '+xhr.responseText); $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').show(); } }; // Upload Form $('#'+_target.attr('id')+'_file_delete').ajaxForm(options_delete); $('#'+_target.attr('id')+'_file_upload').ajaxForm(options_upload); $('#'+_target.attr('id')+'_file_upload #id').val(_target.attr('id')); $('#'+_target.attr('id')+'_file_upload #file_upload_file').change(function (e){ profile_img_uploader_onChange(_target, _img_size_MB, _required_upload_boo); }); // ------- END -- Upload -------------------------------------------- if($('#'+_target.attr('id')+' #file_upload_delete').is(':visible')){ $('#'+_target.attr('id')+' #file_upload_delete').bind("click", uploadDeleteHandler); } _target.hover(targetHover, targetHoverOut); $('#'+_target.attr('id')+' #file_upload_description, #'+_target.attr('id')+' #'+_target.attr('id')+'_img').click(function(e){ profile_img_uploader_onFocus(_target); $('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').css("opacity", 1.0); $('#'+_target.attr('id')+'_file_upload #file_upload_file').val(''); $('#'+_target.attr('id')+'_file_upload #file_upload_file').click(); }); } // if(_target.length){ } function profile_img_uploader_onChange(_target, _img_size_MB, _required_upload_boo){ var cancelSubmission = false; var message = -47; if($('#'+_target.attr('id')+'_file_upload #id').val() == _target.attr('id')){ if(!$('#'+_target.attr('id')+'_file_upload #file_upload_file').val() && _required_upload_boo){ message = -47; cancelSubmission = true; } else { var ext = $('#'+_target.attr('id')+'_file_upload #file_upload_file').val().split('.').pop().toLowerCase(); if($.inArray(ext, ['png','jpg','jpeg']) == -1) { message = -48; cancelSubmission = true; } else { var file = $('#'+_target.attr('id')+'_file_upload #file_upload_file')[0].files[0]; if(file.size > 1024*1024*_img_size_MB){ message = -48-_img_size_MB; cancelSubmission = true; } } } if(cancelSubmission){ if(!$('#'+_target.attr('id')+'_err').length){ var w = $('#'+_target.attr('id')+'_img').width(); _target.after('
'+ajax_showStatusMessage(message)+'
'); } return; } $('#'+_target.attr('id')+'_file_upload').submit(); } // if($('#file_upload #id').val() == _target.attr('id')){ } function profile_img_uploader_onBlur(_target, _default_img){ if(profile_img_uploader_is_onClick){ var haveImage = false; if(typeof _default_img === "undefined"){ if($('#'+_target.attr('id')+'_file_upload #fname').val() == ''){ } else { haveImage = true; } } else { if($('#'+_target.attr('id')+' #'+_target.attr('id')+'_img').attr("src").indexOf(_default_img) !=-1){ } else { haveImage = true; } } if(!$('#'+_target.attr('id')+'_file_upload #file_upload_file').val() && !haveImage){ // Cancel if(!$('#'+_target.attr('id')+'_err').length){ var w = $('#'+_target.attr('id')+'_img').width(); _target.after('
'+ajax_showStatusMessage(-47)+'
'); } } } //if(profile_img_uploader_is_onClick){ } function profile_img_uploader_onHover(_target){ profile_img_uploader_is_onClick = false; } function profile_img_uploader_onFocus(_target){ profile_img_uploader_is_onClick = true; if($('#'+_target.attr('id')+'_err').length){ $('#'+_target.attr('id')+'_err').remove(); } }