(function($) {
$.extend( {
checkUpload: function() {
// Check uploaded file type
// alert($(":file").attr('value'));
Request("function/file/Checkfiletype", {datatype:'json',callback:'$.confirmUpload(data)',method:'get'}, {filename: $(":file").attr('value')});
},
confirmUpload: function(data) {
// Check uploaded file type
if(data.status === false)
{
$(":file").attr('value','');
alert('Virheellinen tiedosto');
}
else
{
//$('#upload_form').submit();
//$(this).parent().find('#upload_form').submit();//$.startUpload();
}
},
startUpload: function() {
//$('#profile_box').append("
");
var dateObject = new Date();
$.uniqueId = dateObject.getFullYear() + '' + dateObject.getMonth() + '' + dateObject.getDate() + '' + dateObject.getTime();
//$("#uuid").attr('value',$.uniqueId);
//console.log('start upload id: '+$.uniqueId);
},
processing: function()
{
console.log('processing');
Request("function/file/UploadInfo", {datatype:'json',callback:'$.processing_output(data)',method:'get'}, {uuid: $.uniqueId});
},
processing_output: function(data)
{
if($.interval)
{
var percentage = Math.floor(100 * parseInt(data.bytes_uploaded) / parseInt(data.bytes_total));
if(isNaN(percentage) && $.iframeReady.ready == true)
$.stopUpload();
else if(!isNaN(percentage))
{
$("#uploadprogressbar").progressBar(percentage);
$("#uploadprogressbar_filename").html(data.filename);
}
}
},
showDiv: function(data,id)
{
$("#main_container").append(data);
var elwidth = $(id).css('width');
var elheight = $(id).css('height');
$(id).css({width:"0px",height:"0px"});
$(id).animate({width:elwidth,height:elheight},200,function(){ $(id).editElement();$(id).click(); });
},
complete: function(data)
{
console.log('complete');
data = eval('(' + data + ')');
if(data.error > 0)
{
alert(data.error_desc);
}
else
{
var name = data.name;
var left=100;
var top=100;
var elid = "uploadedimage_"+Math.floor ( Math.random ( ) * 100 + 1 );
Request('function/XML/GetFormElement',{append:'true', dest:'#main_container', method:'get', callback:'$.showDiv(data,"#newUploadedDiv'+elid+'")'},{file:'action/form/img.xml.html',parm:'{"attributes": {"src":"images/'+data.name+'","style":"position:absolute;top:'+top+'px;left:'+left+'px;width:'+data.width+'px;height:'+data.height+'px;"}, "id":"newUploadedDiv'+elid+'"}' });
}
},
iframeReady: function()
{
if($("#teeko_fuf").contents().attr('readyState') == 'complete' && $("#teeko_fuf").contents().attr('URL') !== 'about:blank')
{
var data = eval('('+$("#teeko_fuf").contents().find("body").html()+')');
var dateObject = new Date();
//var rand = dateObject.getFullYear() + '' + dateObject.getMonth() + '' + dateObject.getDate() + '' + dateObject.getTime();
$.stopUpload();
//$("#teeko_fuf").load(function (){$.iframeReady();});
}
},
stopUpload: function()
{
/*
var upload_status = $("#teeko_fuf").contents().find("body").html();
if(upload_status)
{
$("#teeko_fuf").attr('onLoad', null);
clearInterval($.interval);
$.interval = undefined;
$("#uploadprogressbar").progressBar(100, { callback: function(data) { if(data.running_value == data.value) $.complete(upload_status);} });
}
*/
$("#teeko_fuf").remove();
if(typeof $.uploadercallbackcallbackfn == 'function') $.uploadercallbackcallbackfn.call();
},
});
$.extend($.fn, {
uploader: function()
{
$(this).parent().parent().parent().append("");
$(':input[type=file]').attr('onChange','$.checkUpload()');
$("#teeko_fuf").load(function (){$.iframeReady();});
/*
$('#upload_form').attr({
enctype:'multipart/form-data',
target:'teeko_fuf',
action:'template/function/file/Upload',
onSubmit:'$.startUpload()',
method:'post'
}); */
$(this).attr({
//enctype:'multipart/form-data',
target:'teeko_fuf',
action:'template/function/file/Upload',
onSubmit:'$.startUpload()',
method:'post'
});
},
uploadercallback: function(fn)
{
$.uploadercallbackcallbackfn = fn;
}
});
})(jQuery);