make adminlinkedtags (menu2Tags) finally work with jquery

This commit is contained in:
Christian Weiske 2010-10-01 18:21:33 +02:00
parent 04d360dadb
commit cb1d41054b
2 changed files with 47 additions and 34 deletions

View file

@ -61,7 +61,22 @@ jQuery("#maintagsmenu")
"icons": true, "icons": true,
"url": '<?php echo ROOT ?>js/themes/default/style.css' "url": '<?php echo ROOT ?>js/themes/default/style.css'
}, },
plugins : [ "themes", "html_data"], "json_data" : {
"ajax" : {
"url": function(node) {
//-1 is root
if (node == -1 ) {
node = "";
} else if (node.attr('rel')) {
node = node.attr('rel');
} else {
return;
}
return "<?php echo ROOT ?>ajax/getadminlinkedtags.php?tag=" + node;
}
}
},
plugins : [ "themes", "json_data"]
}); });
</script> </script>
<?php <?php

View file

@ -21,44 +21,42 @@
/* Return a json file with list of linked tags */ /* Return a json file with list of linked tags */
$httpContentType = 'application/json'; $httpContentType = 'application/json';
$httpContentType='text/plain';
require_once '../www-header.php'; require_once '../www-header.php';
/* Service creation: only useful services are created */ $tag = isset($_GET['tag']) ? trim($_GET['tag']) : '';
$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
$bookmarkservice =SemanticScuttle_Service_Factory::get('Tag');
$tagstatservice =SemanticScuttle_Service_Factory::get('TagStat');
/* Managing all possible inputs */ function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
isset($_GET['tag']) ? define('GET_TAG', $_GET['tag']): define('GET_TAG', ''); {
isset($_GET['uId']) ? define('GET_UID', $_GET['uId']): define('GET_UID', ''); if ($tag == '') {
$linkedTags = $GLOBALS['menu2Tags'];
} else {
$linkedTags = $t2t->getAdminLinkedTags($tag, '>');
}
$tagData = array();
foreach ($linkedTags as $tag) {
$tagData[] = createTagArray($tag);
}
function displayTag($tag, $uId) { return $tagData;
$uId = ($uId==0)?NULL:$uId; // if user is nobody, NULL allows to look for every public tags
$tag2tagservice =SemanticScuttle_Service_Factory::get('Tag2Tag');
$output = '{ id:'.rand().', name:\''.$tag.'\'';
$linkedTags = $tag2tagservice->getAdminLinkedTags($tag, '>');
if(count($linkedTags) > 0) {
$output.= ', children: [';
foreach($linkedTags as $linkedTag) {
$output.= displayTag($linkedTag, $uId);
}
$output = substr($output, 0, -1); // remove final comma avoiding IE6 Dojo bug
$output.= "]";
}
$output.= '},';
return $output;
} }
?> function createTagArray($tag)
{
return array(
'data' => $tag,
'attr' => array('rel' => $tag),
//'children' => array('foo', 'bar'),
'state' => 'closed'
);
}
{ label: 'name', identifier: 'id', items: [
<?php $tagData = assembleTagData(
$json = displayTag(GET_TAG, intval(GET_UID)); $tag,
$json = substr($json, 0, -1); // remove final comma avoiding IE6 Dojo bug SemanticScuttle_Service_Factory::get('Tag2Tag')
echo $json; );
//$json = substr($json, 0, -1); // remove final comma avoiding IE6 Dojo bug
echo json_encode($tagData);
?> ?>
] }