diff --git a/htdocs/core/ajaxfileupload.php b/htdocs/core/ajaxfileupload.php index 3420bda0a95..68199e8588d 100644 --- a/htdocs/core/ajaxfileupload.php +++ b/htdocs/core/ajaxfileupload.php @@ -1,13 +1,26 @@ + * Copyright (C) 2011 Laurent Destailleur * - * 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"); diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 46d699019fc..4aa64bed577 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1,5 +1,5 @@ +/* Copyright (c) 2008-2011 Laurent Destailleur * Copyright (C) 2010-2011 Regis Houssin * Copyright (c) 2010 Juanjo Menent * @@ -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(); - }); - } - } - } - }); }); ';