Fix: reload page after file upload done
Todo: use jquery template for view files, don't reload page !
This commit is contained in:
parent
2530d4cee5
commit
7b679f0776
@ -1,13 +1,26 @@
|
||||
<?php
|
||||
/*
|
||||
* jQuery File Upload Plugin PHP Example 5.2.2
|
||||
* https://github.com/blueimp/jQuery-File-Upload
|
||||
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* Copyright 2010, Sebastian Tschan
|
||||
* https://blueimp.net
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://creativecommons.org/licenses/MIT/
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/ajaxfileupload.php
|
||||
* \brief File to return Ajax response on file upload
|
||||
* \version $Id: ajaxfileupload.php,v 1.8 2011/07/06 06:21:51 hregis Exp $
|
||||
*/
|
||||
|
||||
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
|
||||
@ -22,9 +35,7 @@ if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't nee
|
||||
//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
|
||||
|
||||
|
||||
$res=@include("../main.inc.php"); // For "root" directory
|
||||
if (! $res) $res=@include("../../main.inc.php"); // For "custom" directory
|
||||
if (! $res) @include("../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only
|
||||
require("../main.inc.php");
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/* Copyright (c) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (c) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (c) 2010 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
@ -22,7 +22,7 @@
|
||||
* \file htdocs/core/class/html.formfile.class.php
|
||||
* \ingroup core
|
||||
* \brief File of class to offer components to list and upload files
|
||||
* \version $Id: html.formfile.class.php,v 1.39 2011/07/05 22:40:36 eldy Exp $
|
||||
* \version $Id: html.formfile.class.php,v 1.40 2011/07/06 06:21:52 hregis Exp $
|
||||
*/
|
||||
|
||||
|
||||
@ -759,19 +759,46 @@ class FormFile
|
||||
var max_file_size = \''.$max_file_size.'\';
|
||||
|
||||
// Initialize the jQuery File Upload widget:
|
||||
$("#fileupload").fileupload( { maxFileSize: max_file_size} );
|
||||
$("#fileupload").fileupload({
|
||||
maxFileSize: max_file_size,
|
||||
done: function (e, data) {
|
||||
$.ajax(data).success(function () {
|
||||
location.href=\''.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].'\';
|
||||
});
|
||||
},
|
||||
destroy: function (e, data) {
|
||||
var that = $(this).data("fileupload");
|
||||
if ( confirm("Delete this file ?") == true ) {
|
||||
if (data.url) {
|
||||
$.ajax(data).success(function () {
|
||||
that._adjustMaxNumberOfFiles(1);
|
||||
$(this).fadeOut(function () {
|
||||
$(this).remove();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
data.context.fadeOut(function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Load existing files:
|
||||
$.getJSON($("#fileupload form").prop("action"), { fk_element: "'.$object->id.'", element: "'.$object->element.'"}, function (files) {
|
||||
var fu = $("#fileupload").data("fileupload");
|
||||
fu._adjustMaxNumberOfFiles(-files.length);
|
||||
fu._renderDownload(files)
|
||||
.appendTo($("#fileupload .files"))
|
||||
.fadeIn(function () {
|
||||
// Fix for IE7 and lower:
|
||||
$(this).show();
|
||||
});
|
||||
});
|
||||
// TODO do not delete
|
||||
if (1 == 2) {
|
||||
$.getJSON($("#fileupload form").prop("action"), { fk_element: "'.$object->id.'", element: "'.$object->element.'"}, function (files) {
|
||||
var fu = $("#fileupload").data("fileupload");
|
||||
fu._adjustMaxNumberOfFiles(-files.length);
|
||||
fu._renderDownload(files)
|
||||
.appendTo($("#fileupload .files"))
|
||||
.fadeIn(function () {
|
||||
// Fix for IE7 and lower:
|
||||
$(this).show();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Open download dialogs via iframes,
|
||||
// to prevent aborting current uploads:
|
||||
@ -782,27 +809,6 @@ class FormFile
|
||||
.appendTo("body");
|
||||
});
|
||||
|
||||
// Confirm delete file
|
||||
$("#fileupload").fileupload({
|
||||
destroy: function (e, data) {
|
||||
var that = $(this).data("fileupload");
|
||||
if ( confirm("Delete this file ?") == true ) {
|
||||
if (data.url) {
|
||||
$.ajax(data)
|
||||
.success(function () {
|
||||
that._adjustMaxNumberOfFiles(1);
|
||||
$(this).fadeOut(function () {
|
||||
$(this).remove();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
data.context.fadeOut(function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user