[Cpan-forum-commit] rev 354 - in trunk: . lib/CPAN www

svn at pti.co.il svn at pti.co.il
Fri Oct 26 13:45:40 EEST 2007


Author: gabor
Date: 2007-10-26 13:45:40 +0300 (Fri, 26 Oct 2007)
New Revision: 354

Added:
   trunk/www/display_tags.js
Modified:
   trunk/
   trunk/lib/CPAN/Forum.pm
   trunk/www/tagging.js
Log:
split tagging javascript in order to enable use without ajax



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4575
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
   + 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4576
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752

Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm	2007-10-26 10:45:25 UTC (rev 353)
+++ trunk/lib/CPAN/Forum.pm	2007-10-26 10:45:40 UTC (rev 354)
@@ -527,7 +527,8 @@
     rss
     atom
     tags
-); 
+    m
+);
 my @restricted_modes = qw(
     new_post process_post
     mypan 
@@ -559,6 +560,7 @@
     atom
     update
     tags
+    m
 ); 
 
 use base 'CPAN::Forum::RM::Author';
@@ -1617,6 +1619,31 @@
     }
 }
 
+sub m {
+    my ($self) = @_;
+    my $path = ${$self->param("path_parameters")}[0] || '';
+    my $value = ${$self->param("path_parameters")}[1] || '';
+
+
+    my $tags = '';
+print STDERR "here '$path'\n";
+    if ($path eq "list_tags") {
+        my $gr = CPAN::Forum::DB::Groups->info_by(name => $value); # SQL
+        if ($gr) {
+            my $gid = $gr->{id};
+            my $modules = CPAN::Forum::DB::Tags->get_tags_of_module($gid); # SQL
+            use Data::Dumper;
+            print STDERR Dumper $modules;
+            $tags = join ",", map {"$_->{name},$_->{cnt}"} @$modules;
+        }
+    }
+
+    return <<"END_JAVASCRIPT";
+var cpan_forum_tags = "$tags";
+END_JAVASCRIPT
+
+}
+
 sub _check_dist_info {
     my ($self, $download_url, $dist_name) = @_;
     my $d = CPAN::DistnameInfo->new($download_url);

Added: trunk/www/display_tags.js
===================================================================
--- trunk/www/display_tags.js	                        (rev 0)
+++ trunk/www/display_tags.js	2007-10-26 10:45:40 UTC (rev 354)
@@ -0,0 +1,47 @@
+var cpan_forum_url = "http://cgi.cpanforum.local/";
+
+function cpan_forum_list_tags() {
+    //alert("test");
+    //alert(action);
+    //var url = document.URL;
+    //var url = cpan_forum_url;//+ "rm=tags_of&amp;distro=" + distro;
+    //cpan_forum_ajaxFunction(url, function(response) {
+    // this is built by the application
+    //var response = "test,testing,web,app devx";
+    var response = cpan_forum_tags;
+    var tags = response.split(",");
+    // TODO return will not be simple array, it will be a hash with values such as the density of tags
+    //var tags = new Array({"one":1, "two":2, "apple":3, "x":3});
+    //tags.sort();
+    //alert(tags.join());
+    //var tags = new Array("xtest", "testing", "web", "app dev");
+    //action(tags);
+    //});
+    return tags;
+}
+
+function cpan_forum_show_tags_as_li() {
+    var tags = cpan_forum_list_tags()
+    var t =  document.getElementById('cpanforum_tags');
+    for(var i=0; i<tags.length; i++) {
+        //alert(tags[i]);
+        li = document.createElement('li');
+        a  = document.createElement('a');
+        a.setAttribute('href', 'javascript:cpan_forum_popup_tag("' + tags[i] + '")');
+        var text = document.createTextNode(tags[i]);
+        a.appendChild(text);
+        li.appendChild(a);
+        t.appendChild(li);
+    }
+//    alert(tags.length);
+}
+
+function cpan_forum_popup_tag(tag) {
+    var w = window.open(cpan_forum_url, 'cpan_forum_list_distros', "width=600,height=300");
+    //w.document.write("Tag: '" + tag + "'<br/>");
+    //var distros = cpan_forum_get_distros_by_tag(tag);
+    //for(var i=0; i<distros.length; i++) {
+    //    w.document.write('<a href="/dist/' + distros[i] + '">' + distros[i] + '</a><br>');
+    //}
+}
+

Modified: trunk/www/tagging.js
===================================================================
--- trunk/www/tagging.js	2007-10-26 10:45:25 UTC (rev 353)
+++ trunk/www/tagging.js	2007-10-26 10:45:40 UTC (rev 354)
@@ -1,38 +1,46 @@
-var cpan_forum_url = "http://cgi.cpanfoum.local/m?";
 
 
-function cpan_forum_list_tags(distro) {
-    //alert("test");
-    var url = cpan_forum_url + "rm=tags_of&amp;distro=" + distro;
-    var tags = new Array("test", "testing", "web", "app dev");
-    return tags;
-}
-
-function cpan_forum_show_tags_as_li(distro) {
-    var tags = cpan_forum_list_tags(distro);
-    var t =  document.getElementById('cpanforum_tags');
-    for(var i=0; i<tags.length; i++) {
-        //alert(tags[i]);
-        li = document.createElement('li');
-        a  = document.createElement('a');
-        a.setAttribute('href', 'javascript:cpan_forum_popup_tag("' + tags[i] + '")');
-        var text = document.createTextNode(tags[i]);
-        a.appendChild(text);
-        li.appendChild(a);
-        t.appendChild(li);
+function cpan_forum_get_xmlHttp() {
+  var xmlHttp;
+  try {
+    // Firefox, Opera 8.0+, Safari
+    xmlHttp=new XMLHttpRequest();
+  }
+  catch (e) {
+    // Internet Explorer
+    try {
+      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
     }
-//    alert(tags.length);
+    catch (e) {
+      try {
+        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
+      }
+      catch (e) {
+        return false;
+      }
+    }
+  }
+  return xmlHttp;
 }
 
-function cpan_forum_popup_tag(tag) {
-    var w = window.open('', 'cpan_forum_list_distros', "width=600,height=300");
-    w.document.write("Tag: '" + tag + "'<br/>");
-    var distros = cpan_forum_get_distros_by_tag(tag);
-    for(var i=0; i<distros.length; i++) {
-        w.document.write('<a href="/dist/' + distros[i] + '">' + distros[i] + '</a><br>');
+// receives a url to request and function to be executed on response
+function cpan_forum_ajaxFunction(url, action) {
+    var xmlHttp = cpan_forum_get_xmlHttp();
+    if (xmlHttp == false) {
+        alert("Your browser does not support AJAX!");
+        return;
     }
+    xmlHttp.onreadystatechange=function() {
+        if(xmlHttp.readyState==4) {
+            action(xmlHttp.responseText);
+        }
+    }
+alert(url);
+    xmlHttp.open("GET", url, true);
+    xmlHttp.send(null);
 }
 
+
 function cpan_forum_get_distros_by_tag(tag) {
     var distros = Array("CPAN-Forum", "Test-Simple");
     return distros;



More information about the Cpan-forum-commit mailing list