allow serveral instanceѕ of drop folder chooser on one page

This commit is contained in:
Uwe Steinmann 2019-07-30 06:33:18 +02:00
parent b83ef1dd66
commit 1de9ed37d5
3 changed files with 19 additions and 15 deletions

View File

@ -199,7 +199,7 @@ $(document).ready(function() {
'type'=>'text',
'id'=>'name',
'name'=>'name',
'required'=>true
'required'=>false
)
);
$this->formField(
@ -310,7 +310,7 @@ $(document).ready(function() {
);
$this->formField(
getMLText("local_file"),
$enablelargefileupload ? $this->getFineUploaderHtml() : $this->getFileChooserHtml('userfile[]', false).($enablemultiupload ? '<a class="" id="new-file"><?php printMLtext("add_multiple_files") ?></a>' : '')
$enablelargefileupload ? $this->getFineUploaderHtml() : $this->getFileChooserHtml('userfile[]', $enablemultiupload).($enablemultiupload ? '<a class="" id="new-file"><?php printMLtext("add_multiple_files") ?></a>' : '')
);
if($dropfolderdir) {
$this->formField(

View File

@ -1039,7 +1039,7 @@ $(document).ready(function() {
<div class="input-append">
<input type="text" class="form-control" readonly>
<span class="btn btn-default btn-file">
'.getMLText("browse").'&hellip; <input id="'.$id.'" type="file" name="'.$varname.'"'.($multiple ? " multiple" : "").($accept ? ' accept="'.$accept.'"' : "").'">
'.getMLText("browse").'&hellip; <input id="'.$id.'" type="file" name="'.$varname.'"'.($multiple ? " multiple" : "").($accept ? ' accept="'.$accept.'"' : "").'>
</span>
</div>
</div>
@ -1422,7 +1422,7 @@ $(document).ready(function() {
$content = "<div class=\"input-append\">\n";
$content .= "<input readonly type=\"text\" id=\"dropfolderfile".$formName."\" name=\"dropfolderfile".$formName."\" value=\"".$dropfolderfile."\">";
$content .= "<button type=\"button\" class=\"btn\" id=\"clearfilename".$formName."\"><i class=\"icon-remove\"></i></button>";
$content .= "<a data-target=\"#dropfolderChooser\" href=\"../out/out.DropFolderChooser.php?form=form1&dropfolderfile=".urlencode($dropfolderfile)."&showfolders=".$showfolders."\" role=\"button\" class=\"btn\" data-toggle=\"modal\">".($showfolders ? getMLText("choose_target_folder"): getMLText("choose_target_file"))."…</a>\n";
$content .= "<a data-target=\"#dropfolderChooser\" href=\"../out/out.DropFolderChooser.php?form=".$formName."&dropfolderfile=".urlencode($dropfolderfile)."&showfolders=".$showfolders."\" role=\"button\" class=\"btn\" data-toggle=\"modal\">".($showfolders ? getMLText("choose_target_folder"): getMLText("choose_target_file"))."…</a>\n";
$content .= "</div>\n";
$content .= '
<div class="modal hide" id="dropfolderChooser" tabindex="-1" role="dialog" aria-labelledby="dropfolderChooserLabel" aria-hidden="true">
@ -1445,13 +1445,15 @@ $(document).ready(function() {
?>
/* Set up a callback which is called when a folder in the tree is selected */
modalDropfolderChooser = $('#dropfolderChooser');
function fileSelected(name) {
$('#dropfolderfile<?php echo $formName ?>').val(name);
function fileSelected(name, form) {
// $('#dropfolderfile<?php echo $formName ?>').val(name);
$('#dropfolderfile'+form).val(name);
modalDropfolderChooser.modal('hide');
}
<?php if($showfolders) { ?>
function folderSelected(name) {
$('#dropfolderfile<?php echo $formName ?>').val(name);
function folderSelected(name, form) {
// $('#dropfolderfile<?php echo $formName ?>').val(name);
$('#dropfolderfile'+form).val(name);
modalDropfolderChooser.modal('hide');
}
<?php } ?>

View File

@ -40,12 +40,14 @@ class SeedDMS_View_DropFolderChooser extends SeedDMS_Bootstrap_Style {
header('Content-Type: application/javascript');
?>
$('.fileselect').click(function(ev) {
attr_filename = $(ev.currentTarget).attr('filename');
fileSelected(attr_filename);
attr_filename = $(ev.currentTarget).data('filename');
attr_form = $(ev.currentTarget).data('form');
fileSelected(attr_filename, attr_form);
});
$('.folderselect').click(function(ev) {
attr_foldername = $(ev.currentTarget).attr('foldername');
folderSelected(attr_foldername);
attr_foldername = $(ev.currentTarget).data('foldername');
attr_form = $(ev.currentTarget).data('form');
folderSelected(attr_foldername, attr_form);
});
<?php
} /* }}} */
@ -142,13 +144,13 @@ $('.folderselect').click(function(ev) {
$previewer->createRawPreview($dir.'/'.$entry, 'dropfolder/', $mimetype);
echo "<tr><td style=\"min-width: ".$previewwidth."px;\">";
if($previewer->hasRawPreview($dir.'/'.$entry, 'dropfolder/')) {
echo "<img style=\"cursor: pointer;\" class=\"fileselect mimeicon\" filename=\"".$entry."\" width=\"".$previewwidth."\" src=\"../op/op.DropFolderPreview.php?filename=".$entry."&width=".$previewwidth."\" title=\"".htmlspecialchars($mimetype)."\">";
echo "<img style=\"cursor: pointer;\" class=\"fileselect mimeicon\" data-filename=\"".$entry."\" data-form=\"".$form."\" width=\"".$previewwidth."\" src=\"../op/op.DropFolderPreview.php?filename=".$entry."&width=".$previewwidth."\" title=\"".htmlspecialchars($mimetype)."\">";
}
echo "</td><td><span style=\"cursor: pointer;\" class=\"fileselect\" filename=\"".$entry."\">".$entry."</span></td><td align=\"right\">".SeedDMS_Core_File::format_filesize(filesize($dir.'/'.$entry))."</td><td>".date('Y-m-d H:i:s', filectime($dir.'/'.$entry))."</td></tr>\n";
echo "</td><td><span style=\"cursor: pointer;\" class=\"fileselect\" data-filename=\"".$entry."\" data-form=\"".$form."\">".$entry."</span></td><td align=\"right\">".SeedDMS_Core_File::format_filesize(filesize($dir.'/'.$entry))."</td><td>".date('Y-m-d H:i:s', filectime($dir.'/'.$entry))."</td></tr>\n";
} elseif($showfolders && is_dir($dir.'/'.$entry)) {
echo "<tr>";
echo "<td></td>";
echo "<td><span style=\"cursor: pointer;\" class=\"folderselect\" foldername=\"".$entry."\" >".$entry."</span></td><td align=\"right\"></td><td></td>";
echo "<td><span style=\"cursor: pointer;\" class=\"folderselect\" data-foldername=\"".$entry."\" data-form=\"".$form."\">".$entry."</span></td><td align=\"right\"></td><td></td>";
echo "</tr>\n";
}
}