Fixed a number of Matrix datatable problems.
This commit is contained in:
parent
19b8a90139
commit
36d4013dff
5 changed files with 174 additions and 27 deletions
|
|
@ -480,6 +480,31 @@ sub view {
|
|||
$var->{manufacturerUrl_click} = $self->getUrl("func=click;manufacturer=1");
|
||||
$var->{productUrl_click} = $self->getUrl("func=click");
|
||||
|
||||
$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-min.js'),
|
||||
{type => 'text/javascript'});
|
||||
$self->session->style->setScript($self->session->url->extras('yui/build/datatable/datatable-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/matrixListing.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'});
|
||||
|
||||
# Attributes
|
||||
|
||||
foreach my $category (@categories) {
|
||||
|
|
@ -713,6 +738,54 @@ sub www_edit {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_getAttributes ( )
|
||||
|
||||
Gets a listings attributes grouped by category as json.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_getAttributes {
|
||||
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $db = $session->db;
|
||||
|
||||
return $session->privilege->noAccess() unless $self->canView;
|
||||
|
||||
$session->http->setMimeType("application/json");
|
||||
|
||||
my @results;
|
||||
my @categories = keys %{$self->getParent->getCategories};
|
||||
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};
|
||||
$attribute->{attributeId} =~ s/-/_____/g;
|
||||
if ($attribute->{fieldType} eq 'MatrixCompare'){
|
||||
$attribute->{value} = WebGUI::Form::MatrixCompare->new($self->session,$attribute)->getValueAsHtml;
|
||||
}
|
||||
push(@results,$attribute);
|
||||
}
|
||||
#$var->{$categoryLoopName} = \@attribute_loop;
|
||||
#push(@{$var->{category_loop}},{
|
||||
# categoryLabel => $category,
|
||||
# attribute_loop => \@attribute_loop,
|
||||
#});
|
||||
}
|
||||
my $jsonOutput;
|
||||
$jsonOutput->{ResultSet} = {Result=>\@results};
|
||||
|
||||
return JSON->new->utf8->encode($jsonOutput);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_getScreenshots ( )
|
||||
|
||||
Returns the screenshots as xml.
|
||||
|
|
|
|||
|
|
@ -620,7 +620,7 @@ sub www_compare {
|
|||
my $self = shift;
|
||||
my $var = $self->get;
|
||||
my @listingIds = @_;
|
||||
my @columnKeys;
|
||||
my @responseFields;
|
||||
|
||||
unless (scalar(@listingIds)) {
|
||||
@listingIds = $self->session->form->checkList("listingId");
|
||||
|
|
@ -664,13 +664,12 @@ sub www_compare {
|
|||
foreach my $listingId (@listingIds){
|
||||
my $listingId_safe = $listingId;
|
||||
$listingId_safe =~ s/-/_____/g;
|
||||
push(@columnKeys, $listingId_safe);
|
||||
push(@columnKeys, $listingId_safe."_compareColor");
|
||||
push(@responseFields, $listingId_safe, $listingId_safe."_compareColor");
|
||||
}
|
||||
|
||||
$var->{javascript} = "<script type='text/javascript'>\n".
|
||||
'var listingIds = new Array('.join(", ",map {'"'.$_.'"'} @listingIds).");\n".
|
||||
'var columnKeys = new Array("attributeId", "name", '.join(", ",map {'"'.$_.'"'} @columnKeys).");\n".
|
||||
'var responseFields = new Array("attributeId", "name", '.join(", ",map {'"'.$_.'"'} @responseFields).");\n".
|
||||
"var maxComparisons = ".$maxComparisons.";\n".
|
||||
"</script>";
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
|||
this.myDataSource.connXhrMode = "queueRequests";
|
||||
this.myDataSource.responseSchema = {
|
||||
resultsList: "ResultSet.Result",
|
||||
fields: columnKeys
|
||||
fields: responseFields
|
||||
};
|
||||
|
||||
var uri = "func=getCompareListData";
|
||||
|
|
@ -42,6 +42,7 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
|||
|
||||
this.myDataSource.doBeforeParseData = function (oRequest, oFullResponse) {
|
||||
myDataTable.getRecordSet().reset();
|
||||
myDataTable.refreshView();
|
||||
var existingColumns = myDataTable.getColumnSet().keys;
|
||||
for (var i = 0; i < existingColumns.length; i++) {
|
||||
if(i > 1){
|
||||
|
|
@ -66,12 +67,6 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
|||
this.onDataReturnAppendRows.apply(this,arguments);
|
||||
};
|
||||
|
||||
var myCallback2 = function() {
|
||||
this.set("sortedBy", null);
|
||||
this.onDataReturnAppendRows.apply(this,arguments);
|
||||
};
|
||||
|
||||
|
||||
var callback2 = {
|
||||
success : myCallback,
|
||||
failure : myCallback,
|
||||
|
|
@ -81,12 +76,10 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
|||
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++) {
|
||||
if(columnKeys[i] != 'name'){
|
||||
var checkBox = new Dom.get(columnKeys[i] + '_checkBox');
|
||||
if(checkBox.checked == true){
|
||||
uri = uri+';listingId='+columnKeys[i];
|
||||
}
|
||||
var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox','input');
|
||||
for (var i = compareCheckBoxes.length; i--; ) {
|
||||
if(compareCheckBoxes[i].checked == true){
|
||||
uri = uri+';listingId='+compareCheckBoxes[i].value;
|
||||
}
|
||||
}
|
||||
this.myDataSource.sendRequest(uri,callback2);
|
||||
|
|
|
|||
89
www/extras/wobject/Matrix/matrixListing.js
Normal file
89
www/extras/wobject/Matrix/matrixListing.js
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
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 = "<input type='checkBox' class='stickieCheckbox' id='" + oRecord.getData("attributeId") + "_stickied'>";
|
||||
};
|
||||
|
||||
var myColumnDefs = [
|
||||
{key:"stickied",formatter:this.formatStickied},
|
||||
{key:"label"},
|
||||
{key:"value"}
|
||||
];
|
||||
|
||||
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: ["label","value","attributeId"]
|
||||
};
|
||||
|
||||
var uri = "func=getAttributes";
|
||||
|
||||
// for (var i = 0; i < listingIds.length; i++) {
|
||||
// uri = uri+';listingId='+listingIds[i];
|
||||
// }
|
||||
|
||||
var myDataTable = new YAHOO.widget.DataTable("attributes", myColumnDefs,
|
||||
this.myDataSource, {initialRequest:uri});
|
||||
|
||||
|
||||
this.myDataSource.doBeforeParseData = function (oRequest, oFullResponse) {
|
||||
myDataTable.getRecordSet().reset();
|
||||
return oFullResponse;
|
||||
}
|
||||
|
||||
var myCallback = function() {
|
||||
this.set("sortedBy", null);
|
||||
this.onDataReturnAppendRows.apply(this,arguments);
|
||||
};
|
||||
|
||||
var myCallback2 = function() {
|
||||
this.set("sortedBy", null);
|
||||
this.onDataReturnAppendRows.apply(this,arguments);
|
||||
};
|
||||
|
||||
|
||||
var callback2 = {
|
||||
success : myCallback,
|
||||
failure : myCallback,
|
||||
scope : myDataTable
|
||||
};
|
||||
|
||||
|
||||
var btnStickied = new YAHOO.widget.Button("stickied");
|
||||
btnStickied.on("click", function(e) {
|
||||
var elements = myDataTable.getRecordSet().getRecords();
|
||||
if(hideStickies == 0){
|
||||
// hide non-selected attributes
|
||||
for(i=0; i<elements.length; i++){
|
||||
var attributeId = elements[i].getData('attributeId');
|
||||
var checkBox = Dom.get(attributeId+"_stickied");
|
||||
if (checkBox.checked == false){
|
||||
elRow = myDataTable.getTrEl(elements[i]);
|
||||
Dom.setStyle(elRow, "display", "none");
|
||||
}
|
||||
}
|
||||
hideStickies = 1;
|
||||
}else{
|
||||
// show all attributes
|
||||
for(i=0; i<elements.length; i++){
|
||||
var attributeId = elements[i].getData('attributeId');
|
||||
var checkBox = Dom.get(attributeId+"_stickied");
|
||||
if (checkBox.checked == false){
|
||||
elRow = myDataTable.getTrEl(elements[i]);
|
||||
Dom.setStyle(elRow, "display", "table-row");
|
||||
}
|
||||
}
|
||||
hideStickies = 0;
|
||||
}
|
||||
},this,true);
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
|
@ -57,16 +57,9 @@ YAHOO.util.Event.addListener(window, "load", function() {
|
|||
for (var i = attributeSelects.length; i--; ) {
|
||||
newUri = newUri + ';search_' + attributeSelects[i].id + '=' + attributeSelects[i].value;
|
||||
}
|
||||
var elements = myDataTable.getRecordSet().getRecords();
|
||||
for(i=0; i<elements.length; i++){
|
||||
elRow = myDataTable.getTrEl(elements[i]);
|
||||
Dom.setStyle(elRow, "display", "none");
|
||||
}
|
||||
var compareCheckBoxes = YAHOO.util.Dom.getElementsByClassName('compareCheckBox','input');
|
||||
for (var i = compareCheckBoxes.length; i--; ) {
|
||||
compareCheckBoxes[i].checked = false;
|
||||
}
|
||||
myDataTable.getRecordSet().deleteRecord(0,elements.length);
|
||||
myDataTable.getRecordSet().reset();
|
||||
myDataTable.refreshView();
|
||||
|
||||
myDataSource.sendRequest(newUri,callback2);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue