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
|
<?php
|
||||||
/*
|
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
|
||||||
* jQuery File Upload Plugin PHP Example 5.2.2
|
* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* https://github.com/blueimp/jQuery-File-Upload
|
|
||||||
*
|
*
|
||||||
* Copyright 2010, Sebastian Tschan
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* https://blueimp.net
|
* 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:
|
* This program is distributed in the hope that it will be useful,
|
||||||
* http://creativecommons.org/licenses/MIT/
|
* 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');
|
//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)
|
//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
|
require("../main.inc.php");
|
||||||
if (! $res) $res=@include("../../main.inc.php"); // For "custom" directory
|
|
||||||
if (! $res) @include("../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only
|
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php");
|
require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php");
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?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-2011 Regis Houssin <regis@dolibarr.fr>
|
||||||
* Copyright (c) 2010 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (c) 2010 Juanjo Menent <jmenent@2byte.es>
|
||||||
*
|
*
|
||||||
@ -22,7 +22,7 @@
|
|||||||
* \file htdocs/core/class/html.formfile.class.php
|
* \file htdocs/core/class/html.formfile.class.php
|
||||||
* \ingroup core
|
* \ingroup core
|
||||||
* \brief File of class to offer components to list and upload files
|
* \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,37 +759,18 @@ class FormFile
|
|||||||
var max_file_size = \''.$max_file_size.'\';
|
var max_file_size = \''.$max_file_size.'\';
|
||||||
|
|
||||||
// Initialize the jQuery File Upload widget:
|
// Initialize the jQuery File Upload widget:
|
||||||
$("#fileupload").fileupload( { maxFileSize: max_file_size} );
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Open download dialogs via iframes,
|
|
||||||
// to prevent aborting current uploads:
|
|
||||||
$("#fileupload .files a:not([target^=_blank])").live("click", function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
$(\'<iframe style="display:none;"></iframe>\')
|
|
||||||
.prop("src", this.href)
|
|
||||||
.appendTo("body");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Confirm delete file
|
|
||||||
$("#fileupload").fileupload({
|
$("#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) {
|
destroy: function (e, data) {
|
||||||
var that = $(this).data("fileupload");
|
var that = $(this).data("fileupload");
|
||||||
if ( confirm("Delete this file ?") == true ) {
|
if ( confirm("Delete this file ?") == true ) {
|
||||||
if (data.url) {
|
if (data.url) {
|
||||||
$.ajax(data)
|
$.ajax(data).success(function () {
|
||||||
.success(function () {
|
|
||||||
that._adjustMaxNumberOfFiles(1);
|
that._adjustMaxNumberOfFiles(1);
|
||||||
$(this).fadeOut(function () {
|
$(this).fadeOut(function () {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
@ -803,6 +784,31 @@ class FormFile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Load existing files:
|
||||||
|
// 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:
|
||||||
|
$("#fileupload .files a:not([target^=_blank])").live("click", function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
$(\'<iframe style="display:none;"></iframe>\')
|
||||||
|
.prop("src", this.href)
|
||||||
|
.appendTo("body");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>';
|
</script>';
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user