diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index cc45f4033..4eaab8331 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -313,6 +313,41 @@ sub getCategories { #------------------------------------------------------------------- +=head2 getCompareColor ( ) + +Returns the compare form. + +=head3 value + +The value of a MatrixCompare form field. + +=cut + +sub getCompareColor { + + my $self = shift; + my $value = shift; + + if($value == 0){ + return $self->get('compareColorNo'); + } + elsif($value == 1){ + return $self->get('compareColorLimited'); + } + elsif($value == 2){ + return $self->get('compareColorCostsExtra'); + } + elsif($value == 3){ + return $self->get('compareColorFreeAddOn'); + } + elsif($value == 3){ + return $self->get('compareColorYes'); + } + +} + +#------------------------------------------------------------------- + =head2 getCompareForm ( ) Returns the compare form. @@ -340,7 +375,7 @@ sub getCompareForm { orderByClause => $self->get('defaultSort').$sortDirection, returnObjects => 1, }) }; - # Create an options hash based on the orderd array of listings. + # Create an options hash based on the ordered array of listings. foreach my $listing (@listings){ $options{$listing->getId} = ''.$listing->get('title').''; } @@ -632,7 +667,7 @@ sub www_compare { my $self = shift; my $var = $self->get; my @listingIds = @_; - my @columnKeys = ['name']; + my @columnKeys; #my @listingIds = ['AwioUvaZXmAEaFw20t-x3Q', 'CWNjAHcmh0pEF6WJooomJA']; unless (scalar(@listingIds)) { @listingIds = $self->session->form->checkList("listingId"); @@ -667,16 +702,17 @@ sub www_compare { foreach my $listingId (@listingIds){ my $listingId_safe = $listingId; - $listingId_safe =~ s/-//g; + $listingId_safe =~ s/-/_/g; push(@columnKeys, $listingId_safe); + push(@columnKeys, $listingId_safe."_compareColor"); } $var->{javascript} = ""; - return $self->processStyle($self->processTemplate($var,$self->get("compareTemplateId")));; + return $self->processStyle($self->processTemplate($var,$self->get("compareTemplateId"))); } #------------------------------------------------------------------- @@ -884,9 +920,13 @@ Returns the compare form data as JSON. sub www_getCompareFormData { - my $self = shift; + my $self = shift; + my $session = $self->session; + my $form = $session->form; + my $sortDirection = ' asc'; + my @results; - my $sortDirection = ' asc'; + my @listingIds = $self->session->form->checkList("listingId"); $self->session->http->setMimeType("application/json"); =cut @@ -928,7 +968,39 @@ assetData.revisionDate assetData.assetId order by ".$self->get('defaultSort').$sortDirection; - my $results = $self->session->db->buildArrayRefOfHashRefs($sql,[$self->getId]); + @results = @{ $session->db->buildArrayRefOfHashRefs($sql,[$self->getId]) }; + foreach my $result (@results){ + #$result->{checked} = ''; + if($form->process("search")){ + #my $listing = WebGUI::Asset::MatrixListing->new($session,$result->{assetId}); + $self->session->errorHandler->warn("checking listing: ".$result->{title}); + foreach my $param ($form->param) { + if($param =~ m/^search_/){ + my $attributeId = $param; + $attributeId =~ s/^search_//; + $attributeId =~ s/_/-/; + my $listingValue = $session->db->quickScalar(" + select value from MatrixListing_attribute + where attributeId = ? and matrixListingId = ? + ",[$attributeId,$result->{assetId}]); + $self->session->errorHandler->warn("attributeValue: ".$form->process($param).", listingvalue: ".$listingValue); + if($form->process($param) eq $listingValue){ + $self->session->errorHandler->warn("--Checked--"); + $result->{checked} = 'checked'; + } + else{ + undef $result->{checked}; + } + } + } + } + else{ + if(WebGUI::Utility::isIn($result->{assetId},@listingIds)){ + $result->{checked} = 'checked'; + } + } + $result->{assetId} =~ s/-/_/g; + } =cut push(@results,{ Title=>$data->{title}, @@ -945,24 +1017,9 @@ push(@results,{ } =cut my $jsonOutput; - $jsonOutput->{ResultSet} = {Result=>$results}; + $jsonOutput->{ResultSet} = {Result=>\@results}; return JSON->new->utf8->encode($jsonOutput); -=cut - return JSON->new->utf8->encode({ - ResultSet=>{ - totalResultsAvailable=>1, - totalResultsReturned=>1, - firstResultPosition=>1, - Result=>[{ - Title=>"Pizza Depot", - Phone=>"(408) 245-7760", - City=>"Sunnyvale", - ClickUrl=>"http:\/\/local.yahoo.com\/details?id=21332021&stx=pizza&csz=Sunnyvale+CA" - }] - } - }); -=cut } #------------------------------------------------------------------- @@ -986,22 +1043,23 @@ sub www_getCompareListData { my $sortDirection = ' asc'; foreach my $listingId (@listingIds){ + $listingId =~ s/_/-/g; my $listing = WebGUI::Asset::MatrixListing->new($session,$listingId); my $listingId_safe = $listingId; - $listingId_safe =~ s/-//g; - push(@columnDefs,{key=>$listingId_safe,label=>$listing->get('title')}); + $listingId_safe =~ s/-/_/g; + push(@columnDefs,{key=>$listingId_safe,label=>$listing->get('title'),formatter=>"formatColors"}); } my $jsonOutput; $jsonOutput->{ColumnDefs} = \@columnDefs; foreach my $category (keys %{$self->getCategories}) { - my $fields = " a.name, a.fieldType "; + my $fields = " a.name, a.fieldType, a.attributeId "; my $from = "from Matrix_attribute a"; my $tableCount = "b"; foreach my $listingId (@listingIds) { my $listingId_safe = $listingId; - $listingId_safe =~ s/-//g; + $listingId_safe =~ s/-/_/g; $fields .= ", ".$tableCount.".value as `$listingId_safe`"; $from .= " left join MatrixListing_attribute ".$tableCount." on a.attributeId=" .$tableCount.".attributeId and ".$tableCount.".matrixListingId=? "; @@ -1014,9 +1072,12 @@ sub www_getCompareListData { } foreach my $result (@results){ foreach my $listingId (@listingIds) { + $result->{attributId} =~ s/-/_/g; my $listingId_safe = $listingId; - $listingId_safe =~ s/-//g; + $listingId_safe =~ s/-/_/g; if ($result->{fieldType} eq 'MatrixCompare'){ + my $originalValue = $result->{$listingId_safe}; + $result->{$listingId_safe.'_compareColor'} = $self->getCompareColor($result->{$listingId_safe}); $result->{$listingId_safe} = WebGUI::Form::MatrixCompare->new( $self->session, { value=>$result->{$listingId_safe} },defaultValue=>0)->getValueAsHtml; } @@ -1058,6 +1119,74 @@ sub www_listAttributes { return $self->getAdminConsole->render($output, $i18n->get('list attributes title')); } +#------------------------------------------------------------------- + +=head2 www_search ( ) + +Returns the search screen. + +=cut + +sub www_search { + + my $self = shift; + my $var = $self->get; + + #$var->{compareForm} = $self->getCompareForm; + $self->session->style->setScript($self->session->url->extras('yui/build/yahoo/yahoo-min.js'), + {type => 'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('yui/build/dom/dom-min.js'), + {type => 'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('yui/build/event/event-min.js'), + {type => 'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('yui/build/json/json-min.js'), {type => + 'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('yui/build/connection/connection-min.js'), + {type => 'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('yui/build/get/get-min.js'), {type => + 'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('yui/build/element/element-beta-min.js'), {type => + 'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('yui/build/datasource/datasource-beta-min.js'), + {type => 'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('yui/build/datatable/datatable-beta-min.js'), + {type =>'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('yui/build/button/button-min.js'), + {type =>'text/javascript'}); +# $self->session->style->setScript($self->session->url->extras('wobject/Matrix/matrixCompareList.js'), {type => +# 'text/javascript'}); + $self->session->style->setScript($self->session->url->extras('wobject/Matrix/matrixSearch.js'), {type => + 'text/javascript'}); + $self->session->style->setLink($self->session->url->extras('yui/build/datatable/assets/skins/sam/datatable.css'), + {type =>'text/css', rel=>'stylesheet'}); + + foreach my $category (keys %{$self->getCategories}) { + my $attributes; + my @attribute_loop; + my $categoryLoopName = $self->session->url->urlize($category)."_loop"; + $attributes = $self->session->db->read("select * from Matrix_attribute where category =? and assetId = ?", + [$category,$self->getId]); + while (my $attribute = $attributes->hashRef) { + $attribute->{label} = $attribute->{name}; + $attribute->{id} = $attribute->{attributeId}; + $attribute->{id} =~ s/-/_/g; + $attribute->{extras} = " class='attributeSelect'"; + if($attribute->{fieldType} eq 'Combo'){ + $attribute->{fieldType} = 'SelectBox'; + } + $attribute->{form} = WebGUI::Form::DynamicField->new($self->session,%{$attribute})->toHtml; + push(@attribute_loop,$attribute); + } + $var->{$categoryLoopName} = \@attribute_loop; + push(@{$var->{category_loop}},{ + categoryLabel => $category, + attribute_loop => \@attribute_loop, + }); + } + + return $self->processStyle($self->processTemplate($var,$self->get("searchTemplateId"))); +} + #------------------------------------------------------------------- # Everything below here is to make it easier to install your custom # wobject, but has nothing to do with wobjects in general diff --git a/www/extras/wobject/Matrix/matrix.js b/www/extras/wobject/Matrix/matrix.js index 824d6c42a..e37275de2 100644 --- a/www/extras/wobject/Matrix/matrix.js +++ b/www/extras/wobject/Matrix/matrix.js @@ -7,7 +7,12 @@ YAHOO.util.Event.addListener(window, "load", function() { }; this.formatCheckBox = function(elCell, oRecord, oColumn, sData) { - elCell.innerHTML = ""; + var innerHTML = ""; + elCell.innerHTML = innerHTML; }; var myColumnDefs = [ @@ -18,16 +23,23 @@ YAHOO.util.Event.addListener(window, "load", function() { {key:"compares", sortable:true} ]; + var uri = "func=getCompareFormData"; + if(typeof(listingIds) != 'undefined'){ + for (var i = 0; i < listingIds.length; i++) { + uri = uri+';listingId='+listingIds[i]; + } + } + this.myDataSource = new YAHOO.util.DataSource("?"); this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; this.myDataSource.connXhrMode = "queueRequests"; this.myDataSource.responseSchema = { resultsList: "ResultSet.Result", - fields: ["title","views","clicks","compares","assetId"] + fields: ["title","views","clicks","compares","assetId","checked"] }; this.myDataTable = new YAHOO.widget.DataTable("compareForm", myColumnDefs, - this.myDataSource, {initialRequest:"func=getCompareFormData"}); + this.myDataSource, {initialRequest:uri}); var oColumn = this.myDataTable.getColumn(3); this.myDataTable.hideColumn(oColumn); diff --git a/www/extras/wobject/Matrix/matrixCompareList.js b/www/extras/wobject/Matrix/matrixCompareList.js index f613dbbd3..d3228b363 100644 --- a/www/extras/wobject/Matrix/matrixCompareList.js +++ b/www/extras/wobject/Matrix/matrixCompareList.js @@ -2,9 +2,27 @@ YAHOO.util.Event.addListener(window, "load", function() { YAHOO.example.XHR_JSON = new function() { + var Dom = YAHOO.util.Dom; + var hideStickies = 0; + + this.formatStickied = function(elCell, oRecord, oColumn, sData) { + elCell.innerHTML = ""; + }; + + this.formatColors = function(elCell, oRecord, oColumn, sData) { + var colorField = oColumn.key + "_compareColor"; + var color = oRecord.getData(colorField); + if(color){ + Dom.setStyle(elCell.parentNode, "background-color", color); + } + elCell.innerHTML = sData; + }; + + YAHOO.widget.DataTable.Formatter.formatColors = this.formatColors; var myColumnDefs = [ - {key:"name"} + {key:"stickied",formatter:this.formatStickied}, + {key:"name"} ]; this.myDataSource = new YAHOO.util.DataSource("?"); @@ -38,8 +56,10 @@ YAHOO.util.Event.addListener(window, "load", function() { myDataTable.getRecordSet().reset(); var existingColumns = myDataTable.getColumnSet().keys; for (var i = 0; i < existingColumns.length; i++) { - if(i > 0){ - myDataTable.removeColumn(existingColumns[1]); + if(i > 1){ + // after deleting a column the next column will + // allways be no. 2 (the third in the array) + myDataTable.removeColumn(existingColumns[2]); } } if (oFullResponse.ColumnDefs) { @@ -59,11 +79,11 @@ YAHOO.util.Event.addListener(window, "load", function() { }; var myCallback2 = function() { - this.getRecordSet().reset(); - //this.render(); - this.set("sortedBy", null); - this.onDataReturnAppendRows.apply(this,arguments); - this.getRecordSet().reset(); + //this.getRecordSet().reset(); + this.set("sortedBy", null); + this.onDataReturnAppendRows.apply(this,arguments); + + //this.getRecordSet().reset(); }; @@ -72,15 +92,68 @@ YAHOO.util.Event.addListener(window, "load", function() { failure : myCallback, scope : myDataTable }; - this.myDataSource.sendRequest("func=getCompareListData;listingId=CWNjAHcmh0pEF6WJooomJA", - callback2); - + + var btnCompare = new YAHOO.widget.Button("compare"); + btnCompare.on("click", function(e) { + var uri = "func=getCompareListData"; + for (var i = 0; i < columnKeys.length; i++) { + if(columnKeys[i] != 'name'){ + var checkBox = new Dom.get(columnKeys[i] + '_checkBox'); + if(checkBox.checked == true){ + uri = uri+';listingId='+columnKeys[i]; + } + } + } + this.myDataSource.sendRequest(uri,callback2); + },this,true); + + var btnStickied = new YAHOO.widget.Button("stickied"); + btnStickied.on("click", function(e) { + var elements = myDataTable.getRecordSet().getRecords(); + if(hideStickies == 0){ + // hide non-selected attributes + for(i=0; i" + sData + ""; + }; + + this.formatCheckBox = function(elCell, oRecord, oColumn, sData) { + var innerHTML = ""; + elCell.innerHTML = innerHTML; + }; + + var myColumnDefs = [ + {key:"assetId",label:"",sortable:false,formatter:this.formatCheckBox}, + {key:"title", label:"Name", sortable:true, formatter:this.formatUrl}, + {key:"views", sortable:true}, + {key:"clicks", sortable:true}, + {key:"compares", sortable:true} + ]; + + var uri = "func=getCompareFormData"; + if(typeof(listingIds) != 'undefined'){ + for (var i = 0; i < listingIds.length; i++) { + uri = uri+';listingId='+listingIds[i]; + } + } + + var myDataSource = new YAHOO.util.DataSource("?"); + myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; + myDataSource.connXhrMode = "queueRequests"; + myDataSource.responseSchema = { + resultsList: "ResultSet.Result", + fields: ["title","views","clicks","compares","assetId","checked"] + }; + + + var myDataTable = new YAHOO.widget.DataTable("compareForm", myColumnDefs, + myDataSource, {initialRequest:uri}); + + myDataSource.doBeforeParseData = function (oRequest, oFullResponse) { + + myDataTable.getRecordSet().reset(); + return oFullResponse; + } + + var oColumn = myDataTable.getColumn(3); + myDataTable.hideColumn(oColumn); + + + var myCallback = function() { + myDataTable.getRecordSet().reset(); + this.set("sortedBy", null); + this.onDataReturnAppendRows.apply(this,arguments); + }; + + var callback2 = { + success : myCallback, + failure : myCallback, + scope : myDataTable + }; + + var attributeSelects = YAHOO.util.Dom.getElementsByClassName('attributeSelect','select'); + var reloadCompareForm = function() { + myDataTable.getRecordSet().reset(); + myDataTable.initializeTable; + + var elements = myDataTable.getRecordSet().getRecords(); + alert(elements.length); + // hide non-selected attributes + for(i=0; i