Adding search and some compare features to Matrix v2
This commit is contained in:
parent
ab14e4aa0f
commit
7f3193f08e
4 changed files with 358 additions and 48 deletions
|
|
@ -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 ( )
|
=head2 getCompareForm ( )
|
||||||
|
|
||||||
Returns the compare form.
|
Returns the compare form.
|
||||||
|
|
@ -340,7 +375,7 @@ sub getCompareForm {
|
||||||
orderByClause => $self->get('defaultSort').$sortDirection,
|
orderByClause => $self->get('defaultSort').$sortDirection,
|
||||||
returnObjects => 1,
|
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){
|
foreach my $listing (@listings){
|
||||||
$options{$listing->getId} = '<a href="'.$listing->getUrl.'">'.$listing->get('title').'</a>';
|
$options{$listing->getId} = '<a href="'.$listing->getUrl.'">'.$listing->get('title').'</a>';
|
||||||
}
|
}
|
||||||
|
|
@ -632,7 +667,7 @@ sub www_compare {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $var = $self->get;
|
my $var = $self->get;
|
||||||
my @listingIds = @_;
|
my @listingIds = @_;
|
||||||
my @columnKeys = ['name'];
|
my @columnKeys;
|
||||||
#my @listingIds = ['AwioUvaZXmAEaFw20t-x3Q', 'CWNjAHcmh0pEF6WJooomJA'];
|
#my @listingIds = ['AwioUvaZXmAEaFw20t-x3Q', 'CWNjAHcmh0pEF6WJooomJA'];
|
||||||
unless (scalar(@listingIds)) {
|
unless (scalar(@listingIds)) {
|
||||||
@listingIds = $self->session->form->checkList("listingId");
|
@listingIds = $self->session->form->checkList("listingId");
|
||||||
|
|
@ -667,16 +702,17 @@ sub www_compare {
|
||||||
|
|
||||||
foreach my $listingId (@listingIds){
|
foreach my $listingId (@listingIds){
|
||||||
my $listingId_safe = $listingId;
|
my $listingId_safe = $listingId;
|
||||||
$listingId_safe =~ s/-//g;
|
$listingId_safe =~ s/-/_/g;
|
||||||
push(@columnKeys, $listingId_safe);
|
push(@columnKeys, $listingId_safe);
|
||||||
|
push(@columnKeys, $listingId_safe."_compareColor");
|
||||||
}
|
}
|
||||||
|
|
||||||
$var->{javascript} = "<script type='text/javascript'>\n".
|
$var->{javascript} = "<script type='text/javascript'>\n".
|
||||||
'var listingIds = new Array('.join(", ",map {'"'.$_.'"'} @listingIds).');'.
|
'var listingIds = new Array('.join(", ",map {'"'.$_.'"'} @listingIds).');'.
|
||||||
'var columnKeys = new Array("name", '.join(", ",map {'"'.$_.'"'} @columnKeys).');'.
|
'var columnKeys = new Array("attributeId", "name", '.join(", ",map {'"'.$_.'"'} @columnKeys).');'.
|
||||||
"</script>";
|
"</script>";
|
||||||
|
|
||||||
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 {
|
sub www_getCompareFormData {
|
||||||
|
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $form = $session->form;
|
||||||
|
my $sortDirection = ' asc';
|
||||||
|
|
||||||
my @results;
|
my @results;
|
||||||
my $sortDirection = ' asc';
|
my @listingIds = $self->session->form->checkList("listingId");
|
||||||
|
|
||||||
$self->session->http->setMimeType("application/json");
|
$self->session->http->setMimeType("application/json");
|
||||||
=cut
|
=cut
|
||||||
|
|
@ -928,7 +968,39 @@ assetData.revisionDate
|
||||||
assetData.assetId
|
assetData.assetId
|
||||||
order by ".$self->get('defaultSort').$sortDirection;
|
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
|
=cut
|
||||||
push(@results,{
|
push(@results,{
|
||||||
Title=>$data->{title},
|
Title=>$data->{title},
|
||||||
|
|
@ -945,24 +1017,9 @@ push(@results,{
|
||||||
}
|
}
|
||||||
=cut
|
=cut
|
||||||
my $jsonOutput;
|
my $jsonOutput;
|
||||||
$jsonOutput->{ResultSet} = {Result=>$results};
|
$jsonOutput->{ResultSet} = {Result=>\@results};
|
||||||
|
|
||||||
return JSON->new->utf8->encode($jsonOutput);
|
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';
|
my $sortDirection = ' asc';
|
||||||
|
|
||||||
foreach my $listingId (@listingIds){
|
foreach my $listingId (@listingIds){
|
||||||
|
$listingId =~ s/_/-/g;
|
||||||
my $listing = WebGUI::Asset::MatrixListing->new($session,$listingId);
|
my $listing = WebGUI::Asset::MatrixListing->new($session,$listingId);
|
||||||
my $listingId_safe = $listingId;
|
my $listingId_safe = $listingId;
|
||||||
$listingId_safe =~ s/-//g;
|
$listingId_safe =~ s/-/_/g;
|
||||||
push(@columnDefs,{key=>$listingId_safe,label=>$listing->get('title')});
|
push(@columnDefs,{key=>$listingId_safe,label=>$listing->get('title'),formatter=>"formatColors"});
|
||||||
}
|
}
|
||||||
|
|
||||||
my $jsonOutput;
|
my $jsonOutput;
|
||||||
$jsonOutput->{ColumnDefs} = \@columnDefs;
|
$jsonOutput->{ColumnDefs} = \@columnDefs;
|
||||||
|
|
||||||
foreach my $category (keys %{$self->getCategories}) {
|
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 $from = "from Matrix_attribute a";
|
||||||
my $tableCount = "b";
|
my $tableCount = "b";
|
||||||
foreach my $listingId (@listingIds) {
|
foreach my $listingId (@listingIds) {
|
||||||
my $listingId_safe = $listingId;
|
my $listingId_safe = $listingId;
|
||||||
$listingId_safe =~ s/-//g;
|
$listingId_safe =~ s/-/_/g;
|
||||||
$fields .= ", ".$tableCount.".value as `$listingId_safe`";
|
$fields .= ", ".$tableCount.".value as `$listingId_safe`";
|
||||||
$from .= " left join MatrixListing_attribute ".$tableCount." on a.attributeId="
|
$from .= " left join MatrixListing_attribute ".$tableCount." on a.attributeId="
|
||||||
.$tableCount.".attributeId and ".$tableCount.".matrixListingId=? ";
|
.$tableCount.".attributeId and ".$tableCount.".matrixListingId=? ";
|
||||||
|
|
@ -1014,9 +1072,12 @@ sub www_getCompareListData {
|
||||||
}
|
}
|
||||||
foreach my $result (@results){
|
foreach my $result (@results){
|
||||||
foreach my $listingId (@listingIds) {
|
foreach my $listingId (@listingIds) {
|
||||||
|
$result->{attributId} =~ s/-/_/g;
|
||||||
my $listingId_safe = $listingId;
|
my $listingId_safe = $listingId;
|
||||||
$listingId_safe =~ s/-//g;
|
$listingId_safe =~ s/-/_/g;
|
||||||
if ($result->{fieldType} eq 'MatrixCompare'){
|
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,
|
$result->{$listingId_safe} = WebGUI::Form::MatrixCompare->new( $self->session,
|
||||||
{ value=>$result->{$listingId_safe} },defaultValue=>0)->getValueAsHtml;
|
{ value=>$result->{$listingId_safe} },defaultValue=>0)->getValueAsHtml;
|
||||||
}
|
}
|
||||||
|
|
@ -1058,6 +1119,74 @@ sub www_listAttributes {
|
||||||
return $self->getAdminConsole->render($output, $i18n->get('list attributes title'));
|
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
|
# Everything below here is to make it easier to install your custom
|
||||||
# wobject, but has nothing to do with wobjects in general
|
# wobject, but has nothing to do with wobjects in general
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,12 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.formatCheckBox = function(elCell, oRecord, oColumn, sData) {
|
this.formatCheckBox = function(elCell, oRecord, oColumn, sData) {
|
||||||
elCell.innerHTML = "<input type='checkbox' name='listingId' value='" + sData + "'>";
|
var innerHTML = "<input type='checkbox' name='listingId' value='" + sData + "' id='" + sData + "_checkBox'";
|
||||||
|
if(typeof(oRecord.getData("checked")) != 'undefined'){
|
||||||
|
innerHTML = innerHTML + " checked='checked'";
|
||||||
|
}
|
||||||
|
innerHTML = innerHTML + ">";
|
||||||
|
elCell.innerHTML = innerHTML;
|
||||||
};
|
};
|
||||||
|
|
||||||
var myColumnDefs = [
|
var myColumnDefs = [
|
||||||
|
|
@ -18,16 +23,23 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
||||||
{key:"compares", 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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.myDataSource = new YAHOO.util.DataSource("?");
|
this.myDataSource = new YAHOO.util.DataSource("?");
|
||||||
this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
|
this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
|
||||||
this.myDataSource.connXhrMode = "queueRequests";
|
this.myDataSource.connXhrMode = "queueRequests";
|
||||||
this.myDataSource.responseSchema = {
|
this.myDataSource.responseSchema = {
|
||||||
resultsList: "ResultSet.Result",
|
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.myDataTable = new YAHOO.widget.DataTable("compareForm", myColumnDefs,
|
||||||
this.myDataSource, {initialRequest:"func=getCompareFormData"});
|
this.myDataSource, {initialRequest:uri});
|
||||||
|
|
||||||
var oColumn = this.myDataTable.getColumn(3);
|
var oColumn = this.myDataTable.getColumn(3);
|
||||||
this.myDataTable.hideColumn(oColumn);
|
this.myDataTable.hideColumn(oColumn);
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,27 @@
|
||||||
|
|
||||||
YAHOO.util.Event.addListener(window, "load", function() {
|
YAHOO.util.Event.addListener(window, "load", function() {
|
||||||
YAHOO.example.XHR_JSON = new function() {
|
YAHOO.example.XHR_JSON = new function() {
|
||||||
|
var Dom = YAHOO.util.Dom;
|
||||||
|
var hideStickies = 0;
|
||||||
|
|
||||||
|
this.formatStickied = function(elCell, oRecord, oColumn, sData) {
|
||||||
|
elCell.innerHTML = "<input type='checkBox' class='stickieCheckbox' id='" + oRecord.getData("attributeId") + "_stickied'>";
|
||||||
|
};
|
||||||
|
|
||||||
|
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 = [
|
var myColumnDefs = [
|
||||||
{key:"name"}
|
{key:"stickied",formatter:this.formatStickied},
|
||||||
|
{key:"name"}
|
||||||
];
|
];
|
||||||
|
|
||||||
this.myDataSource = new YAHOO.util.DataSource("?");
|
this.myDataSource = new YAHOO.util.DataSource("?");
|
||||||
|
|
@ -38,8 +56,10 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
||||||
myDataTable.getRecordSet().reset();
|
myDataTable.getRecordSet().reset();
|
||||||
var existingColumns = myDataTable.getColumnSet().keys;
|
var existingColumns = myDataTable.getColumnSet().keys;
|
||||||
for (var i = 0; i < existingColumns.length; i++) {
|
for (var i = 0; i < existingColumns.length; i++) {
|
||||||
if(i > 0){
|
if(i > 1){
|
||||||
myDataTable.removeColumn(existingColumns[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) {
|
if (oFullResponse.ColumnDefs) {
|
||||||
|
|
@ -59,11 +79,11 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
var myCallback2 = function() {
|
var myCallback2 = function() {
|
||||||
this.getRecordSet().reset();
|
//this.getRecordSet().reset();
|
||||||
//this.render();
|
this.set("sortedBy", null);
|
||||||
this.set("sortedBy", null);
|
this.onDataReturnAppendRows.apply(this,arguments);
|
||||||
this.onDataReturnAppendRows.apply(this,arguments);
|
|
||||||
this.getRecordSet().reset();
|
//this.getRecordSet().reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -72,15 +92,68 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
||||||
failure : myCallback,
|
failure : myCallback,
|
||||||
scope : myDataTable
|
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<elements.length; i++){
|
||||||
|
var attributeId = elements[i].getData('attributeId');
|
||||||
|
var checkBox = Dom.get(attributeId+"_stickied");
|
||||||
|
if (checkBox.checked == false){
|
||||||
|
elRow = myDataTable.getTrEl(elements[i]);
|
||||||
|
//var styleNow = Dom.getStyle(elRow, "display");
|
||||||
|
//alert(styleNow);
|
||||||
|
Dom.setStyle(elRow, "display", "none");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hideStickies = 1;
|
||||||
|
}else{
|
||||||
|
// show all attributes
|
||||||
|
for(i=0; i<elements.length; i++){
|
||||||
|
var attributeId = elements[i].getData('attributeId');
|
||||||
|
var checkBox = Dom.get(attributeId+"_stickied");
|
||||||
|
if (checkBox.checked == false){
|
||||||
|
elRow = myDataTable.getTrEl(elements[i]);
|
||||||
|
Dom.setStyle(elRow, "display", "table-row");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hideStickies = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// var elements = Dom.getElementsByClassName('yui-dt-even yui-dt-first', 'tr');
|
||||||
|
// for(i=0; i<elements.length; i++){
|
||||||
|
// alert(elements[i].id);
|
||||||
|
// Dom.setStyle(elements[i], "display", "none");
|
||||||
|
// Dom.addClass(elements[i],'hidden')
|
||||||
|
// alert(elements[i].className);
|
||||||
|
// var show = true;
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
},this,true);
|
||||||
|
|
||||||
|
//var hideEl = new Dom.get('yui-dt0-bdrow0');
|
||||||
|
//alert(hideEl.id);
|
||||||
|
//Dom.addClass(hideEl,'hidden');
|
||||||
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
//function sort() {
|
|
||||||
// myCompareTable.sortColumn()
|
|
||||||
// var oColumn = myCompareTable.getColumn(3);
|
|
||||||
// myCompareTable.hideColumn(oColumn);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
|
||||||
96
www/extras/wobject/Matrix/matrixSearch.js
Normal file
96
www/extras/wobject/Matrix/matrixSearch.js
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
var myCompareTable;
|
||||||
|
//var search;
|
||||||
|
|
||||||
|
YAHOO.util.Event.addListener(window, "load", function() {
|
||||||
|
YAHOO.example.XHR_JSON = new function() {
|
||||||
|
this.formatUrl = function(elCell, oRecord, oColumn, sData) {
|
||||||
|
elCell.innerHTML = "<a href='" + oRecord.getData("ClickUrl") + "' target='_blank'>" + sData + "</a>";
|
||||||
|
};
|
||||||
|
|
||||||
|
this.formatCheckBox = function(elCell, oRecord, oColumn, sData) {
|
||||||
|
var innerHTML = "<input type='checkbox' name='listingId' value='" + sData + "' id='" + sData + "_checkBox'";
|
||||||
|
if(typeof(oRecord.getData("checked")) != 'undefined'){
|
||||||
|
if(oRecord.getData("checked") == 'checked'){
|
||||||
|
innerHTML = innerHTML + " checked='checked'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
innerHTML = 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<elements.length; i++){
|
||||||
|
|
||||||
|
myDataTable.getRecordSet().deleteRecords(0,elements.length);
|
||||||
|
alert("deleting record " + i);
|
||||||
|
}
|
||||||
|
myDataSource.sendRequest(newUri,callback2);
|
||||||
|
myDataTable.getRecordSet().reset();
|
||||||
|
myDataTable.initializeTable;
|
||||||
|
}
|
||||||
|
var newUri = "func=getCompareFormData;search=1";
|
||||||
|
for (var i = attributeSelects.length; i--; ) {
|
||||||
|
newUri = newUri + ';search_' + attributeSelects[i].id + '=' + attributeSelects[i].value;
|
||||||
|
attributeSelects[i].onchange = reloadCompareForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue