Adding more features to Matrix v2
This commit is contained in:
parent
58a1f2a85e
commit
ab14e4aa0f
4 changed files with 614 additions and 48 deletions
|
|
@ -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|
|
||||
<script language="javascript">AC_FL_RunContent = 0;</script>
|
||||
<script src="/extras/ukplayer/AC_RunActiveContent.js" language="javascript"></script>
|
||||
<script language="javascript">
|
||||
if (AC_FL_RunContent == 0) {
|
||||
alert("This page requires AC_RunActiveContent.js.");
|
||||
} else {
|
||||
AC_FL_RunContent(
|
||||
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
|
||||
'width', '400',
|
||||
'height', '300',
|
||||
'src', 'swc/assets',
|
||||
'quality', 'high',
|
||||
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
|
||||
'align', 'middle',
|
||||
'play', 'true',
|
||||
'loop', 'true',
|
||||
'scale', 'showall',
|
||||
'wmode', 'window',
|
||||
'devicefont', 'false',
|
||||
'id', 'slideShow',
|
||||
'bgcolor', '#ffffff',
|
||||
'name', 'coverflow',
|
||||
'menu', 'true',
|
||||
// note: the width & height in the flashVars below MUST match the width & height set above
|
||||
'flashVars',
|
||||
'config=?func=getScreenshotsConfig&width=400&height=300&backgroundColor=0xCCCCCC&fontColor=&textBorderColor=&textBackgroundColor=&controlsColor=&controlsBorderColor=&controlsBackgroundColor=',
|
||||
'allowFullScreen', 'false',
|
||||
'allowScriptAccess','sameDomain',
|
||||
'movie', '/extras/ukplayer/slideShow',
|
||||
'salign', ''
|
||||
); //end AC code
|
||||
}
|
||||
</script>
|
||||
<noscript>
|
||||
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
|
||||
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400"
|
||||
height="300" id="swc/assets" align="middle">
|
||||
<param name="allowScriptAccess" value="sameDomain" />
|
||||
<param name="allowFullScreen" value="false" />
|
||||
<param name="flashVars" value="config=?func=getScreenshotsConfig" />
|
||||
<param name="movie" value="/extras/ukplayer/slideShow.swf" /><param name="quality" value="high" /><param
|
||||
name="bgcolor" value="#ffffff" /> <embed src="/extras/ukplayer/slideShow.swf" quality="high" bgcolor="#ffffff"
|
||||
width="400" height="300" name="swc/assets" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false"
|
||||
flashvars="config=?func=getScreenshotsConfig" type="application/x-shockwave-flash"
|
||||
pluginspage="http://www.macromedia.com/go/getflashplayer" />
|
||||
</object>
|
||||
</noscript>
|
||||
|;
|
||||
}
|
||||
|
||||
# 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 |<?xml version="1.0" encoding="UTF-8"?>
|
||||
<content>
|
||||
<slides>
|
||||
|;
|
||||
|
||||
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 .= "
|
||||
<slide>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<title><![CDATA[<b>Slide</b> One]]></title>
|
||||
<description><![CDATA[ Screenshots ]]></description>
|
||||
<image_source>".$storage->getUrl($file)."</image_source>
|
||||
<duration>5</duration>
|
||||
<thumb_source>".$storage->getUrl($thumb)."</thumb_source>
|
||||
</slide>
|
||||
";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$xml .= qq |
|
||||
</slides>
|
||||
</content>
|
||||
|;
|
||||
|
||||
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|<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config>
|
||||
|
||||
<content_url>?func=getScreenshots</content_url>
|
||||
|
||||
<width>400</width><!-- this value is overwritten by the flashVars but the tag needs to be here (and it is
|
||||
useful for offline testing) -->
|
||||
<height>300</height><!-- this value is overwritten by the flashVars but the tag needs to be here (and it is
|
||||
useful for offline testing) -->
|
||||
<background_color>0xDDDDEE</background_color>
|
||||
<default_duration>20</default_duration>
|
||||
<default_slidewidth>100</default_slidewidth>
|
||||
<default_slideheight>100</default_slideheight>
|
||||
|
||||
<font>Verdana</font>
|
||||
<font_size>12</font_size>
|
||||
<font_color>0xCCCCCC</font_color>
|
||||
<text_border_color>0xCCCCCC</text_border_color>
|
||||
<text_bg_color>0x000000</text_bg_color>
|
||||
<text_autohide>true</text_autohide>
|
||||
|
||||
<controls_color>0xCCCCCC</controls_color>
|
||||
<controls_border_color>0xCCCCCC</controls_border_color>
|
||||
<controls_bg_color>0x000000</controls_bg_color>
|
||||
<controls_autohide>false</controls_autohide>
|
||||
|
||||
<thumbnail_width>48</thumbnail_width>
|
||||
<thumbnail_height>36</thumbnail_height>
|
||||
<thumbnail_border_color>0x000000</thumbnail_border_color>
|
||||
<menu_autohide>true</menu_autohide>
|
||||
<menu_dead_zone_width>100</menu_dead_zone_width>
|
||||
<menu_gaps>5</menu_gaps>
|
||||
|
||||
<mute_at_start>false</mute_at_start>
|
||||
<autostart>true</autostart>
|
||||
<autopause>false</autopause>
|
||||
<loop>false</loop>
|
||||
<error_message_content><![CDATA[XML not found: ]]></error_message_content>
|
||||
<error_message_image><![CDATA[Image not found]]></error_message_image>
|
||||
|
||||
</config>
|
||||
|;
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_rate ( )
|
||||
|
||||
Saves a rating of a matrix listing and returns the listing view.
|
||||
|
|
|
|||
|
|
@ -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} = '<a href="'.$listing->getUrl.'">'.$listing->get('title').'</a>';
|
||||
|
|
@ -365,17 +356,19 @@ sub getCompareForm {
|
|||
name=>"func",
|
||||
value=>"compare"
|
||||
})
|
||||
.WebGUI::Form::checkList($self->session, {
|
||||
name=>"listingId",
|
||||
vertical=>1,
|
||||
value=>\@selectedListingIds,
|
||||
options=>\%options,
|
||||
})
|
||||
.'<div id="compareForm"></div> '
|
||||
# .WebGUI::Form::checkList($self->session, {
|
||||
# name=>"listingId",
|
||||
# vertical=>1,
|
||||
# value=>\@selectedListingIds,
|
||||
# options=>\%options,
|
||||
# })
|
||||
."<br />"
|
||||
.WebGUI::Form::submit($self->session,{
|
||||
value=>"compare"
|
||||
})
|
||||
.WebGUI::Form::formFooter($self->session);
|
||||
#.'<div id="compareForm"></div> ';
|
||||
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} = "<script type='text/javascript'>\n".
|
||||
'var listingIds = new Array('.join(", ",map {'"'.$_.'"'} @listingIds).');'.
|
||||
'var columnKeys = new Array("name", '.join(", ",map {'"'.$_.'"'} @columnKeys).');'.
|
||||
"</script>";
|
||||
|
||||
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} = '<a href="'.$listing->getUrl.'">'.$listing->get('title').'</a>';
|
||||
}
|
||||
=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.
|
||||
|
|
|
|||
74
www/extras/wobject/Matrix/matrix.js
Normal file
74
www/extras/wobject/Matrix/matrix.js
Normal file
|
|
@ -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 = "<a href='" + oRecord.getData("ClickUrl") + "' target='_blank'>" + sData + "</a>";
|
||||
};
|
||||
|
||||
this.formatCheckBox = function(elCell, oRecord, oColumn, sData) {
|
||||
elCell.innerHTML = "<input type='checkbox' name='listingId' value='" + sData + "'>";
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
86
www/extras/wobject/Matrix/matrixCompareList.js
Normal file
86
www/extras/wobject/Matrix/matrixCompareList.js
Normal file
|
|
@ -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);
|
||||
//}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue