From e37f2996cb729212a839a155916ff077b2539907 Mon Sep 17 00:00:00 2001
From: Yung Han Khoe
Date: Thu, 25 Sep 2008 22:12:55 +0000
Subject: [PATCH 1/9] Creating a branch for matrix work
From 22f5565351608e8e32f21c0e9733998c538f9051 Mon Sep 17 00:00:00 2001
From: Yung Han Khoe
Date: Mon, 20 Oct 2008 16:17:27 +0000
Subject: [PATCH 2/9] initial import of Matrix v2 files into Matrix branch
---
lib/WebGUI/Asset/MatrixListing.pm | 420 ++++
lib/WebGUI/Asset/Wobject/Matrix.pm | 1918 ++++++-----------
lib/WebGUI/Form/MatrixCompare.pm | 156 ++
lib/WebGUI/Form/MatrixFieldType.pm | 153 ++
lib/WebGUI/i18n/English/Asset_Matrix.pm | 392 ++--
.../i18n/English/Asset_MatrixListing.pm | 103 +
lib/WebGUI/i18n/English/Form_MatrixCompare.pm | 32 +
lib/WebGUI/i18n/English/WebGUI.pm | 12 +
t/Asset/MatrixListing.t | 63 +
t/Asset/Wobject/Matrix.t | 98 +
10 files changed, 1860 insertions(+), 1487 deletions(-)
create mode 100644 lib/WebGUI/Asset/MatrixListing.pm
create mode 100644 lib/WebGUI/Form/MatrixCompare.pm
create mode 100644 lib/WebGUI/Form/MatrixFieldType.pm
create mode 100644 lib/WebGUI/i18n/English/Asset_MatrixListing.pm
create mode 100644 lib/WebGUI/i18n/English/Form_MatrixCompare.pm
create mode 100644 t/Asset/MatrixListing.t
create mode 100644 t/Asset/Wobject/Matrix.t
diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm
new file mode 100644
index 000000000..8f92a93d6
--- /dev/null
+++ b/lib/WebGUI/Asset/MatrixListing.pm
@@ -0,0 +1,420 @@
+package WebGUI::Asset::MatrixListing;
+
+=head1 LEGAL
+
+ -------------------------------------------------------------------
+ WebGUI is Copyright 2001-2008 Plain Black Corporation.
+ -------------------------------------------------------------------
+ Please read the legal notices (docs/legal.txt) and the license
+ (docs/license.txt) that came with this distribution before using
+ this software.
+ -------------------------------------------------------------------
+ http://www.plainblack.com info@plainblack.com
+ -------------------------------------------------------------------
+
+=cut
+
+use strict;
+use Tie::IxHash;
+use base 'WebGUI::Asset';
+use WebGUI::Utility;
+
+
+
+=head1 NAME
+
+Package WebGUI::Asset::MatrixListing
+
+=head1 DESCRIPTION
+
+Describe your New Asset's functionality and features here.
+
+=head1 SYNOPSIS
+
+use WebGUI::Asset::MatrixListing;
+
+
+=head1 METHODS
+
+These methods are available from this class:
+
+=cut
+
+
+
+#-------------------------------------------------------------------
+
+=head2 addRevision
+
+ This method exists for demonstration purposes only. The superclass
+ handles revisions to MatrixListing Assets.
+
+=cut
+
+sub addRevision {
+ my $self = shift;
+ my $newSelf = $self->SUPER::addRevision(@_);
+ return $newSelf;
+}
+
+#-------------------------------------------------------------------
+
+=head2 definition ( session, definition )
+
+defines asset properties for MatrixListing instances.
+
+=head3 session
+
+=head3 definition
+
+A hash reference passed in from a subclass definition.
+
+=cut
+
+sub definition {
+ my $class = shift;
+ my $session = shift;
+ my $definition = shift;
+ my %properties;
+ tie %properties, 'Tie::IxHash';
+ my $i18n = WebGUI::International->new($session, "Asset_MatrixListing");
+ %properties = (
+ templateId => {
+ tab =>"display",
+ fieldType =>"template",
+ defaultValue =>'MatrixListingTmpl00001',
+ noFormPost =>0,
+ namespace =>"MatrixListing",
+ hoverHelp =>$i18n->get('template description'),
+ label =>$i18n->get('template label')
+ },
+ screenshots => {
+ tab =>"properties",
+ fieldType =>"image",
+ defaultValue =>undef,
+ label =>$i18n->get("screenshots label"),
+ hoverHelp =>$i18n->get("screenshots description")
+ },
+ description => {
+ tab =>"properties",
+ fieldType =>"HTMLArea",
+ defaultValue =>undef,
+ label =>$i18n->get("description label"),
+ hoverHelp =>$i18n->get("description description")
+ },
+ version => {
+ tab =>"properties",
+ fieldType =>"text",
+ defaultValue =>undef,
+ label =>$i18n->get("version label"),
+ hoverHelp =>$i18n->get("version description")
+ },
+ views => {
+ defaultValue =>0,
+ autoGenerate =>0,
+ noFormPost =>1,
+ },
+ compares => {
+ defaultValue =>0,
+ autoGenerate =>0,
+ noFormPost =>1,
+ },
+ clicks => {
+ defaultValue =>0,
+ autoGenerate =>0,
+ noFormPost =>1,
+ },
+ viewsLastIp => {
+ defaultValue =>undef,
+ autoGenerate =>0,
+ noFormPost =>1,
+ },
+ comparesLastIp => {
+ defaultValue =>undef,
+ autoGenerate =>0,
+ noFormPost =>1,
+ },
+ clicksLastIp => {
+ defaultValue =>undef,
+ autoGenerate =>0,
+ noFormPost =>1,
+ },
+ maintainer => {
+ tab =>"properties",
+ fieldType =>"user",
+ defaultValue =>$session->user->userId,
+ label =>$i18n->get("maintainer label"),
+ hoverHelp =>$i18n->get("maintainer description")
+ },
+ manufacturerName => {
+ tab =>"properties",
+ fieldType =>"text",
+ defaultValue =>undef,
+ label =>$i18n->get("manufacturerName label"),
+ hoverHelp =>$i18n->get("manufacturerName description")
+ },
+ manufacturerURL => {
+ tab =>"properties",
+ fieldType =>"url",
+ defaultValue =>undef,
+ label =>$i18n->get("manufacturerURL label"),
+ hoverHelp =>$i18n->get("manufacturerURL description")
+ },
+ productURL => {
+ tab =>"properties",
+ fieldType =>"url",
+ defaultValue =>undef,
+ label =>$i18n->get("productURL label"),
+ hoverHelp =>$i18n->get("productURL description")
+ },
+ lastUpdated => {
+ defaultValue =>time(),
+ autoGenerate =>0,
+ noFormPost =>1,
+ },
+ );
+ push(@{$definition}, {
+ assetName=>$i18n->get('assetName'),
+ icon=>'MatrixListing.gif',
+ autoGenerateForms=>1,
+ tableName=>'MatrixListing',
+ className=>'WebGUI::Asset::MatrixListing',
+ properties=>\%properties
+ });
+ return $class->SUPER::definition($session, $definition);
+}
+
+
+#-------------------------------------------------------------------
+
+=head2 duplicate
+
+ This method exists for demonstration purposes only. The superclass
+ handles duplicating MatrixListing Assets. This method will be called
+ whenever a copy action is executed
+
+=cut
+
+sub duplicate {
+ my $self = shift;
+ my $newAsset = $self->SUPER::duplicate(@_);
+ return $newAsset;
+}
+
+#-------------------------------------------------------------------
+
+=head2 getAutoCommitWorkflowId
+
+Gets the WebGUI::VersionTag workflow to use to automatically commit MatrixListings.
+By specifying this method, you activate this feature.
+
+=cut
+
+sub getAutoCommitWorkflowId {
+ my $self = shift;
+ return $self->getParent->get("submissionApprovalWorkflowId");
+}
+
+#-------------------------------------------------------------------
+
+=head2 indexContent ( )
+
+Making private. See WebGUI::Asset::indexContent() for additonal details.
+
+=cut
+
+sub indexContent {
+ my $self = shift;
+ my $indexer = $self->SUPER::indexContent;
+ $indexer->setIsPublic(0);
+}
+
+
+#-------------------------------------------------------------------
+
+=head2 prepareView ( )
+
+See WebGUI::Asset::prepareView() for details.
+
+=cut
+
+sub prepareView {
+ my $self = shift;
+ $self->SUPER::prepareView();
+ my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
+ $template->prepare;
+ $self->{_viewTemplate} = $template;
+}
+
+
+#-------------------------------------------------------------------
+
+=head2 processPropertiesFromFormPost ( )
+
+Used to process properties from the form posted. Do custom things with
+noFormPost fields here, or do whatever you want. This method is called
+when /yourAssetUrl?func=editSave is requested/posted.
+
+=cut
+
+sub processPropertiesFromFormPost {
+ my $self = shift;
+ $self->SUPER::processPropertiesFromFormPost;
+ $self->requestAutoCommit;
+}
+
+
+#-------------------------------------------------------------------
+
+=head2 purge ( )
+
+This method is called when data is purged by the system.
+removes collateral data associated with a MatrixListing when the system
+purges it's data.
+
+=cut
+
+sub purge {
+ my $self = shift;
+ return $self->SUPER::purge;
+}
+
+#-------------------------------------------------------------------
+
+=head2 purgeRevision ( )
+
+This method is called when data is purged by the system.
+
+=cut
+
+sub purgeRevision {
+ my $self = shift;
+ return $self->SUPER::purgeRevision;
+}
+
+#-------------------------------------------------------------------
+=head2 view ( )
+
+method called by the container www_view method.
+
+=cut
+
+sub view {
+ my $self = shift;
+ my $var = $self->get; # $var is a hash reference.
+ $var->{controls} = $self->getToolbar;
+ $var->{fileUrl} = $self->getFileUrl;
+ $var->{fileIcon} = $self->getFileIconUrl;
+ return $self->processTemplate($var,undef, $self->{_viewTemplate});
+}
+
+
+#-------------------------------------------------------------------
+
+=head2 www_edit ( )
+
+Web facing method which is the default edit page
+
+=cut
+
+sub www_edit {
+ my $self = shift;
+
+ return $self->session->privilege->noAccess() unless $self->getParent->canAddMatrixListing();
+
+ my $i18n = WebGUI::International->new($self->session, "Asset_MatrixListing");
+ return $self->session->privilege->insufficient() unless $self->canEdit;
+ return $self->session->privilege->locked() unless $self->canEditIfLocked;
+ return $self->getAdminConsole->render($self->getEditForm->print,$i18n->get('edit matrix listing title'));
+}
+
+#-------------------------------------------------------------------
+
+=head2 www_view ( )
+
+Web facing method which is the default view page. This method does a
+302 redirect to the "showPage" file in the storage location.
+
+=cut
+
+sub www_view {
+ my $self = shift;
+ return $self->session->privilege->noAccess() unless $self->canView;
+ if ($self->session->var->isAdminOn) {
+ return $self->getContainer->www_view;
+ }
+ $self->session->http->setRedirect($self->getFileUrl($self->getValue("showPage")));
+ return undef;
+}
+
+#-------------------------------------------------------------------
+# Everything below here is to make it easier to install your custom
+# asset, but has nothing to do with assets in general
+#-------------------------------------------------------------------
+# cd /data/WebGUI/lib
+# perl -MWebGUI::Asset::MatrixListing -e install www.example.com.conf [ /path/to/WebGUI ]
+# - or -
+# perl -MWebGUI::Asset::MatrixListing -e uninstall www.example.com.conf [ /path/to/WebGUI ]
+#-------------------------------------------------------------------
+
+
+use base 'Exporter';
+our @EXPORT = qw(install uninstall);
+use WebGUI::Session;
+
+#-------------------------------------------------------------------
+sub install {
+ my $config = $ARGV[0];
+ my $home = $ARGV[1] || "/data/WebGUI";
+ die "usage: perl -MWebGUI::Asset::MatrixListing -e install www.example.com.conf\n" unless ($home && $config);
+ print "Installing asset.\n";
+ my $session = WebGUI::Session->open($home, $config);
+ $session->config->addToArray("assets","WebGUI::Asset::MatrixListing");
+ $session->db->write("create table MatrixListing (
+ assetId varchar(22) binary not null,
+ revisionDate bigint not null,
+ title varchar(255),
+ screenshots varchar(22),
+ description text,
+ version varchar(255),
+ views int(11),
+ compares int(11),
+ clicks int(11),
+ viewsLastIp varchar(255),
+ comparesLastIp varchar(255),
+ clicksLastIp varchar(255),
+ lastUpdated int(11),
+ maintainer varchar(22),
+ manufacturerName varchar(255),
+ manufacturerURL varchar(255),
+ productURL varchar(255),
+ primary key (assetId, revisionDate)
+ )");
+ $session->var->end;
+ $session->close;
+ print "Done. Please restart Apache.\n";
+}
+
+#-------------------------------------------------------------------
+sub uninstall {
+ my $config = $ARGV[0];
+ my $home = $ARGV[1] || "/data/WebGUI";
+ die "usage: perl -MWebGUI::Asset::MatrixListing -e uninstall www.example.com.conf\n" unless ($home && $config);
+ print "Uninstalling asset.\n";
+ my $session = WebGUI::Session->open($home, $config);
+ $session->config->deleteFromArray("assets","WebGUI::Asset::MatrixListing");
+ my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::MatrixListing'");
+ while (my ($id) = $rs->array) {
+ my $asset = WebGUI::Asset->new($session, $id, "WebGUI::Asset::MatrixListing");
+ $asset->purge if defined $asset;
+ }
+ $session->db->write("drop table MatrixListing");
+ $session->var->end;
+ $session->close;
+ print "Done. Please restart Apache.\n";
+}
+
+
+1;
+
+#vim:ft=perl
diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm
index 8c4120e2c..b71ad07b2 100644
--- a/lib/WebGUI/Asset/Wobject/Matrix.pm
+++ b/lib/WebGUI/Asset/Wobject/Matrix.pm
@@ -1,183 +1,334 @@
package WebGUI::Asset::Wobject::Matrix;
-
+
+$VERSION = "2.0.0";
+
+#-------------------------------------------------------------------
+# WebGUI is Copyright 2001-2008 Plain Black Corporation.
+#-------------------------------------------------------------------
+# Please read the legal notices (docs/legal.txt) and the license
+# (docs/license.txt) that came with this distribution before using
+# this software.
+#-------------------------------------------------------------------
+# http://www.plainblack.com info@plainblack.com
+#-------------------------------------------------------------------
+
use strict;
+use warnings;
use Tie::IxHash;
-use WebGUI::Form;
-use WebGUI::HTMLForm;
-use WebGUI::Cache;
-use WebGUI::Mail::Send;
-use WebGUI::SQL;
-use WebGUI::Storage::Image;
-use WebGUI::User;
+use WebGUI::International;
use WebGUI::Utility;
-use WebGUI::Inbox;
-use WebGUI::Asset::Wobject;
-use WebGUI::Asset::Wobject::Collaboration;
+use base 'WebGUI::Asset::Wobject';
+
+#----------------------------------------------------------------------------
+
+=head2 canAddMatrixListing ( )
+
+Returns true if able to add MatrixListings.
+
+ Checks to make sure that the
+ Calendar has been committed at least once. Checks to make sure that
+ the user is in the appropriate group (either the group that can edit
+ the calendar, or the group that can edit events in the calendar).
+
+=cut
+
+sub canAddMatrixListing {
+ my $self = shift;
+
+ return 1;
+=cut
+ my $userId = shift;
+
+ my $user = $userId
+ ? WebGUI::User->new( $self->session, $userId )
+ : $self->session->user
+ ;
+
+ return 1 if (
+ $user->isInGroup( $self->get("groupIdEventEdit") )
+ );
+=cut
+}
-
-our @ISA = qw(WebGUI::Asset::Wobject);
-
#-------------------------------------------------------------------
+
+=head2 definition ( )
+
+defines wobject properties for Matrix instances.
+
+=cut
+
sub definition {
- my $class = shift;
+ my $class = shift;
my $session = shift;
- my $definition = shift;
- my $i18n = WebGUI::International->new($session,"Asset_Matrix");
- push(@{$definition}, {
- icon=>'matrix.gif',
- tableName=>'Matrix',
- className=>'WebGUI::Asset::Wobject::Matrix',
+ my $definition = shift;
+ my $i18n = WebGUI::International->new($session, 'Asset_Matrix');
+
+ my %properties;
+ tie %properties, 'Tie::IxHash';
+ %properties = (
+ templateId =>{
+ fieldType =>"template",
+ defaultValue =>'matrixtmpl000000000001',
+ tab =>"display",
+ #www_editSave will ignore anyone's attempts to update this field if this is set to 1
+ noFormPost =>0,
+ #This is an option specific to the template fieldType.
+ namespace =>"Matrix",
+ hoverHelp =>$i18n->get('template description'),
+ label =>$i18n->get('template label'),
+ },
+ searchTemplateId=>{
+ defaultValue =>"matrixtmpl000000000005",
+ fieldType =>"template",
+ tab =>"display",
+ namespace =>"Matrix/Search",
+ hoverHelp =>$i18n->get('search template description'),
+ label =>$i18n->get('search template label'),
+ },
+ detailTemplateId=>{
+ defaultValue =>"matrixtmpl000000000003",
+ fieldType =>"template",
+ tab =>"display",
+ namespace =>"Matrix/Detail",
+ hoverHelp =>$i18n->get('detail template description'),
+ label =>$i18n->get('detail template label'),
+ },
+ ratingDetailTemplateId=>{
+ defaultValue =>"matrixtmpl000000000004",
+ fieldType =>"template",
+ tab =>"display",
+ namespace =>"Matrix/RatingDetail",
+ hoverHelp =>$i18n->get('rating detail template description'),
+ label =>$i18n->get('rating detail template label'),
+ },
+ compareTemplateId=>{
+ defaultValue =>"matrixtmpl000000000002",
+ fieldType =>"template",
+ tab =>"display",
+ namespace =>"Matrix/Compare",
+ hoverHelp =>$i18n->get('compare template description'),
+ label =>$i18n->get('compare template label'),
+ },
+ defaultSort=>{
+ fieldType =>"selectBox",
+ tab =>"display",
+ options =>{
+ score => $i18n->get('sort by score label'),
+ alphaNumeric => $i18n->get('sort alpha numeric label'),
+ assetRank => $i18n->get('sort by asset rank label'),
+ lastUpdated => $i18n->get('sort by last updated label'),
+ },
+ defaultValue =>"score",
+ hoverHelp =>$i18n->get('default sort description'),
+ label =>$i18n->get('default sort label'),
+ },
+ compareColorNo=>{
+ fieldType =>"color",
+ tab =>"display",
+ defaultValue =>"#ffaaaa",
+ hoverHelp =>$i18n->get('compare color no description'),
+ label =>$i18n->get('compare color no label'),
+ },
+ compareColorLimited=>{
+ fieldType =>"color",
+ tab =>"display",
+ defaultValue =>"#ffffaa",
+ hoverHelp =>$i18n->get('compare color limited description'),
+ label =>$i18n->get('compare color limited label'),
+ },
+ compareColorCostsExtra=>{
+ fieldType =>"color",
+ tab =>"display",
+ defaultValue =>"#ffffaa",
+ hoverHelp =>$i18n->get('compare color costs extra description'),
+ label =>$i18n->get('compare color costs extra label'),
+ },
+ compareColorFreeAddOn=>{
+ fieldType =>"color",
+ tab =>"display",
+ defaultValue =>"#ffffaa",
+ hoverHelp =>$i18n->get('compare color free add on description'),
+ label =>$i18n->get('compare color free add on label'),
+ },
+ compareColorYes=>{
+ fieldType =>"color",
+ tab =>"display",
+ defaultValue =>"#aaffaa",
+ hoverHelp =>$i18n->get('compare color yes description'),
+ label =>$i18n->get('compare color yes label'),
+ },
+ categories=>{
+ fieldType =>"textarea",
+ tab =>"properties",
+ defaultValue =>$i18n->get('categories default value'),
+ hoverHelp =>$i18n->get('categories description'),
+ label =>$i18n->get('categories label'),
+ subtext =>$i18n->get('categories subtext'),
+ },
+ maxComparisons=>{
+ fieldType =>"integer",
+ tab =>"properties",
+ defaultValue =>25,
+ hoverHelp =>$i18n->get('max comparisons description'),
+ label =>$i18n->get('max comparisons label'),
+ },
+ maxComparisonsPrivileged=>{
+ fieldType =>"integer",
+ tab =>"properties",
+ defaultValue =>10,
+ hoverHelp =>$i18n->get('max comparisons privileged description'),
+ label =>$i18n->get('max comparisons privileged label'),
+ },
+ submissionApprovalWorkflowId=>{
+ fieldType =>"workflow",
+ tab =>"security",
+ type =>'WebGUI::VersionTag',
+ defaultValue =>"pbworkflow000000000003",
+ hoverHelp =>$i18n->get('submission approval workflow description'),
+ label =>$i18n->get('submission approval workflow label'),
+ },
+ ratingsDuration=>{
+ fieldType =>"interval",
+ tab =>"properties",
+ defaultValue =>7776000, # 3 months 3*30*24*60*60
+ hoverHelp =>$i18n->get('ratings duration description'),
+ label =>$i18n->get('ratings duration label'),
+ },
+ );
+ push(@{$definition}, {
assetName=>$i18n->get('assetName'),
- properties=>{
- visitorCacheTimeout => {
- tab => "display",
- fieldType => "interval",
- defaultValue => 3600,
- uiLevel => 8,
- label => $i18n->get("visitor cache timeout"),
- hoverHelp => $i18n->get("visitor cache timeout help")
- },
- categories=>{
- defaultValue=>"Features\nBenefits",
- fieldType=>"textarea"
- },
- maxComparisons=>{
- defaultValue=>10,
- fieldName=>"integer"
- },
- templateId=>{
- defaultValue=>"matrixtmpl000000000001",
- fieldType=>"template"
- },
- searchTemplateId=>{
- defaultValue=>"matrixtmpl000000000005",
- fieldType=>"template"
- },
- detailTemplateId=>{
- defaultValue=>"matrixtmpl000000000003",
- fieldType=>"template"
- },
- ratingDetailTemplateId=>{
- defaultValue=>"matrixtmpl000000000004",
- fieldType=>"template"
- },
- compareTemplateId=>{
- defaultValue=>"matrixtmpl000000000002",
- fieldType=>"template"
- },
- privilegedGroup=>{
- defaultValue=>'2',
- fieldType=>"group",
- },
- groupToRate=>{
- defaultValue=>'2',
- fieldType=>"group",
- },
- groupToAdd=>{
- defaultValue=>'2',
- fieldType=>"group",
- },
- maxComparisonsPrivileged=>{
- defaultValue=>10,
- fieldType=>"integer",
- },
- ratingTimeout=>{
- defaultValue=>60*60*24*365,
- fieldType=>"interval"
- },
- ratingTimeoutPrivileged=>{
- defaultValue=>60*60*24*365,
- fieldType=>"interval"
- }
- }
- });
- return $class->SUPER::definition($session, $definition);
+ icon=>'matrix.gif',
+ autoGenerateForms=>1,
+ tableName=>'Matrix',
+ className=>'WebGUI::Asset::Wobject::Matrix',
+ properties=>\%properties
+ });
+ return $class->SUPER::definition($session, $definition);
}
#-------------------------------------------------------------------
+
+=head2 deleteAttribute ( attributeId )
+
+Deletes an attribute and listing data for this attribute from Collateral.
+
+=head3 attributeId
+
+The id of the attribute that should be deleted.
+
+=cut
+
+sub deleteAttribute {
+
+ my $self = shift;
+ my $attributeId = shift;
+
+ $self->deleteCollateral("Matrix_attribute","attributeId",$attributeId);
+ #TODO: delete listing data, $self->deleteCollateral("Matrix_listingData","attributeId",$attributeId);
+
+ return undef;
+}
+
+#-------------------------------------------------------------------
+
+=head2 duplicate ( )
+
+duplicates a Matrix.
+
+=cut
+
sub duplicate {
- # Buggo: how do we duplicate these?
- return undef;
-}
-
-#-------------------------------------------------------------------
-# Too much data to keep track of modification dates, always assume new data
-sub getContentLastModified {
- return time();
-}
-
-#-------------------------------------------------------------------
-sub formatURL {
my $self = shift;
- my $func = shift;
- my $listingId = shift;
- my $url = $self->getUrl("func=".$func.";listingId=".$listingId);
- return $url;
+ my $newAsset = $self->SUPER::duplicate(@_);
+ return $newAsset;
}
+#-------------------------------------------------------------------
+
+=head2 editAttributeSave ( attributeProperties )
+
+Saves an attribute.
+
+=head3 attributeProperties
+
+A hashref containing the properties of the attribute.
+
+=cut
+
+sub editAttributeSave {
+ my $self = shift;
+ my $attributeProperties = shift;
+ my $session = $self->session;
+ my $form = $session->form;
+
+ return $session->privilege->insufficient() unless $self->canEdit;
+
+ my $attributeId = $self->setCollateral("Matrix_attribute","attributeId",$attributeProperties,0,1);
+
+ return $attributeId;
+}
#-------------------------------------------------------------------
+
+=head2 getAttribute ( attributeId )
+
+Returns a hash reference of the properties of an attribute.
+
+=head3 attributeId
+
+The unique id of an attribute.
+
+=cut
+
+sub getAttribute {
+ my ($self, $attributeId) = @_;
+ return $self->session->db->quickHashRef("select * from Matrix_attribute where attributeId=?",[$attributeId]);
+}
+
+#-------------------------------------------------------------------
+
+=head2 getCategories ( )
+
+Returns the categories for this Matrix as a hashref.
+
+=cut
+
sub getCategories {
- my $self = shift;
- my $cat = $self->getValue("categories");
- $cat =~ s/\r//g;
- chomp($cat);
- my @categories = split(/\n/,$cat);
- return @categories;
-}
+ my $self = shift;
+ my %categories;
+ tie %categories, 'Tie::IxHash';
+ my $categories = $self->getValue("categories");
+ $categories =~ s/\r//g;
+ chomp($categories);
+ my @categories = split(/\n/,$categories);
+ foreach my $category (@categories) {
+ $categories{$category} = $category;
+ }
+ return \%categories;
-#-------------------------------------------------------------------
-sub getCompareForm {
- my $self = shift;
- my @ids = @_;
- my $form = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl})
- .WebGUI::Form::submit($self->session, {
- value=>"compare"
- })
- ." "
- ." "
- .WebGUI::Form::hidden($self->session, {
- name=>"func",
- value=>"compare"
- })
- .WebGUI::Form::checkList($self->session, {
- name=>"listingId",
- vertical=>1,
- value=>\@ids,
- options=>$self->session->db->buildHashRef("select listingId, concat('getUrl("func=viewDetail").";listingId=',listingId,'\\\">', productName,' ') from Matrix_listing
- where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by productName")
- })
- ." "
- .WebGUI::Form::submit($self->session,{
- value=>"compare"
- })
- .WebGUI::Form::formFooter($self->session);
- return $form;
}
#-------------------------------------------------------------------
-sub hasRated {
- my $self = shift;
- my $listingId = shift;
- return 1 unless ($self->session->user->isInGroup($self->get("groupToRate")));
- my $ratingTimeout = $self->session->user->isInGroup($self->get("privilegedGroup")) ? $self->get("ratingTimeoutPrivileged") : $self->get("ratingTimeout");
- my ($hasRated) = $self->session->db->quickArray("select count(*) from Matrix_rating where
- ((userId=".$self->session->db->quote($self->session->user->userId)." and userId<>'1') or (userId='1' and ipAddress=".$self->session->db->quote($self->session->env->get("HTTP_X_FORWARDED_FOR")).")) and
- listingId=".$self->session->db->quote($listingId)." and timeStamp>".($self->session->datetime->time()-$ratingTimeout));
- return $hasRated;
-}
-#-------------------------------------------------------------------
-sub incrementCounter {
+=head2 getEditForm ( )
+
+returns the tabform object that will be used in generating the edit page for Matrix.
+
+=cut
+
+sub getEditForm {
my $self = shift;
- my $listingId = shift;
- my $counter = shift;
- my ($lastIp) = $self->session->db->quickArray("select ".$counter."LastIp from Matrix_listing where listingId = ".$self->session->db->quote($listingId));
- unless ($lastIp eq $self->session->env->get("HTTP_X_FORWARDED_FOR")) {
- $self->session->db->write("update Matrix_listing set $counter=$counter+1, ".$counter."LastIp=".$self->session->db->quote($self->session->env->get("HTTP_X_FORWARDED_FOR"))." where listingId=".$self->session->db->quote($listingId));
- }
+ my $tabform = $self->SUPER::getEditForm();
+=cut
+ $tabform->getTab("display")->template(
+ -value=>$self->getValue("templateId"),
+ -label=>WebGUI::International::get("template_label","Asset_Matrix"),
+ -namespace=>"Matrix"
+ );
+=cut
+ return $tabform;
}
#-------------------------------------------------------------------
@@ -192,1185 +343,350 @@ sub prepareView {
my $self = shift;
$self->SUPER::prepareView();
my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
- $template->prepare($self->getMetaDataAsTemplateVariables);
+ $template->prepare;
$self->{_viewTemplate} = $template;
}
#-------------------------------------------------------------------
+
+=head2 purge ( )
+
+removes collateral data associated with a Matrix when the system
+purges it's data.
+
+=cut
+
sub purge {
- my $self = shift;
- $self->session->db->write("delete from Matrix_listing where assetId=".$self->session->db->quote($self->getId));
- $self->session->db->write("delete from Matrix_listingData where assetId=".$self->session->db->quote($self->getId));
- $self->session->db->write("delete from Matrix_field where assetId=".$self->session->db->quote($self->getId));
- $self->session->db->write("delete from Matrix_rating where assetId=".$self->session->db->quote($self->getId));
- $self->session->db->write("delete from Matrix_ratingSummary where assetId=".$self->session->db->quote($self->getId));
- $self->SUPER::purge;
+ my $self = shift;
+ #purge your wobject-specific data here. This does not include fields
+ # you create for your Matrix asset/wobject table.
+ return $self->SUPER::purge;
}
#-------------------------------------------------------------------
-=head2 purgeCache ( )
+=head2 view ( )
-See WebGUI::Asset::purgeCache() for details.
+method called by the www_view method. Returns a processed template
+to be displayed within the page style.
=cut
-sub purgeCache {
- my $self = shift;
- WebGUI::Cache->new($self->session,"view_".$self->getId)->delete;
- $self->SUPER::purgeCache;
-}
-
-#-------------------------------------------------------------------
-sub setRatings {
- my $self = shift;
- my $listingId = shift;
- my $ratings = shift;
- foreach my $category ($self->getCategories) {
- if ($ratings->{$category}) {
- $self->session->db->write("insert into Matrix_rating (userId, category, rating, timeStamp, listingId,ipAddress, assetId) values (
- ".$self->session->db->quote($self->session->user->userId).", ".$self->session->db->quote($category).", ".$self->session->db->quote($ratings->{$category}).", ".$self->session->datetime->time()
- .", ".$self->session->db->quote($listingId).", ".$self->session->db->quote($self->session->env->get("HTTP_X_FORWARDED_FOR")).",".$self->session->db->quote($self->getId).")");
- }
- my $sql = "from Matrix_rating where listingId=".$self->session->db->quote($listingId)." and category=".$self->session->db->quote($category);
- my ($sum) = $self->session->db->quickArray("select sum(rating) $sql");
- my ($count) = $self->session->db->quickArray("select count(*) $sql");
- my $half = round($count/2);
- my $mean = $sum / ($count || 1);
- my ($median) = $self->session->db->quickArray("select rating $sql limit $half,$half");
- $self->session->db->write("replace into Matrix_ratingSummary (listingId, category, meanValue, medianValue, countValue,assetId) values (
- ".$self->session->db->quote($listingId).", ".$self->session->db->quote($category).", $mean, ".$self->session->db->quote($median).", $count, ".$self->session->db->quote($self->getId).")");
- }
-}
-
-#-------------------------------------------------------------------
-sub www_approveListing {
- my $self = shift;
- return $self->session->privilege->insufficient() unless($self->canEdit);
- my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId"));
- $self->session->db->write("update Matrix_listing set status='approved' where listingId=".$self->session->db->quote($self->session->form->process("listingId")));
- my $inbox = WebGUI::Inbox->new($self->session);
- $inbox->addMessage({
- subject=>"New Listing Approved",
- message=>"Your new listing, ".$listing->{productName}.", has been approved.",
- status=>'completed',
- userId=>$listing->{maintainerId}
- });
- my $message = $inbox->getMessage($listing->{approvalMessageId});
- if (defined $message) {
- $message->setCompleted;
- }
- return $self->www_viewDetail;
-}
-
-
-#-------------------------------------------------------------------
-sub www_click {
- my $self = shift;
- $self->incrementCounter($self->session->form->process("listingId"),"clicks");
- my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId"));
- if ($self->session->form->process("m")) {
- $self->session->http->setRedirect($listing->{manufacturerUrl});
- }
- else {
- $self->session->http->setRedirect($listing->{productUrl});
- }
- return undef;
-}
-
-
-#-------------------------------------------------------------------
-sub www_compare {
- my $self = shift;
- my @cmsList = @_;
- unless (scalar(@cmsList)) {
- @cmsList = $self->session->form->checkList("listingId");
- }
- my ($style, $url) = ($self->session->style, $self->session->url);
- my ( %var, @prodcol, @datecol);
- my $max = $self->session->user->isInGroup($self->get("privilegedGroup")) ? $self->get("maxComparisonsPrivileged") : $self->get("maxComparisons");
- $var{isTooMany} = (scalar(@cmsList)>$max);
- $var{isTooFew} = (scalar(@cmsList)<2);
- $var{'compare.form'} = $self->getCompareForm(@cmsList);
- $var{'isLoggedIn'} = ($self->session->user->isRegistered);
- if ($var{isTooMany} || $var{isTooFew}) {
- return $self->processStyle($self->processTemplate(\%var,$self->get("compareTemplateId")));
- }
- foreach my $cms (@cmsList) {
- $self->incrementCounter($cms,"compares");
- my $data = $self->session->db->quickHashRef("select listingId, productName, versionNumber, lastUpdated
- from Matrix_listing where listingId=".$self->session->db->quote($cms));
- push(@prodcol, {
- name=>$data->{productName} || "__untitled__",
- version=>$data->{versionNumber},
- url=>$self->formatURL("viewDetail",$cms)
- });
- push(@datecol, {
- lastUpdated=>$self->session->datetime->epochToHuman($data->{lastUpdated},"%z")
- });
- }
- my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
- my %goodBad = (
- "No" => $i18n->get("no"),
- "Yes" => $i18n->get("yes"),
- "Free Add On" => $i18n->get("free"),
- "Costs Extra" => $i18n->get("extra"),
- "Limited" => $i18n->get("limited"),
- );
- $var{product_loop} = \@prodcol;
- $var{lastupdated_loop} = \@datecol;
- my @categoryloop;
- foreach my $category ($self->getCategories()) {
- my @rowloop;
- my $select = "select a.fieldType, a.label, a.description";
- my $from = "from Matrix_field a";
- my $tableCount = "b";
- foreach my $cms (@cmsList) {
- $select .= ", ".$tableCount.".value";
- $from .= " left join Matrix_listingData ".$tableCount." on a.fieldId="
- .$tableCount.".fieldId and ".$tableCount.".listingId=".$self->session->db->quote($cms);
- $tableCount++;
- }
- my $sth = $self->session->db->read("$select $from where a.category=".$self->session->db->quote($category)." and a.assetId=".$self->session->db->quote($self->getId)." order by a.label");
- while (my @row = $sth->array) {
- my @columnloop;
- my $first = 1;
- my $type = shift @row;
- foreach my $value (@row) {
- my $desc = "";
- if ($first) {
- $desc = $row[1];
- shift(@row);
- $first = 0;
- }
- elsif ($type eq 'goodBad') {
- $value = $goodBad{$value};
- }
- my $class = lc($value);
- $class =~ s/\s/_/g;
- $class =~ s/\W//g;
- push(@columnloop,{
- value=>$value,
- class=>$class,
- description=>$desc
- });
- }
- push(@rowloop,{
- column_loop=>\@columnloop
- });
- }
- $sth->finish;
- push(@categoryloop,{
- category=>$category,
- columnCount=>$#cmsList+2,
- row_loop=>\@rowloop
- });
- }
- $var{category_loop} = \@categoryloop;
- return $self->processStyle($self->processTemplate(\%var,$self->get("compareTemplateId")));
-}
-
-#-------------------------------------------------------------------
-sub www_copy {
- my $self = shift;
- my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
- return $i18n->get('no copy');
-}
-
-#-------------------------------------------------------------------
-sub www_deleteField {
- my $self = shift;
- my $id = $self->session->form->param("fieldId");
- $self->session->db->write("delete from Matrix_field where fieldId=?",[$id]);
- $self->session->db->write("delete from Matrix_listingData where fieldId=?",[$id]);
- $self->www_listFields();
-}
-
-#-------------------------------------------------------------------
-sub www_deleteListing {
- my $self = shift;
- my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
- my $output = sprintf $i18n->get('delete listing confirmation'),
- $self->getUrl("func=deleteListingConfirm;listingId=".$self->session->form->process("listingId")),
- $self->formatURL("viewDetail",$self->session->form->process("listingId"));
- return $self->processStyle($output);
-}
-
-#-------------------------------------------------------------------
-sub www_deleteListingConfirm {
- my $self = shift;
- return $self->session->privilege->insufficient() unless($self->canEdit);
- my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId"));
- WebGUI::Asset::Wobject::Collaboration->new($self->session, $listing->{forumId})->purge;
- $self->session->db->write("delete from Matrix_listing where listingId=".$self->session->db->quote($self->session->form->process("listingId")));
- $self->session->db->write("delete from Matrix_listingData where listingId=".$self->session->db->quote($self->session->form->process("listingId")));
- $self->session->db->write("delete from Matrix_rating where listingId=".$self->session->db->quote($self->session->form->process("listingId")));
- $self->session->db->write("delete from Matrix_ratingSummary where listingId=".$self->session->db->quote($self->session->form->process("listingId")));
- my $inbox = WebGUI::Inbox->new($self->session);
- $inbox->addMessage({
- status=>'completed',
- subject=>"Listing Deleted",
- message=>"Your listing, ".$listing->{productName}.", has been deleted from the matrix.",
- userId=>$listing->{maintainerId}
- });
- my $message = $inbox->getMessage($listing->{approvalMessageId});
- if (defined $message) {
- $message->setCompleted;
- }
- return "";
-}
-
-#-------------------------------------------------------------------
-sub getEditForm {
- my $self = shift;
- my $tabform = $self->SUPER::getEditForm();
- my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
- $tabform->getTab("display")->interval(
- -name=>"visitorCacheTimeout",
- -label=>$i18n->get('visitor cache timeout'),
- -hoverHelp=>$i18n->get('visitor cache timeout help'),
- -value=>$self->getValue('visitorCacheTimeout'),
- -uiLevel=>8,
- -defaultValue=>3600
- );
- $tabform->getTab("properties")->textarea(
- -name=>"categories",
- -label=>$i18n->get('categories'),
- -hoverHelp=>$i18n->get('categories description'),
- -value=>$self->getValue("categories"),
- -subtext=>$i18n->get('categories subtext'),
- );
- $tabform->getTab("properties")->integer(
- -name=>"maxComparisons",
- -label=>$i18n->get("max comparisons"),
- -hoverHelp=>$i18n->get("max comparisons description"),
- -value=>$self->getValue("maxComparisons")
- );
- $tabform->getTab("properties")->integer(
- -name=>"maxComparisonsPrivileged",
- -label=>$i18n->get("max comparisons privileged"),
- -hoverHelp=>$i18n->get("max comparisons privileged description"),
- -value=>$self->getValue("maxComparisonsPrivileged")
- );
- $tabform->getTab("properties")->interval(
- -name=>"ratingTimeout",
- -label=>$i18n->get("rating timeout"),
- -hoverHelp=>$i18n->get("rating timeout description"),
- -value=>$self->getValue("ratingTimeout")
- );
- $tabform->getTab("properties")->interval(
- -name=>"ratingTimeoutPrivileged",
- -label=>$i18n->get("rating timeout privileged"),
- -hoverHelp=>$i18n->get("rating timeout privileged description"),
- -value=>$self->getValue("ratingTimeoutPrivileged")
- );
- $tabform->getTab("security")->group(
- -name=>"groupToAdd",
- -label=>$i18n->get("group to add"),
- -hoverHelp=>$i18n->get("group to add description"),
- -value=>[$self->getValue("groupToAdd")]
- );
- $tabform->getTab("security")->group(
- -name=>"privilegedGroup",
- -label=>$i18n->get("privileged group"),
- -hoverHelp=>$i18n->get("privileged group description"),
- -value=>[$self->getValue("privilegedGroup")]
- );
- $tabform->getTab("security")->group(
- -name=>"groupToRate",
- -label=>$i18n->get("rating group"),
- -hoverHelp=>$i18n->get("rating group description"),
- -value=>[$self->getValue("groupToRate")]
- );
- $tabform->getTab("display")->template(
- -name=>"templateId",
- -value=>$self->getValue("templateId"),
- -label=>$i18n->get("main template"),
- -hoverHelp=>$i18n->get("main template description"),
- -namespace=>"Matrix"
- );
- $tabform->getTab("display")->template(
- -name=>"detailTemplateId",
- -value=>$self->getValue("detailTemplateId"),
- -label=>$i18n->get("detail template"),
- -hoverHelp=>$i18n->get("detail template description"),
- -namespace=>"Matrix/Detail"
- );
- $tabform->getTab("display")->template(
- -name=>"ratingDetailTemplateId",
- -value=>$self->getValue("ratingDetailTemplateId"),
- -label=>$i18n->get("rating detail template"),
- -hoverHelp=>$i18n->get("rating detail template description"),
- -namespace=>"Matrix/RatingDetail"
- );
- $tabform->getTab("display")->template(
- -name=>"searchTemplateId",
- -value=>$self->getValue("searchTemplateId"),
- -label=>$i18n->get("search template"),
- -hoverHelp=>$i18n->get("search template description"),
- -namespace=>"Matrix/Search"
- );
- $tabform->getTab("display")->template(
- -name=>"compareTemplateId",
- -value=>$self->getValue("compareTemplateId"),
- -label=>$i18n->get("compare template"),
- -hoverHelp=>$i18n->get("compare template description"),
- -namespace=>"Matrix/Compare"
- );
- return $tabform;
-}
-
-#-------------------------------------------------------------------
-sub www_edit {
- my $self = shift;
- return $self->session->privilege->insufficient() unless $self->canEdit;
- return $self->session->privilege->locked() unless $self->canEditIfLocked;
- my $i18n = WebGUI::International->new($self->session, 'Asset_Wobject');
- my $addEdit = ($self->session->form->process("func") eq 'add') ? $i18n->get('add') : $i18n->get('edit');
- return $self->getAdminConsole->render($self->getEditForm->print, $self->addEditLabel);
-}
-
-#-------------------------------------------------------------------
-
-=head2 www_deleteImage ( )
-
-Deletes and attached file.
-
-=cut
-
-sub www_deleteImage {
- my $self = shift;
- my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId"));
- my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
- return $i18n->get('no edit rights') unless ($self->session->user->userId eq $listing->{maintainerId} || $self->canEdit);
- if ($listing->{storageId} ne "") {
- my $storage = WebGUI::Storage::Image->get($self->session, $listing->{storageId});
- $storage->delete;
- }
- return $self->www_editListing($listing, $i18n);
-}
-
-
-
-#-------------------------------------------------------------------
-sub www_editListing {
- my $self = shift;
- my $listing= shift || $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId"));
- my $i18n = shift || WebGUI::International->new($self->session,'Asset_Matrix');
- return $i18n->get('no edit rights') unless (($self->session->form->process("listingId") eq "new" && $self->session->user->isInGroup($self->get("groupToAdd"))) || $self->session->user->userId eq $listing->{maintainerId} || $self->canEdit);
- my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
- $f->hidden(
- -name=>"func",
- -value=>"editListingSave"
- );
- $f->hidden(
- -name=>"listingId",
- -value=>$self->session->form->process("listingId")
- );
- $f->text(
- -name=>"productName",
- -value=>$listing->{productName} || 'Undefined',
- -label=>$i18n->get('product name'),
- -hoverHelp=>$i18n->get('product name description'),
- -maxLength=>25
- );
- $f->text(
- -name=>"versionNumber",
- -value=>$listing->{versionNumber},
- -label=>$i18n->get('version number'),
- -hoverHelp=>$i18n->get('version number description'),
- );
- $f->url(
- -name=>"productUrl",
- -value=>$listing->{productUrl},
- -label=>$i18n->get('product url'),
- -hoverHelp=>$i18n->get('product url description'),
- );
- $f->image(
- name=>"screenshot",
- label=>$i18n->get("screenshot"),
- value=>$listing->{storageId},
- hoverHelp=>$i18n->get("screenshot help"),
- deleteFileUrl=>$self->getUrl("func=deleteImage;listingId=".$listing->{listingId}.";filename=")
- );
- $f->text(
- -name=>"manufacturerName",
- -value=>$listing->{manufacturerName},
- -label=>$i18n->get('manufacturer name'),
- -hoverHelp=>$i18n->get('manufacturer name description'),
- );
- $f->url(
- -name=>"manufacturerUrl",
- -value=>$listing->{manufacturerUrl},
- -label=>$i18n->get('manufacturer url'),
- );
- $f->textarea(
- -name=>"description",
- -value=>$listing->{description},
- -label=>$i18n->get('description'),
- );
- if ($self->canEdit) {
- $f->user(
- name=>"maintainerId",
- value=>$listing->{maintainerId},
- label=>$i18n->get('listing maintainer'),
- hoverHelp=>$i18n->get('listing maintainer description'),
- );
- }
- my %goodBad = (
- "No" => $i18n->get("no"),
- "Yes" => $i18n->get("yes"),
- "Free Add On" => $i18n->get("free"),
- "Costs Extra" => $i18n->get("extra"),
- "Limited" => $i18n->get("limited"),
- );
- foreach my $category ($self->getCategories()) {
- $f->raw(''.$category.' ');
- my $a;
- if ($self->session->form->process("listingId") ne "new") {
- $a = $self->session->db->read(
- "select a.name, a.fieldType, a.defaultValue, a.description, a.label, b.value, a.fieldId
- from Matrix_field a left join Matrix_listingData b on a.fieldId=b.fieldId and
- listingId=? where a.category=? and a.assetId=? order by a.label",
- [$self->session->form->process("listingId"), $category, $self->getId]);
- } else {
- $a = $self->session->db->read("select name, fieldType, defaultValue, description, label, fieldId
- from Matrix_field where category=".$self->session->db->quote($category)." and assetId=".$self->session->db->quote($self->getId));
- }
- while (my $field = $a->hashRef) {
- if ($field->{fieldType} eq "text") {
- $f->text(
- -name=>$field->{name},
- -value=>$field->{value} || $field->{defaultValue},
- -label=>$field->{label},
- -subtext=>" ".$field->{description}
- );
- } elsif ($field->{fieldType} eq "goodBad") {
- my $value = ($field->{value} || $field->{defaultValue} || $i18n->get("no"));
- $f->selectBox(
- -name=>$field->{name},
- -value=>[$value],
- -label=>$field->{label},
- -options=>\%goodBad,
- -subtext=>" ".$field->{description}
- );
- } elsif ($field->{fieldType} eq "textarea") {
- $f->textarea(
- -name=>$field->{name},
- -value=>$field->{value} || $field->{defaultValue},
- -label=>$field->{label},
- -subtext=>" ".$field->{description}
- );
- } elsif ($field->{fieldType} eq "url") {
- $f->url(
- -name=>$field->{name},
- -value=>$field->{value} || $field->{defaultValue},
- -label=>$field->{label},
- -subtext=>" ".$field->{description}
- );
- } elsif ($field->{fieldType} eq "combo") {
- my $value = ($field->{value} || $field->{defaultValue});
- $f->combo(
- -name=>$field->{name},
- -value=>[$value],
- -label=>$field->{label},
- -options=>$self->session->db->buildHashRef("select distinct value,value from Matrix_listingData
- where fieldId=".$self->session->db->quote($field->{fieldId})." and
- assetId=".$self->session->db->quote($self->getId)." order by value"),
- -subtext=>" ".$field->{description}
- );
- }
-
- }
- $a->finish;
- }
- $f->submit;
- return $self->processStyle($i18n->get('edit listing').$f->print);
-}
-
-
-#-------------------------------------------------------------------
-sub www_editListingSave {
- my $self = shift;
- my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId"));
- my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
- return $i18n->get('no edit rights') unless (($self->session->form->process("listingId") eq "new" && $self->session->user->isInGroup($self->get("groupToAdd"))) || $self->session->user->userId eq $listing->{maintainerId} || $self->canEdit);
- my %data = (
- listingId => $self->session->form->process("listingId"),
- lastUpdated => $self->session->datetime->time(),
- productName => $self->session->form->process("productName") || 'Undefined',
- productUrl => $self->session->form->process("productUrl"),
- manufacturerName => $self->session->form->process("manufacturerName"),
- manufacturerUrl => $self->session->form->process("manufacturerUrl"),
- description => $self->session->form->process("description"),
- versionNumber=>$self->session->form->process("versionNumber")
- );
-
- my $storageId = WebGUI::Form::Image->new($self->session,{name => 'screenshot', value => $listing->{storageId}})->getValue;
- if ($storageId) {
- $data{storageId} = $storageId;
- $data{filename} = WebGUI::Storage->get($self->session, $storageId)->getFiles->[0];
- }
-
- my $productName = $self->session->form->process("productName");
-
- my $isNew = 0;
- if ($self->session->form->process("listingId") eq "new") {
- $data{maintainerId} = $self->session->user->userId if ($self->session->form->process("listingId") eq "new");
-
- my $newTag = WebGUI::VersionTag->create($self->session, {
- name => $productName.' / '.$self->session->user->username,
- workflowId => 'pbworkflow000000000003' });
- my $oldTag = WebGUI::VersionTag->getWorking($self->session, 1);
- $newTag->setWorking;
-
- my $forum = $self->addChild({
- className=>"WebGUI::Asset::Wobject::Collaboration",
- title=>$productName,
- menuTitle=>$productName,
- url=>$productName,
- groupIdView=>$self->get('groupIdView'),
- groupIdEdit=>$self->get('groupIdEdit'),
- displayLastReply => 0,
- allowReplies => 1,
- threadsPerPage => 30,
- postsPerPage => 10,
- archiveAfter =>31536000,
- useContentFilter => 1,
- filterCode => 'javascript',
- richEditor => "PBrichedit000000000002",
- attachmentsPerPost => 0,
- editTimeout => 3600,
- addEditStampToPosts => 0,
- usePreview => 1,
- sortOrder => 'desc',
- sortBy => 'assetData.revisionDate',
- rssTemplateId=>'PBtmpl0000000000000142',
- notificationTemplateId=>'PBtmpl0000000000000027',
- searchTemplateId=>'PBtmpl0000000000000031',
- postFormTemplateId=>'PBtmpl0000000000000029',
- threadTemplateId=>'PBtmpl0000000000000032',
- collaborationTemplateId=>'PBtmpl0000000000000026',
- karmaPerPost =>0,
- karmaSpentToRate => 0,
- approvalWorkflow=>"pbworkflow000000000003",
- karmaRatingMultiplier => 0,
- moderatePosts => 0,
- moderateGroupId => $self->get('groupIdEdit'),
- postGroupId => $self->get('groupIdView'),
- styleTemplateId => $self->get('styleTemplateId'),
- printableStyleTemplateId => $self->get('printableStyleTemplateId'),
- });
- $newTag->requestCommit;
- $newTag->clearWorking;
- $oldTag->setWorking if defined $oldTag;
-
- $data{forumId} = $forum->getId;
- $data{status} = "pending";
- $isNew = 1;
- }
- else {
- my $forum = WebGUI::Asset::Wobject::Collaboration->new($self->session, $listing->{forumId});
- if ($forum && $forum->get('title') ne $productName) {
- my $oldTag = WebGUI::VersionTag->getWorking($self->session, 1);
- my $newTag = WebGUI::VersionTag->create($self->session, {
- name => $productName.' / '.$self->session->user->username,
- workflowId => 'pbworkflow000000000003' });
- $newTag->setWorking;
- $forum->addRevision({
- title => $productName,
- menuTitle => $productName,
- url => $productName,
- });
- $newTag->requestCommit;
- $newTag->clearWorking;
- $oldTag->setWorking
- if defined $oldTag;
- }
- my $forum = WebGUI::
- }
- $data{maintainerId} = $self->session->form->process("maintainerId") if ($self->canEdit);
- $data{assetId} = $self->getId;
- my $listingId = $self->session->db->setRow("Matrix_listing","listingId",\%data);
- if ($data{status} eq "pending" && !$listing->{approvalMessageId}) {
- my $approvalMessage = WebGUI::Inbox->new($self->session)->addMessage({
- status=>'pending',
- groupId=>$self->get("groupIdEdit"),
- userId=>$self->get("ownerUserId"),
- subject=>"New Listing Added",
- message=>"A new listing, ".$data{productName}.", is waiting to be added.\n\n".$self->session->url->getSiteURL()."/".$self->formatURL("viewDetail",$listingId)
- });
- $self->session->db->setRow("Matrix_listing","listingId",{listingId=>$listingId, approvalMessageId=>$approvalMessage->getId});
- }
- my $a = $self->session->db->read("select fieldId, name, fieldType from Matrix_field");
- while (my ($id, $name, $type) = $a->array) {
- my $value;
- if ($type eq "goodBad") {
- $value = $self->session->form->selectBox($name);
- } else {
- $value = $self->session->form->process($name,$type);
- }
- $self->session->db->write("replace into Matrix_listingData (assetId, listingId, fieldId, value) values (
- ".$self->session->db->quote($self->getId).", ".$self->session->db->quote($listingId).", ".$self->session->db->quote($id).", ".$self->session->db->quote($value).")");
- }
- $a->finish;
- return $self->www_viewDetail($listingId);
-}
-
-#-------------------------------------------------------------------
-sub www_editField {
- my $self = shift;
- return $self->session->privilege->insufficient() unless($self->canEdit);
- my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
- my $field = $self->session->db->getRow("Matrix_field","fieldId",$self->session->form->process("fieldId"));
- my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
- $f->hidden(
- -name=>"func",
- -value=>"editFieldSave"
- );
- $f->hidden(
- -name=>"fieldId",
- -value=>$self->session->form->process("fieldId")
- );
- $f->text(
- -name=>"name",
- -value=>$field->{name},
- -label=>$i18n->get('field name'),
- -hoverHelp=>$i18n->get('field name description'),
- );
- $f->text(
- -name=>"label",
- -value=>$field->{label},
- -label=>$i18n->get('field label'),
- -hoverHelp=>$i18n->get('field label description'),
- );
- $f->selectBox(
- -name=>"fieldType",
- -value=>[$field->{fieldType}],
- -label=>$i18n->get('field type'),
- -hoverHelp=>$i18n->get('field type description'),
- -options=>{
- 'goodBad' => $i18n->get('good bad'),
- 'text' => $i18n->get('text'),
- 'url' => $i18n->get('url'),
- 'textarea' => $i18n->get('text area'),
- 'combo' => $i18n->get('combo'),
- }
- );
- $f->textarea(
- -name=>"description",
- -value=>$field->{description},
- -label=>$i18n->get('field description'),
- -hoverHelp=>$i18n->get('field description description'),
- );
- $f->text(
- -name=>"defaultValue",
- -value=>$field->{defaultValue},
- -label=>$i18n->get('default value'),
- -hoverHelp=>$i18n->get('default value description'),
- );
- my %cats;
- foreach my $category ($self->getCategories) {
- $cats{$category} = $category;
- }
- $f->selectBox(
- -name=>"category",
- -value=>[$field->{category}],
- -label=>$i18n->get('category'),
- -hoverHelp=>$i18n->get('category description'),
- -options=>\%cats
- );
- $f->submit;
- return $self->processStyle($i18n->get('edit field').$f->print);
-}
-
-
-#-------------------------------------------------------------------
-sub www_editFieldSave {
- my $self = shift;
- return $self->session->privilege->insufficient() unless($self->canEdit);
- $self->session->db->setRow("Matrix_field","fieldId",{
- fieldId=>$self->session->form->process("fieldId"),
- name=>$self->session->form->process("name"),
- label=>$self->session->form->process("label"),
- fieldType=>$self->session->form->process("fieldType"),
- description=>$self->session->form->process("description"),
- defaultValue=>$self->session->form->process("defaultValue"),
- category=>$self->session->form->process("category"),
- assetId=>$self->getId
- });
- return $self->www_listFields();
-}
-
-#-------------------------------------------------------------------
-sub www_listFields {
- my $self = shift;
- return $self->session->privilege->insufficient() unless($self->canEdit);
- my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
- my $output = sprintf $i18n->get('list fields'),
- $self->getUrl("func=editField;fieldId=new");
- my $sth = $self->session->db->read("select fieldId, label from Matrix_field where assetId=".$self->session->db->quote($self->getId)." order by label");
- while (my ($id, $label) = $sth->array) {
- $output .= $self->session->icon->delete("func=deleteField;fieldId=".$id, $self->get("url"), $i18n->get("delete field confirm"))
- .$self->session->icon->edit("func=editField;fieldId=".$id)
- .' '.$label." \n";
- }
- $sth->finish;
- return $self->processStyle($output);
-}
-
-
-#-------------------------------------------------------------------
-sub www_rate {
- my $self = shift;
- my $hasRated = $self->hasRated($self->session->form->process("listingId"));
- my $sameRating = 1;
- my $first = 1;
- my $lastRating;
- foreach my $category ($self->getCategories) {
- if ($first) {
- $first=0;
- } else {
- if ($lastRating != $self->session->form->process($category)) {
- $sameRating = 0;
- }
- }
- $lastRating = $self->session->form->process($category);
- }
- return $self->www_viewDetail("",1) if ($hasRated || $sameRating); # Throw out ratings that are all the same number, or if the user rates twice.
- $self->setRatings($self->session->form->process("listingId"),$self->session->form->paramsHashRef);
- return $self->www_viewDetail;
-}
-
-#-------------------------------------------------------------------
-sub www_search {
- my $self = shift;
- my %var;
- my @list = $self->session->db->buildArray("select listingId from Matrix_listing");
- if ($self->session->form->process("doit")) {
- my $count;
- my $keyword;
- if ($self->session->form->process("keyword")) {
- $keyword = " and (a.value like ".$self->session->db->quote('%'.$self->session->form->process("keyword").'%')." or a.value='Any')";
- }
- my $sth = $self->session->db->read("select name,fieldType from Matrix_field");
- while (my ($name,$fieldType) = $sth->array) {
- next unless ($self->session->form->process($name));
- push(@list,0);
- my $where;
- if ($fieldType ne "goodBad") {
- $where = "("
- ."a.value like ".$self->session->db->quote("%".$self->session->form->process($name)."%")
- ." or a.value='Any'"
- ." or a.value='Free'"
- .")";
- } else {
- $where = "a.value<>'no'";
- }
- @list = $self->session->db->buildArray("select a.listingId from Matrix_listingData a left join Matrix_field b
- on (a.fieldId=b.fieldId)
- where a.listingId in (".$self->session->db->quoteAndJoin(\@list).") and $where and b.name=".$self->session->db->quote($name));
- $count = scalar(@list);
- last unless ($count > 0);
- }
- $sth->finish;
- if ($count > 1 && $count < 11) {
- return $self->www_compare(@list);
- } elsif ($count == 1) {
- return $self->www_viewDetail($list[0]);
- } else {
- my $max = $self->session->user->isInGroup($self->get("privilegedGroup")) ? $self->get("maxComparisonsPrivileged") : $self->get("maxComparisons");
- $var{isTooMany} = ($count>$max);
- $var{isTooFew} = ($count<2);
- }
- }
- $var{'isLoggedIn'} = ($self->session->user->isRegistered);
- $var{'compare.form'} = $self->getCompareForm(@list);
- $var{'form.header'} = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl})
- .WebGUI::Form::hidden($self->session,{
- name=>"doit",
- value=>"1"
- })
- .WebGUI::Form::hidden($self->session,{
- name=>"func",
- value=>"search"
- });
- $var{'form.footer'} = "";
- $var{'form.keyword'} = WebGUI::Form::text($self->session,{
- name=>"keyword",
- value=>$self->session->form->process("keyword")
- });
- $var{'form.submit'} = WebGUI::Form::submit($self->session,{
- value=>"search"
- });
- foreach my $category ($self->getCategories()) {
- my $sth = $self->session->db->read("select name, fieldType, label, description from Matrix_field where category = ".$self->session->db->quote($category)." order by label");
- my @loop;
- while (my $data = $sth->hashRef) {
- if ($data->{fieldType} ne "goodBad") {
- $data->{form} = WebGUI::Form::text($self->session,{
- name=>$data->{name},
- value=>$self->session->form->process($data->{name})
- });
- } else {
- $data->{form} = WebGUI::Form::checkbox($self->session,{
- name=>$data->{name},
- value=>"1",
- checked=>$self->session->form->process($data->{name})
- });
- }
- push(@loop,$data);
- }
- $sth->finish;
- $var{$self->session->url->urlize($category)."_loop"} = \@loop;
- }
- return $self->processStyle($self->processTemplate(\%var,$self->get("searchTemplateId")));
-}
-
-
-#-------------------------------------------------------------------
sub view {
- my $self = shift;
- if ($self->session->user->isVisitor) {
- my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get;
- return $out if $out;
- }
- my (%var);
- $var{'compare.form'} = $self->getCompareForm;
- $var{'search.url'} = $self->getUrl("func=search");
- $var{'isLoggedIn'} = ($self->session->user->isRegistered);
- $var{'field.list.url'} = $self->getUrl('func=listFields');
- $var{'listing.add.url'} = $self->formatURL("editListing","new");
+ my $self = shift;
+ my $session = $self->session;
- my $data = $self->session->db->quickHashRef("select views, productName, listingId from Matrix_listing
- where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by views desc limit 1");
- $var{'best.views.url'} = $self->formatURL("viewDetail",$data->{listingId});
- $var{'best.views.count'} = $data->{views};
- $var{'best.views.name'} = $data->{productName};
- $data = $self->session->db->quickHashRef("select compares, productName, listingId from Matrix_listing
- where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by compares desc limit 1");
- $var{'best.compares.url'} = $self->formatURL("viewDetail",$data->{listingId});
- $var{'best.compares.count'} = $data->{compares};
- $var{'best.compares.name'} = $data->{productName};
- $data = $self->session->db->quickHashRef("select clicks, productName, listingId from Matrix_listing
- where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by clicks desc limit 1");
- $var{'best.clicks.url'} = $self->formatURL("viewDetail",$data->{listingId});
- $var{'best.clicks.count'} = $data->{clicks};
- $var{'best.clicks.name'} = $data->{productName};
- my (@best,@worst);
- foreach my $category ($self->getCategories) {
- my $sql = "
- select
- Matrix_listing.productName,
- Matrix_listing.listingId,
- Matrix_ratingSummary.meanValue,
- Matrix_ratingSummary.medianValue,
- Matrix_ratingSummary.countValue
- from
- Matrix_listing
- left join
- Matrix_ratingSummary
- on
- Matrix_listing.listingId=Matrix_ratingSummary.listingId and
- Matrix_ratingSummary.category=".$self->session->db->quote($category)."
- where
- Matrix_listing.assetId=".$self->session->db->quote($self->getId)." and
- Matrix_listing.status='approved' and
- Matrix_ratingSummary.countValue >= 10
- order by
- Matrix_ratingSummary.meanValue
- ";
- $data = $self->session->db->quickHashRef($sql." desc limit 1");
- push(@best,{
- url=>$self->formatURL("viewDetail",$data->{listingId}),
- category=>$category,
- name=>$data->{productName},
- mean=>$data->{meanValue},
- median=>$data->{medianValue},
- count=>$data->{countValue}
- });
- $data = $self->session->db->quickHashRef($sql." asc limit 1");
- push(@worst,{
- url=>$self->formatURL("viewDetail",$data->{listingId}),
- category=>$category,
- name=>$data->{productName},
- mean=>$data->{meanValue},
- median=>$data->{medianValue},
- count=>$data->{countValue}
- });
- }
- $var{'best_rating_loop'} = \@best;
- $var{'worst_rating_loop'} = \@worst;
- $var{'ratings.details.url'} = $self->getUrl("func=viewRatingDetails");
- $data = $self->session->db->quickHashRef("select lastUpdated, productName, listingId from Matrix_listing
- where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by lastUpdated desc limit 1");
- my @lastUpdated;
- my $sth = $self->session->db->read("select listingId,lastUpdated,productName from Matrix_listing order by lastUpdated desc limit 20");
- while (my ($listingId, $lastUpdated, $productName) = $sth->array) {
- push(@lastUpdated, {
- url => $self->formatURL("viewDetail",$listingId),
- name=>$productName,
- lastUpdated=>$self->session->datetime->epochToHuman($lastUpdated,"%z")
- });
- }
- $var{'last_updated_loop'} = \@lastUpdated;
- $var{'best.updated.url'} = $self->formatURL("viewDetail",$data->{listingId});
- $var{'best.updated.date'} = $self->session->datetime->epochToHuman($data->{lastUpdated},"%z");;
- $var{'best.updated.name'} = $data->{productName};
-
- # site stats
- ($var{'user.count'}) = $self->session->db->quickArray("select count(*) from users");
- ($var{'current.user.count'}) = $self->session->db->quickArray("select count(*)+0 from userSession where lastPageView>".($self->session->datetime->time()-600));
- ($var{'listing.count'}) = $self->session->db->quickArray("select count(*) from Matrix_listing where status = 'approved' and assetId=".$self->session->db->quote($self->getId));
- $sth = $self->session->db->read("select listingId,productName from Matrix_listing where status='pending' and assetId=?",[$self->getId]);
- while (my ($id,$name) = $sth->array) {
- push(@{$var{pending_list}},{
- url=>$self->formatURL("viewDetail",$id),
- productName=>$name
- });
- }
- $sth->finish;
- my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
- if ($self->session->user->isVisitor) {
- WebGUI::Cache->new($self->session,"view_".$self->getId)->set($out,$self->get("visitorCacheTimeout"));
- }
- return $out;
+ #This automatically creates template variables for all of your wobject's properties.
+ my $var = $self->get;
+
+ #This is an example of debugging code to help you diagnose problems.
+ #WebGUI::ErrorHandler::warn($self->get("templateId"));
+
+ return $self->processTemplate($var, undef, $self->{_viewTemplate});
}
-
+
#-------------------------------------------------------------------
-=head2 www_view ( )
+=head2 www_deleteAttribute ( )
-See WebGUI::Asset::Wobject::www_view() for details.
+Deletes an Attribute, including listing data for this attribute.
=cut
-sub www_view {
- my $self = shift;
- $self->session->http->setCacheControl($self->get("visitorCacheTimeout")) if ($self->session->user->isVisitor);
- $self->SUPER::www_view(@_);
+sub www_deleteAttribute {
+ my $self = shift;
+ my $attributeId = $self->session->form->process("attributeId");
+ return $self->session->privilege->insufficient() unless $self->canEdit;
+
+ $self->deleteAttribute($attributeId);
+
+ return $self->www_listAttributes;
}
#-------------------------------------------------------------------
-sub www_viewDetail {
- my $self = shift;
- my $listingId = shift || $self->session->form->process("listingId");
- my $hasRated = shift || $self->hasRated($listingId);
- my %var;
- my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
- my $listing = $self->session->db->getRow("Matrix_listing","listingId",$listingId);
- my $forum = WebGUI::Asset::Wobject::Collaboration->new($self->session, $listing->{forumId});
- if ($listing->{storageId} && $listing->{filename}) {
- my $storage = WebGUI::Storage::Image->get($self->session, $listing->{storageId});
- $var{screenshot} = $storage->getUrl($listing->{filename});
- $var{thumbnail} = $storage->getThumbnailUrl($listing->{filename});
- }
- $var{"discussion"} = $forum && $forum->view;
- $var{'isLoggedIn'} = ($self->session->user->isRegistered);
- if ($self->session->form->process("do") eq "sendEmail" && $self->session->form->process("verify","captcha")) {
- if ($self->session->form->process("body") ne "") {
- my $u = WebGUI::User->new($self->session, $listing->{maintainerId});
- my $mail = WebGUI::Mail::Send->create($self->session, {to=>$u->profileField("email"),subject=>$listing->{productName}." - ".$self->session->form->process("subject"),from=>$self->session->form->process("from")});
- $mail->addText($self->session->form->process("body"));
- $mail->addFooter;
- $mail->queue;
- }
- $var{'email.wasSent'} = 1;
- } else {
- $self->incrementCounter($listingId,"views");
- }
- $var{'edit.url'} = $self->formatURL("editListing",$listingId);
- $var{id} = $listingId;
- $var{'user.canEdit'} = ($self->session->user->userId eq $listing->{maintainerId} || $self->canEdit);
- $var{'user.canApprove'} = $self->canEdit;
- $var{'approve.url'} = $self->getUrl("func=approveListing;listingId=".$listingId);
- $var{'delete.url'} = $self->getUrl("func=deleteListing;listingId=".$listingId);
- $var{'isPending'} = ($listing->{status} eq "pending");
- $var{'lastUpdated.epoch'} = $listing->{lastupdated};
- $var{'lastUpdated.date'} = $self->session->datetime->epochToHuman($listing->{lastUpdated},"%z");
- $var{description} = $listing->{description};
- $var{productName} = $listing->{productName};
- $var{productUrl} = $listing->{productUrl};
- $var{'productUrl.click'} = $self->formatURL("click",$listingId);
- $var{manufacturerName} = $listing->{manufacturerName};
- $var{manufacturerUrl} = $listing->{manufacturerUrl};
- $var{'manufacturerUrl.click'} = $self->getUrl("m=1;func=click;listingId=".$listingId);
- $var{versionNumber} = $listing->{versionNumber};
- my $f = WebGUI::HTMLForm->new($self->session,
- -extras=>'class="content"',
- -tableExtras=>'class="content"'
- );
- $f->hidden(
- -name=>"func",
- -value=>"viewDetail"
- );
- $f->hidden(
- -name=>"do",
- -value=>"sendEmail"
- );
- $f->hidden(
- -name=>"listingId",
- -value=>$listingId
- );
- $f->captcha(
- -name=>"verify"
- );
- $f->email(
- -extras=>'class="content"',
- -name=>"from",
- -value=>$self->session->user->profileField("email"),
- -label=>$i18n->get('your email'),
- );
- $f->selectBox(
- -name=>"subject",
- -extras=>'class="content"',
- -options=>{
- $i18n->get('report error')=>"Report an error.",
- $i18n->get('general comment')=>"General comment.",
- },
- -label=>$i18n->get('request type'),
- );
- $f->textarea(
- -rows=>4,
- -extras=>'class="content"',
- -columns=>35,
- -name=>"body",
- -label=>$i18n->get('comment'),
- );
- $f->submit(
- -extras=>'class="content"',
- -value=>"Send..."
- );
- $var{'email.form'} = $f->print;
- $var{views} = $listing->{views};
- $var{compares} = $listing->{compares};
- $var{clicks} = $listing->{clicks};
- my $sth = $self->session->db->read("select a.value, b.name, b.label, b.description, category, fieldType from Matrix_listingData a left join
- Matrix_field b on a.fieldId=b.fieldId and b.assetId=? where listingId=? order by b.label",[$self->getId, $listingId]);
- my %goodBad = (
- "No" => $i18n->get("no"),
- "Yes" => $i18n->get("yes"),
- "Free Add On" => $i18n->get("free"),
- "Costs Extra" => $i18n->get("extra"),
- "Limited" => $i18n->get("limited"),
- );
- while (my $data = $sth->hashRef) {
- $data->{class} = lc($data->{value});
- $data->{class} =~ s/\s/_/g;
- $data->{class} =~ s/\W//g;
- if ($data->{fieldType} eq 'goodBad') {
- $data->{value} = $goodBad{$data->{value}};
- }
- my $cat = $self->session->url->urlize($data->{category})."_loop";
- push(@{$var{$cat}},$data);
- }
- $sth->finish;
- my %rating;
- tie %rating, 'Tie::IxHash';
- %rating = (
- 1=>"1 - Worst",
- 2=>2,
- 3=>3,
- 4=>4,
- 5=>"5 - Respectable",
- 6=>6,
- 7=>7,
- 8=>8,
- 9=>9,
- 10=>"10 - Best"
- );
- my $ratingsTable = '';
- $f->submit(
- -extras=>'class="ratingForm"',
- -value=>"Rate",
- -label=>''.$i18n->get('show ratings').' '
- );
- if ($hasRated) {
- $var{'ratings'} = $ratingsTable;
- } else {
- $var{'ratings'} = $f->print;
- }
- return $self->processStyle($self->processTemplate(\%var,$self->get("detailTemplateId")));
+
+=head2 www_edit ( )
+
+Web facing method which is the default edit page. This method is entirely
+optional. Take it out unless you specifically want to set a submenu in your
+adminConsole views.
+
+=cut
+
+#sub www_edit {
+# my $self = shift;
+# return $self->session->privilege->insufficient() unless $self->canEdit;
+# return $self->session->privilege->locked() unless $self->canEditIfLocked;
+# my $i18n = WebGUI::International->new($self->session, "Asset_Matrix");
+# return $self->getAdminConsole->render($self->getEditForm->print, $i18n->get("edit title"));
+#}
+
+#-------------------------------------------------------------------
+
+=head2 www_editAttribute ( )
+
+Shows a form to edit or add an attribute.
+
+=cut
+
+sub www_editAttribute {
+ my $self = shift;
+ my $session = $self->session;
+ my ($attributeId, $attribute);
+
+ return $session->privilege->insufficient() unless $self->canEdit;
+ my $i18n = WebGUI::International->new($session, "Asset_Matrix");
+
+ $attributeId = $session->form->process("attributeId") || 'new';
+
+ unless($attributeId eq 'new'){
+ $attribute = $self->getAttribute($attributeId);
+ }
+
+ my $form = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
+ $form->hidden(
+ -name =>"func",
+ -value =>"editAttributeSave"
+ );
+ $form->hidden(
+ -name =>"attributeId",
+ -value =>$attributeId,
+ );
+ $form->text(
+ -name =>"name",
+ -value =>$attribute->{name},
+ -label =>$i18n->get('attribute name label'),
+ -hoverHelp =>$i18n->get('attribute name description'),
+ );
+ $form->textarea(
+ -name =>"description",
+ -value =>$attribute->{description},
+ -label =>$i18n->get('attribute description label'),
+ -hoverHelp =>$i18n->get('attribute description description'),
+ );
+ $form->matrixFieldType(
+ -name =>"fieldType",
+ -value =>$attribute->{fieldType},
+ -label =>$i18n->get('fieldType label'),
+ -hoverHelp =>$i18n->get('fieldType description'),
+ );
+ my $defaultValueForm = WebGUI::Form::Text($self->session, {
+ name=>"defaultValue",
+ value=>$attribute->{defaultValue},
+ #subtext=>' '.$i18n->get('default value subtext'),
+ #width=>200,
+ #height=>60,
+ resizable=>0,
+ });
+ my $optionsForm = WebGUI::Form::Textarea($self->session, {
+ name=>"options",
+ value=>$attribute->{options},
+ });
+
+ my $html = "\n\n";
+ $html .= "\t\n";
+ $html .= "\t
\n";
+ $html .= "\t
\n";
+
+ $html .= "\t"
+ .$i18n->get('attribute defaultValue label')
+ ."".$i18n->get('attribute defaultValue description')."
"
+ .""
+ .$defaultValueForm." "
+ ."\t\n \n";
+
+ $html .= "\t"
+ .$i18n->get('attribute options label')
+ ."".$i18n->get('attribute options description')."
"
+ .""
+ .$optionsForm." "
+ ."\t\n \n";
+
+
+ $html .= "\t
";
+ $html .= "\t\n
\t\n
\n";
+ $html .= " ";
+
+ $html .= "\n";
+
+ $form->raw($html);
+=cut
+ $form->text(
+ -name =>"defaultValue",
+ -value =>$attribute->{defaultValue},
+ -label =>$i18n->get('attribute defaultValue label'),
+ -hoverHelp =>$i18n->get('attribute defaultValue description'),
+ );
+ $form->textarea(
+ -name =>"options",
+ -value =>$attribute->{options},
+ -label =>$i18n->get('attribute options label'),
+ -hoverHelp =>$i18n->get('attribute options description'),
+ );
+=cut
+ $form->selectBox(
+ -name =>"category",
+ -value =>[$attribute->{category}],
+ -label =>$i18n->get('category label'),
+ -hoverHelp =>$i18n->get('category description'),
+ -options =>$self->getCategories,
+ );
+ $form->submit;
+ return $self->getAdminConsole->render($form->print, $i18n->get('edit attribute title'));
}
+#-------------------------------------------------------------------
-#-----------------------------------------------
-sub www_viewRatingDetails {
- my $self = shift;
- my %var;
- my @ratingloop;
- foreach my $category ($self->getCategories) {
- my @detailloop;
- my $sql = "
- select
- Matrix_listing.productName,
- Matrix_listing.listingId,
- Matrix_ratingSummary.meanValue,
- Matrix_ratingSummary.medianValue,
- Matrix_ratingSummary.countValue
- from
- Matrix_listing
- left join
- Matrix_ratingSummary
- on
- Matrix_listing.listingId=Matrix_ratingSummary.listingId and
- Matrix_ratingSummary.category=".$self->session->db->quote($category)."
- where
- Matrix_listing.assetId=".$self->session->db->quote($self->getId)." and
- Matrix_listing.status='approved' and
- Matrix_ratingSummary.countValue > 0
- order by
- Matrix_ratingSummary.meanValue desc
- ";
- my $sth = $self->session->db->read($sql);
- while (my $data = $sth->hashRef) {
- push(@detailloop,{
- url=>$self->formatURL("viewDetail",$data->{listingId}),
- mean=>$data->{meanValue},
- median=>$data->{medianValue},
- count=>$data->{countValue},
- name=>$data->{productName}
- });
- }
- $sth->finish;
- push(@ratingloop,{
- category=>$category,
- detail_loop=>\@detailloop
- });
- }
- $var{rating_loop} = \@ratingloop;
- return $self->processStyle($self->processTemplate(\%var,$self->get("ratingDetailTemplateId")));
+=head2 www_editAttributeSave ( )
+
+Processes and saves an attribute.
+
+=cut
+
+sub www_editAttributeSave {
+ my $self = shift;
+ my $session = $self->session;
+ my $form = $session->form;
+
+ return $session->privilege->insufficient() unless $self->canEdit;
+
+ my $attributeProperties = {
+ attributeId =>$form->process("attributeId") || 'new',
+ assetId =>$self->getId,
+ name =>$form->process('name'),
+ description =>$form->process('description'),
+ fieldType =>$form->process('fieldType'),
+ options =>$form->process('options'),
+ defaultValue =>$form->process('defaultValue'),
+ category =>$form->process('category'),
+ };
+
+ $self->editAttributeSave($attributeProperties);
+
+ return $self->www_listAttributes;
}
+#-------------------------------------------------------------------
-
+=head2 www_listAttributes ( )
+
+Lists all attributes of this Matrix.
+
+=cut
+
+sub www_listAttributes {
+ my $self = shift;
+ my $session = $self->session;
+
+ return $session->privilege->insufficient() unless($self->canEdit);
+
+ my $i18n = WebGUI::International->new($session,'Asset_Matrix');
+ my $output = ""
+ .$i18n->get('add attribute label')." ";
+
+ my $attributes = $session->db->read("select attributeId, name from Matrix_attribute where assetId=? order by name"
+ ,[$self->getId]);
+ while (my $attribute = $attributes->hashRef) {
+ $output .= $session->icon->delete("func=deleteAttribute;attributeId=".$attribute->{attributeId}
+ , $self->getUrl,$i18n->get("delete attribute confirm message"))
+ .$session->icon->edit("func=editAttribute;attributeId=".$attribute->{attributeId})
+ .' '.$attribute->{name}." \n";
+ }
+ return $self->getAdminConsole->render($output, $i18n->get('list attributes title'));
+}
+
+#-------------------------------------------------------------------
+# Everything below here is to make it easier to install your custom
+# wobject, but has nothing to do with wobjects in general
+#-------------------------------------------------------------------
+# cd /data/WebGUI/lib
+# perl -MWebGUI::Asset::Wobject::Matrix -e install www.example.com.conf [ /path/to/WebGUI ]
+# - or -
+# perl -MWebGUI::Asset::Wobject::Matrix -e uninstall www.example.com.conf [ /path/to/WebGUI ]
+#-------------------------------------------------------------------
+
+
+use base 'Exporter';
+our @EXPORT = qw(install uninstall);
+use WebGUI::Session;
+
+#-------------------------------------------------------------------
+sub install {
+ my $config = $ARGV[0];
+ my $home = $ARGV[1] || "/data/WebGUI";
+ die "usage: perl -MWebGUI::Asset::Wobject::Matrix -e install www.example.com.conf\n" unless ($home && $config);
+ print "Installing asset.\n";
+ my $session = WebGUI::Session->open($home, $config);
+ $session->config->addToArray("assets","WebGUI::Asset::Wobject::Matrix");
+ $session->db->write("create table Matrix (
+ assetId varchar(22) binary not null,
+ revisionDate bigint not null,
+ templateId varchar(22) not null,
+ searchTemplateId varchar(22) not null,
+ compareTemplateId varchar(22) not null,
+ detailTemplateId varchar(22) not null,
+ maxComparisons int(11) not null default 10,
+ maxComparisonsPrivileged int(11) not null default 25,
+ defaultSort varchar(22) not null default 'score',
+ categories text,
+ compareColorNo varchar(22) not null default '#ffaaaa',
+ compareColorLimited varchar(22) not null default '#ffffaa',
+ compareColorCostsExtra varchar(22) not null default '#ffffaa',
+ compareColorFreeAddOn varchar(22) not null default '#ffffaa',
+ compareColorYes varchar(22) not null default '#aaffaa',
+ submissionApprovalWorkflowId varchar(22) not null,
+ ratingsDuration int(11) not null default 7776000,
+ primary key (assetId, revisionDate)
+ )");
+ $session->db->write("create table Matrix_attribute (
+ assetId varchar(22) binary not null,
+ attributeId varchar(22) binary not null,
+ name varchar(255) not null,
+ description text,
+ fieldType varchar(255) not null default 'MatrixField',
+ category varchar(22) not null,
+ options text,
+ defaultValue varchar(255),
+ primary key (attributeId)
+ )");
+ $session->var->end;
+ $session->close;
+ print "Done. Please restart Apache.\n";
+}
+
+#-------------------------------------------------------------------
+sub uninstall {
+ my $config = $ARGV[0];
+ my $home = $ARGV[1] || "/data/WebGUI";
+ die "usage: perl -MWebGUI::Asset::Wobject::Matrix -e uninstall www.example.com.conf\n" unless ($home && $config);
+ print "Uninstalling asset.\n";
+ my $session = WebGUI::Session->open($home, $config);
+ $session->config->deleteFromArray("assets","WebGUI::Asset::Wobject::Matrix");
+ my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::Wobject::Matrix'");
+ while (my ($id) = $rs->array) {
+ my $asset = WebGUI::Asset->new($session, $id, "WebGUI::Asset::Wobject::Matrix");
+ $asset->purge if defined $asset;
+ }
+ $session->db->write("drop table Matrix");
+ $session->var->end;
+ $session->close;
+ print "Done. Please restart Apache.\n";
+}
1;
-
diff --git a/lib/WebGUI/Form/MatrixCompare.pm b/lib/WebGUI/Form/MatrixCompare.pm
new file mode 100644
index 000000000..476925235
--- /dev/null
+++ b/lib/WebGUI/Form/MatrixCompare.pm
@@ -0,0 +1,156 @@
+package WebGUI::Form::MatrixCompare;
+
+=head1 LEGAL
+
+ -------------------------------------------------------------------
+ WebGUI is Copyright 2001-2008 Plain Black Corporation.
+ -------------------------------------------------------------------
+ Please read the legal notices (docs/legal.txt) and the license
+ (docs/license.txt) that came with this distribution before using
+ this software.
+ -------------------------------------------------------------------
+ http://www.plainblack.com info@plainblack.com
+ -------------------------------------------------------------------
+
+=cut
+
+use strict;
+use base 'WebGUI::Form::SelectBox';
+use Tie::IxHash;
+use WebGUI::International;
+use WebGUI::Pluggable;
+use WebGUI::Utility;
+
+=head1 NAME
+
+Package WebGUI::Form::MatrixCompare
+
+=head1 DESCRIPTION
+
+Creates a form control that will allow you to select a field type that can be used by the Matrix wobject.
+It's meant to be used in conjunction with the DynamicField form control.
+
+=head1 SEE ALSO
+
+This is a subclass of WebGUI::Form::SelectBox.
+
+=head1 METHODS
+
+The following methods are specifically available from this class. Check the superclass for additional methods.
+
+=cut
+
+#-------------------------------------------------------------------
+
+=head2 areOptionsSettable ( )
+
+Returns 0.
+
+=cut
+
+sub areOptionsSettable {
+ return 0;
+}
+
+#-------------------------------------------------------------------
+
+=head2 definition ( [ additionalTerms ] )
+
+See the super class for additional details.
+
+=head3 additionalTerms
+
+The following additional parameters have been added via this sub class.
+
+=head4 types
+
+An array reference containing the form control types to be selectable. Defaults to all available dynamic types.
+
+=head4 label
+
+A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName().
+
+=cut
+
+sub definition {
+ my $class = shift;
+ my $session = shift;
+ my $definition = shift || [];
+ my $i18n = WebGUI::International->new($session);
+ push(@{$definition}, {
+ label=>{
+ defaultValue=>$i18n->get("matrix compare","WebGUI")
+ },
+ });
+ return $class->SUPER::definition($session, $definition);
+}
+
+#-------------------------------------------------------------------
+
+=head2 getName ( session )
+
+Returns the human readable name of this control.
+
+=cut
+
+sub getName {
+ my ($self, $session) = @_;
+ return WebGUI::International->new($session, 'WebGUI')->get('matrix compare');
+}
+
+#-------------------------------------------------------------------
+
+=head2 getValue ( )
+
+Returns either what's posted or if nothing comes back it returns "text".
+
+=cut
+
+sub getValue {
+ my $self = shift;
+ my $compareValue = $self->SUPER::getValue(@_);
+ $compareValue =~ s/[^\w]//g;
+ return $compareValue || 0;
+}
+
+#-------------------------------------------------------------------
+
+=head2 isDynamicCompatible ( )
+
+Returns 0.
+
+=cut
+
+sub isDynamicCompatible {
+ return 0;
+}
+
+#-------------------------------------------------------------------
+
+=head2 toHtml ( )
+
+Renders a fieldType selector.
+
+=cut
+
+sub toHtml {
+ my $self = shift;
+ my $i18n = WebGUI::International->new($session,'Form_MatrixCompare');
+ my %options;
+ tie %options, "Tie::IxHash";
+ %options = (
+ 0 => $i18n->get('no'),
+ 1 => $i18n->get('limited'),
+ 2 => $i18n->get('costs extra'),
+ 3 => $i18n->get('free add on'),
+ 4 => $i18n->get('yes'),
+ );
+ $self->set('options', \%options);
+ $self->set('defaultValue',0);
+ return $self->SUPER::toHtml();
+}
+
+
+
+1;
+
diff --git a/lib/WebGUI/Form/MatrixFieldType.pm b/lib/WebGUI/Form/MatrixFieldType.pm
new file mode 100644
index 000000000..0485d033f
--- /dev/null
+++ b/lib/WebGUI/Form/MatrixFieldType.pm
@@ -0,0 +1,153 @@
+package WebGUI::Form::MatrixFieldType;
+
+=head1 LEGAL
+
+ -------------------------------------------------------------------
+ WebGUI is Copyright 2001-2008 Plain Black Corporation.
+ -------------------------------------------------------------------
+ Please read the legal notices (docs/legal.txt) and the license
+ (docs/license.txt) that came with this distribution before using
+ this software.
+ -------------------------------------------------------------------
+ http://www.plainblack.com info@plainblack.com
+ -------------------------------------------------------------------
+
+=cut
+
+use strict;
+use base 'WebGUI::Form::SelectBox';
+use Tie::IxHash;
+use WebGUI::International;
+use WebGUI::Pluggable;
+use WebGUI::Utility;
+
+=head1 NAME
+
+Package WebGUI::Form::MatrixFieldType
+
+=head1 DESCRIPTION
+
+Creates a form control that will allow you to select a field type that can be used by the Matrix wobject.
+It's meant to be used in conjunction with the DynamicField form control.
+
+=head1 SEE ALSO
+
+This is a subclass of WebGUI::Form::SelectBox.
+
+=head1 METHODS
+
+The following methods are specifically available from this class. Check the superclass for additional methods.
+
+=cut
+
+#-------------------------------------------------------------------
+
+=head2 areOptionsSettable ( )
+
+Returns 0.
+
+=cut
+
+sub areOptionsSettable {
+ return 0;
+}
+
+#-------------------------------------------------------------------
+
+=head2 definition ( [ additionalTerms ] )
+
+See the super class for additional details.
+
+=head3 additionalTerms
+
+The following additional parameters have been added via this sub class.
+
+=head4 types
+
+An array reference containing the form control types to be selectable. Defaults to all available dynamic types.
+
+=head4 label
+
+A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName().
+
+=cut
+
+sub definition {
+ my $class = shift;
+ my $session = shift;
+ my $definition = shift || [];
+ my $i18n = WebGUI::International->new($session);
+ push(@{$definition}, {
+ label=>{
+ defaultValue=>$i18n->get("matrix fieldtype","WebGUI")
+ },
+ });
+ return $class->SUPER::definition($session, $definition);
+}
+
+#-------------------------------------------------------------------
+
+=head2 getName ( session )
+
+Returns the human readable name of this control.
+
+=cut
+
+sub getName {
+ my ($self, $session) = @_;
+ return WebGUI::International->new($session, 'WebGUI')->get('matrix fieldtype');
+}
+
+#-------------------------------------------------------------------
+
+=head2 getValue ( )
+
+Returns either what's posted or if nothing comes back it returns "text".
+
+=cut
+
+sub getValue {
+ my $self = shift;
+ my $fieldType = $self->SUPER::getValue(@_);
+ $fieldType =~ s/[^\w]//g;
+ return $fieldType || "MatrixCompare";
+}
+
+#-------------------------------------------------------------------
+
+=head2 isDynamicCompatible ( )
+
+Returns 0.
+
+=cut
+
+sub isDynamicCompatible {
+ return 0;
+}
+
+#-------------------------------------------------------------------
+
+=head2 toHtml ( )
+
+Renders a fieldType selector.
+
+=cut
+
+sub toHtml {
+ my $self = shift;
+ my %options;
+ tie %options, "Tie::IxHash";
+ %options = (
+ MatrixCompare => WebGUI::Pluggable::instanciate('WebGUI::Form::MatrixCompare', 'getName',[$self->session]),
+ SelectBox => WebGUI::Pluggable::instanciate('WebGUI::Form::SelectBox', 'getName',[$self->session]),
+ Combo => WebGUI::Pluggable::instanciate('WebGUI::Form::Combo', 'getName',[$self->session]),
+ );
+ $self->set('options', \%options);
+ $self->set('defaultValue','MatrixCompare');
+ return $self->SUPER::toHtml();
+}
+
+
+
+1;
+
diff --git a/lib/WebGUI/i18n/English/Asset_Matrix.pm b/lib/WebGUI/i18n/English/Asset_Matrix.pm
index a120a9156..32a8c9d0a 100644
--- a/lib/WebGUI/i18n/English/Asset_Matrix.pm
+++ b/lib/WebGUI/i18n/English/Asset_Matrix.pm
@@ -4,30 +4,18 @@ use strict;
our $I18N = {
'delete field confirm' => {
message => q|Are you certain you wish to delete this field and all the data linked to it?|,
- lastUpdated => 0,
+ lastUpdated => 1230,
context => q|displayed in field manager before delete|
},
- 'screenshot' => {
- message => q|Screenshot/Photo|,
- lastUpdated => 0,
- context => q|edit listing property|
- },
-
- 'screenshot help' => {
- message => q|Upload a picture of the product, or a screen shot if it's a software package.|,
- lastUpdated => 0,
- context => q|edit listing property help|
- },
-
'visitor cache timeout' => {
message => q|Visitor Cache Timeout|,
- lastUpdated => 0
+ lastUpdated => 1230
},
'visitor cache timeout help' => {
message => q|Since all visitors will see this asset the same way, we can cache it to increase performance. How long should we cache it?|,
- lastUpdated => 0
+ lastUpdated => 1230
},
'isTooMany' => {
@@ -55,11 +43,6 @@ our $I18N = {
lastUpdated => 1149783768,
},
- 'version' => {
- message => q|The version number or model number of the product.|,
- lastUpdated => 1149783768,
- },
-
'details url' => {
message => q|The URL to the details page for this listing.|,
lastUpdated => 1149783768,
@@ -210,11 +193,6 @@ our $I18N = {
lastUpdated => 1149784175,
},
- 'manufacturerName' => {
- message => q|The name of the company that manufactures the product or provides the service represented in this listing.|,
- lastUpdated => 1167186054,
- },
-
'manufacturerUrl' => {
message => q|The manufacturer's URL.|,
lastUpdated => 1149784175,
@@ -225,11 +203,6 @@ our $I18N = {
lastUpdated => 1149784175,
},
- 'versionNumber' => {
- message => q|The version number or model number of this product.|,
- lastUpdated => 1149784175,
- },
-
'views' => {
message => q|The total number of views this listing has received.|,
lastUpdated => 1149784175,
@@ -281,7 +254,7 @@ our $I18N = {
},
'detail template help title' => {
- lastUpdated => 0,
+ lastUpdated =>
message => q|Matrix Listing Detail Template Variables|
},
@@ -501,7 +474,7 @@ our $I18N = {
},
'ratings detail template help title' => {
- lastUpdated => 0,
+ lastUpdated => 1230,
message => q|Matrix Ratings Detail Template Variables|
},
@@ -582,23 +555,68 @@ our $I18N = {
'categories description' => {
message => q|Specify one category per line here to define the categories for this matrix. Categories are used to subdivide fields and also represent the things users can rate each listing on.|,
- lastUpdated => 1136503559,
- },
+ lastUpdated => 0,
+ },
+
+ 'categories default value' => {
+ message => q|Features\nBenefits|,
+ lastUpdated => 0,
+ },
+
+ 'submission approval workflow description' => {
+ message => q|Select the workflow that is used to approve submissions.|,
+ lastUpdated => 0,
+ },
+
+ 'ratings duration description' => {
+ message => q|Select the interval after which old ratings are cleaned out.|,
+ lastUpdated => 0,
+ },
+
+ 'default sort description' => {
+ message => q|Select the default sort order for the listings in the compare box.|,
+ lastUpdated => 0,
+ },
+
+ 'compare color no description' => {
+ message => q|Select the color for compare result 'No' in the compare display.|,
+ lastUpdated => 0,
+ },
+
+ 'compare color limited description' => {
+ message => q|Select the color for compare result 'Limited' in the compare display.|,
+ lastUpdated => 0,
+ },
+
+ 'compare color costs extra description' => {
+ message => q|Select the color for compare result 'Costs Extra' in the compare display.|,
+ lastUpdated => 0,
+ },
+
+ 'compare color free add on description' => {
+ message => q|Select the color for compare result 'Free Add On' in the compare display.|,
+ lastUpdated => 0,
+ },
+
+ 'compare color yes description' => {
+ message => q|Select the color for compare result 'Yes' in the compare display.|,
+ lastUpdated => 0,
+ },
'categories subtext' => {
message => q| Enter one per line in the order you want them to appear. Be sure to watch leading and trailing whitespace.|,
lastUpdated => 1135271460,
},
- 'max comparisons description' => {
- message => q|Specifies how many comparisons are allowed in searches and comparisons.|,
- lastUpdated => 1135271460,
- },
+ 'max comparisons description' => {
+ message => q|Specifies how many comparisons are allowed in searches and comparisons.|,
+ lastUpdated => 0,
+ },
- 'max comparisons privileged description' => {
- message => q|Specifies how many comparisons are allowed in searches and comparisons for users in the privileged group.|,
- lastUpdated => 1135271460,
- },
+ 'max comparisons privileged description' => {
+ message => q|Specifies how many comparisons are allowed in searches and comparisons for users in the privileged group.|,
+ lastUpdated => 0,
+ },
'rating timeout description' => {
message => q|Set a timeout so that users are prevented from rating a given listing too often.|,
@@ -625,43 +643,103 @@ our $I18N = {
lastUpdated => 1135271460,
},
- 'main template description' => {
+ 'template description' => {
message => q|Select a template to be used to display the default view of the Matrix.|,
- lastUpdated => 1135271460,
+ lastUpdated => 0,
},
'detail template description' => {
message => q|Select a template to be used to display the detailed information about a listing.|,
- lastUpdated => 1135271460,
+ lastUpdated => 0,
},
'rating detail template description' => {
message => q|Select a template to be used to display the detailed ratings information.|,
- lastUpdated => 1135271460,
+ lastUpdated => 0,
},
'search template description' => {
message => q|Select a template to be used to display the search engine interface.|,
- lastUpdated => 1135271460,
+ lastUpdated => 0,
},
'compare template description' => {
message => q|Select a template to be used to show the listing comparison data.|,
- lastUpdated => 1135271460,
+ lastUpdated => 0,
},
- 'categories' => {
+ 'categories label' => {
message => q|Categories|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'max comparisons' => {
+ 'submission approval workflow label' => {
+ message => q|Submission Approval Workflow|,
+ lastUpdated => 0,
+ },
+
+ 'ratings duration label' => {
+ message => q|Ratings Duration|,
+ lastUpdated => 0,
+ },
+
+ 'default sort label' => {
+ message => q|Default Sort|,
+ lastUpdated => 0,
+ },
+
+ 'sort by score label' => {
+ message => q|Score|,
+ lastUpdated => 0,
+ },
+
+ 'sort alpha numeric label' => {
+ message => q|Alpha Numeric|,
+ lastUpdated => 0,
+ },
+
+ 'sort by asset rank label' => {
+ message => q|Asset Rank|,
+ lastUpdated => 0,
+ },
+
+ 'sort by last updated label' => {
+ message => q|Most Recent Update|,
+ lastUpdated => 0,
+ },
+
+ 'compare color no label' => {
+ message => q|Compare Color: No|,
+ lastUpdated => 0,
+ },
+
+ 'compare color limited label' => {
+ message => q|Compare Color: Limited|,
+ lastUpdated => 0,
+ },
+
+ 'compare color costs extra label' => {
+ message => q|Compare Color: Costs Extra|,
+ lastUpdated => 0,
+ },
+
+ 'compare color free add on label' => {
+ message => q|Compare Color: Free Add On|,
+ lastUpdated => 0,
+ },
+
+ 'compare color yes label' => {
+ message => q|Compare Color: Yes|,
+ lastUpdated => 0,
+ },
+
+ 'max comparisons label' => {
message => q|Maximum Comparisons|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'max comparisons privileged' => {
+ 'max comparisons privileged label' => {
message => q|Maximum Comparisons (For Privileged Users)|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
'rating timeout' => {
@@ -689,29 +767,29 @@ our $I18N = {
lastUpdated => 1133758944,
},
- 'main template' => {
- message => q|Main Template|,
- lastUpdated => 1133758944,
+ 'template label' => {
+ message => q|Matrix Template|,
+ lastUpdated => 0,
},
- 'detail template' => {
+ 'detail template label' => {
message => q|Detail Template|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'rating detail template' => {
+ 'rating detail template label' => {
message => q|Rating Detail Template|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'search template' => {
+ 'search template label' => {
message => q|Search Template|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'compare template' => {
+ 'compare template label' => {
message => q|Compare Template|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
'product name' => {
@@ -719,59 +797,34 @@ our $I18N = {
lastUpdated => 1133758944,
},
- 'version number' => {
- message => q|Version/Model Number|,
- lastUpdated => 1133758944,
+ 'attribute name label' => {
+ message => q|Name|,
+ lastUpdated => 0,
},
- 'product url' => {
- message => q|Product URL|,
- lastUpdated => 1135279964,
- },
-
- 'manufacturer name' => {
- message => q|Manufacturer Name|,
- lastUpdated => 1133758944,
- },
-
- 'manufacturer url' => {
- message => q|Manufacturer URL|,
- lastUpdated => 1133758944,
- },
-
- 'description' => {
- message => q|Description|,
- lastUpdated => 1133758944,
- },
-
- 'listing maintainer' => {
- message => q|Listing Maintainer|,
- lastUpdated => 1133758944,
- },
-
- 'field name' => {
- message => q|Field Name|,
- lastUpdated => 1136499280,
- },
-
- 'field label' => {
- message => q|Field Label|,
- lastUpdated => 1136499282,
- },
-
- 'field type' => {
+# 'field label' => {
+# message => q|Field Label|,
+# lastUpdated => 1136499282,
+# },
+
+ 'fieldType label' => {
message => q|Field Type|,
- lastUpdated => 1136499283,
+ lastUpdated => 0,
},
- 'default value' => {
+ 'attribute defaultValue label' => {
message => q|Default Value|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'category' => {
+ 'attribute options label' => {
+ message => q|Options|,
+ lastUpdated => 0,
+ },
+
+ 'category label' => {
message => q|Category|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
'your email' => {
@@ -829,9 +882,9 @@ our $I18N = {
message => q|Edit Listing |
},
- 'edit field' => {
- lastUpdated => 1135279558,
- message => q|Edit Field |
+ 'edit attribute title' => {
+ lastUpdated => 0,
+ message => q|Edit/Add Attribute|
},
'good bad' => {
@@ -869,12 +922,20 @@ our $I18N = {
No, I made a mistake.
|,
},
- 'list fields' => {
- lastUpdated => 1135289632,
- message => q|Field List
- Add new field.
-
|,
- },
+ 'list attributes title' => {
+ lastUpdated => 0,
+ message => q|Attribute List|,
+ },
+
+ 'delete attribute confirm message' => {
+ message => q|Are you certain you wish to delete this attribute and all the data linked to it?|,
+ lastUpdated => 0,
+ },
+
+ 'add attribute label' => {
+ lastUpdated => 0,
+ message => q|Add Attribute|,
+ },
'yes' => {
lastUpdated => 1135279558,
@@ -906,38 +967,6 @@ our $I18N = {
message => q|Enter the name of the product. If there are entries for the product with different revisions, it would be best to make sure the names are the same.|
},
- 'version number description' => {
- lastUpdated => 1135279558,
- message => q|Enter the release or version number for the product.|
- },
-
- 'product url description' => {
- lastUpdated => 1135279558,
- message => q|If the product has its own website, enter the complete URL for it here.|
- },
-
- 'manufacturer name description' => {
- lastUpdated => 1135279558,
- message => q|Enter the manufacturer of the product.|
- },
-
- 'manufacturer url description' => {
- lastUpdated => 1135279558,
- message => q|If the manufacturer has a website, enter the complete URL for it here.|
- },
-
- 'description description' => {
- lastUpdated => 1135279558,
- message => q|Please give a general description of the product. Specific details can be rated in the form fields below.|
- },
-
- 'listing maintainer description' => {
- lastUpdated => 1136488950,
- message => q|If left blank, this will be the name of the user who created this product listing. The
- listing maintainer is allowed to edit this listing, even if they are not members of the group
- to add or edit listings.|
- },
-
'matrix specific fields description' => {
lastUpdated => 1135279558,
message => q|Each matrix is configured to compare the features and performance of various products. These features and performance criteria are displayed for you to rate on an item by item basis.|
@@ -948,55 +977,46 @@ our $I18N = {
message => q|Matrix Specific Fields|
},
- 'field name description' => {
- lastUpdated => 1135279558,
- message => q|The name of the field that you are creating. It is case sensitive and must be unique.|
+ 'attribute name description' => {
+ lastUpdated => 0,
+ message => q|The name of the attribute that you are creating. It is case sensitive and must be unique.|
},
- 'field label description' => {
- lastUpdated => 1135279558,
- message => q|The name of the field that you are creating. It is case sensitive and must be unique.|
+# 'field label description' => {
+# lastUpdated => 1135279558,
+# message => q|The name of the field that you are creating. It is case sensitive and must be unique.|
+# },
+
+ 'fieldType description' => {
+ lastUpdated => 0,
+ message => q|The field type of attribute you are creating. Please select the field type from the options in the drop-down list.
|
},
- 'field type description' => {
- lastUpdated => 1167185918,
- message => q|The type of field you are creating. Please select the type from the following options in the drop-down list.
-
-
- Good Bad
- Defines availability of a feature, has it, doesn't have it, limited functionality, free add on, etc.
- Text
- A single line of text, like a short description or title.
- TextArea
- Multiple lines of text.
- URL
- A URL.
- Combo
- A combination Text box and drop down list.
- |
+ 'attribute description label' => {
+ lastUpdated => 0,
+ message => q|Description|
},
- 'field description' => {
- lastUpdated => 1135279558,
- message => q|Field Description|
+ 'attribute description description' => {
+ lastUpdated => 0,
+ message => q|Please give a general description of the attribute.|
},
- 'field description description' => {
- lastUpdated => 1135279558,
- message => q|Please give a general description of the field.|
+ 'attribute defaultValue description' => {
+ lastUpdated => 0,
+ message => q|Enter in a default value for the attribute that will be used if the fieldType is
+selectBox.
|
},
- 'default value description' => {
- translatorsNote => q|Please do not translate the GoodBad field values, as described below|,
- lastUpdated => 1135279558,
- message => q|Enter in a default value for the field that will be used if the user leaves the field blank.
- For the GoodBad field, the possible values are "No", "Yes", "Free Add On", "Costs Extra", "Limited". While the displayed labels are internationalized, these values are not.
- For the Combo field, you may only enter in 1 value, but the user will be allowed to select any value entered in by other users. In other words, the drop-down list will contain all values entered in by users who enter unique data into this field.
|
+ 'attribute options description' => {
+ lastUpdated => 0,
+ message => q|Enter in options (one per line) for the attribute that will be used if the fieldType is
+selectBox.
|
},
'category description' => {
- lastUpdated => 1136503500,
- message => q|Select the category which this field falls into.|
+ lastUpdated => 0,
+ message => q|Select the category which this attribute falls into.|
},
};
diff --git a/lib/WebGUI/i18n/English/Asset_MatrixListing.pm b/lib/WebGUI/i18n/English/Asset_MatrixListing.pm
new file mode 100644
index 000000000..100a6393f
--- /dev/null
+++ b/lib/WebGUI/i18n/English/Asset_MatrixListing.pm
@@ -0,0 +1,103 @@
+package WebGUI::i18n::English::Asset_MatrixListing;
+
+use strict;
+
+our $I18N = {
+ 'assetName' => {
+ message => q|Matrix Listing|,
+ lastUpdated => 0,
+ },
+
+ 'edit matrix listing title' => {
+ message => q|Edit/Add Listing|,
+ lastUpdated => 0,
+ },
+
+
+ 'template description' => {
+ message => q|Select a template to be used to display the default view of the Matrix.|,
+ lastUpdated => 0,
+ },
+
+ 'template label' => {
+ message => q|Matrix Listing Template|,
+ lastUpdated => 0,
+ },
+
+ 'screenshots description' => {
+ message => q|Upload a picture of the product, or a screen shot if it's a software package.|,
+ lastUpdated => 0,
+ },
+
+ 'screenshots label' => {
+ message => q|Screenshots/Photos|,
+ lastUpdated => 0,
+ },
+
+ 'description description' => {
+ message => q|Please give a general description of the product. Specific details can be rated in the form
+fields below.|,
+ lastUpdated => 0,
+ },
+
+ 'description label' => {
+ message => q|Description|,
+ lastUpdated => 0,
+ },
+
+ 'version description' => {
+ message => q|Enter the version/edition/model number for the product.|,
+ lastUpdated => 0,
+ },
+
+ 'version label' => {
+ message => q|Version/Model|,
+ lastUpdated => 0,
+ },
+
+ 'maintainer description' => {
+ message => q|If left blank, this will be the name of the user who created this product listing. The
+ listing maintainer is allowed to edit this listing, even if they are not members of the group
+ to add or edit listings.|,
+ lastUpdated => 0,
+ },
+
+ 'maintainer label' => {
+ message => q|Maintainer|,
+ lastUpdated => 0,
+ },
+
+ 'manufacturerName description' => {
+ message => q|The name of the company that manufactures the product or provides the service represented in
+this listing.|,
+ lastUpdated => 0,
+ },
+
+ 'manufacturerName label' => {
+ message => q|Manufacturer Name|,
+ lastUpdated => 0,
+ },
+
+ 'manufacturerURL description' => {
+ message => q|If the manufacturer has a website, enter the complete URL for it here.|,
+ lastUpdated => 0,
+ },
+
+ 'manufacturerURL label' => {
+ message => q|Manufacturer URL|,
+ lastUpdated => 0,
+ },
+
+ 'productURL description' => {
+ message => q|If the product has its own website, enter the complete URL for it here.|,
+ lastUpdated => 0,
+ },
+
+ 'productURL label' => {
+ message => q|Product URL|,
+ lastUpdated => 0,
+ },
+
+};
+
+1;
diff --git a/lib/WebGUI/i18n/English/Form_MatrixCompare.pm b/lib/WebGUI/i18n/English/Form_MatrixCompare.pm
new file mode 100644
index 000000000..2c3dff83f
--- /dev/null
+++ b/lib/WebGUI/i18n/English/Form_MatrixCompare.pm
@@ -0,0 +1,32 @@
+package WebGUI::i18n::English::Form_MatrixCompare;
+use strict;
+
+our $I18N = {
+ 'no' => {
+ message => q|No|,
+ lastUpdated => 0,
+ },
+
+ 'limited' => {
+ message => q|Limited|,
+ lastUpdated => 0,
+ },
+
+ 'costs extra' => {
+ message => q|Costs Extra|,
+ lastUpdated => 0,
+ },
+
+ 'free add on' => {
+ message => q|Free Add On|,
+ lastUpdated => 0,
+ },
+
+ 'yes' => {
+ message => q|Yes|,
+ lastUpdated => 0,
+ },
+
+};
+
+1;
diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm
index 080cbfcdf..ea63f9f0a 100644
--- a/lib/WebGUI/i18n/English/WebGUI.pm
+++ b/lib/WebGUI/i18n/English/WebGUI.pm
@@ -2880,6 +2880,18 @@ or are under your current version tag.
context => q|Field type name|
},
+ 'matrix fieldtype' => {
+ message => q|Matrix Field Type|,
+ lastUpdated =>0,
+ context => q|Field type name|
+ },
+
+ 'matrix compare' => {
+ message => q|Matrix Compare|,
+ lastUpdated =>0,
+ context => q|Field type name|
+ },
+
'hidden list' => {
message => q|Hidden List|,
lastUpdated =>0,
diff --git a/t/Asset/MatrixListing.t b/t/Asset/MatrixListing.t
new file mode 100644
index 000000000..3ff5fd1a0
--- /dev/null
+++ b/t/Asset/MatrixListing.t
@@ -0,0 +1,63 @@
+#-------------------------------------------------------------------
+# WebGUI is Copyright 2001-2008 Plain Black Corporation.
+#-------------------------------------------------------------------
+# Please read the legal notices (docs/legal.txt) and the license
+# (docs/license.txt) that came with this distribution before using
+# this software.
+#-------------------------------------------------------------------
+# http://www.plainblack.com info@plainblack.com
+#-------------------------------------------------------------------
+
+use FindBin;
+use strict;
+use lib "$FindBin::Bin/../lib";
+
+##The goal of this test is to test the creation of a MatrixListing Asset.
+
+use WebGUI::Test;
+use WebGUI::Session;
+use Test::More tests => 2; # increment this value for each test you create
+use WebGUI::Asset::Wobject::Matrix;
+use WebGUI::Asset::MatrixListing;
+
+
+my $session = WebGUI::Test->session;
+my $node = WebGUI::Asset->getImportNode($session);
+my ($matrix, $matrixListing);
+
+my $versionTag = WebGUI::VersionTag->getWorking($session);
+$versionTag->set({name=>"Matrix Listing Test"});
+
+$matrix = $node->addChild({className=>'WebGUI::Asset::Wobject::Matrix'});
+$versionTag->commit;
+$matrixListing = $matrix->addChild({className=>'WebGUI::Asset::MatrixListing'});
+
+# Wikis create and autocommit a version tag when a child is added. Lets get the name so we can roll it back.
+my $secondVersionTag = WebGUI::VersionTag->new($session,$matrixListing->get("tagId"));
+
+# Test for sane object types
+isa_ok($matrix, 'WebGUI::Asset::Wobject::Matrix');
+isa_ok($matrixListing, 'WebGUI::Asset::MatrixListing');
+
+# Try to add content under a MatrixListing asset
+#my $article = $matrixListing->addChild({className=>'WebGUI::Asset::Wobject::Article'});
+#is($article, undef, "Can't add an Article wobject as a child to a Matrix Listing.");
+
+# See if the duplicate method works
+#my $wikiPageCopy = $wikipage->duplicate();
+#isa_ok($wikiPageCopy, 'WebGUI::Asset::WikiPage');
+#my $thirdVersionTag = WebGUI::VersionTag->new($session,$wikiPageCopy->get("tagId"));
+
+
+#TODO: {
+# local $TODO = "Tests to make later";
+# ok(0, 'Lots and lots to do');
+#}
+
+END {
+ # Clean up after thy self
+ $versionTag->rollback();
+ $secondVersionTag->rollback();
+ #$thirdVersionTag->rollback();
+}
+
diff --git a/t/Asset/Wobject/Matrix.t b/t/Asset/Wobject/Matrix.t
new file mode 100644
index 000000000..4fc36012b
--- /dev/null
+++ b/t/Asset/Wobject/Matrix.t
@@ -0,0 +1,98 @@
+#-------------------------------------------------------------------
+# WebGUI is Copyright 2001-2008 Plain Black Corporation.
+#-------------------------------------------------------------------
+# Please read the legal notices (docs/legal.txt) and the license
+# (docs/license.txt) that came with this distribution before using
+# this software.
+#-------------------------------------------------------------------
+# http://www.plainblack.com info@plainblack.com
+#-------------------------------------------------------------------
+
+use FindBin;
+use strict;
+use File::Spec;
+use lib "$FindBin::Bin/../../lib";
+
+##The goal of this test is to test the creation of UserList Wobjects.
+
+use WebGUI::Test;
+use WebGUI::Session;
+use Test::More tests => 10; # increment this value for each test you create
+use Test::Deep;
+use WebGUI::Asset::Wobject::Matrix;
+
+my $session = WebGUI::Test->session;
+
+# Do our work in the import node
+my $node = WebGUI::Asset->getImportNode($session);
+
+my $versionTag = WebGUI::VersionTag->getWorking($session);
+$versionTag->set({name=>"Matrix Test"});
+my $matrix = $node->addChild({className=>'WebGUI::Asset::Wobject::Matrix'});
+
+# Test for a sane object type
+isa_ok($matrix, 'WebGUI::Asset::Wobject::Matrix');
+
+# Test to see if we can set new values
+my $newMatrixSettings = {
+ maxComparisons => 20,
+ defaultSort => 'assetRank',
+ compareColorNo => '#aaffaa',
+ submissionApprovalWorkflowId => 'pbworkflow000000000005',
+ categories => "category1\ncategory2",
+};
+$matrix->update($newMatrixSettings);
+
+foreach my $newSetting (keys %{$newMatrixSettings}) {
+ unless ($newSetting eq 'categories'){
+ is ($matrix->get($newSetting), $newMatrixSettings->{$newSetting}, "updated $newSetting is ".$newMatrixSettings->{$newSetting});
+ }
+}
+
+cmp_deeply (
+ $matrix->getCategories,
+ {
+ category1=>'category1',
+ category2=>'category2'
+ },
+ 'getCategories method returned correct hashref'
+ );
+
+
+# add a new attribute
+
+$session->user({userId => 3});
+
+my $attributeProperties = {
+ name =>'test attribute',
+ description =>'description of the test attribute',
+ category =>'category1',
+ };
+
+my $newAttributeId = $matrix->editAttributeSave($attributeProperties);
+
+my $newAttribute = $matrix->getAttribute($newAttributeId);
+
+my $isValidId = $session->id->valid($newAttributeId);
+
+is($isValidId,1,"editAttributeSave returnes a valid guid");
+
+is($newAttribute->{name},'test attribute',"Adding a new attribute, attribute name was set correctly");
+is($newAttribute->{fieldType},'MatrixCompare',"Adding a new attribute, undefined fieldType was set correctly to
+default value");
+
+# delete new attribute
+
+$matrix->deleteAttribute($newAttributeId);
+
+my $newAttribute = $matrix->getAttribute($newAttributeId);
+
+is($newAttribute->{attributeId},undef,"The new attribute was successfully deleted.");
+
+# TODO: test deleting of listing data for attribute
+
+END {
+ # Clean up after thy self
+ $versionTag->rollback();
+}
+
From c9228b432430585c1a58060d31b7b6ddeacbeca6 Mon Sep 17 00:00:00 2001
From: Yung Han Khoe
Date: Sun, 9 Nov 2008 01:14:36 +0000
Subject: [PATCH 3/9] Adding features to Matrix v2
---
lib/WebGUI/Asset/MatrixListing.pm | 485 ++++++++++++++++++++++--
lib/WebGUI/Asset/Wobject/Matrix.pm | 152 +++++++-
lib/WebGUI/Form/MatrixCompare.pm | 23 +-
lib/WebGUI/Help/Asset_Matrix.pm | 32 +-
lib/WebGUI/i18n/English/Asset_Matrix.pm | 191 ++++++----
5 files changed, 756 insertions(+), 127 deletions(-)
diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm
index 8f92a93d6..528331e8b 100644
--- a/lib/WebGUI/Asset/MatrixListing.pm
+++ b/lib/WebGUI/Asset/MatrixListing.pm
@@ -79,19 +79,20 @@ sub definition {
tie %properties, 'Tie::IxHash';
my $i18n = WebGUI::International->new($session, "Asset_MatrixListing");
%properties = (
- templateId => {
- tab =>"display",
- fieldType =>"template",
- defaultValue =>'MatrixListingTmpl00001',
- noFormPost =>0,
- namespace =>"MatrixListing",
- hoverHelp =>$i18n->get('template description'),
- label =>$i18n->get('template label')
- },
+# templateId => {
+# tab =>"display",
+# fieldType =>"template",
+# defaultValue =>'MatrixListingTmpl00001',
+# noFormPost =>0,
+# namespace =>"MatrixListing",
+# hoverHelp =>$i18n->get('template description'),
+# label =>$i18n->get('template label')
+# },
screenshots => {
tab =>"properties",
fieldType =>"image",
defaultValue =>undef,
+ maxAttachments =>20,
label =>$i18n->get("screenshots label"),
hoverHelp =>$i18n->get("screenshots description")
},
@@ -217,6 +218,119 @@ sub getAutoCommitWorkflowId {
#-------------------------------------------------------------------
+=head2 getEditForm ( )
+
+Returns the TabForm object that will be used in generating the edit page for this asset.
+
+=cut
+
+sub getEditForm {
+ my $self = shift;
+ my $session = $self->session;
+ my $db = $session->db;
+ my $matrixId = $self->getParent->getId;
+ my $tabform = $self->SUPER::getEditForm();
+ my $i18n = WebGUI::International->new($session, 'Asset_MatrixListing');
+
+ #$self->session->style->setScript($self->session->url->extras('FileUploadControl.js'), {type =>'text/javascript'});
+
+ foreach my $category (keys %{$self->getParent->getCategories}) {
+ $tabform->getTab('properties')->raw(''.$category.' ');
+ my $attributes;
+ if ($session->form->process('func') eq 'add'){
+ $attributes = $db->read("select * from Matrix_attribute where category = ? and assetId = ?",
+ [$category,$matrixId]);
+ }
+ else{
+ $attributes = $db->read("select * from Matrix_attribute as a
+ left join MatrixListing_attribute as l on (a.attributeId = l.attributeId and l.matrixListingId = ?)
+ where category =? and a.assetId = ?",
+ [$self->getId,$category,$matrixId]);
+ }
+ while (my $attribute = $attributes->hashRef) {
+ $attribute->{label} = $attribute->{name};
+ $attribute->{subtext} = $attribute->{description};
+ $attribute->{name} = 'attribute_'.$attribute->{attributeId};
+ $tabform->getTab("properties")->dynamicField(%{$attribute});
+ }
+ }
+ return $tabform;
+=cut
+ $tabform->hidden({
+ name=>"returnUrl",
+ value=>$self->session->form->get("returnUrl")
+ });
+ if ($self->getValue("namespace") eq "") {
+ my $namespaces = $self->session->dbSlave->buildHashRef("select distinct(namespace) from template order by
+namespace");
+ $tabform->getTab("properties")->combo(
+ -name=>"namespace",
+ -options=>$namespaces,
+ -label=>$i18n->get('namespace'),
+ -hoverHelp=>$i18n->get('namespace description'),
+ -value=>[$self->session->form->get("namespace")]
+ );
+ }
+=cut
+}
+
+#-------------------------------------------------------------------
+
+=head2 hasRated ( )
+
+Returns whether the user has already rated this listing or not.
+
+=cut
+
+sub hasRated {
+ my $self = shift;
+ my $session = $self->session;
+
+=cut
+ return 1 unless ($self->session->user->isInGroup($self->get("groupToRate")));
+
+ my $ratingTimeout = $self->session->user->isInGroup($self->get("privilegedGroup")) ?
+$self->get("ratingTimeoutPrivileged") : $self->get("ratingTimeout");
+=cut
+
+ my $hasRated = $self->session->db->quickScalar("select count(*) from MatrixListing_rating where
+ ((userId=? and userId<>'1') or (userId='1' and ipAddress=?)) and listingId=?",
+ [$session->user->userId,$session->env->get("HTTP_X_FORWARDED_FOR"),$self->getId]);
+ return $hasRated;
+
+}
+
+#-------------------------------------------------------------------
+
+=head2 incrementCounter ( counter )
+
+Increments one of the Matrix Listing's counters.
+
+=head3 counter
+
+The name of the counter to increment this should be 'views', 'clicks' or 'compares').
+
+=cut
+
+sub incrementCounter {
+ my $self = shift;
+ my $db = $self->session->db;
+ my $counter = shift;
+
+ my $currentIp = $self->session->env->get("HTTP_X_FORWARDED_FOR");
+ print "current ip: ".$currentIp." ";
+
+ print "dsfsdf lastIp : ".$self->get($counter."LastIp")." ";
+ unless ($self->get($counter."LastIp") eq $currentIp) {
+ $self->update({
+ $counter."LastIp" => $currentIp,
+ $counter => $self->get($counter)+1,
+ });
+ }
+}
+
+#-------------------------------------------------------------------
+
=head2 indexContent ( )
Making private. See WebGUI::Asset::indexContent() for additonal details.
@@ -241,8 +355,8 @@ See WebGUI::Asset::prepareView() for details.
sub prepareView {
my $self = shift;
$self->SUPER::prepareView();
- my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
- $template->prepare;
+ my $template = WebGUI::Asset::Template->new($self->session, $self->getParent->get('detailTemplateId'));
+ $template->prepare;
$self->{_viewTemplate} = $template;
}
@@ -251,15 +365,26 @@ sub prepareView {
=head2 processPropertiesFromFormPost ( )
-Used to process properties from the form posted. Do custom things with
-noFormPost fields here, or do whatever you want. This method is called
-when /yourAssetUrl?func=editSave is requested/posted.
+Used to process properties from the form posted.
=cut
sub processPropertiesFromFormPost {
- my $self = shift;
+ my $self = shift;
+ my $session = $self->session;
+
$self->SUPER::processPropertiesFromFormPost;
+
+ my $attributes = $session->db->read("select * from Matrix_attribute where assetId = ?",[$self->getParent->getId]);
+ while (my $attribute = $attributes->hashRef) {
+ my $name = 'attribute_'.$attribute->{attributeId};
+ #my $value = $session->form->process($name);
+ my $value = $session->form->process($name,$attribute->{fieldType},$attribute->{defaultValue},$attribute);
+ $session->db->write("replace into MatrixListing_attribute (matrixId, matrixListingId, attributeId, value)
+ values (?, ?, ?, ?)",
+ [$self->getParent->getId,$self->getId,$attribute->{attributeId},$value]);
+ }
+
$self->requestAutoCommit;
}
@@ -275,7 +400,13 @@ purges it's data.
=cut
sub purge {
- my $self = shift;
+ my $self = shift;
+ my $db = $self->session->db;
+
+ $db->write("delete from MatrixListing_attribute where matrixListingId=?",[$self->getId]);
+ $db->write("delete from MatrixListing_rating where listingId=?" ,[$self->getId]);
+ $db->write("delete from MatrixListing_ratingSummary where listingId=?" ,[$self->getId]);
+
return $self->SUPER::purge;
}
@@ -293,22 +424,249 @@ sub purgeRevision {
}
#-------------------------------------------------------------------
-=head2 view ( )
+
+=head2 setRatings ( ratings )
+
+Sets the ratings for a matrix listing
+
+=head3 ratings
+
+A hashref containing the ratings to set for this listing.
+
+=cut
+
+sub setRatings {
+ my $self = shift;
+ my $ratings = shift;
+ my $session = $self->session;
+ my $db = $session->db;
+ my $matrixId = $self->getParent->getId;
+
+ foreach my $category (keys %{$self->getParent->getCategories}) {
+ if ($ratings->{$category}) {
+ $db->write("insert into MatrixListing_rating
+ (userId, category, rating, timeStamp, listingId, ipAddress, matrixId) values (?,?,?,?,?,?,?)",
+ [$session->user->userId,$category,$ratings->{$category},$session->datetime->time(),$self->getId,
+ $session->env->get("HTTP_X_FORWARDED_FOR"),$matrixId]);
+ }
+ my $sql = "from MatrixListing_rating where listingId=? and category=?";
+ my $sum = $db->quickScalar("select sum(rating) $sql", [$self->getId,$category]);
+ my $count = $db->quickScalar("select count(*) $sql", [$self->getId,$category]);
+
+ my $half = round($count/2);
+ my $mean = $sum / ($count || 1);
+ my $median = $db->quickScalar("select rating $sql limit $half,$half",[$self->getId,$category]);
+
+ $db->write("replace into MatrixListing_ratingSummary
+ (listingId, category, meanValue, medianValue, countValue, matrixId)
+ values (?,?,?,?,?,?)",[$self->getId,$category,$mean,$median,$count,$matrixId]);
+ }
+}
+
+#-------------------------------------------------------------------
+
+=head2 view ( hasRated )
method called by the container www_view method.
+=head3 hasRated
+
+A boolean indicating if the user has rated this listing.
+
+=head3 hasRated
+
+A boolean indicating if an email to the listing maintianer was sent.
+
=cut
sub view {
- my $self = shift;
- my $var = $self->get; # $var is a hash reference.
- $var->{controls} = $self->getToolbar;
- $var->{fileUrl} = $self->getFileUrl;
- $var->{fileIcon} = $self->getFileIconUrl;
+ my $self = shift;
+ my $hasRated = shift || $self->hasRated;
+ my $emailSent = shift;
+ my $db = $self->session->db;
+ my $i18n = WebGUI::International->new($self->session, "Asset_Matrix");
+ my @categories = keys %{$self->getParent->getCategories};
+
+ # Increment views before getting template var hash so that the views tmpl_var has the incremented value.
+ $self->incrementCounter("views");
+
+ my $var = $self->get;
+ if ($emailSent){
+ $var->{emailSent} = 1;
+ }
+ $var->{controls} = $self->getToolbar;
+ $var->{productName} = $var->{title};
+ $var->{lastUpdated_epoch} = $self->get('lastUpdated');
+ $var->{lastUpdated_date} = $self->session->datetime->epochToHuman($self->get('lastUpdated'),"%z");
+
+ $var->{manufacturerUrl_click} = $self->getUrl("func=click;manufacturer=1");
+ $var->{productUrl_click} = $self->getUrl("func=click");
+
+ # Attributes
+
+ foreach my $category (@categories) {
+ my $attributes;
+ my @attribute_loop;
+ my $categoryLoopName = $self->session->url->urlize($category)."_loop";
+ $attributes = $db->read("select * from Matrix_attribute as a
+ left join MatrixListing_attribute as l on (a.attributeId = l.attributeId and l.matrixListingId = ?)
+ where category =? and a.assetId = ?",
+ [$self->getId,$category,$self->getParent->getId]);
+ while (my $attribute = $attributes->hashRef) {
+ $attribute->{label} = $attribute->{name};
+ if ($attribute->{fieldType} eq 'MatrixCompare'){
+ $attribute->{value} = WebGUI::Form::MatrixCompare->new($self->session,$attribute)->getValueAsHtml;
+ }
+ #$attribute->{value} = $attribute->{description};
+ #$tabform->getTab("properties")->dynamicField(%{$attribute});
+ #my $categoryLoopName = $self->session->url->urlize($category)."_loop";
+ push(@attribute_loop,$attribute);
+ }
+ $var->{$categoryLoopName} = \@attribute_loop;
+ push(@{$var->{category_loop}},{
+ categoryLabel => $category,
+ attribute_loop => \@attribute_loop,
+ });
+ }
+
+ # Screenshots
+
+ if ($var->{screenshots}) {
+ my $file = WebGUI::Form::File->new($self->session,{ value=>$var->{screenshots} });
+ my $storage = $file->getStorageLocation;
+ my @files = @{ $storage->getFiles } if (defined $storage);
+ if (scalar(@files)) {
+ $var->{screenshots} = $file->getFilePreview($storage);
+ }
+ }
+
+ # Rating form
+
+ my %rating;
+ tie %rating, 'Tie::IxHash';
+ %rating = (
+ 1=>"1 - Worst",
+ 2=>2,
+ 3=>3,
+ 4=>4,
+ 5=>"5 - Respectable",
+ 6=>6,
+ 7=>7,
+ 8=>8,
+ 9=>9,
+ 10=>"10 - Best"
+ );
+ my $ratingsTable = "';
+ $ratingForm->submit(
+ -extras =>'class="ratingForm"',
+ -value =>$i18n->get('rate submit label'),
+ -label =>''.$i18n->get('show ratings').' '
+ );
+ if ($hasRated) {
+ $var->{ratings} = $ratingsTable;
+ } else {
+ $var->{ratings} = $ratingForm->print;
+ }
+
+ # Mail form
+
+ my $mailForm = WebGUI::HTMLForm->new($self->session,
+ -extras =>'class="content"',
+ -tableExtras=>'class="content"'
+ );
+ $mailForm->hidden(
+ -name =>"func",
+ -value =>"sendEmail"
+ );
+ $mailForm->captcha(
+ -name =>"verify"
+ );
+ $mailForm->email(
+ -extras =>'class="content"',
+ -name =>"from",
+ -value =>$self->session->user->profileField("email"),
+ -label =>$i18n->get('your email label'),
+ );
+ $mailForm->selectBox(
+ -name =>"subject",
+ -extras =>'class="content"',
+ -options =>{
+ $i18n->get('report error label') =>$i18n->get('report error label'),
+ $i18n->get('general comment label') =>$i18n->get('general comment label'),
+ },
+ -label =>$i18n->get('request type label'),
+ );
+ $mailForm->textarea(
+ -rows =>4,
+ -extras =>'class="content"',
+ -columns =>35,
+ -name =>"body",
+ -label =>$i18n->get('comment label'),
+ );
+ $mailForm->submit(
+ -extras =>'class="content"',
+ -value =>$i18n->get('send button label'),
+ );
+ $var->{emailForm} = $mailForm->print;
+
return $self->processTemplate($var,undef, $self->{_viewTemplate});
}
+#-------------------------------------------------------------------
+
+=head2 www_click ( )
+
+Redirects to the manufacturerUrl or productUrl and increments clicks.
+
+=cut
+
+sub www_click {
+ my $self = shift;
+ my $session = $self->session;
+
+ $self->incrementCounter('clicks');
+ if ($session->form->process("manufacturer")) {
+ $session->http->setRedirect( $self->get('manufacturerUrl') );
+ }
+ else {
+ $session->http->setRedirect( $self->get('productUrl') );
+ }
+ return undef;
+}
+
#-------------------------------------------------------------------
=head2 www_edit ( )
@@ -330,6 +688,75 @@ sub www_edit {
#-------------------------------------------------------------------
+=head2 www_rate ( )
+
+Saves a rating of a matrix listing and returns the listing view.
+
+=cut
+
+sub www_rate {
+ my $self = shift;
+ my $form = $self->session->form;
+
+ my $hasRated = $self->hasRated;
+ my $sameRating = 1;
+ my $first = 1;
+ my $lastRating;
+
+ foreach my $category (keys %{$self->getParent->getCategories}) {
+ if ($first) {
+ $first=0;
+ } else {
+ if ($lastRating != $form->process($category)) {
+ $sameRating = 0;
+ }
+ }
+ $lastRating = $form->process($category);
+ }
+
+ # Throw out ratings that are all the same number, or if the user rates twice.
+ unless ($hasRated || $sameRating) {
+ $self->setRatings($self->session->form->paramsHashRef);
+ }
+
+ $self->prepareView;
+ return $self->view;
+}
+
+#-------------------------------------------------------------------
+
+=head2 www_sendEmail ( )
+
+Sends an email to the maintainer of this matrix listing and returns www_view
+
+=cut
+
+sub www_sendEmail {
+ my $self = shift;
+ my $form = $self->session->form;
+
+ return $self->session->privilege->noAccess() unless $self->canView;
+
+ if ($form->process("verify","captcha")) {
+ if ($form->process("body") ne "") {
+ my $user = WebGUI::User->new($self->session, $self->get('maintainerId'));
+ my $mail = WebGUI::Mail::Send->create($self->session,{
+ to =>$user->profileField("email"),
+ subject =>$self->get('productName')." - ".$form->process("subject"),
+ from=>$form->process("from")
+ });
+ $mail->addText($form->process("body"));
+ $mail->addFooter;
+ $mail->queue;
+ }
+ }
+
+ $self->prepareView;
+ return $self->view(0,1);
+}
+
+#-------------------------------------------------------------------
+
=head2 www_view ( )
Web facing method which is the default view page. This method does a
@@ -340,11 +767,8 @@ Web facing method which is the default view page. This method does a
sub www_view {
my $self = shift;
return $self->session->privilege->noAccess() unless $self->canView;
- if ($self->session->var->isAdminOn) {
- return $self->getContainer->www_view;
- }
- $self->session->http->setRedirect($self->getFileUrl($self->getValue("showPage")));
- return undef;
+ $self->prepareView;
+ return $self->view;
}
#-------------------------------------------------------------------
@@ -390,6 +814,13 @@ sub install {
productURL varchar(255),
primary key (assetId, revisionDate)
)");
+ $session->db->write("create table MatrixListing_attribute (
+ matrixId char(22) not null,
+ matrixListingId char(22) not null,
+ attributeId char(22) not null,
+ value char(255),
+ primary key (matrixId, matrixListingId, attributeId)
+ )");
$session->var->end;
$session->close;
print "Done. Please restart Apache.\n";
diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm
index b71ad07b2..824ef9161 100644
--- a/lib/WebGUI/Asset/Wobject/Matrix.pm
+++ b/lib/WebGUI/Asset/Wobject/Matrix.pm
@@ -374,11 +374,161 @@ to be displayed within the page style.
=cut
sub view {
- my $self = shift;
+ my $self = shift;
my $session = $self->session;
+ my $db = $session->db;
#This automatically creates template variables for all of your wobject's properties.
my $var = $self->get;
+ $var->{isLoggedIn} = ($self->session->user->userId ne "1");
+ $var->{addMatrixListing_url} = $self->getUrl('func=add;class=WebGUI::Asset::MatrixListing');
+
+ # Get the MatrixListing with the most views as an object using getLineage.
+ my ($bestViews_listing) = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ joinClass => "WebGUI::Asset::MatrixListing",
+ orderByClause => "views desc",
+ limit => 1,
+ returnObjects => 1,
+ }) };
+ $var->{bestViews_url} = $bestViews_listing->getUrl;
+ $var->{bestViews_count} = $bestViews_listing->get('views');
+ $var->{bestViews_name} = $bestViews_listing->get('title');
+
+ # Get the MatrixListing with the most compares as an object using getLineage.
+
+ my ($bestCompares_listing) = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ joinClass => "WebGUI::Asset::MatrixListing",
+ orderByClause => "compares desc",
+ limit => 1,
+ returnObjects => 1,
+ }) };
+ $var->{bestCompares_url} = $bestCompares_listing->getUrl;
+ $var->{bestCompares_count} = $bestCompares_listing->get('views');
+ $var->{bestCompares_name} = $bestCompares_listing->get('title');
+
+ # Get the MatrixListing with the most clicks as an object using getLineage.
+ my ($bestClicks_listing) = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ joinClass => "WebGUI::Asset::MatrixListing",
+ orderByClause => "clicks desc",
+ limit => 1,
+ returnObjects => 1,
+ }) };
+ $var->{bestClicks_url} = $bestClicks_listing->getUrl;
+ $var->{bestClicks_count} = $bestClicks_listing->get('views');
+ $var->{bestClicks_name} = $bestClicks_listing->get('title');
+
+ # Get the MatrixListing that was last updated as an object using getLineage.
+
+ my ($bestUpdated_listing) = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ orderByClause => "revisionDate desc",
+ limit => 1,
+ returnObjects => 1,
+ }) };
+ $var->{bestUpdated_url} = $bestUpdated_listing->getUrl;
+ $var->{bestUpdated_date} = $session->datetime->epochToHuman( $bestUpdated_listing->get('revisionDate') );
+ $var->{bestUpdated_name} = $bestUpdated_listing->get('title');
+
+ # Get the 5 MatrixListings that were last updated as objects using getLineage.
+
+ my @lastUpdatedListings = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ orderByClause => "revisionDate desc",
+ limit => 5,
+ returnObjects => 1,
+ }) };
+ foreach my $lastUpdatedListing (@lastUpdatedListings){
+ push (@{ $var->{last_updated_loop} }, {
+ url => $lastUpdatedListing->getUrl,
+ name => $lastUpdatedListing->get('title'),
+ lastUpdated => $self->session->datetime->epochToHuman($lastUpdatedListing->get('revisionDate'),"%z")
+ });
+ }
+
+ # Get all the MatrixListings that are still pending.
+
+ my @pendingListings = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ orderByClause => "revisionDate asc",
+ returnObjects => 1,
+ statusToInclude => ['pending'],
+ }) };
+ foreach my $pendingListing (@pendingListings){
+ push (@{ $var->{pending_loop} }, {
+ url => $pendingListing->getUrl,
+ name => $pendingListing->get('title'),
+ });
+ }
+
+ # For each category, get the MatrixListings with the best ratings.
+
+ foreach my $category (keys %{$self->getCategories}) {
+ my $data;
+ my $sql = "
+ select
+ assetData.title as productName,
+ assetData.url,
+ listing.assetId,
+ rating.meanValue,
+ rating.medianValue,
+ rating.countValue
+ from MatrixListing as listing
+ left join asset on listing.assetId = asset.assetId
+ left join MatrixListing_ratingSummary as rating on rating.listingId = listing.assetId
+ left join assetData on assetData.assetId = listing.assetId and listing.revisionDate =
+assetData.revisionDate
+ where
+ asset.parentId=?
+ and asset.state='published'
+ and asset.className='WebGUI::Asset::MatrixListing'
+ and assetData.revisionDate=(
+ select
+ max(revisionDate)
+ from
+ assetData
+ where
+ assetData.assetId=asset.assetId
+ and (status='approved' or status='archived')
+ )
+ and status='approved'
+ and rating.category=?
+ group by
+ assetData.assetId
+ order by rating.meanValue ";
+
+ $data = $db->quickHashRef($sql." desc limit 1",[$self->getId,$category]);
+ push(@{ $var->{best_rating_loop} },{
+ url=>'/'.$data->{url},
+ category=>$category,
+ name=>$data->{productName},
+ mean=>$data->{meanValue},
+ median=>$data->{medianValue},
+ count=>$data->{countValue}
+ });
+ $data = $db->quickHashRef($sql." asc limit 1",[$self->getId,$category]);
+ push(@{ $var->{worst_rating_loop} },{
+ url=>'/'.$data->{url},
+ category=>$category,
+ name=>$data->{productName},
+ mean=>$data->{meanValue},
+ median=>$data->{medianValue},
+ count=>$data->{countValue}
+ });
+ }
+
+ $var->{listingCount} = scalar $db->buildArray("
+ select *
+ from asset, assetData
+ where asset.assetId=assetData.assetId
+ and asset.parentId=?
+ and asset.state='published'
+ and asset.className='WebGUI::Asset::MatrixListing'
+ and assetData.status='approved'
+ group by asset.assetId",
+ [$self->getId]);
#This is an example of debugging code to help you diagnose problems.
#WebGUI::ErrorHandler::warn($self->get("templateId"));
diff --git a/lib/WebGUI/Form/MatrixCompare.pm b/lib/WebGUI/Form/MatrixCompare.pm
index 476925235..c69d0c70d 100644
--- a/lib/WebGUI/Form/MatrixCompare.pm
+++ b/lib/WebGUI/Form/MatrixCompare.pm
@@ -115,6 +115,27 @@ sub getValue {
#-------------------------------------------------------------------
+=head2 getValueAsHtml ()
+
+Shows either Yes or No.
+
+=cut
+
+sub getValueAsHtml {
+ my $self = shift;
+ my $i18n = WebGUI::International->new($self->session,'Form_MatrixCompare');
+ my %options = (
+ 0 => $i18n->get('no'),
+ 1 => $i18n->get('limited'),
+ 2 => $i18n->get('costs extra'),
+ 3 => $i18n->get('free add on'),
+ 4 => $i18n->get('yes'),
+ );
+ return $options{$self->getOriginalValue};
+}
+
+#-------------------------------------------------------------------
+
=head2 isDynamicCompatible ( )
Returns 0.
@@ -135,7 +156,7 @@ Renders a fieldType selector.
sub toHtml {
my $self = shift;
- my $i18n = WebGUI::International->new($session,'Form_MatrixCompare');
+ my $i18n = WebGUI::International->new($self->session,'Form_MatrixCompare');
my %options;
tie %options, "Tie::IxHash";
%options = (
diff --git a/lib/WebGUI/Help/Asset_Matrix.pm b/lib/WebGUI/Help/Asset_Matrix.pm
index 2d20b0f42..7ec7f6d0b 100644
--- a/lib/WebGUI/Help/Asset_Matrix.pm
+++ b/lib/WebGUI/Help/Asset_Matrix.pm
@@ -153,16 +153,16 @@ our $HELP = {
{ 'name' => 'search.url' },
{ 'name' => 'isLoggedIn' },
{ 'name' => 'field.list.url' },
- { 'name' => 'listing.add.url' },
- { 'name' => 'best.views.url' },
- { 'name' => 'best.views.count' },
- { 'name' => 'best.views.name' },
- { 'name' => 'best.compares.url' },
- { 'name' => 'best.compares.count' },
- { 'name' => 'best.compares.name' },
- { 'name' => 'best.clicks.url' },
- { 'name' => 'best.clicks.count' },
- { 'name' => 'best.clicks.name' },
+ { 'name' => 'addMatrixListing_url' },
+ { 'name' => 'bestViews_url' },
+ { 'name' => 'bestViews_count' },
+ { 'name' => 'bestViews_name' },
+ { 'name' => 'bestCompares_url' },
+ { 'name' => 'bestCompares_count' },
+ { 'name' => 'bestCompares_name' },
+ { 'name' => 'bestClicks_url' },
+ { 'name' => 'bestClicks_count' },
+ { 'name' => 'bestClicks_name' },
{ 'name' => 'best_rating_loop',
'variables' => [
{ 'name' => 'url',
@@ -203,9 +203,9 @@ our $HELP = {
},
{ 'name' => 'ratings.details.url' },
{ 'name' => 'best.posts.url' },
- { 'name' => 'best.updated.url' },
- { 'name' => 'best.updated.date' },
- { 'name' => 'best.updated.name' },
+ { 'name' => 'bestUpdated_url' },
+ { 'name' => 'bestUpdated_date' },
+ { 'name' => 'bestUpdated_name' },
{ 'name' => 'last_update_loop',
'variables' => [
{ 'name' => 'url',
@@ -221,7 +221,7 @@ our $HELP = {
},
{ 'name' => 'user.count' },
{ 'name' => 'current.user.count' },
- { 'name' => 'listing.count' },
+ { 'name' => 'listingCount' },
{ 'name' => 'pending_list',
'variables' => [
{ 'name' => 'url',
@@ -266,8 +266,8 @@ our $HELP = {
{ 'name' => 'approve.url' },
{ 'name' => 'delete.url' },
{ 'name' => 'isPending' },
- { 'name' => 'lastUpdated.epoch' },
- { 'name' => 'lastUpdated.date' },
+ { 'name' => 'lastUpdated_epoch' },
+ { 'name' => 'lastUpdated_date' },
{ 'name' => 'id' },
{ 'name' => 'description',
'description' => 'listing description'
diff --git a/lib/WebGUI/i18n/English/Asset_Matrix.pm b/lib/WebGUI/i18n/English/Asset_Matrix.pm
index 32a8c9d0a..f386ae918 100644
--- a/lib/WebGUI/i18n/English/Asset_Matrix.pm
+++ b/lib/WebGUI/i18n/English/Asset_Matrix.pm
@@ -63,6 +63,12 @@ our $I18N = {
lastUpdated => 1149783768,
},
+ 'categoryLabel' => {
+ message => q|The label of a category.|,
+ lastUpdated => 1149783768,
+ },
+
+
'tmplVar category' => {
message => q|The name of the current category.|,
lastUpdated => 1149783768,
@@ -158,64 +164,59 @@ our $I18N = {
lastUpdated => 1167186037,
},
- 'lastUpdated.epoch' => {
+ 'lastUpdated_epoch' => {
message => q|The epoch date of when this listing was last updated.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
- 'lastUpdated.date' => {
+ 'lastUpdated_date' => {
message => q|A human readable date of when this listing was last updated.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
- 'id' => {
- message => q|The unique identifier of this listing.|,
- lastUpdated => 1149784175,
- },
-
- 'listing description' => {
+ 'description' => {
message => q|The description of this listing.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
'productName' => {
- message => q|The name of this listing.|,
- lastUpdated => 1149784175,
+ message => q|The name of this listing. This is the same as this matrix listing's asset title.|,
+ lastUpdated => 0,
},
'productUrl' => {
message => q|The manufacturer's URL for this listing.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
- 'productUrl.click' => {
+ 'productUrl_click' => {
message => q|The product URL to use if you want to register the click count for this listing.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
'manufacturerUrl' => {
message => q|The manufacturer's URL.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
- 'manufacturerUrl.click' => {
+ 'manufacturerUrl_click' => {
message => q|The manufacturer URL to use if you want to register the click count for this listing.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
'views' => {
message => q|The total number of views this listing has received.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
'compares' => {
message => q|The total number of compares this listing has received.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
'clicks' => {
message => q|The total number of clicks this listing has received.|,
- lastUpdated => 1149784175,
+ lastUpdated => 0,
},
'ratings' => {
@@ -224,10 +225,15 @@ our $I18N = {
},
'CATEGORY_NAME_loop' => {
- message => q|A loop is created for each category in this matrix. The name of the loop is the category name with spaces replaced with hyphens and a _loop added to the end. So if you have a category called "Bells and Whistles" then the loop would be called "bells-and-whistles_loop".|,
- lastUpdated => 1167186070,
+ message => q|A loop containting attributes and values for those attributes is created for each category in this matrix. The name of the loop is the category name with spaces replaced with hyphens and a _loop added to the end. So if you have a category called "Bells and Whistles" then the loop would be called "bells-and-whistles_loop".|,
+ lastUpdated => 0,
},
+ 'attribute_loop' => {
+ message => q|A loop containing attributes and values for those attributes.|,
+ lastUpdated => 0,
+ },
+
'tmplVar name' => {
message => q|The name of this field.|,
lastUpdated => 1149784175,
@@ -273,124 +279,124 @@ our $I18N = {
lastUpdated => 1149795214,
},
- 'listing.add.url' => {
+ 'addMatrixListing_url' => {
message => q|The URL to the page where a user can add a new listing to the matrix.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.views.url' => {
+ 'bestViews_url' => {
message => q|The URL to the listing that has the most views.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.views.count' => {
+ 'bestViews_count' => {
message => q|The total number of views of the listing that has the most views.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.views.name' => {
+ 'bestViews_name' => {
message => q|The name of the listing that has the most views.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.compares.url' => {
+ 'bestCompares_url' => {
message => q|The URL to the listing that has the most compares.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.compares.count' => {
+ 'bestCompares_count' => {
message => q|The number of compares of the listing that has the most compares.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.compares.name' => {
+ 'bestCompares_name' => {
message => q|The name of the listing that has the most compares.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.clicks.url' => {
+ 'bestClicks_url' => {
message => q|The URL of the listing that has the most clicks.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.clicks.count' => {
+ 'bestClicks_count' => {
message => q|The number of clicks of the listing that has the most clicks.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.clicks.name' => {
+ 'bestClicks_name' => {
message => q|The name of the listing that has the most clicks.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'best_rating_loop' => {
message => q|A loop containing all of the categories for this matrix and their best ratings.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'tmplVar best.url' => {
message => q|The URL of the listing that has the best rating for this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'tmplVar best.category' => {
message => q|The name of this category.|,
- lastUpdated => 1167186103,
+ lastUpdated => 0,
},
'tmplVar best.name' => {
message => q|The name of the listing that has the best rating for this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'mean' => {
message => q|The mean (or average) rating of the best listing in this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'median' => {
message => q|The median (or middle) rating of the best listing in this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'count' => {
message => q|The sum of all the votes of the best listing in this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'worst_rating_loop' => {
message => q|A loop containing all of the categories for this matrix and their worst ratings.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'tmplVar worst.url' => {
message => q|The URL of the listing that has the worst rating for this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'tmplVar worst.category' => {
message => q|The name of this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'tmplVar worst.name' => {
message => q|The name of the listing that has the worst rating for this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'tmplVar worst.mean' => {
message => q|The mean (or average) rating of the worst listing in this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'tmplVar worst.median' => {
message => q|The median (or middle) rating of the worst listing in this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'tmplVar worst.count' => {
message => q|The sum of all the votes of the worst listing in this category.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'ratings.details.url' => {
@@ -403,19 +409,19 @@ our $I18N = {
lastUpdated => 1149795214,
},
- 'best.updated.url' => {
+ 'bestUpdated_url' => {
message => q|The URL to the listing that was updated most recently.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.updated.date' => {
+ 'bestUpdated_date' => {
message => q|The date of the most recently updated listing.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'best.updated.name' => {
+ 'bestUpdated_name' => {
message => q|The name of the listing that was most recently updated.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'last_update_loop' => {
@@ -448,26 +454,36 @@ our $I18N = {
lastUpdated => 1149795214,
},
- 'listing.count' => {
+ 'listingCount' => {
message => q|The number of listings in this matrix.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'pending_list' => {
+ 'pending_loop' => {
message => q|A loop containing the list of pending listing.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
'tmplVar pending.url' => {
message => q|The URL to the pending listing.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
- 'tmplVar pending.productName' => {
+ 'tmplVar pending.name' => {
message => q|The product title of the pending listing.|,
- lastUpdated => 1149795214,
+ lastUpdated => 0,
},
+ 'narrow the matrix label' => {
+ message => q|Narrow The Matrix|,
+ lastUpdated => 0,
+ },
+
+ 'expand the matrix label' => {
+ message => q|Expand The Matrix|,
+ lastUpdated => 0,
+ },
+
'matrix template help title' => {
message => q|Matrix Main Template Variables|,
lastUpdated => 1184949132,
@@ -827,36 +843,47 @@ our $I18N = {
lastUpdated => 0,
},
- 'your email' => {
+ 'your email label' => {
message => q|Your Email Address|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'report error' => {
+ 'report error label' => {
message => q|Report an error.|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'general comment' => {
+ 'general comment label' => {
message => q|General comment.|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'request type' => {
+ 'request type label' => {
message => q|Type of Request|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
- 'comment' => {
+ 'comment label' => {
message => q|Comment|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
+ 'send button label' => {
+ message => q|Send...|,
+ lastUpdated => 0,
+ },
+
+
'show ratings' => {
message => q|Show Ratings|,
- lastUpdated => 1133758944,
+ lastUpdated => 0,
},
+ 'rate submit label' => {
+ message => q|Rate|,
+ lastUpdated => 0,
+ },
+
'no copy' => {
message => q|This asset may not be copied.|,
lastUpdated => 1133758944,
From 58a1f2a85ed1709b27dae05c8044218975107135 Mon Sep 17 00:00:00 2001
From: Yung Han Khoe
Date: Mon, 10 Nov 2008 22:37:07 +0000
Subject: [PATCH 4/9] Added Compare box to Matrix v2
---
lib/WebGUI/Asset/Wobject/Matrix.pm | 78 ++++++++++++++++++++++++++++--
1 file changed, 75 insertions(+), 3 deletions(-)
diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm
index 824ef9161..c4173421a 100644
--- a/lib/WebGUI/Asset/Wobject/Matrix.pm
+++ b/lib/WebGUI/Asset/Wobject/Matrix.pm
@@ -115,9 +115,9 @@ sub definition {
tab =>"display",
options =>{
score => $i18n->get('sort by score label'),
- alphaNumeric => $i18n->get('sort alpha numeric label'),
- assetRank => $i18n->get('sort by asset rank label'),
- lastUpdated => $i18n->get('sort by last updated label'),
+ title => $i18n->get('sort alpha numeric label'),
+ lineage => $i18n->get('sort by asset rank label'),
+ revisionDate => $i18n->get('sort by last updated label'),
},
defaultValue =>"score",
hoverHelp =>$i18n->get('default sort description'),
@@ -309,6 +309,77 @@ sub getCategories {
}
+#-------------------------------------------------------------------
+
+=head2 getCompareForm ( )
+
+Returns the compare form.
+
+=head3 selectedListingIds
+
+An array of listingIds that should be selected in the compare form.
+
+=cut
+
+sub getCompareForm {
+ my $self = shift;
+ my @selectedListingIds = @_;
+
+ my (%options, @listings);
+ tie %options, 'Tie::IxHash';
+
+ if ($self->get('defaultSort') eq 'score'){
+ my @unorderedListings = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ returnObjects => 1,
+ }) };
+ foreach my $listing (@unorderedListings) {
+ }
+ # sort an array of hashrefs:
+ # @listings = sort { $$a{'ques'} <=> $$b{'ques'} } @listings;
+ }
+ else{
+ my $sortDirection = " asc";
+ if ($self->get('defaultSort') eq "revisionDate"){
+ $sortDirection = " desc";
+ }
+ @listings = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ orderByClause => $self->get('defaultSort').$sortDirection,
+ returnObjects => 1,
+ }) };
+ }
+ # Create an options hash based on the orderd array of listings.
+ foreach my $listing (@listings){
+ $options{$listing->getId} = ''.$listing->get('title').' ';
+ }
+
+
+ my $form = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl})
+ .WebGUI::Form::submit($self->session, {
+ value=>"compare"
+ })
+ ." "
+ ." "
+ .WebGUI::Form::hidden($self->session, {
+ name=>"func",
+ value=>"compare"
+ })
+ .WebGUI::Form::checkList($self->session, {
+ name=>"listingId",
+ vertical=>1,
+ value=>\@selectedListingIds,
+ options=>\%options,
+ })
+ ." "
+ .WebGUI::Form::submit($self->session,{
+ value=>"compare"
+ })
+ .WebGUI::Form::formFooter($self->session);
+ return $form;
+}
+
+
#-------------------------------------------------------------------
@@ -382,6 +453,7 @@ sub view {
my $var = $self->get;
$var->{isLoggedIn} = ($self->session->user->userId ne "1");
$var->{addMatrixListing_url} = $self->getUrl('func=add;class=WebGUI::Asset::MatrixListing');
+ $var->{compareForm} = $self->getCompareForm;
# Get the MatrixListing with the most views as an object using getLineage.
my ($bestViews_listing) = @{ $self->getLineage(['descendants'], {
From ab14e4aa0f74e33d50f19add2f6d10ff62a0877e Mon Sep 17 00:00:00 2001
From: Yung Han Khoe
Date: Sun, 16 Nov 2008 21:05:27 +0000
Subject: [PATCH 5/9] Adding more features to Matrix v2
---
lib/WebGUI/Asset/MatrixListing.pm | 208 ++++++++++++-
lib/WebGUI/Asset/Wobject/Matrix.pm | 294 ++++++++++++++++--
www/extras/wobject/Matrix/matrix.js | 74 +++++
.../wobject/Matrix/matrixCompareList.js | 86 +++++
4 files changed, 614 insertions(+), 48 deletions(-)
create mode 100644 www/extras/wobject/Matrix/matrix.js
create mode 100644 www/extras/wobject/Matrix/matrixCompareList.js
diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm
index 528331e8b..68da4beed 100644
--- a/lib/WebGUI/Asset/MatrixListing.pm
+++ b/lib/WebGUI/Asset/MatrixListing.pm
@@ -16,7 +16,9 @@ package WebGUI::Asset::MatrixListing;
use strict;
use Tie::IxHash;
-use base 'WebGUI::Asset';
+use Class::C3;
+use base qw(WebGUI::AssetAspect::Comments WebGUI::Asset);
+#use base 'WebGUI::Asset';
use WebGUI::Utility;
@@ -53,7 +55,7 @@ These methods are available from this class:
sub addRevision {
my $self = shift;
- my $newSelf = $self->SUPER::addRevision(@_);
+ my $newSelf = $self->next::method(@_);
return $newSelf;
}
@@ -110,6 +112,11 @@ sub definition {
label =>$i18n->get("version label"),
hoverHelp =>$i18n->get("version description")
},
+ score => {
+ defaultValue =>0,
+ autoGenerate =>0,
+ noFormPost =>1,
+ },
views => {
defaultValue =>0,
autoGenerate =>0,
@@ -182,7 +189,7 @@ sub definition {
className=>'WebGUI::Asset::MatrixListing',
properties=>\%properties
});
- return $class->SUPER::definition($session, $definition);
+ return $class->next::method($session, $definition);
}
@@ -198,7 +205,7 @@ sub definition {
sub duplicate {
my $self = shift;
- my $newAsset = $self->SUPER::duplicate(@_);
+ my $newAsset = $self->next::method(@_);
return $newAsset;
}
@@ -229,7 +236,7 @@ sub getEditForm {
my $session = $self->session;
my $db = $session->db;
my $matrixId = $self->getParent->getId;
- my $tabform = $self->SUPER::getEditForm();
+ my $tabform = $self->next::method();#SUPER::getEditForm();
my $i18n = WebGUI::International->new($session, 'Asset_MatrixListing');
#$self->session->style->setScript($self->session->url->extras('FileUploadControl.js'), {type =>'text/javascript'});
@@ -339,7 +346,7 @@ Making private. See WebGUI::Asset::indexContent() for additonal details.
sub indexContent {
my $self = shift;
- my $indexer = $self->SUPER::indexContent;
+ my $indexer = $self->next::method;
$indexer->setIsPublic(0);
}
@@ -354,7 +361,7 @@ See WebGUI::Asset::prepareView() for details.
sub prepareView {
my $self = shift;
- $self->SUPER::prepareView();
+ $self->next::method();
my $template = WebGUI::Asset::Template->new($self->session, $self->getParent->get('detailTemplateId'));
$template->prepare;
$self->{_viewTemplate} = $template;
@@ -372,18 +379,26 @@ Used to process properties from the form posted.
sub processPropertiesFromFormPost {
my $self = shift;
my $session = $self->session;
+ my $score = 0;
- $self->SUPER::processPropertiesFromFormPost;
+ $self->next::method(@_);#SUPER::processPropertiesFromFormPost;
my $attributes = $session->db->read("select * from Matrix_attribute where assetId = ?",[$self->getParent->getId]);
while (my $attribute = $attributes->hashRef) {
my $name = 'attribute_'.$attribute->{attributeId};
- #my $value = $session->form->process($name);
- my $value = $session->form->process($name,$attribute->{fieldType},$attribute->{defaultValue},$attribute);
+ my $value;
+ if ($attribute->{fieldType} eq 'MatrixCompare'){
+ $value = $session->form->process($name);
+ $score = $score + $value;
+ }
+ else{
+ $value = $session->form->process($name,$attribute->{fieldType},$attribute->{defaultValue},$attribute);
+ }
$session->db->write("replace into MatrixListing_attribute (matrixId, matrixListingId, attributeId, value)
values (?, ?, ?, ?)",
[$self->getParent->getId,$self->getId,$attribute->{attributeId},$value]);
}
+ $self->update({score => $score});
$self->requestAutoCommit;
}
@@ -407,7 +422,7 @@ sub purge {
$db->write("delete from MatrixListing_rating where listingId=?" ,[$self->getId]);
$db->write("delete from MatrixListing_ratingSummary where listingId=?" ,[$self->getId]);
- return $self->SUPER::purge;
+ return $self->next::method;
}
#-------------------------------------------------------------------
@@ -420,7 +435,7 @@ This method is called when data is purged by the system.
sub purgeRevision {
my $self = shift;
- return $self->SUPER::purgeRevision;
+ return $self->next::method;
}
#-------------------------------------------------------------------
@@ -495,6 +510,7 @@ sub view {
$var->{emailSent} = 1;
}
$var->{controls} = $self->getToolbar;
+ $var->{comments} = $self->getFormattedComments(),
$var->{productName} = $var->{title};
$var->{lastUpdated_epoch} = $self->get('lastUpdated');
$var->{lastUpdated_date} = $self->session->datetime->epochToHuman($self->get('lastUpdated'),"%z");
@@ -536,8 +552,57 @@ sub view {
my $storage = $file->getStorageLocation;
my @files = @{ $storage->getFiles } if (defined $storage);
if (scalar(@files)) {
- $var->{screenshots} = $file->getFilePreview($storage);
+ #$var->{screenshots} = $file->getFilePreview($storage);
}
+ $var->{screenshots} = qq|
+
+
+
+
+
+
+
+
+
+
+
+|;
}
# Rating form
@@ -641,7 +706,7 @@ sub view {
);
$var->{emailForm} = $mailForm->print;
- return $self->processTemplate($var,undef, $self->{_viewTemplate});
+ return $self->getParent->processStyle($self->processTemplate($var,undef, $self->{_viewTemplate}));
}
@@ -655,6 +720,9 @@ Redirects to the manufacturerUrl or productUrl and increments clicks.
sub www_click {
my $self = shift;
+
+ return $self->session->privilege->noAccess() unless $self->canView;
+
my $session = $self->session;
$self->incrementCounter('clicks');
@@ -688,6 +756,118 @@ sub www_edit {
#-------------------------------------------------------------------
+=head2 www_getScreenshots ( )
+
+Returns the screenshots as xml.
+
+=cut
+
+sub www_getScreenshots {
+ my $self = shift;
+
+ return $self->session->privilege->noAccess() unless $self->canView;
+
+ $self->session->http->setMimeType('text/xml');
+
+ my $xml = qq |
+
+
+|;
+
+ if ( $self->get('screenshots') ) {
+ my $fileObject = WebGUI::Form::File->new($self->session,{ value=>$self->get('screenshots') });
+ my $storage = $fileObject->getStorageLocation;
+ my $path = $storage->getPath;
+ my @files = @{ $storage->getFiles } if (defined $storage);
+ foreach my $file (@files) {
+ unless ($file =~ m/^thumb-/){
+ my $thumb = 'thumb-'.$file;
+ $xml .= "
+
+ 400
+ 300
+ Slide One]]>
+
+ ".$storage->getUrl($file)."
+ 5
+ ".$storage->getUrl($thumb)."
+
+ ";
+ }
+ }
+ }
+
+ $xml .= qq |
+
+
+|;
+
+ return $xml;
+}
+
+#-------------------------------------------------------------------
+
+=head2 www_getScreenshotsConfig ( )
+
+Returns the xml config file for the ukplayer that displays the screenshots.
+
+=cut
+
+sub www_getScreenshotsConfig {
+ my $self = shift;
+
+ return $self->session->privilege->noAccess() unless $self->canView;
+
+ $self->session->http->setMimeType('text/xml');
+
+ my $xml = qq|
+
+
+ ?func=getScreenshots
+
+ 400
+ 300
+ 0xDDDDEE
+ 20
+ 100
+ 100
+
+ Verdana
+ 12
+ 0xCCCCCC
+ 0xCCCCCC
+ 0x000000
+ true
+
+ 0xCCCCCC
+ 0xCCCCCC
+ 0x000000
+ false
+
+ 48
+ 36
+ 0x000000
+ true
+ 100
+ 5
+
+ false
+ true
+ false
+ false
+
+
+
+
+|;
+
+ return $xml;
+}
+
+#-------------------------------------------------------------------
+
=head2 www_rate ( )
Saves a rating of a matrix listing and returns the listing view.
diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm
index c4173421a..cc45f4033 100644
--- a/lib/WebGUI/Asset/Wobject/Matrix.pm
+++ b/lib/WebGUI/Asset/Wobject/Matrix.pm
@@ -15,8 +15,10 @@ $VERSION = "2.0.0";
use strict;
use warnings;
use Tie::IxHash;
+use JSON;
use WebGUI::International;
use WebGUI::Utility;
+use WebGUI::Asset::MatrixListing;
use base 'WebGUI::Asset::Wobject';
#----------------------------------------------------------------------------
@@ -94,14 +96,14 @@ sub definition {
hoverHelp =>$i18n->get('detail template description'),
label =>$i18n->get('detail template label'),
},
- ratingDetailTemplateId=>{
- defaultValue =>"matrixtmpl000000000004",
- fieldType =>"template",
- tab =>"display",
- namespace =>"Matrix/RatingDetail",
- hoverHelp =>$i18n->get('rating detail template description'),
- label =>$i18n->get('rating detail template label'),
- },
+# ratingDetailTemplateId=>{
+# defaultValue =>"matrixtmpl000000000004",
+# fieldType =>"template",
+# tab =>"display",
+# namespace =>"Matrix/RatingDetail",
+# hoverHelp =>$i18n->get('rating detail template description'),
+# label =>$i18n->get('rating detail template label'),
+# },
compareTemplateId=>{
defaultValue =>"matrixtmpl000000000002",
fieldType =>"template",
@@ -328,27 +330,16 @@ sub getCompareForm {
my (%options, @listings);
tie %options, 'Tie::IxHash';
- if ($self->get('defaultSort') eq 'score'){
- my @unorderedListings = @{ $self->getLineage(['descendants'], {
- includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
- returnObjects => 1,
- }) };
- foreach my $listing (@unorderedListings) {
- }
- # sort an array of hashrefs:
- # @listings = sort { $$a{'ques'} <=> $$b{'ques'} } @listings;
- }
- else{
- my $sortDirection = " asc";
- if ($self->get('defaultSort') eq "revisionDate"){
- $sortDirection = " desc";
- }
- @listings = @{ $self->getLineage(['descendants'], {
- includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
- orderByClause => $self->get('defaultSort').$sortDirection,
- returnObjects => 1,
- }) };
+ my $sortDirection = " asc";
+ if ( WebGUI::Utility::isIn($self->get('defaultSort'),qw(revisionDate score)) ){
+ $sortDirection = " desc";
}
+ @listings = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ joinClass => "WebGUI::Asset::MatrixListing",
+ orderByClause => $self->get('defaultSort').$sortDirection,
+ returnObjects => 1,
+ }) };
# Create an options hash based on the orderd array of listings.
foreach my $listing (@listings){
$options{$listing->getId} = ''.$listing->get('title').' ';
@@ -365,17 +356,19 @@ sub getCompareForm {
name=>"func",
value=>"compare"
})
- .WebGUI::Form::checkList($self->session, {
- name=>"listingId",
- vertical=>1,
- value=>\@selectedListingIds,
- options=>\%options,
- })
+ .'
'
+# .WebGUI::Form::checkList($self->session, {
+# name=>"listingId",
+# vertical=>1,
+# value=>\@selectedListingIds,
+# options=>\%options,
+# })
." "
.WebGUI::Form::submit($self->session,{
value=>"compare"
})
.WebGUI::Form::formFooter($self->session);
+ #.'
';
return $form;
}
@@ -449,6 +442,24 @@ sub view {
my $session = $self->session;
my $db = $session->db;
+ # javascript and css files for compare form datatable
+ $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('wobject/Matrix/matrix.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'});
+
#This automatically creates template variables for all of your wobject's properties.
my $var = $self->get;
$var->{isLoggedIn} = ($self->session->user->userId ne "1");
@@ -610,6 +621,66 @@ assetData.revisionDate
#-------------------------------------------------------------------
+=head2 www_compare ( )
+
+Returns the compare screen
+
+=cut
+
+sub www_compare {
+
+ my $self = shift;
+ my $var = $self->get;
+ my @listingIds = @_;
+ my @columnKeys = ['name'];
+ #my @listingIds = ['AwioUvaZXmAEaFw20t-x3Q', 'CWNjAHcmh0pEF6WJooomJA'];
+ unless (scalar(@listingIds)) {
+ @listingIds = $self->session->form->checkList("listingId");
+ }
+
+ $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/matrix.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 $listingId (@listingIds){
+ my $listingId_safe = $listingId;
+ $listingId_safe =~ s/-//g;
+ push(@columnKeys, $listingId_safe);
+ }
+
+ $var->{javascript} = "";
+
+ return $self->processStyle($self->processTemplate($var,$self->get("compareTemplateId")));;
+}
+
+#-------------------------------------------------------------------
+
=head2 www_deleteAttribute ( )
Deletes an Attribute, including listing data for this attribute.
@@ -805,6 +876,161 @@ sub www_editAttributeSave {
#-------------------------------------------------------------------
+=head2 www_getCompareFormData ( )
+
+Returns the compare form data as JSON.
+
+=cut
+
+sub www_getCompareFormData {
+
+ my $self = shift;
+ my @results;
+ my $sortDirection = ' asc';
+
+ $self->session->http->setMimeType("application/json");
+=cut
+ my @listings = @{ $self->getLineage(['descendants'], {
+ includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
+ joinClass => "WebGUI::Asset::MatrixListing",
+ orderByClause => $self->get('defaultSort').$sortDirection,
+ returnObjects => 1,
+ }) };
+=cut
+ my $sql = "
+ select
+ assetData.title,
+ assetData.url,
+ listing.assetId,
+ listing.views,
+ listing.compares,
+ listing.clicks,
+ listing.lastUpdated
+ from MatrixListing as listing
+ left join asset on listing.assetId = asset.assetId
+ left join assetData on assetData.assetId = listing.assetId and listing.revisionDate =
+assetData.revisionDate
+ where
+ asset.parentId=?
+ and asset.state='published'
+ and asset.className='WebGUI::Asset::MatrixListing'
+ and assetData.revisionDate=(
+ select
+ max(revisionDate)
+ from
+ assetData
+ where
+ assetData.assetId=asset.assetId
+ and (status='approved' or status='archived')
+ )
+ and status='approved'
+ group by
+ assetData.assetId
+ order by ".$self->get('defaultSort').$sortDirection;
+
+ my $results = $self->session->db->buildArrayRefOfHashRefs($sql,[$self->getId]);
+=cut
+push(@results,{
+ Title=>$data->{title},
+ Views=>$data->{views},
+ Compares=>$data->{compares},
+ Clicks=>$data->{clicks}
+ });
+=cut
+ # Create an options hash based on the orderd array of listings.
+=cut
+ foreach my $listing (@listings){
+ push(@results,{Title=>$listing->get('title'),Phone=>'123'})
+ #$options{$listing->getId} = ''.$listing->get('title').' ';
+ }
+=cut
+ my $jsonOutput;
+ $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
+}
+
+#-------------------------------------------------------------------
+
+=head2 www_getCompareListData ( )
+
+Returns the compare list data as JSON.
+
+=cut
+
+sub www_getCompareListData {
+
+ my $self = shift;
+ my @listingIds = @_;
+ unless (scalar(@listingIds)) {
+ @listingIds = $self->session->form->checkList("listingId");
+ }
+
+ my $session = $self->session;
+ my (@results,$results,@columnDefs);
+ my $sortDirection = ' asc';
+
+ foreach my $listingId (@listingIds){
+ 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')});
+ }
+
+ my $jsonOutput;
+ $jsonOutput->{ColumnDefs} = \@columnDefs;
+
+ foreach my $category (keys %{$self->getCategories}) {
+ my $fields = " a.name, a.fieldType ";
+ my $from = "from Matrix_attribute a";
+ my $tableCount = "b";
+ foreach my $listingId (@listingIds) {
+ my $listingId_safe = $listingId;
+ $listingId_safe =~ s/-//g;
+ $fields .= ", ".$tableCount.".value as `$listingId_safe`";
+ $from .= " left join MatrixListing_attribute ".$tableCount." on a.attributeId="
+ .$tableCount.".attributeId and ".$tableCount.".matrixListingId=? ";
+ $tableCount++;
+ }
+ push(@results, @{ $self->session->db->buildArrayRefOfHashRefs(
+ "select $fields $from where a.category=? and a.assetId=? order by a.name",
+ [@listingIds,$category,$self->getId]
+ ) });
+ }
+ foreach my $result (@results){
+ foreach my $listingId (@listingIds) {
+ my $listingId_safe = $listingId;
+ $listingId_safe =~ s/-//g;
+ if ($result->{fieldType} eq 'MatrixCompare'){
+ $result->{$listingId_safe} = WebGUI::Form::MatrixCompare->new( $self->session,
+ { value=>$result->{$listingId_safe} },defaultValue=>0)->getValueAsHtml;
+ }
+ }
+ }
+
+ $jsonOutput->{ResultSet} = {Result=>\@results};
+
+ $session->http->setMimeType("application/json");
+
+ return JSON->new->utf8->encode($jsonOutput);
+}
+#-------------------------------------------------------------------
+
=head2 www_listAttributes ( )
Lists all attributes of this Matrix.
diff --git a/www/extras/wobject/Matrix/matrix.js b/www/extras/wobject/Matrix/matrix.js
new file mode 100644
index 000000000..824d6c42a
--- /dev/null
+++ b/www/extras/wobject/Matrix/matrix.js
@@ -0,0 +1,74 @@
+var myCompareTable;
+
+YAHOO.util.Event.addListener(window, "load", function() {
+ YAHOO.example.XHR_JSON = new function() {
+ this.formatUrl = function(elCell, oRecord, oColumn, sData) {
+ elCell.innerHTML = "" + sData + " ";
+ };
+
+ this.formatCheckBox = function(elCell, oRecord, oColumn, sData) {
+ elCell.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}
+ ];
+
+ 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"]
+ };
+
+ this.myDataTable = new YAHOO.widget.DataTable("compareForm", myColumnDefs,
+ this.myDataSource, {initialRequest:"func=getCompareFormData"});
+
+ var oColumn = this.myDataTable.getColumn(3);
+ this.myDataTable.hideColumn(oColumn);
+
+
+ var btnAddRows = new YAHOO.widget.Button("hidecolumn");
+ btnAddRows.on("click", function(e) {
+
+ //var oColumn = this.myDataTable.getColumn(3);
+ this.myDataTable.sortColumn(oColumn);
+ },this,true);
+
+
+ var myCallback = function() {
+ this.set("sortedBy", null);
+ this.onDataReturnAppendRows.apply(this,arguments);
+ };
+
+ };
+});
+
+//function sort() {
+// myCompareTable.sortColumn()
+// var oColumn = myCompareTable.getColumn(3);
+// myCompareTable.hideColumn(oColumn);
+//}
+
+function bla() {
+ var callback1 = {
+ success : myCallback,
+ failure : myCallback,
+ scope : this.myDataTable
+ };
+ this.myDataSource.sendRequest("func=getCompareFormData",
+ callback1);
+
+ var callback2 = {
+ success : myCallback,
+ failure : myCallback,
+ scope : this.myDataTable
+ };
+ this.myDataSource.sendRequest("func=getCompareFormData",
+ callback2);
+}
\ No newline at end of file
diff --git a/www/extras/wobject/Matrix/matrixCompareList.js b/www/extras/wobject/Matrix/matrixCompareList.js
new file mode 100644
index 000000000..f613dbbd3
--- /dev/null
+++ b/www/extras/wobject/Matrix/matrixCompareList.js
@@ -0,0 +1,86 @@
+//var myCompareTable;
+
+YAHOO.util.Event.addListener(window, "load", function() {
+ YAHOO.example.XHR_JSON = new function() {
+
+ var myColumnDefs = [
+ {key:"name"}
+ ];
+
+ 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: columnKeys //["name","AwioUvaZXmAEaFw20tx3Q","CWNjAHcmh0pEF6WJooomJA"]
+ };
+
+ var uri = "func=getCompareListData";
+ for (var i = 0; i < listingIds.length; i++) {
+ uri = uri+';listingId='+listingIds[i];
+ }
+
+ var myDataTable = new YAHOO.widget.DataTable("compareList", myColumnDefs,
+ this.myDataSource, {initialRequest:uri});
+
+ //var oColumn = this.myDataTable.getColumn(3);
+ //this.myDataTable.hideColumn(oColumn);
+
+
+ //var btnAddRows = new YAHOO.widget.Button("hidecolumn");
+ //btnAddRows.on("click", function(e) {
+
+ //var oColumn = this.myDataTable.getColumn(3);
+ // this.myDataTable.sortColumn(oColumn);
+ //},this,true);
+
+ this.myDataSource.doBeforeParseData = function (oRequest, oFullResponse) {
+ myDataTable.getRecordSet().reset();
+ var existingColumns = myDataTable.getColumnSet().keys;
+ for (var i = 0; i < existingColumns.length; i++) {
+ if(i > 0){
+ myDataTable.removeColumn(existingColumns[1]);
+ }
+ }
+ if (oFullResponse.ColumnDefs) {
+ var len = oFullResponse.ColumnDefs.length;
+
+ for (var i = 0; i < len; i++) {
+ var c = oFullResponse.ColumnDefs[i];
+ myDataTable.insertColumn(c);
+ }
+ }
+ return oFullResponse;
+ }
+
+ var myCallback = function() {
+ this.set("sortedBy", null);
+ this.onDataReturnAppendRows.apply(this,arguments);
+ };
+
+ var myCallback2 = function() {
+ this.getRecordSet().reset();
+ //this.render();
+ this.set("sortedBy", null);
+ this.onDataReturnAppendRows.apply(this,arguments);
+ this.getRecordSet().reset();
+ };
+
+
+ var callback2 = {
+ success : myCallback,
+ failure : myCallback,
+ scope : myDataTable
+ };
+ this.myDataSource.sendRequest("func=getCompareListData;listingId=CWNjAHcmh0pEF6WJooomJA",
+ callback2);
+
+ };
+});
+
+//function sort() {
+// myCompareTable.sortColumn()
+// var oColumn = myCompareTable.getColumn(3);
+// myCompareTable.hideColumn(oColumn);
+//}
+
From 7f3193f08ecf00abd201bd855e41739538883d49 Mon Sep 17 00:00:00 2001
From: Yung Han Khoe
Date: Tue, 18 Nov 2008 00:39:52 +0000
Subject: [PATCH 6/9] Adding search and some compare features to Matrix v2
---
lib/WebGUI/Asset/Wobject/Matrix.pm | 187 +++++++++++++++---
www/extras/wobject/Matrix/matrix.js | 18 +-
.../wobject/Matrix/matrixCompareList.js | 105 ++++++++--
www/extras/wobject/Matrix/matrixSearch.js | 96 +++++++++
4 files changed, 358 insertions(+), 48 deletions(-)
create mode 100644 www/extras/wobject/Matrix/matrixSearch.js
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
Date: Tue, 18 Nov 2008 18:11:16 +0000
Subject: [PATCH 7/9] Adding more features to Matrix v2
---
lib/WebGUI/Asset/MatrixListing.pm | 4 +-
lib/WebGUI/Asset/Wobject/Matrix.pm | 90 ++++++++++++-------
www/extras/wobject/Matrix/matrix.js | 63 ++++++++++---
.../wobject/Matrix/matrixCompareList.js | 25 +++++-
www/extras/wobject/Matrix/matrixSearch.js | 55 ++++++------
5 files changed, 157 insertions(+), 80 deletions(-)
diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm
index 68da4beed..27416611d 100644
--- a/lib/WebGUI/Asset/MatrixListing.pm
+++ b/lib/WebGUI/Asset/MatrixListing.pm
@@ -325,9 +325,9 @@ sub incrementCounter {
my $counter = shift;
my $currentIp = $self->session->env->get("HTTP_X_FORWARDED_FOR");
- print "current ip: ".$currentIp." ";
+ #print "current ip: ".$currentIp." ";
- print "dsfsdf lastIp : ".$self->get($counter."LastIp")." ";
+ #print "dsfsdf lastIp : ".$self->get($counter."LastIp")." ";
unless ($self->get($counter."LastIp") eq $currentIp) {
$self->update({
$counter."LastIp" => $currentIp,
diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm
index 4eaab8331..c4bf353ca 100644
--- a/lib/WebGUI/Asset/Wobject/Matrix.pm
+++ b/lib/WebGUI/Asset/Wobject/Matrix.pm
@@ -478,6 +478,8 @@ sub view {
my $db = $session->db;
# javascript and css files for compare form datatable
+ $self->session->style->setLink($self->session->url->extras('yui/build/datatable/assets/skins/sam/datatable.css'),
+ {type =>'text/css', rel=>'stylesheet'});
$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 =>
@@ -490,12 +492,11 @@ sub view {
'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/matrix.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'});
- #This automatically creates template variables for all of your wobject's properties.
my $var = $self->get;
$var->{isLoggedIn} = ($self->session->user->userId ne "1");
$var->{addMatrixListing_url} = $self->getUrl('func=add;class=WebGUI::Asset::MatrixListing');
@@ -509,9 +510,10 @@ sub view {
limit => 1,
returnObjects => 1,
}) };
- $var->{bestViews_url} = $bestViews_listing->getUrl;
- $var->{bestViews_count} = $bestViews_listing->get('views');
- $var->{bestViews_name} = $bestViews_listing->get('title');
+ $var->{bestViews_url} = $bestViews_listing->getUrl;
+ $var->{bestViews_count} = $bestViews_listing->get('views');
+ $var->{bestViews_name} = $bestViews_listing->get('title');
+ $var->{bestViews_sortButton} = "Sort by views ";
# Get the MatrixListing with the most compares as an object using getLineage.
@@ -522,9 +524,10 @@ sub view {
limit => 1,
returnObjects => 1,
}) };
- $var->{bestCompares_url} = $bestCompares_listing->getUrl;
- $var->{bestCompares_count} = $bestCompares_listing->get('views');
- $var->{bestCompares_name} = $bestCompares_listing->get('title');
+ $var->{bestCompares_url} = $bestCompares_listing->getUrl;
+ $var->{bestCompares_count} = $bestCompares_listing->get('views');
+ $var->{bestCompares_name} = $bestCompares_listing->get('title');
+ $var->{bestCompares_sortButton} = "Sort by compares ";
# Get the MatrixListing with the most clicks as an object using getLineage.
my ($bestClicks_listing) = @{ $self->getLineage(['descendants'], {
@@ -534,10 +537,12 @@ sub view {
limit => 1,
returnObjects => 1,
}) };
- $var->{bestClicks_url} = $bestClicks_listing->getUrl;
- $var->{bestClicks_count} = $bestClicks_listing->get('views');
- $var->{bestClicks_name} = $bestClicks_listing->get('title');
+ $var->{bestClicks_url} = $bestClicks_listing->getUrl;
+ $var->{bestClicks_count} = $bestClicks_listing->get('views');
+ $var->{bestClicks_name} = $bestClicks_listing->get('title');
+ $var->{bestClicks_sortButton} = "Sort by clicks ";
+=cut
# Get the MatrixListing that was last updated as an object using getLineage.
my ($bestUpdated_listing) = @{ $self->getLineage(['descendants'], {
@@ -546,9 +551,11 @@ sub view {
limit => 1,
returnObjects => 1,
}) };
- $var->{bestUpdated_url} = $bestUpdated_listing->getUrl;
- $var->{bestUpdated_date} = $session->datetime->epochToHuman( $bestUpdated_listing->get('revisionDate') );
- $var->{bestUpdated_name} = $bestUpdated_listing->get('title');
+ $var->{bestUpdated_url} = $bestUpdated_listing->getUrl;
+ $var->{bestUpdated_date} = $session->datetime->epochToHuman( $bestUpdated_listing->get('revisionDate') );
+ $var->{bestUpdated_name} = $bestUpdated_listing->get('title');
+ $var->{bestUpdated_sortButton} = "Sort by updated ";
+=cut
# Get the 5 MatrixListings that were last updated as objects using getLineage.
@@ -565,6 +572,8 @@ sub view {
lastUpdated => $self->session->datetime->epochToHuman($lastUpdatedListing->get('revisionDate'),"%z")
});
}
+ $var->{lastUpdated_sortButton} = "Sort by updated ";
+
# Get all the MatrixListings that are still pending.
@@ -702,7 +711,7 @@ 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");
}
@@ -978,28 +987,42 @@ assetData.revisionDate
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 =~ s/_____/-/;
+ my ($listingValue,$fieldType) = $session->db->quickArray("
+ select value, fieldType from MatrixListing_attribute as listing
+ left join Matrix_attribute using(attributeId)
+ where listing.attributeId = ? and listing.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';
+ $self->session->errorHandler->warn("fieldType:".$fieldType.", attributeValue: ".$form->process($param).", listingvalue: ".$listingValue);
+ if(($fieldType eq 'MatrixCompare') && ($listingValue < $form->process($param))){
+ undef $result->{checked};
+ last;
+ }
+ elsif(($fieldType ne 'MatrixCompare') && ($form->process($param) ne $listingValue)){
+ undef $result->{checked};
+ last;
}
else{
- undef $result->{checked};
+ $self->session->errorHandler->warn("--Checked--");
+ $result->{checked} = 'checked';
}
}
}
}
else{
+ $result->{assetId} =~ s/-/_____/g;
if(WebGUI::Utility::isIn($result->{assetId},@listingIds)){
$result->{checked} = 'checked';
}
}
- $result->{assetId} =~ s/-/_/g;
+ $result->{assetId} =~ s/-/_____/g;
+ $result->{url} = "/".$result->{url};
+ $result->{checkBox} = " {checked}){
+ $result->{checkBox} .= " checked='checked'";
+ }
+ $result->{checkBox} .= " onChange='javascript:compareFormButton()' class='compareCheckBox'>";
}
=cut
push(@results,{
@@ -1043,10 +1066,11 @@ sub www_getCompareListData {
my $sortDirection = ' asc';
foreach my $listingId (@listingIds){
- $listingId =~ s/_/-/g;
+ $listingId =~ s/_____/-/g;
my $listing = WebGUI::Asset::MatrixListing->new($session,$listingId);
+ $listing->incrementCounter("compares");
my $listingId_safe = $listingId;
- $listingId_safe =~ s/-/_/g;
+ $listingId_safe =~ s/-/_____/g;
push(@columnDefs,{key=>$listingId_safe,label=>$listing->get('title'),formatter=>"formatColors"});
}
@@ -1059,7 +1083,7 @@ sub www_getCompareListData {
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=? ";
@@ -1072,9 +1096,9 @@ sub www_getCompareListData {
}
foreach my $result (@results){
foreach my $listingId (@listingIds) {
- $result->{attributId} =~ s/-/_/g;
+ $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});
@@ -1132,7 +1156,7 @@ sub www_search {
my $self = shift;
my $var = $self->get;
- #$var->{compareForm} = $self->getCompareForm;
+ $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'),
@@ -1169,7 +1193,7 @@ sub www_search {
while (my $attribute = $attributes->hashRef) {
$attribute->{label} = $attribute->{name};
$attribute->{id} = $attribute->{attributeId};
- $attribute->{id} =~ s/-/_/g;
+ $attribute->{id} =~ s/-/_____/g;
$attribute->{extras} = " class='attributeSelect'";
if($attribute->{fieldType} eq 'Combo'){
$attribute->{fieldType} = 'SelectBox';
diff --git a/www/extras/wobject/Matrix/matrix.js b/www/extras/wobject/Matrix/matrix.js
index e37275de2..0783fd0e2 100644
--- a/www/extras/wobject/Matrix/matrix.js
+++ b/www/extras/wobject/Matrix/matrix.js
@@ -3,7 +3,7 @@ var myCompareTable;
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.XHR_JSON = new function() {
this.formatUrl = function(elCell, oRecord, oColumn, sData) {
- elCell.innerHTML = "" + sData + " ";
+ elCell.innerHTML = "" + sData + " ";
};
this.formatCheckBox = function(elCell, oRecord, oColumn, sData) {
@@ -16,11 +16,12 @@ YAHOO.util.Event.addListener(window, "load", function() {
};
var myColumnDefs = [
- {key:"assetId",label:"",sortable:false,formatter:this.formatCheckBox},
+ {key:"checkBox",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}
+ {key:"views", sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC}},
+ {key:"clicks", sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC}},
+ {key:"compares", sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC}},
+ {key:"lastUpdated", sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC}}
];
var uri = "func=getCompareFormData";
@@ -35,31 +36,65 @@ YAHOO.util.Event.addListener(window, "load", function() {
this.myDataSource.connXhrMode = "queueRequests";
this.myDataSource.responseSchema = {
resultsList: "ResultSet.Result",
- fields: ["title","views","clicks","compares","assetId","checked"]
+ fields: ["title","views","clicks","compares","checkBox","checked","lastUpdated","url"]
};
this.myDataTable = new YAHOO.widget.DataTable("compareForm", myColumnDefs,
this.myDataSource, {initialRequest:uri});
- var oColumn = this.myDataTable.getColumn(3);
- this.myDataTable.hideColumn(oColumn);
+ //var oColumn = this.myDataTable.getColumn(3);
+ this.myDataTable.hideColumn(this.myDataTable.getColumn(2));
+ this.myDataTable.hideColumn(this.myDataTable.getColumn(3));
+ this.myDataTable.hideColumn(this.myDataTable.getColumn(4));
+ this.myDataTable.hideColumn(this.myDataTable.getColumn(5));
+
-
- var btnAddRows = new YAHOO.widget.Button("hidecolumn");
- btnAddRows.on("click", function(e) {
-
- //var oColumn = this.myDataTable.getColumn(3);
- this.myDataTable.sortColumn(oColumn);
+ var btnSortByViews = new YAHOO.widget.Button("sortByViews");
+ btnSortByViews.on("click", function(e) {
+ this.myDataTable.sortColumn(this.myDataTable.getColumn(2));
},this,true);
+ var btnSortByClicks = new YAHOO.widget.Button("sortByClicks");
+ btnSortByClicks.on("click", function(e) {
+ this.myDataTable.sortColumn(this.myDataTable.getColumn(3));
+ },this,true);
+
+ var btnSortByCompares = new YAHOO.widget.Button("sortByCompares");
+ btnSortByCompares.on("click", function(e) {
+ this.myDataTable.sortColumn(this.myDataTable.getColumn(4));
+ },this,true);
+
+ var btnSortByUpdated = new YAHOO.widget.Button("sortByUpdated");
+ btnSortByUpdated.on("click", function(e) {
+ this.myDataTable.sortColumn(this.myDataTable.getColumn(5));
+ },this,true);
var myCallback = function() {
this.set("sortedBy", null);
this.onDataReturnAppendRows.apply(this,arguments);
};
+
+
+
+ //var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox');
+ //for (var i = compareCheckBoxes.length; i--; ) {
+ // alert('bla');
+ // compareCheckBoxes[i].onchange = compareFormButton;
+ //}
};
});
+ function compareFormButton () {
+ var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox','input');
+ //alert(compareCheckBoxes.length);
+ var checked = 0;
+ for (var i = compareCheckBoxes.length; i--; ) {
+ if(compareCheckBoxes[i].checked){
+ checked++;
+ }
+ }
+ //alert(checked);
+ }
//function sort() {
// myCompareTable.sortColumn()
diff --git a/www/extras/wobject/Matrix/matrixCompareList.js b/www/extras/wobject/Matrix/matrixCompareList.js
index d3228b363..c24f95761 100644
--- a/www/extras/wobject/Matrix/matrixCompareList.js
+++ b/www/extras/wobject/Matrix/matrixCompareList.js
@@ -93,7 +93,7 @@ YAHOO.util.Event.addListener(window, "load", function() {
scope : myDataTable
};
- var btnCompare = new YAHOO.widget.Button("compare");
+ var btnCompare = new YAHOO.widget.Button("compare",{disabled:true,id:"compareButton"});
btnCompare.on("click", function(e) {
var uri = "func=getCompareListData";
for (var i = 0; i < columnKeys.length; i++) {
@@ -107,6 +107,25 @@ YAHOO.util.Event.addListener(window, "load", function() {
this.myDataSource.sendRequest(uri,callback2);
},this,true);
+ //btnCompare.set("disabled",true);
+ alert(btnCompare.get("disabled"));
+
+
+ window.compareFormButton = function() {
+ var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox','input');
+ var checked = 0;
+ for (var i = compareCheckBoxes.length; i--; ) {
+ if(compareCheckBoxes[i].checked){
+ checked++;
+ }
+ }
+ if (checked > 1){
+ btnCompare.set("disabled",false);
+ }else{
+ btnCompare.set("disabled",true);
+ }
+ }
+
var btnStickied = new YAHOO.widget.Button("stickied");
btnStickied.on("click", function(e) {
var elements = myDataTable.getRecordSet().getRecords();
@@ -117,9 +136,7 @@ YAHOO.util.Event.addListener(window, "load", function() {
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");
+ Dom.setStyle(elRow, "display", "none");
}
}
hideStickies = 1;
diff --git a/www/extras/wobject/Matrix/matrixSearch.js b/www/extras/wobject/Matrix/matrixSearch.js
index e649479f3..3380ca361 100644
--- a/www/extras/wobject/Matrix/matrixSearch.js
+++ b/www/extras/wobject/Matrix/matrixSearch.js
@@ -1,10 +1,12 @@
-var myCompareTable;
+//var myCompareTable;
//var search;
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.XHR_JSON = new function() {
+ var Dom = YAHOO.util.Dom;
+
this.formatUrl = function(elCell, oRecord, oColumn, sData) {
- elCell.innerHTML = "" + sData + " ";
+ elCell.innerHTML = "" + sData + " ";
};
this.formatCheckBox = function(elCell, oRecord, oColumn, sData) {
@@ -19,7 +21,7 @@ YAHOO.util.Event.addListener(window, "load", function() {
};
var myColumnDefs = [
- {key:"assetId",label:"",sortable:false,formatter:this.formatCheckBox},
+ {key:"checkBox",label:""},//,sortable:false,formatter:this.formatCheckBox
{key:"title", label:"Name", sortable:true, formatter:this.formatUrl},
{key:"views", sortable:true},
{key:"clicks", sortable:true},
@@ -33,26 +35,27 @@ YAHOO.util.Event.addListener(window, "load", function() {
}
}
- var myDataSource = new YAHOO.util.DataSource("?");
- myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
- myDataSource.connXhrMode = "queueRequests";
- myDataSource.responseSchema = {
+ 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","checked"]
+ fields: ["title","views","clicks","compares","checkBox","checked","url"]
};
var myDataTable = new YAHOO.widget.DataTable("compareForm", myColumnDefs,
- myDataSource, {initialRequest:uri});
+ this.myDataSource, {initialRequest:uri});
- myDataSource.doBeforeParseData = function (oRequest, oFullResponse) {
+ this.myDataSource.doBeforeParseData = function (oRequest, oFullResponse) {
myDataTable.getRecordSet().reset();
return oFullResponse;
}
+ var myDataSource = this.myDataSource;
- var oColumn = myDataTable.getColumn(3);
- myDataTable.hideColumn(oColumn);
+ //var oColumn = myDataTable.getColumn(3);
+ //myDataTable.hideColumn(oColumn);
var myCallback = function() {
@@ -66,29 +69,27 @@ YAHOO.util.Event.addListener(window, "load", function() {
failure : myCallback,
scope : myDataTable
};
-
- var attributeSelects = YAHOO.util.Dom.getElementsByClassName('attributeSelect','select');
+
var reloadCompareForm = function() {
- myDataTable.getRecordSet().reset();
- myDataTable.initializeTable;
-
+ var attributeSelects = YAHOO.util.Dom.getElementsByClassName('attributeSelect','select');
+ var newUri = "func=getCompareFormData;search=1";
+ for (var i = attributeSelects.length; i--; ) {
+ newUri = newUri + ';search_' + attributeSelects[i].id + '=' + attributeSelects[i].value;
+ }
var elements = myDataTable.getRecordSet().getRecords();
alert(elements.length);
- // hide non-selected attributes
for(i=0; i
Date: Wed, 19 Nov 2008 03:40:28 +0000
Subject: [PATCH 8/9] Fixed some yui features in Matrix v2
---
lib/WebGUI/Asset/MatrixListing.pm | 22 ++---
lib/WebGUI/Asset/Wobject/Matrix.pm | 93 +++++++++++++++----
www/extras/wobject/Matrix/matrix.js | 31 ++++++-
.../wobject/Matrix/matrixCompareList.js | 7 +-
www/extras/wobject/Matrix/matrixSearch.js | 27 +++++-
5 files changed, 140 insertions(+), 40 deletions(-)
diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm
index 27416611d..3a090ed22 100644
--- a/lib/WebGUI/Asset/MatrixListing.pm
+++ b/lib/WebGUI/Asset/MatrixListing.pm
@@ -975,23 +975,23 @@ sub install {
my $session = WebGUI::Session->open($home, $config);
$session->config->addToArray("assets","WebGUI::Asset::MatrixListing");
$session->db->write("create table MatrixListing (
- assetId varchar(22) binary not null,
+ assetId char(22) binary not null,
revisionDate bigint not null,
- title varchar(255),
- screenshots varchar(22),
+ screenshots char(22),
description text,
- version varchar(255),
+ version char(255),
views int(11),
compares int(11),
clicks int(11),
- viewsLastIp varchar(255),
- comparesLastIp varchar(255),
- clicksLastIp varchar(255),
+ viewsLastIp char(255),
+ comparesLastIp char(255),
+ clicksLastIp char(255),
lastUpdated int(11),
- maintainer varchar(22),
- manufacturerName varchar(255),
- manufacturerURL varchar(255),
- productURL varchar(255),
+ maintainer char(22),
+ manufacturerName char(255),
+ manufacturerURL char(255),
+ productURL char(255),
+ score int(11),
primary key (assetId, revisionDate)
)");
$session->db->write("create table MatrixListing_attribute (
diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm
index c4bf353ca..7d118379d 100644
--- a/lib/WebGUI/Asset/Wobject/Matrix.pm
+++ b/lib/WebGUI/Asset/Wobject/Matrix.pm
@@ -360,6 +360,8 @@ An array of listingIds that should be selected in the compare form.
sub getCompareForm {
my $self = shift;
+
+=cut
my @selectedListingIds = @_;
my (%options, @listings);
@@ -380,12 +382,19 @@ sub getCompareForm {
$options{$listing->getId} = ''.$listing->get('title').' ';
}
-
- my $form = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl})
- .WebGUI::Form::submit($self->session, {
- value=>"compare"
- })
- ." "
+ my $maxComparisons;
+ if($self->session->user->isVisitor){
+ $maxComparisons = $self->get('maxComparisons');
+ }
+ else{
+ $maxComparisons = $self->get('maxComparisonsPrivileged');
+ }
+=cut
+ my $form = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl,extras=>'name="doCompare"'})
+# .WebGUI::Form::submit($self->session, {
+# value=>"compare"
+# })
+# ." "
." "
.WebGUI::Form::hidden($self->session, {
name=>"func",
@@ -399,11 +408,21 @@ sub getCompareForm {
# options=>\%options,
# })
." "
- .WebGUI::Form::submit($self->session,{
- value=>"compare"
- })
+# .WebGUI::Form::submit($self->session,{
+# value=>"compare"
+# })
.WebGUI::Form::formFooter($self->session);
- #.'
';
+
+ my $maxComparisons;
+ if($self->session->user->isVisitor){
+ $maxComparisons = $self->get('maxComparisons');
+ }
+ else{
+ $maxComparisons = $self->get('maxComparisonsPrivileged');
+ }
+ $form .= "\n\n";
return $form;
}
@@ -501,6 +520,8 @@ sub view {
$var->{isLoggedIn} = ($self->session->user->userId ne "1");
$var->{addMatrixListing_url} = $self->getUrl('func=add;class=WebGUI::Asset::MatrixListing');
$var->{compareForm} = $self->getCompareForm;
+ $var->{exportAttributes_url} = $self->getUrl('func=exportAttributes');
+ $var->{listAttributes_url} = $self->getUrl('func=listAttributes');
# Get the MatrixListing with the most views as an object using getLineage.
my ($bestViews_listing) = @{ $self->getLineage(['descendants'], {
@@ -709,16 +730,25 @@ sub www_compare {
$self->session->style->setLink($self->session->url->extras('yui/build/datatable/assets/skins/sam/datatable.css'),
{type =>'text/css', rel=>'stylesheet'});
+ my $maxComparisons;
+ if($self->session->user->isVisitor){
+ $maxComparisons = $self->get('maxComparisons');
+ }
+ else{
+ $maxComparisons = $self->get('maxComparisonsPrivileged');
+ }
+
foreach my $listingId (@listingIds){
my $listingId_safe = $listingId;
$listingId_safe =~ s/-/_____/g;
push(@columnKeys, $listingId_safe);
push(@columnKeys, $listingId_safe."_compareColor");
}
-
+
$var->{javascript} = "";
return $self->processStyle($self->processTemplate($var,$self->get("compareTemplateId")));
@@ -921,6 +951,31 @@ sub www_editAttributeSave {
#-------------------------------------------------------------------
+=head2 www_exportAttributes ( )
+
+Exports search attributes as csv.
+
+=cut
+
+sub www_exportAttributes {
+ my $self = shift;
+ my $session = $self->session;
+ my $output = WebGUI::Text::joinCSV("name","description","category");
+
+ my $attributes = $session->db->read("select name, description, category
+ from Matrix_attribute where assetId = ? order by category, name",[$self->getId]);
+
+ while (my $attribute = $attributes->hashRef) {
+ $output .= "\n".WebGUI::Text::joinCSV($attribute->{name},$attribute->{description},$attribute->{category});
+ }
+ my $fileName = "export_matrix_attributes.csv";
+ $self->session->http->setFilename($fileName,"application/octet-stream");
+ $self->session->http->sendHeader;
+ return $output;
+}
+
+#-------------------------------------------------------------------
+
=head2 www_getCompareFormData ( )
Returns the compare form data as JSON.
@@ -1255,14 +1310,14 @@ sub install {
primary key (assetId, revisionDate)
)");
$session->db->write("create table Matrix_attribute (
- assetId varchar(22) binary not null,
- attributeId varchar(22) binary not null,
- name varchar(255) not null,
+ assetId char(22) binary not null,
+ attributeId char(22) binary not null,
+ name char(255) not null,
description text,
- fieldType varchar(255) not null default 'MatrixField',
- category varchar(22) not null,
+ fieldType char(255) not null default 'MatrixCompare',
+ category char(22) not null,
options text,
- defaultValue varchar(255),
+ defaultValue char(255),
primary key (attributeId)
)");
$session->var->end;
diff --git a/www/extras/wobject/Matrix/matrix.js b/www/extras/wobject/Matrix/matrix.js
index 0783fd0e2..bd85203d5 100644
--- a/www/extras/wobject/Matrix/matrix.js
+++ b/www/extras/wobject/Matrix/matrix.js
@@ -82,19 +82,40 @@ YAHOO.util.Event.addListener(window, "load", function() {
// compareCheckBoxes[i].onchange = compareFormButton;
//}
- };
-});
- function compareFormButton () {
+ var btnCompare = new YAHOO.widget.Button("compare",{disabled:true,id:"compareButton"});
+ btnCompare.on("click", function(e) {
+ alert('bla');
+ window.document.forms['doCompare'].submit();
+ },this,true);
+
+ window.compareFormButton = function() {
var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox','input');
- //alert(compareCheckBoxes.length);
var checked = 0;
for (var i = compareCheckBoxes.length; i--; ) {
if(compareCheckBoxes[i].checked){
checked++;
}
}
- //alert(checked);
+ if (checked > 1 && checked < maxComparisons){
+ btnCompare.set("disabled",false);
+ }else{
+ btnCompare.set("disabled",true);
+ }
}
+ };
+});
+
+// function compareFormButton () {
+// var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox','input');
+ //alert(compareCheckBoxes.length);
+// var checked = 0;
+// for (var i = compareCheckBoxes.length; i--; ) {
+// if(compareCheckBoxes[i].checked){
+// checked++;
+// }
+// }
+ //alert(checked);
+// }
//function sort() {
// myCompareTable.sortColumn()
diff --git a/www/extras/wobject/Matrix/matrixCompareList.js b/www/extras/wobject/Matrix/matrixCompareList.js
index c24f95761..2db979d74 100644
--- a/www/extras/wobject/Matrix/matrixCompareList.js
+++ b/www/extras/wobject/Matrix/matrixCompareList.js
@@ -108,9 +108,7 @@ YAHOO.util.Event.addListener(window, "load", function() {
},this,true);
//btnCompare.set("disabled",true);
- alert(btnCompare.get("disabled"));
-
-
+ //alert(btnCompare.get("disabled"));
window.compareFormButton = function() {
var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox','input');
var checked = 0;
@@ -119,7 +117,8 @@ YAHOO.util.Event.addListener(window, "load", function() {
checked++;
}
}
- if (checked > 1){
+ //alert(maxComparisons);
+ if (checked > 1 && checked < maxComparisons){
btnCompare.set("disabled",false);
}else{
btnCompare.set("disabled",true);
diff --git a/www/extras/wobject/Matrix/matrixSearch.js b/www/extras/wobject/Matrix/matrixSearch.js
index 3380ca361..ee60d5e7f 100644
--- a/www/extras/wobject/Matrix/matrixSearch.js
+++ b/www/extras/wobject/Matrix/matrixSearch.js
@@ -62,6 +62,7 @@ YAHOO.util.Event.addListener(window, "load", function() {
myDataTable.getRecordSet().reset();
this.set("sortedBy", null);
this.onDataReturnAppendRows.apply(this,arguments);
+ compareFormButton();
};
var callback2 = {
@@ -77,19 +78,43 @@ YAHOO.util.Event.addListener(window, "load", function() {
newUri = newUri + ';search_' + attributeSelects[i].id + '=' + attributeSelects[i].value;
}
var elements = myDataTable.getRecordSet().getRecords();
- alert(elements.length);
for(i=0; i 1 && checked < maxComparisons){
+ btnCompare.set("disabled",false);
+ }else{
+ btnCompare.set("disabled",true);
+ }
+ }
};
From cd8f7a1f307bd50738562c04877344d2e80577e0 Mon Sep 17 00:00:00 2001
From: Yung Han Khoe
Date: Wed, 19 Nov 2008 05:18:37 +0000
Subject: [PATCH 9/9] Some code cleanup
---
lib/WebGUI/Asset/MatrixListing.pm | 123 +--------
lib/WebGUI/Asset/Wobject/Matrix.pm | 238 ++----------------
www/extras/wobject/Matrix/matrix.js | 59 +----
.../wobject/Matrix/matrixCompareList.js | 37 +--
www/extras/wobject/Matrix/matrixSearch.js | 33 +--
5 files changed, 25 insertions(+), 465 deletions(-)
diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm
index 3a090ed22..730a86086 100644
--- a/lib/WebGUI/Asset/MatrixListing.pm
+++ b/lib/WebGUI/Asset/MatrixListing.pm
@@ -18,7 +18,6 @@ use strict;
use Tie::IxHash;
use Class::C3;
use base qw(WebGUI::AssetAspect::Comments WebGUI::Asset);
-#use base 'WebGUI::Asset';
use WebGUI::Utility;
@@ -81,15 +80,6 @@ sub definition {
tie %properties, 'Tie::IxHash';
my $i18n = WebGUI::International->new($session, "Asset_MatrixListing");
%properties = (
-# templateId => {
-# tab =>"display",
-# fieldType =>"template",
-# defaultValue =>'MatrixListingTmpl00001',
-# noFormPost =>0,
-# namespace =>"MatrixListing",
-# hoverHelp =>$i18n->get('template description'),
-# label =>$i18n->get('template label')
-# },
screenshots => {
tab =>"properties",
fieldType =>"image",
@@ -236,11 +226,9 @@ sub getEditForm {
my $session = $self->session;
my $db = $session->db;
my $matrixId = $self->getParent->getId;
- my $tabform = $self->next::method();#SUPER::getEditForm();
+ my $tabform = $self->next::method();
my $i18n = WebGUI::International->new($session, 'Asset_MatrixListing');
- #$self->session->style->setScript($self->session->url->extras('FileUploadControl.js'), {type =>'text/javascript'});
-
foreach my $category (keys %{$self->getParent->getCategories}) {
$tabform->getTab('properties')->raw(''.$category.' ');
my $attributes;
@@ -262,23 +250,6 @@ sub getEditForm {
}
}
return $tabform;
-=cut
- $tabform->hidden({
- name=>"returnUrl",
- value=>$self->session->form->get("returnUrl")
- });
- if ($self->getValue("namespace") eq "") {
- my $namespaces = $self->session->dbSlave->buildHashRef("select distinct(namespace) from template order by
-namespace");
- $tabform->getTab("properties")->combo(
- -name=>"namespace",
- -options=>$namespaces,
- -label=>$i18n->get('namespace'),
- -hoverHelp=>$i18n->get('namespace description'),
- -value=>[$self->session->form->get("namespace")]
- );
- }
-=cut
}
#-------------------------------------------------------------------
@@ -293,13 +264,6 @@ sub hasRated {
my $self = shift;
my $session = $self->session;
-=cut
- return 1 unless ($self->session->user->isInGroup($self->get("groupToRate")));
-
- my $ratingTimeout = $self->session->user->isInGroup($self->get("privilegedGroup")) ?
-$self->get("ratingTimeoutPrivileged") : $self->get("ratingTimeout");
-=cut
-
my $hasRated = $self->session->db->quickScalar("select count(*) from MatrixListing_rating where
((userId=? and userId<>'1') or (userId='1' and ipAddress=?)) and listingId=?",
[$session->user->userId,$session->env->get("HTTP_X_FORWARDED_FOR"),$self->getId]);
@@ -325,9 +289,7 @@ sub incrementCounter {
my $counter = shift;
my $currentIp = $self->session->env->get("HTTP_X_FORWARDED_FOR");
- #print "current ip: ".$currentIp." ";
- #print "dsfsdf lastIp : ".$self->get($counter."LastIp")." ";
unless ($self->get($counter."LastIp") eq $currentIp) {
$self->update({
$counter."LastIp" => $currentIp,
@@ -381,7 +343,7 @@ sub processPropertiesFromFormPost {
my $session = $self->session;
my $score = 0;
- $self->next::method(@_);#SUPER::processPropertiesFromFormPost;
+ $self->next::method(@_);
my $attributes = $session->db->read("select * from Matrix_attribute where assetId = ?",[$self->getParent->getId]);
while (my $attribute = $attributes->hashRef) {
@@ -533,9 +495,6 @@ sub view {
if ($attribute->{fieldType} eq 'MatrixCompare'){
$attribute->{value} = WebGUI::Form::MatrixCompare->new($self->session,$attribute)->getValueAsHtml;
}
- #$attribute->{value} = $attribute->{description};
- #$tabform->getTab("properties")->dynamicField(%{$attribute});
- #my $categoryLoopName = $self->session->url->urlize($category)."_loop";
push(@attribute_loop,$attribute);
}
$var->{$categoryLoopName} = \@attribute_loop;
@@ -551,9 +510,7 @@ sub view {
my $file = WebGUI::Form::File->new($self->session,{ value=>$var->{screenshots} });
my $storage = $file->getStorageLocation;
my @files = @{ $storage->getFiles } if (defined $storage);
- if (scalar(@files)) {
- #$var->{screenshots} = $file->getFilePreview($storage);
- }
+
$var->{screenshots} = qq|
@@ -951,80 +908,6 @@ sub www_view {
return $self->view;
}
-#-------------------------------------------------------------------
-# Everything below here is to make it easier to install your custom
-# asset, but has nothing to do with assets in general
-#-------------------------------------------------------------------
-# cd /data/WebGUI/lib
-# perl -MWebGUI::Asset::MatrixListing -e install www.example.com.conf [ /path/to/WebGUI ]
-# - or -
-# perl -MWebGUI::Asset::MatrixListing -e uninstall www.example.com.conf [ /path/to/WebGUI ]
-#-------------------------------------------------------------------
-
-
-use base 'Exporter';
-our @EXPORT = qw(install uninstall);
-use WebGUI::Session;
-
-#-------------------------------------------------------------------
-sub install {
- my $config = $ARGV[0];
- my $home = $ARGV[1] || "/data/WebGUI";
- die "usage: perl -MWebGUI::Asset::MatrixListing -e install www.example.com.conf\n" unless ($home && $config);
- print "Installing asset.\n";
- my $session = WebGUI::Session->open($home, $config);
- $session->config->addToArray("assets","WebGUI::Asset::MatrixListing");
- $session->db->write("create table MatrixListing (
- assetId char(22) binary not null,
- revisionDate bigint not null,
- screenshots char(22),
- description text,
- version char(255),
- views int(11),
- compares int(11),
- clicks int(11),
- viewsLastIp char(255),
- comparesLastIp char(255),
- clicksLastIp char(255),
- lastUpdated int(11),
- maintainer char(22),
- manufacturerName char(255),
- manufacturerURL char(255),
- productURL char(255),
- score int(11),
- primary key (assetId, revisionDate)
- )");
- $session->db->write("create table MatrixListing_attribute (
- matrixId char(22) not null,
- matrixListingId char(22) not null,
- attributeId char(22) not null,
- value char(255),
- primary key (matrixId, matrixListingId, attributeId)
- )");
- $session->var->end;
- $session->close;
- print "Done. Please restart Apache.\n";
-}
-
-#-------------------------------------------------------------------
-sub uninstall {
- my $config = $ARGV[0];
- my $home = $ARGV[1] || "/data/WebGUI";
- die "usage: perl -MWebGUI::Asset::MatrixListing -e uninstall www.example.com.conf\n" unless ($home && $config);
- print "Uninstalling asset.\n";
- my $session = WebGUI::Session->open($home, $config);
- $session->config->deleteFromArray("assets","WebGUI::Asset::MatrixListing");
- my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::MatrixListing'");
- while (my ($id) = $rs->array) {
- my $asset = WebGUI::Asset->new($session, $id, "WebGUI::Asset::MatrixListing");
- $asset->purge if defined $asset;
- }
- $session->db->write("drop table MatrixListing");
- $session->var->end;
- $session->close;
- print "Done. Please restart Apache.\n";
-}
-
1;
diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm
index 7d118379d..a66933441 100644
--- a/lib/WebGUI/Asset/Wobject/Matrix.pm
+++ b/lib/WebGUI/Asset/Wobject/Matrix.pm
@@ -69,17 +69,15 @@ sub definition {
my %properties;
tie %properties, 'Tie::IxHash';
%properties = (
- templateId =>{
- fieldType =>"template",
- defaultValue =>'matrixtmpl000000000001',
- tab =>"display",
- #www_editSave will ignore anyone's attempts to update this field if this is set to 1
- noFormPost =>0,
- #This is an option specific to the template fieldType.
- namespace =>"Matrix",
- hoverHelp =>$i18n->get('template description'),
- label =>$i18n->get('template label'),
- },
+ templateId =>{
+ fieldType =>"template",
+ defaultValue =>'matrixtmpl000000000001',
+ tab =>"display",
+ noFormPost =>0,
+ namespace =>"Matrix",
+ hoverHelp =>$i18n->get('template description'),
+ label =>$i18n->get('template label'),
+ },
searchTemplateId=>{
defaultValue =>"matrixtmpl000000000005",
fieldType =>"template",
@@ -96,14 +94,6 @@ sub definition {
hoverHelp =>$i18n->get('detail template description'),
label =>$i18n->get('detail template label'),
},
-# ratingDetailTemplateId=>{
-# defaultValue =>"matrixtmpl000000000004",
-# fieldType =>"template",
-# tab =>"display",
-# namespace =>"Matrix/RatingDetail",
-# hoverHelp =>$i18n->get('rating detail template description'),
-# label =>$i18n->get('rating detail template label'),
-# },
compareTemplateId=>{
defaultValue =>"matrixtmpl000000000002",
fieldType =>"template",
@@ -361,56 +351,14 @@ An array of listingIds that should be selected in the compare form.
sub getCompareForm {
my $self = shift;
-=cut
- my @selectedListingIds = @_;
-
- my (%options, @listings);
- tie %options, 'Tie::IxHash';
-
- my $sortDirection = " asc";
- if ( WebGUI::Utility::isIn($self->get('defaultSort'),qw(revisionDate score)) ){
- $sortDirection = " desc";
- }
- @listings = @{ $self->getLineage(['descendants'], {
- includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
- joinClass => "WebGUI::Asset::MatrixListing",
- orderByClause => $self->get('defaultSort').$sortDirection,
- returnObjects => 1,
- }) };
- # Create an options hash based on the ordered array of listings.
- foreach my $listing (@listings){
- $options{$listing->getId} = ''.$listing->get('title').' ';
- }
-
- my $maxComparisons;
- if($self->session->user->isVisitor){
- $maxComparisons = $self->get('maxComparisons');
- }
- else{
- $maxComparisons = $self->get('maxComparisonsPrivileged');
- }
-=cut
my $form = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl,extras=>'name="doCompare"'})
-# .WebGUI::Form::submit($self->session, {
-# value=>"compare"
-# })
-# ." "
." "
.WebGUI::Form::hidden($self->session, {
name=>"func",
value=>"compare"
})
.'
'
-# .WebGUI::Form::checkList($self->session, {
-# name=>"listingId",
-# vertical=>1,
-# value=>\@selectedListingIds,
-# options=>\%options,
-# })
." "
-# .WebGUI::Form::submit($self->session,{
-# value=>"compare"
-# })
.WebGUI::Form::formFooter($self->session);
my $maxComparisons;
@@ -439,13 +387,6 @@ returns the tabform object that will be used in generating the edit page for Mat
sub getEditForm {
my $self = shift;
my $tabform = $self->SUPER::getEditForm();
-=cut
- $tabform->getTab("display")->template(
- -value=>$self->getValue("templateId"),
- -label=>WebGUI::International::get("template_label","Asset_Matrix"),
- -namespace=>"Matrix"
- );
-=cut
return $tabform;
}
@@ -563,21 +504,6 @@ sub view {
$var->{bestClicks_name} = $bestClicks_listing->get('title');
$var->{bestClicks_sortButton} = "Sort by clicks ";
-=cut
- # Get the MatrixListing that was last updated as an object using getLineage.
-
- my ($bestUpdated_listing) = @{ $self->getLineage(['descendants'], {
- includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
- orderByClause => "revisionDate desc",
- limit => 1,
- returnObjects => 1,
- }) };
- $var->{bestUpdated_url} = $bestUpdated_listing->getUrl;
- $var->{bestUpdated_date} = $session->datetime->epochToHuman( $bestUpdated_listing->get('revisionDate') );
- $var->{bestUpdated_name} = $bestUpdated_listing->get('title');
- $var->{bestUpdated_sortButton} = "Sort by updated ";
-=cut
-
# Get the 5 MatrixListings that were last updated as objects using getLineage.
my @lastUpdatedListings = @{ $self->getLineage(['descendants'], {
@@ -678,9 +604,6 @@ assetData.revisionDate
group by asset.assetId",
[$self->getId]);
- #This is an example of debugging code to help you diagnose problems.
- #WebGUI::ErrorHandler::warn($self->get("templateId"));
-
return $self->processTemplate($var, undef, $self->{_viewTemplate});
}
@@ -698,7 +621,7 @@ sub www_compare {
my $var = $self->get;
my @listingIds = @_;
my @columnKeys;
- #my @listingIds = ['AwioUvaZXmAEaFw20t-x3Q', 'CWNjAHcmh0pEF6WJooomJA'];
+
unless (scalar(@listingIds)) {
@listingIds = $self->session->form->checkList("listingId");
}
@@ -774,24 +697,6 @@ sub www_deleteAttribute {
#-------------------------------------------------------------------
-=head2 www_edit ( )
-
-Web facing method which is the default edit page. This method is entirely
-optional. Take it out unless you specifically want to set a submenu in your
-adminConsole views.
-
-=cut
-
-#sub www_edit {
-# my $self = shift;
-# return $self->session->privilege->insufficient() unless $self->canEdit;
-# return $self->session->privilege->locked() unless $self->canEditIfLocked;
-# my $i18n = WebGUI::International->new($self->session, "Asset_Matrix");
-# return $self->getAdminConsole->render($self->getEditForm->print, $i18n->get("edit title"));
-#}
-
-#-------------------------------------------------------------------
-
=head2 www_editAttribute ( )
Shows a form to edit or add an attribute.
@@ -893,20 +798,7 @@ sub www_editAttribute {
."\n";
$form->raw($html);
-=cut
- $form->text(
- -name =>"defaultValue",
- -value =>$attribute->{defaultValue},
- -label =>$i18n->get('attribute defaultValue label'),
- -hoverHelp =>$i18n->get('attribute defaultValue description'),
- );
- $form->textarea(
- -name =>"options",
- -value =>$attribute->{options},
- -label =>$i18n->get('attribute options label'),
- -hoverHelp =>$i18n->get('attribute options description'),
- );
-=cut
+
$form->selectBox(
-name =>"category",
-value =>[$attribute->{category}],
@@ -993,14 +885,7 @@ sub www_getCompareFormData {
my @listingIds = $self->session->form->checkList("listingId");
$self->session->http->setMimeType("application/json");
-=cut
- my @listings = @{ $self->getLineage(['descendants'], {
- includeOnlyClasses => ['WebGUI::Asset::MatrixListing'],
- joinClass => "WebGUI::Asset::MatrixListing",
- orderByClause => $self->get('defaultSort').$sortDirection,
- returnObjects => 1,
- }) };
-=cut
+
my $sql = "
select
assetData.title,
@@ -1034,9 +919,7 @@ assetData.revisionDate
@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_/){
@@ -1061,7 +944,7 @@ assetData.revisionDate
$self->session->errorHandler->warn("--Checked--");
$result->{checked} = 'checked';
}
- }
+ }
}
}
else{
@@ -1079,21 +962,7 @@ assetData.revisionDate
}
$result->{checkBox} .= " onChange='javascript:compareFormButton()' class='compareCheckBox'>";
}
-=cut
-push(@results,{
- Title=>$data->{title},
- Views=>$data->{views},
- Compares=>$data->{compares},
- Clicks=>$data->{clicks}
- });
-=cut
- # Create an options hash based on the orderd array of listings.
-=cut
- foreach my $listing (@listings){
- push(@results,{Title=>$listing->get('title'),Phone=>'123'})
- #$options{$listing->getId} = ''.$listing->get('title').' ';
- }
-=cut
+
my $jsonOutput;
$jsonOutput->{ResultSet} = {Result=>\@results};
@@ -1232,8 +1101,6 @@ sub www_search {
{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'),
@@ -1266,83 +1133,6 @@ sub www_search {
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
-#-------------------------------------------------------------------
-# cd /data/WebGUI/lib
-# perl -MWebGUI::Asset::Wobject::Matrix -e install www.example.com.conf [ /path/to/WebGUI ]
-# - or -
-# perl -MWebGUI::Asset::Wobject::Matrix -e uninstall www.example.com.conf [ /path/to/WebGUI ]
-#-------------------------------------------------------------------
-
-
-use base 'Exporter';
-our @EXPORT = qw(install uninstall);
-use WebGUI::Session;
-
-#-------------------------------------------------------------------
-sub install {
- my $config = $ARGV[0];
- my $home = $ARGV[1] || "/data/WebGUI";
- die "usage: perl -MWebGUI::Asset::Wobject::Matrix -e install www.example.com.conf\n" unless ($home && $config);
- print "Installing asset.\n";
- my $session = WebGUI::Session->open($home, $config);
- $session->config->addToArray("assets","WebGUI::Asset::Wobject::Matrix");
- $session->db->write("create table Matrix (
- assetId varchar(22) binary not null,
- revisionDate bigint not null,
- templateId varchar(22) not null,
- searchTemplateId varchar(22) not null,
- compareTemplateId varchar(22) not null,
- detailTemplateId varchar(22) not null,
- maxComparisons int(11) not null default 10,
- maxComparisonsPrivileged int(11) not null default 25,
- defaultSort varchar(22) not null default 'score',
- categories text,
- compareColorNo varchar(22) not null default '#ffaaaa',
- compareColorLimited varchar(22) not null default '#ffffaa',
- compareColorCostsExtra varchar(22) not null default '#ffffaa',
- compareColorFreeAddOn varchar(22) not null default '#ffffaa',
- compareColorYes varchar(22) not null default '#aaffaa',
- submissionApprovalWorkflowId varchar(22) not null,
- ratingsDuration int(11) not null default 7776000,
- primary key (assetId, revisionDate)
- )");
- $session->db->write("create table Matrix_attribute (
- assetId char(22) binary not null,
- attributeId char(22) binary not null,
- name char(255) not null,
- description text,
- fieldType char(255) not null default 'MatrixCompare',
- category char(22) not null,
- options text,
- defaultValue char(255),
- primary key (attributeId)
- )");
- $session->var->end;
- $session->close;
- print "Done. Please restart Apache.\n";
-}
-
-#-------------------------------------------------------------------
-sub uninstall {
- my $config = $ARGV[0];
- my $home = $ARGV[1] || "/data/WebGUI";
- die "usage: perl -MWebGUI::Asset::Wobject::Matrix -e uninstall www.example.com.conf\n" unless ($home && $config);
- print "Uninstalling asset.\n";
- my $session = WebGUI::Session->open($home, $config);
- $session->config->deleteFromArray("assets","WebGUI::Asset::Wobject::Matrix");
- my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::Wobject::Matrix'");
- while (my ($id) = $rs->array) {
- my $asset = WebGUI::Asset->new($session, $id, "WebGUI::Asset::Wobject::Matrix");
- $asset->purge if defined $asset;
- }
- $session->db->write("drop table Matrix");
- $session->var->end;
- $session->close;
- print "Done. Please restart Apache.\n";
-}
1;
diff --git a/www/extras/wobject/Matrix/matrix.js b/www/extras/wobject/Matrix/matrix.js
index bd85203d5..f31787aea 100644
--- a/www/extras/wobject/Matrix/matrix.js
+++ b/www/extras/wobject/Matrix/matrix.js
@@ -1,22 +1,11 @@
-var myCompareTable;
-
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.XHR_JSON = new function() {
this.formatUrl = function(elCell, oRecord, oColumn, sData) {
elCell.innerHTML = "" + sData + " ";
};
- this.formatCheckBox = function(elCell, oRecord, oColumn, sData) {
- var innerHTML = " ";
- elCell.innerHTML = innerHTML;
- };
-
var myColumnDefs = [
- {key:"checkBox",label:"",sortable:false},//,formatter:this.formatCheckBox
+ {key:"checkBox",label:"",sortable:false},
{key:"title", label:"Name", sortable:true, formatter:this.formatUrl},
{key:"views", sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC}},
{key:"clicks", sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC}},
@@ -42,13 +31,11 @@ YAHOO.util.Event.addListener(window, "load", function() {
this.myDataTable = new YAHOO.widget.DataTable("compareForm", myColumnDefs,
this.myDataSource, {initialRequest:uri});
- //var oColumn = this.myDataTable.getColumn(3);
this.myDataTable.hideColumn(this.myDataTable.getColumn(2));
this.myDataTable.hideColumn(this.myDataTable.getColumn(3));
this.myDataTable.hideColumn(this.myDataTable.getColumn(4));
this.myDataTable.hideColumn(this.myDataTable.getColumn(5));
-
var btnSortByViews = new YAHOO.widget.Button("sortByViews");
btnSortByViews.on("click", function(e) {
this.myDataTable.sortColumn(this.myDataTable.getColumn(2));
@@ -73,18 +60,9 @@ YAHOO.util.Event.addListener(window, "load", function() {
this.set("sortedBy", null);
this.onDataReturnAppendRows.apply(this,arguments);
};
-
-
-
- //var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox');
- //for (var i = compareCheckBoxes.length; i--; ) {
- // alert('bla');
- // compareCheckBoxes[i].onchange = compareFormButton;
- //}
var btnCompare = new YAHOO.widget.Button("compare",{disabled:true,id:"compareButton"});
btnCompare.on("click", function(e) {
- alert('bla');
window.document.forms['doCompare'].submit();
},this,true);
@@ -105,38 +83,3 @@ YAHOO.util.Event.addListener(window, "load", function() {
};
});
-// function compareFormButton () {
-// var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox','input');
- //alert(compareCheckBoxes.length);
-// var checked = 0;
-// for (var i = compareCheckBoxes.length; i--; ) {
-// if(compareCheckBoxes[i].checked){
-// checked++;
-// }
-// }
- //alert(checked);
-// }
-
-//function sort() {
-// myCompareTable.sortColumn()
-// var oColumn = myCompareTable.getColumn(3);
-// myCompareTable.hideColumn(oColumn);
-//}
-
-function bla() {
- var callback1 = {
- success : myCallback,
- failure : myCallback,
- scope : this.myDataTable
- };
- this.myDataSource.sendRequest("func=getCompareFormData",
- callback1);
-
- var callback2 = {
- success : myCallback,
- failure : myCallback,
- scope : this.myDataTable
- };
- this.myDataSource.sendRequest("func=getCompareFormData",
- callback2);
-}
\ No newline at end of file
diff --git a/www/extras/wobject/Matrix/matrixCompareList.js b/www/extras/wobject/Matrix/matrixCompareList.js
index 2db979d74..e51305daf 100644
--- a/www/extras/wobject/Matrix/matrixCompareList.js
+++ b/www/extras/wobject/Matrix/matrixCompareList.js
@@ -1,5 +1,3 @@
-//var myCompareTable;
-
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.XHR_JSON = new function() {
var Dom = YAHOO.util.Dom;
@@ -30,7 +28,7 @@ YAHOO.util.Event.addListener(window, "load", function() {
this.myDataSource.connXhrMode = "queueRequests";
this.myDataSource.responseSchema = {
resultsList: "ResultSet.Result",
- fields: columnKeys //["name","AwioUvaZXmAEaFw20tx3Q","CWNjAHcmh0pEF6WJooomJA"]
+ fields: columnKeys
};
var uri = "func=getCompareListData";
@@ -41,16 +39,6 @@ YAHOO.util.Event.addListener(window, "load", function() {
var myDataTable = new YAHOO.widget.DataTable("compareList", myColumnDefs,
this.myDataSource, {initialRequest:uri});
- //var oColumn = this.myDataTable.getColumn(3);
- //this.myDataTable.hideColumn(oColumn);
-
-
- //var btnAddRows = new YAHOO.widget.Button("hidecolumn");
- //btnAddRows.on("click", function(e) {
-
- //var oColumn = this.myDataTable.getColumn(3);
- // this.myDataTable.sortColumn(oColumn);
- //},this,true);
this.myDataSource.doBeforeParseData = function (oRequest, oFullResponse) {
myDataTable.getRecordSet().reset();
@@ -79,11 +67,8 @@ YAHOO.util.Event.addListener(window, "load", function() {
};
var myCallback2 = function() {
- //this.getRecordSet().reset();
- this.set("sortedBy", null);
+ this.set("sortedBy", null);
this.onDataReturnAppendRows.apply(this,arguments);
-
- //this.getRecordSet().reset();
};
@@ -107,8 +92,6 @@ YAHOO.util.Event.addListener(window, "load", function() {
this.myDataSource.sendRequest(uri,callback2);
},this,true);
- //btnCompare.set("disabled",true);
- //alert(btnCompare.get("disabled"));
window.compareFormButton = function() {
var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox','input');
var checked = 0;
@@ -117,7 +100,6 @@ YAHOO.util.Event.addListener(window, "load", function() {
checked++;
}
}
- //alert(maxComparisons);
if (checked > 1 && checked < maxComparisons){
btnCompare.set("disabled",false);
}else{
@@ -151,23 +133,8 @@ YAHOO.util.Event.addListener(window, "load", function() {
}
hideStickies = 0;
}
-
-// var elements = Dom.getElementsByClassName('yui-dt-even yui-dt-first', 'tr');
-// for(i=0; i" + sData + "";
};
- this.formatCheckBox = function(elCell, oRecord, oColumn, sData) {
- var innerHTML = " ";
- elCell.innerHTML = innerHTML;
- };
-
var myColumnDefs = [
- {key:"checkBox",label:""},//,sortable:false,formatter:this.formatCheckBox
+ {key:"checkBox",label:""},
{key:"title", label:"Name", sortable:true, formatter:this.formatUrl},
{key:"views", sortable:true},
{key:"clicks", sortable:true},
@@ -29,10 +15,10 @@ YAHOO.util.Event.addListener(window, "load", function() {
];
var uri = "func=getCompareFormData";
- if(typeof(listingIds) != 'undefined'){
- for (var i = 0; i < listingIds.length; i++) {
- uri = uri+';listingId='+listingIds[i];
- }
+ if(typeof(listingIds) != 'undefined'){
+ for (var i = 0; i < listingIds.length; i++) {
+ uri = uri+';listingId='+listingIds[i];
+ }
}
this.myDataSource = new YAHOO.util.DataSource("?");
@@ -43,21 +29,15 @@ YAHOO.util.Event.addListener(window, "load", function() {
fields: ["title","views","clicks","compares","checkBox","checked","url"]
};
-
var myDataTable = new YAHOO.widget.DataTable("compareForm", myColumnDefs,
this.myDataSource, {initialRequest:uri});
this.myDataSource.doBeforeParseData = function (oRequest, oFullResponse) {
-
myDataTable.getRecordSet().reset();
return oFullResponse;
}
var myDataSource = this.myDataSource;
- //var oColumn = myDataTable.getColumn(3);
- //myDataTable.hideColumn(oColumn);
-
-
var myCallback = function() {
myDataTable.getRecordSet().reset();
this.set("sortedBy", null);
@@ -108,15 +88,12 @@ YAHOO.util.Event.addListener(window, "load", function() {
checked++;
}
}
- alert(checked);
if (checked > 1 && checked < maxComparisons){
btnCompare.set("disabled",false);
}else{
btnCompare.set("disabled",true);
}
}
-
-
};
});