allow to use jqtree more than once on a page

also uses just 'docid' for id in the document chooser instead of appending
the form name.
This commit is contained in:
Uwe Steinmann 2013-06-03 07:55:39 +02:00
parent 7710ea7a6b
commit 31015784ac
3 changed files with 13 additions and 13 deletions

View File

@ -49,11 +49,11 @@ if ($public && ($document->getAccessMode($user) == M_READ)) {
$public = false; $public = false;
} }
if (!isset($_GET["docidform1"]) || !is_numeric($_GET["docidform1"]) || intval($_GET["docidform1"])<1) { if (!isset($_GET["docid"]) || !is_numeric($_GET["docid"]) || intval($_GET["docid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_target_doc_id")); UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_target_doc_id"));
} }
$docid = $_GET["docidform1"]; $docid = $_GET["docid"];
$doc = $dms->getDocument($docid); $doc = $dms->getDocument($docid);
if (!is_object($doc)) { if (!is_object($doc)) {

View File

@ -63,8 +63,8 @@ $userid=$user->getID();
if ($_GET["type"]=="document"){ if ($_GET["type"]=="document"){
if ($_GET["action"]=="add"){ if ($_GET["action"]=="add"){
if (!isset($_POST["docidform1"])) UI::exitError(getMLText("my_account"),getMLText("error_occured")); if (!isset($_POST["docid"])) UI::exitError(getMLText("my_account"),getMLText("error_occured"));
$documentid = $_POST["docidform1"]; $documentid = $_POST["docid"];
}else if ($_GET["action"]=="del"){ }else if ($_GET["action"]=="del"){
if (!isset($_GET["id"])) UI::exitError(getMLText("my_account"),getMLText("error_occured")); if (!isset($_GET["id"])) UI::exitError(getMLText("my_account"),getMLText("error_occured"));
$documentid = $_GET["id"]; $documentid = $_GET["id"];

View File

@ -705,7 +705,7 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
} /* }}} */ } /* }}} */
function printDocumentChooser($formName) { /* {{{ */ function printDocumentChooser($formName) { /* {{{ */
print "<input type=\"hidden\" id=\"docid".$formName."\" name=\"docid".$formName."\">"; print "<input type=\"hidden\" id=\"docid".$formName."\" name=\"docid\">";
print "<div class=\"input-append\">\n"; print "<div class=\"input-append\">\n";
print "<input type=\"text\" id=\"choosedocsearch\" data-provide=\"typeahead\" name=\"docname".$formName."\" placeholder=\"".getMLText('type_to_search')."\" autocomplete=\"off\" />"; print "<input type=\"text\" id=\"choosedocsearch\" data-provide=\"typeahead\" name=\"docname".$formName."\" placeholder=\"".getMLText('type_to_search')."\" autocomplete=\"off\" />";
print "<a data-target=\"#docChooser".$formName."\" href=\"out.DocumentChooser.php?form=".$formName."&folderid=".$this->params['rootfolderid']."\" role=\"button\" class=\"btn\" data-toggle=\"modal\">".getMLText("document")."…</a>\n"; print "<a data-target=\"#docChooser".$formName."\" href=\"out.DocumentChooser.php?form=".$formName."&folderid=".$this->params['rootfolderid']."\" role=\"button\" class=\"btn\" data-toggle=\"modal\">".getMLText("document")."…</a>\n";
@ -725,7 +725,7 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
</div> </div>
<script language="JavaScript"> <script language="JavaScript">
modalDocChooser<?= $formName ?> = $('#docChooser<?= $formName ?>'); modalDocChooser<?= $formName ?> = $('#docChooser<?= $formName ?>');
function documentSelected(id, name) { function documentSelected<?= $formName ?>(id, name) {
$('#docid<?= $formName ?>').val(id); $('#docid<?= $formName ?>').val(id);
$('#choosedocsearch').val(name); $('#choosedocsearch').val(name);
modalDocChooser<?= $formName ?>.modal('hide'); modalDocChooser<?= $formName ?>.modal('hide');
@ -756,7 +756,7 @@ function documentSelected(id, name) {
<script language="JavaScript"> <script language="JavaScript">
/* Set up a callback which is called when a folder in the tree is selected */ /* Set up a callback which is called when a folder in the tree is selected */
modalFolderChooser<?= $formName ?> = $('#folderChooser<?= $formName ?>'); modalFolderChooser<?= $formName ?> = $('#folderChooser<?= $formName ?>');
function folderSelected(id, name) { function folderSelected<?= $formName ?>(id, name) {
$('#targetid<?= $formName ?>').val(id); $('#targetid<?= $formName ?>').val(id);
$('#choosefoldersearch<?= $formName ?>').val(name); $('#choosefoldersearch<?= $formName ?>').val(name);
modalFolderChooser<?= $formName ?>.modal('hide'); modalFolderChooser<?= $formName ?>.modal('hide');
@ -951,7 +951,7 @@ function clearFilename<?php print $formName ?>() {
* @params boolean $showdocs set to true if tree shall contain documents * @params boolean $showdocs set to true if tree shall contain documents
* as well. * as well.
*/ */
function printNewTreeNavigation($folderid=0, $accessmode=M_READ, $showdocs=0) { /* {{{ */ function printNewTreeNavigation($folderid=0, $accessmode=M_READ, $showdocs=0, $formid='form1') { /* {{{ */
function jqtree($path, $folder, $user, $accessmode, $showdocs=1) { function jqtree($path, $folder, $user, $accessmode, $showdocs=1) {
if($path) { if($path) {
$pathfolder = array_shift($path); $pathfolder = array_shift($path);
@ -1005,20 +1005,20 @@ function clearFilename<?php print $formName ?>() {
$tree = array(array('label'=>$root->getName(), 'id'=>$root->getID(), 'load_on_demand'=>true, 'is_folder'=>true)); $tree = array(array('label'=>$root->getName(), 'id'=>$root->getID(), 'load_on_demand'=>true, 'is_folder'=>true));
} }
echo "<div id=\"jqtree\" style=\"margin-left: 10px;\" data-url=\"../op/op.Ajax.php?command=subtree&showdocs=".$showdocs."\"></div>\n"; echo "<div id=\"jqtree".$formid."\" style=\"margin-left: 10px;\" data-url=\"../op/op.Ajax.php?command=subtree&showdocs=".$showdocs."\"></div>\n";
?> ?>
<script language="JavaScript"> <script language="JavaScript">
var data = <?php echo json_encode($tree); ?>; var data = <?php echo json_encode($tree); ?>;
$(function() { $(function() {
$('#jqtree').tree({ $('#jqtree<?= $formid ?>').tree({
data: data, data: data,
openedIcon: '<i class="icon-minus-sign"></i>', openedIcon: '<i class="icon-minus-sign"></i>',
closedIcon: '<i class="icon-plus-sign"></i>', closedIcon: '<i class="icon-plus-sign"></i>',
onCanSelectNode: function(node) { onCanSelectNode: function(node) {
if(node.is_folder) if(node.is_folder)
folderSelected(node.id, node.name); folderSelected<?= $formid ?>(node.id, node.name);
else else
documentSelected(node.id, node.name); documentSelected<?= $formid ?>(node.id, node.name);
}, },
autoOpen: true, autoOpen: true,
drapAndDrop: true, drapAndDrop: true,
@ -1046,7 +1046,7 @@ $(function() {
} }
</script> </script>
<?php <?php
$this->printNewTreeNavigation($folderid, M_READ, 0); $this->printNewTreeNavigation($folderid, M_READ, 0, '');
$this->contentContainerEnd(); $this->contentContainerEnd();
} else { } else {
$this->contentHeading("<a href=\"../out/out.ViewFolder.php?folderid=". $folderid."&showtree=1\"><i class=\"icon-plus-sign\"></i></a>", true); $this->contentHeading("<a href=\"../out/out.ViewFolder.php?folderid=". $folderid."&showtree=1\"><i class=\"icon-plus-sign\"></i></a>", true);