Skip to content

Commit

Permalink
Merge branch '3.2' of https://github.com/Dolibarr/dolibarr into 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rdoursenaud committed May 31, 2012
2 parents 086a0ae + 7ed980f commit 0a8016e
Show file tree
Hide file tree
Showing 42 changed files with 3,228 additions and 1,702 deletions.
4 changes: 2 additions & 2 deletions COPYRIGHT
Expand Up @@ -21,8 +21,8 @@ PHPExcel 1.7.6 LGPL 2.1 Yes Read/Write XLS files, read ODS files
TCPDF 5.9.098 LGPL 3.0 Yes PDF generation

JS libraries:
jQuery 1.7.1 GPL and MIT Licence Yes JS library
jQuery UI 1.8.17 GPL and MIT Licence Yes JS library plugin UI
jQuery 1.7.2 GPL and MIT Licence Yes JS library
jQuery UI 1.8.20 GPL and MIT Licence Yes JS library plugin UI
jQuery Colorpicker 1.1 MIT Licence Yes JS library for color picker for a defined list of colors
jQuery DataTable 1.8.1 BSD Yes JS library for tables output
jQuery Flot 0.7 MIT Licence Yes JS library to build graph
Expand Down
99 changes: 4 additions & 95 deletions htdocs/core/class/html.formfile.class.php
Expand Up @@ -804,103 +804,12 @@ private function _formAjaxFileUpload($object)
$upload_max_filesize = $mul_upload_max_filesize * (int) $upload_max_filesize;
// Max file size
$max_file_size = (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize);

print '<script type="text/javascript">
$(function () {
\'use strict\';
var max_file_size = \''.$max_file_size.'\';
// Initialize the jQuery File Upload widget:
$("#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:
// 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>';

print '<div id="fileupload">';
print '<form action="'.DOL_URL_ROOT.'/core/ajax/fileupload.php" method="POST" enctype="multipart/form-data">';
print '<input type="hidden" name="fk_element" value="'.$object->id.'">';
print '<input type="hidden" name="element" value="'.$object->element.'">';
print '<div class="fileupload-buttonbar">';
print '<input type="hidden" name="protocol" value="http">';
print '<label class="fileinput-button">';
print '<span>'.$langs->trans('AddFiles').'</span>';
print '<input type="file" name="files[]" multiple>';
print '</label>';
print '<button type="submit" class="start">'.$langs->trans('StartUpload').'</button>';
print '<button type="reset" class="cancel">'.$langs->trans('CancelUpload').'</button>';
print '</div></form>';

print '</div><!-- end div fileupload -->';

print '<div id="fileupload-view">';
print '<div class="fileupload-content">';

print '<table width="100%" class="files">';
/*print '<tr>';
print '<td>'.$langs->trans("Documents2").'</td>';
print '<td>'.$langs->trans("Preview").'</td>';
print '<td align="right">'.$langs->trans("Size").'</td>';
print '<td colspan="3"></td>';
print '</tr>';*/
print '</table>';

// We remove this because there is already individual bars.
//print '<div class="fileupload-progressbar"></div>';

print '</div><!-- end div fileupload-content -->';
print '</div><!-- end div fileupload-view -->';

// Include main
include(DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php');

// Include template
include(DOL_DOCUMENT_ROOT.'/core/tpl/ajaxfileupload.tpl.php');
include(DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php');

}

Expand Down
76 changes: 76 additions & 0 deletions htdocs/core/tpl/ajax/fileupload_main.tpl.php
@@ -0,0 +1,76 @@
<?php
/* Copyright (C) 2011-2012 Regis Houssin <regis@dolibarr.fr>
*
* 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.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
?>

<!-- START TEMPLATE FILE UPLOAD MAIN -->
<script type="text/javascript">
window.locale = {
"fileupload": {
"errors": {
"maxFileSize": "<?php echo $langs->trans('FileIsTooBig'); ?>",
"minFileSize": "<?php echo $langs->trans('FileIsTooSmall'); ?>",
"acceptFileTypes": "<?php echo $langs->trans('FileTypeNotAllowed'); ?>",
"maxNumberOfFiles": "<?php echo $langs->trans('MaxNumberOfFilesExceeded'); ?>",
"uploadedBytes": "<?php echo $langs->trans('UploadedBytesExceedFileSize'); ?>",
"emptyResult": "<?php echo $langs->trans('EmptyFileUploadResult'); ?>"
},
"error": "<?php echo $langs->trans('Error'); ?>",
"start": "<?php echo $langs->trans('Start'); ?>",
"cancel": "<?php echo $langs->trans('Cancel'); ?>",
"destroy": "<?php echo $langs->trans('Delete'); ?>"
}
};

$(function () {
'use strict';

// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload();

// Options
$('#fileupload').fileupload('option', {
maxFileSize: '<?php echo $max_file_size; ?>'
});

// Events
$('#fileupload')
.bind('fileuploaddestroy', 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();
});
}
}
})
.bind('fileuploadcompleted', function (e, data) {
$.ajax(data).success(function () {
location.href='<?php echo $_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"]; ?>';
});
});
});
</script>
<!-- END TEMPLATE FILE UPLOAD MAIN -->
129 changes: 129 additions & 0 deletions htdocs/core/tpl/ajax/fileupload_view.tpl.php
@@ -0,0 +1,129 @@
<?php
/* Copyright (C) 2011-2012 Regis Houssin <regis@dolibarr.fr>
*
* 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.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
?>

<!-- START TEMPLATE FILE UPLOAD -->

<!-- The file upload form used as target for the file upload widget -->
<form id="fileupload" action="<?php echo DOL_URL_ROOT; ?>/core/ajax/fileupload.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="fk_element" value="<?php echo $object->id; ?>">
<input type="hidden" name="element" value="<?php echo $object->element; ?>">
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="row fileupload-buttonbar">
<div class="span7">
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn btn-success fileinput-button">
<i class="icon-plus icon-white"></i>
<span><?php echo $langs->trans('AddFiles'); ?></span>
<input type="file" name="files[]" multiple>
</span>
<button type="submit" class="btn btn-primary start">
<i class="icon-upload icon-white"></i>
<span><?php echo $langs->trans('StartUpload'); ?></span>
</button>
<button type="reset" class="btn btn-warning cancel">
<i class="icon-ban-circle icon-white"></i>
<span><?php echo $langs->trans('CancelUpload'); ?></span>
</button>
<button type="button" class="btn btn-danger delete">
<i class="icon-trash icon-white"></i>
<span><?php echo $langs->trans('Delete'); ?></span>
</button>
<input type="checkbox" class="toggle">
</div>
<!-- The global progress information -->
<div class="span5 fileupload-progress fade">
<!-- The global progress bar -->
<div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="bar" style="width:0%;"></div>
</div>
<!-- The extended global progress information -->
<div class="progress-extended">&nbsp;</div>
</div>
</div>
<!-- The loading indicator is shown during file processing -->
<div class="fileupload-loading"></div>
<br>
<!-- The table listing the files available for upload/download -->
<table role="presentation" class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
</form>

<!-- The template to display files available for upload -->
<!-- Warning id on script is not W3C compliant and is reported as error by phpcs but it is required by fileupload plugin -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td class="preview"><span class="fade"></span></td>
<td class="name"><span>{%=file.name%}</span></td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
{% if (file.error) { %}
<td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
{% } else if (o.files.valid && !i) { %}
<td>
<div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
</td>
<td class="start">{% if (!o.options.autoUpload) { %}
<button class="btn btn-primary">
<i class="icon-upload icon-white"></i>
<span>{%=locale.fileupload.start%}</span>
</button>
{% } %}</td>
{% } else { %}
<td colspan="2"></td>
{% } %}
<td class="cancel">{% if (!i) { %}
<button class="btn btn-warning">
<i class="icon-ban-circle icon-white"></i>
<span>{%=locale.fileupload.cancel%}</span>
</button>
{% } %}</td>
</tr>
{% } %}
</script>
<!-- The template to display files available for download -->
<!-- Warning id on script is not W3C compliant and is reported as error by phpcs but it is required by jfilepload plugin -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-download fade">
{% if (file.error) { %}
<td></td>
<td class="name"><span>{%=file.name%}</span></td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
<td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
{% } else { %}
<td class="preview">{% if (file.thumbnail_url) { %}
<a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
{% } %}</td>
<td class="name">
<a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
</td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
<td colspan="2"></td>
{% } %}
<td class="delete">
<button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
<i class="icon-trash icon-white"></i>
<span>{%=locale.fileupload.destroy%}</span>
</button>
<input type="checkbox" name="delete" value="1">
</td>
</tr>
{% } %}
</script>
<br>
<!-- END PHP TEMPLATE -->

0 comments on commit 0a8016e

Please sign in to comment.