Permalink
Browse files

Json not working properly, getting malformed error

  • Loading branch information...
1 parent feb0c08 commit 533111002cafaa5e84271d92e63860084dfd7a4d Sonu Lall committed Feb 28, 2011
@@ -79,8 +79,10 @@ END
unless ($uid) {
# this creates a new session for the admin user
my $session = $globals->session;
+ my $favoritetable = $globals->favorites;
my $sessionid = $session->id;
my $uploadsid = $session->uploadsid;
+ my @favorites_list = $favoritetable->favorites;
$session->flush();
my ($status,undef,$message) =
View
@@ -33,7 +33,14 @@ CREATE TABLE sessions (
username varchar(32) not null,
sessionid char(32) not null UNIQUE,
uploadsid char(32) not null UNIQUE
+
) ENGINE=InnoDB;
+DROP TABLE IF EXISTS favorites;
+CREATE TABLE favorites (
+ userid integer not null PRIMARY KEY auto_increment,
+ username varchar(32) not null,
+ favorite varchar(32) not null
+)ENGINE=InnoDB;
DROP TABLE IF EXISTS uploads;
CREATE TABLE uploads (
View
@@ -64,7 +64,7 @@ function togglestars(imgID, txtID, favorites,cellid)
var getfileNameExt = pathSplit.length - 1;
var fullFilePath = '';
var str = imgID.replace("ficonpic_"," ");
-
+ var jsonfavstr;
@@ -84,6 +84,7 @@ function togglestars(imgID, txtID, favorites,cellid)
var fileNameMainSpilt = fileName.split("_"); // check for a spilt on '_'
var imgName ='';
+
if (fileNameMainSpilt.length > 1)
{
@@ -96,13 +97,15 @@ function togglestars(imgID, txtID, favorites,cellid)
txtTag.style.fontWeight = "normal";
favorite = false;
+ ;
}
else
{
imgName = fileName + '_2.' + fileExt;
txtTag.style.fontWeight = "900";
favorite = true;
+
}
}
else
@@ -118,6 +121,7 @@ function togglestars(imgID, txtID, favorites,cellid)
txtTag.className= 'favoritelist';
cellTag.className= 'favoritelist';
+
}
@@ -127,14 +131,29 @@ function togglestars(imgID, txtID, favorites,cellid)
removeByElement(favorites,cellTag.id);
txtTag.className = 'notselected';
cellTag.className = 'notselected';
- alert(favorites.length);
+// /*alert*/(favorites.length);
}
var finalFile = fullFilePath + imgName;
imgTag.src = finalFile;
+
+// jsonfavstr = JSON.stringify(favorites);
+
+// var direction = favorite ? 'false' : 'true';
+
+ new Ajax.Request(document.URL, {
+ method: 'post',
+ asynchronous: false,
+ parameters: {
+ action: 'store_favorites',
+ 'direction': direction,
+ favorites: Object.toJSON(favorites);
+ }});
+
+
// alert(celltag);
// alert(cellTag.className);
}
@@ -331,6 +331,20 @@ sub ACTION_open_collapse_track {
return (204,'text/plain',undef);
}
+
+sub ACTION_store_favorites {
+
+ my $self = shift;
+ my $q = shift;
+# my $direction= $q->param('direction');
+ my @favorites = JSON::from_json($q->param('favorites'));
+ my $settings = $self->state;
+ $self->state->{favorites}{@favorites} = @favorites;
+ $self->session->flush;
+ return (204,'text/plain',undef);
+}
+
+
sub ACTION_change_track_order {
my $self = shift;
my $q = shift;
@@ -13,7 +13,7 @@ use Carp qw(croak cluck);
use CGI qw(:standard escape start_table end_table);
use Text::Tabs;
use POSIX qw(floor);
-
+use DBI;
use constant JS => '/gbrowse2/js';
use constant ANNOTATION_EDIT_ROWS => 25;
use constant ANNOTATION_EDIT_COLS => 100;
@@ -827,7 +827,6 @@ sub render_toggle_track_table {
my $filter = $self->track_filter_plugin;
## adding javascript array at the top so we can pass it into a js array -- ugly but it works
my $html = "<script>var favoritearray = []; </script>" ;
-
my $showicon = img({
-style => 'cursor:pointer; float:left;',
@@ -864,7 +863,6 @@ sub render_track_table {
my $self = shift;
my $settings = $self->state;
my $source = $self->data_source;
-
# read category table information
@@ -873,14 +871,16 @@ sub render_track_table {
# tracks beginning with "_" are special, and should not appear in the
# track table.
my @labels = $self->potential_tracks;
-
+# my @favorited = JSON::from_json('jsonfavstr');
warn "potential tracks = @labels" if DEBUG;
my ($filter_active,@hilite);
if (my $filter = $self->track_filter_plugin) {
$filter_active++;
eval {@labels = $filter->filter_tracks(\@labels,$source)};
warn $@ if $@;
+# eval {@favorited = $filter->filter_tracks(\@favorited,$source)};
+# warn $@ if $@;
eval {@hilite = $filter->hilite_terms};
warn $@ if $@;
}
@@ -932,10 +932,17 @@ my $showicon = img({ -id =>"ficonpic_${key}",
-style => 'cursor:pointer;',
-src => $self->data_source->button_url."/ficon.png",},);
-
-
-
-
+# my $sql = 'INSERT INTO favorites (favorites) VALUES (favoritearray)';
+#
+# my $sth = $dbh->prepare($sql);
+#
+# while (<DATA>) {
+# chomp;
+# my @vals = split /\s+/, $_;
+#
+# $sth->execute(@vals);
+# };
+# $dbh->disconnect();
my $favoriteicon = span({-href => '#',
-id => 'favclick',
@@ -1351,7 +1358,8 @@ sub render_select_track_link {
sub render_select_favorites_link {
my $self = shift;
my $style = shift || 'button';
- my $favoritelist = 'favoritelist';
+#
+ my @favorites = JSON::from_json('favorites');
my $title = $self->translate('FAVORITES');
@@ -1364,7 +1372,7 @@ sub render_select_favorites_link {
} elsif ($style eq 'link') {
return a({-href=>'javascript:void(0)',
- -onClick => "toggleDiv('notselected');",
+ -onClick => "Controller.update_sections(new Array('@favorites'));",
},
$title);
}
@@ -2009,15 +2017,15 @@ sub tableize {
$html .= "<td><b>$row_labels[$row]</b></td>" if @row_labels;
for (my $column=0;$column<$columns;$column++) {
my $checkbox = $array->[$column*$rows + $row] || '&nbsp;';
-
+ my $label = $labelnames->[$column*$rows + $row];
# de-couple the checkbox and label click behaviors
$checkbox =~ s/\<\/?label\>//gi;
- my $label = $labelnames->[$column*$rows + $row];
+
- $html .=td({-width=>$cwidth,-style => 'visibility:visible'},span({ -id => "notselectedcheck_$label", -class => 'notselected'},$checkbox));
+ $html .=td({-width=>$cwidth,-style => 'visibility:visible'},span({ -id => "notselectedcheck_${label}", -class => 'notselected'},$checkbox));
#
@@ -31,8 +31,8 @@ use constant DEBUG_LOCK => DEBUG || 0;
sub new {
my $class = shift;
my %args = @_;
- my ($driver,$id,$session_args,$default_source,$lockdir,$locktype,$expire_time,$favorites)
- = @args{'driver','id','args','source','lockdir','locktype','expires','favorites'};
+ my ($driver,$id,$session_args,$default_source,$lockdir,$locktype,$expire_time)
+ = @args{'driver','id','args','source','lockdir','locktype','expires',};
$CGI::Session::NAME = 'gbrowse_sess'; # custom cookie
$CGI::Session::Driver::file::NoFlock = 1; # flocking unnecessary because we roll our own
View
@@ -33,7 +33,14 @@ CREATE TABLE sessions (
username varchar(32) not null,
sessionid char(32) not null UNIQUE,
uploadsid char(32) not null UNIQUE
+
) ENGINE=InnoDB;
+DROP TABLE IF EXISTS favorites;
+CREATE TABLE favorites (
+ userid integer not null PRIMARY KEY auto_increment,
+ username varchar(32) not null,
+ favorite varchar(32) not null
+)ENGINE=InnoDB;
DROP TABLE IF EXISTS uploads;
CREATE TABLE uploads (

0 comments on commit 5331110

Please sign in to comment.