#1148: Fixed dashboards upload: use the more modern fileupload component, since we now hook the ajax call in iTopWebPage and removed references to the old component ajax.fileupload from (almost) everywhere...

SVN:trunk[3753]
This commit is contained in:
Denis Flaven
2015-09-12 12:06:33 +00:00
parent 489820cfe7
commit 972c94bff7
3 changed files with 33 additions and 103 deletions

View File

@@ -546,6 +546,8 @@ class RuntimeDashboard extends Dashboard
public function RenderEditionTools($oPage)
{
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.iframe-transport.js');
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.fileupload.js');
$sEditMenu = "<td><span id=\"DashboardMenu\"><ul><li><img src=\"../images/edit.png\"><ul>";
$aActions = array();

View File

@@ -250,65 +250,6 @@ EOF
$('#attachment_plugin').trigger('remove_attachment', [att_id]);
return false; // Do not submit the form !
}
function ajaxFileUpload()
{
//starting setting some animation when the ajax starts and completes
$("#attachment_loading").ajaxStart(function(){
$(this).show();
}).ajaxComplete(function(){
$(this).hide();
});
/*
prepareing ajax file upload
url: the url of script file handling the uploaded files
fileElementId: the file type of input element id and it will be the index of \$_FILES Array()
dataType: it support json, xml
secureuri:use secure protocol
success: call back function when the ajax complete
error: callback function when the ajax failed
*/
$.ajaxFileUpload
(
{
url: GetAbsoluteUrlModulesRoot()+'itop-attachments/ajax.attachment.php?obj_class={$sClass}&temp_id={$sTempId}&operation=add',
secureuri:false,
fileElementId:'file',
dataType: 'json',
success: function (data, status)
{
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
alert(data.error);
}
else
{
var sDownloadLink = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?operation=download_document&class=Attachment&id='+data.att_id+'&field=contents';
$('#attachments').append('<div class="attachment" id="display_attachment_'+data.att_id+'"><a data-preview="'+data.preview+'" href="'+sDownloadLink+'"><img src="'+data.icon+'"><br/>'+data.msg+'<input id="attachment_'+data.att_id+'" type="hidden" name="attachments[]" value="'+data.att_id+'"/></a><br/><input type="button" class="btn_hidden" value="{$sDeleteBtn}" onClick="RemoveAttachment('+data.att_id+');"/></div>');
if($sIsDeleteEnabled)
{
$('#display_attachment_'+data.att_id).hover( function() { $(this).children(':button').toggleClass('btn_hidden'); } );
}
$('#attachment_plugin').trigger('add_attachment', [data.att_id, data.msg]);
//alert(data.msg);
}
}
},
error: function (data, status, e)
{
alert(e);
}
}
)
return false;
}
EOF
);
$oPage->add('<span id="attachments">');
@@ -357,11 +298,10 @@ EOF
$oPage->add('</span>');
$oPage->add('<div style="clear:both"></div>');
$sMaxUpload = $this->GetMaxUpload();
// $oPage->p(Dict::S('Attachments:AddAttachment').'<input type="file" name="file" id="file" onChange="ajaxFileUpload();"><span style="display:none;" id="attachment_loading">&nbsp;<img src="../images/indicator.gif"></span> '.$sMaxUpload);
$oPage->p(Dict::S('Attachments:AddAttachment').'<input type="file" name="file" id="file"><span style="display:none;" id="attachment_loading">&nbsp;<img src="../images/indicator.gif"></span> '.$sMaxUpload);
$oPage->add_linked_script('../js/jquery.iframe-transport.js');
$oPage->add_linked_script('../js/jquery.fileupload.js');
$oPage->p(Dict::S('Attachments:AddAttachment').'<input type="file" name="file" id="file"><span style="display:none;" id="attachment_loading">&nbsp;<img src="../images/indicator.gif"></span> '.$sMaxUpload);
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.iframe-transport.js');
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.fileupload.js');
$oPage->add_ready_script(
<<< EOF
@@ -399,14 +339,13 @@ $oPage->add_ready_script(
$(document).bind('dragover', function (e) {
var bFiles = false;
if (e.dataTransfer.types)
if (e.dataTransfer && e.dataTransfer.types)
{
for (var i = 0; i < e.dataTransfer.types.length; i++)
{
if (e.dataTransfer.types[i] == "text/plain")
if (e.dataTransfer.types[i] == "application/x-moz-nativeimage")
{
bFiles = false; // mozilla contains "Files" in the types list when dragging images inside the page, but it also contains "text/plain" before
bFiles = false; // mozilla contains "Files" in the types list when dragging images inside the page, but it also contains "application/x-moz-nativeimage" before
break;
}

View File

@@ -381,7 +381,30 @@ $(function()
me.element.dialog('close');
//me.onClose();
};
$('#'+this.options.file_id).bind('change', function() { me._doUpload(); } );
$('#'+this.options.file_id).fileupload({
url: me.options.submit_to+'&id='+me.options.dashboard_id,
dataType: 'json',
pasteZone: null, // Don't accept files via Chrome's copy/paste
done: function (e, data) {
if(typeof(data.result.error) != 'undefined')
{
if(data.result.error != '')
{
alert(data.result.error);
me.element.dialog('close');
}
else
{
me.element.dialog('close');
location.reload();
}
}
},
start: function() {
$('#'+me.options.file_id).prop('disabled', true);
}
});
this.element
.addClass('itop-dashboard_upload_dlg')
.dialog({
@@ -421,40 +444,6 @@ $(function()
_onClose: function()
{
this.element.remove();
},
_doUpload: function()
{
var me = this;
$.ajaxFileUpload
(
{
url: me.options.submit_to+'&id='+me.options.dashboard_id,
secureuri:false,
fileElementId: me.options.file_id,
dataType: 'json',
success: function (data, status)
{
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
alert(data.error);
me.element.dialog('close');
}
else
{
me.element.dialog('close');
location.reload();
}
}
},
error: function (data, status, e)
{
alert(e);
me.element.dialog('close');
}
}
);
}
});
});