Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-545: Reverted bank.js/selector.js

Mike McGann1de4052049cf
diff --git a/src/js/bank.js b/src/js/bank.js
index c40a1cffe..42c0d89e0 100644
--- a/src/js/bank.js
+++ b/src/js/bank.js
@@ -3,12 +3,11 @@ SOTE.namespace("SOTE.widget.Bank");
SOTE.widget.Bank.prototype = new SOTE.widget.Component;
/**
- * A selection device classifying radio buttons/checkboxes into categories that are displayed in Accordion form.
- * Radio buttons allow single selection accross categories. Checkboxes allow multiple selections accross categories.
- * Radio selections cannot span multiple categories.
+ * Instantiate the Bank
*
- * @module SOTE.widget
- * @class Bank
+ * @class A selection device classifying radio buttons/checkboxes into categories that are displayed in Accordion form.
+ * Radio buttons allow single selection accross categories. Checkboxes allow multiple selections accross categories.
+ * Radio selections cannot span multiple categories.
* @constructor
* @this {Bank}
* @param {String} containerId is the container id of the div in which to render the object
@@ -19,7 +18,7 @@ SOTE.widget.Bank.prototype = new SOTE.widget.Component;
* @augments SOTE.widget.Component
*
*/
-SOTE.widget.Bank = function(containerId, spec){
+SOTE.widget.Bank = function(containerId, config){
this.log = Logging.getLogger("Worldview.Widget.Bank");
this.VALID_PROJECTIONS = ["geographic", "arctic", "antarctic"];
this.hidden = {};
@@ -35,46 +34,53 @@ SOTE.widget.Bank = function(containerId, spec){
this.containerId=containerId;
//Define an object for holding configuration
- if (spec===undefined){
- spec={};
+ if (config===undefined){
+ config={};
}
- if(spec.title === undefined){
- spec.title = "My Bank";
+ if(config.title === undefined){
+ config.title = "My Bank";
}
- if(spec.categories === undefined){
- spec.categories = ["Category 1","Category 2"];
+ if(config.categories === undefined){
+ config.categories = ["Category 1","Category 2"];
}
- if(spec.callback === undefined){
- spec.callback = null;
+ if(config.callback === undefined){
+ config.callback = null;
}
- if(spec.state === undefined || spec.state === ""){
- spec.state = "geographic";
+ if(config.state === undefined || config.state === ""){
+ config.state = "geographic";
}
- this.state = spec.state;
- this.selected = spec.selected;
+ this.state = config.state;
+ //console.log("state: " + this.state);
+ this.selected = config.selected;
+ this.values = this.unserialize(this.selected[this.state]);
- this.dataSourceUrl = spec.dataSourceUrl;
-
- this.title = spec.title;
- this.callback = spec.callback;
- this.selector = spec.selector;
- this.data = new Object;
+ this.dataSourceUrl = config.dataSourceUrl;
+ //console.log("dataSourceUrl: " + this.dataSourceUrl);
+ this.title = config.title;
+ this.callback = config.callback;
+ this.selector = config.selector;
+ this.meta = new Object;
this.buildMetaDone = false;
- this.categories = spec.categories;
+ /*this.meta["MODIS_Terra_CorrectedReflectance_TrueColor"] = {label:"Corrected Reflectance (True Color)",sublabel:"Terra / MODIS"};
+ this.meta["fires48"] = {label:"Fires (Past 48 Hours)",sublabel:"MODIS Fire and Thermal Anomalies"};
+ this.meta["AIRS_Dust_Score"] = {label:"Dust Score",sublabel:"Aqua / AIRS"};
+ this.meta["OMI_Aerosol_Index"] = {label:"Aerosol Index",sublabel:"Aura / OMI"};*/
+ this.categories = config.categories;
this.initRenderComplete = false;
- this.dataSourceUrl = spec.dataSourceUrl;
+ this.dataSourceUrl = config.dataSourceUrl;
this.statusStr = "";
- this.config = spec.config;
- this.paletteWidget = spec.paletteWidget;
+ this.config = config.config;
+ this.paletteWidget = config.paletteWidget;
this.queryString = "";
this.noFireVal = null;
this.init();
+ //this.updateComponent(this.id+"=baselayers.MODIS_Terra_CorrectedReflectance_TrueColor-overlays.fires48.AIRS_Dust_Score.OMI_Aerosol_Index")
};
@@ -86,55 +92,49 @@ SOTE.widget.Bank.prototype.buildMeta = function(cb,val){
callback: cb,
val: val
});
-
};
SOTE.widget.Bank.handleMetaSuccess = function(data,status,xhr,args){
var self = args.self;
- var dupes = new Object;
- var count = 0;
-
for(var i in data){
if(i != "palettes") {
-
- for(var j=0; j<data[i].length; j++){
- if(!self.data[data[i][j].category]){
- self.data[data[i][j].category] = new Object;
- self.data[data[i][j].category].title = self.categories[count++];
- self.data[data[i][j].category].items = [];
- }
-
- if(! (data[i][j].value in dupes) ){
- var categories = {"All":1};
- self.data[data[i][j].category].items.push({label:data[i][j].label,sublabel:data[i][j].sublabel,value:data[i][j].value,categories:categories});
- dupes[data[i][j].value] = 1;
- }
+ for(var j=0; j<data[i].length; j++){
+
+ self.meta[data[i][j].value] = {label:data[i][j].label,sublabel:data[i][j].sublabel,type:data[i][j].type};
+
}
}
}
- /*$.each(self.meta, function(name, meta) {
- if ( name in self.config.layers ) {
- var layer = self.config.layers[name];
- if ( "rendered" in layer ) {
- meta.units = layer.units;
- meta.min = ( layer.min === undefined )
+ /* TODO: This breaks when switching to polar projections
+ var key = data["Floods"][0].value;
+ //console.log("Key = " + key);
+ //console.log("Meta Label = " + self.meta[key].label);
+ //console.log("Meta Sublabel = " + self.meta[key].sublabel);
+ */
+ $.each(self.meta, function(name, meta) {
+ if ( name in self.config.products ) {
+ var product = self.config.products[name];
+ if ( "rendered" in product ) {
+ meta.units = product.units;
+ meta.min = ( product.min === undefined )
? "&nbsp;&nbsp;&nbsp;&nbsp"
- : layer.min;
- meta.max = ( layer.max === undefined )
+ : product.min;
+ meta.max = ( product.max === undefined )
? "&nbsp;&nbsp;&nbsp;"
- : layer.max;
- meta.bins = layer.bins;
- meta.stops = layer.stops;
- meta.palette = self.config.palettes[layer.rendered];
+ : product.max;
+ meta.bins = product.bins;
+ meta.stops = product.stops;
+ meta.palette = self.config.palettes[product.rendered];
}
}
- });*/
-
+ });
if(args.callback){
args.callback({self:self,val:args.val});
}
else{
+ self.values = null;
+ self.values = self.unserialize(self.selected[self.state]);
self.render();
self.fire();
}
@@ -173,42 +173,128 @@ SOTE.widget.Bank.prototype.init = function(){
*/
SOTE.widget.Bank.prototype.render = function(){
- $(this.container).empty();
+ this.container.innerHTML = "";
+/* var tabs = document.createElement("ul");
+ tabs.innerHTML = "<li><a href='#bank' class='activetab'>Active</a></li><li><a class='addlayerstab' href='#selectorbox'>Add Layers</a></li>";
+ this.container.appendChild(tabs);
+ */
var tabs_height = $(".ui-tabs-nav").outerHeight(true);
$('#'+this.id).addClass('bank');
- $('#'+this.id).height($('#'+this.id).parent().outerHeight() - tabs_height);
+ $('#'+this.id).height($('#'+this.id).parent().outerHeight() - tabs_height); /*var container = document.createElement("div");
+ container.setAttribute("id","bank");
+ container.setAttribute("class","bank");*/
- this.list = new SOTE.widget.List(this.id,{
- config: this.config,
- data: this.data,
- selected: this.selected[this.state],
- hide: true,
- close: true,
- filter: true,
- search: false,
- sortable: true,
- onchange: SOTE.widget.Bank.handleFire,
- args: this,
- paletteWidget: this.paletteWidget
- });
+ //var titleContainer = document.createElement("div");
+ //titleContainer.setAttribute("class","tabContainer");
+ //var title = document.createElement("h2");
+ //title.innerHTML = "Active"; //this.title;
+ /*var ext = document.createElement("a");
+ ext.setAttribute("id","callSelectorLink");
+ ext.setAttribute("class","callSelectorLink");
+ ext.setAttribute("title","Show Product Listing");
+ */
+ //titleContainer.appendChild(title);
+ //titleContainer.appendChild(ext);
+
+ //container.appendChild(titleContainer);
- //$("#"+this.id).bind("listchange", {self:this}, SOTE.widget.Bank.handleFire);
+ //$('#'+this.id).delegate('.callSelectorLink','click',{selector:this.selector},this.callback);
- /*var m = this.meta[myVal];
-
- if(m && m.palette){
- var paletteString = "<div><span class='palette'><span class='p-min' style='margin-right:10px;'>"+m.min+"</span>" +
- "<canvas class='colorBar' id='canvas"+this.values[formattedCategoryName.toLowerCase()][j].value+"' width=100px height=14px'></canvas>" +
- "<span class='p-max' style='margin-left:10px;'>"+m.max+"</span>";
- if(m.units && m.units != ""){
- paletteString += "<span class='units' style='margin-left:3px;'>("+m.units+")</span></span></div>";
+ for(var i=0; i<this.categories.length; i++){
+ var formattedCategoryName = this.categories[i].replace(/\s/g, "");
+ var category = document.createElement("ul");
+ category.setAttribute("id",formattedCategoryName.toLowerCase());
+ category.setAttribute("class",this.id+"category category");
+
+ var categoryContainer = document.createElement("div");
+ categoryContainer.setAttribute("id",this.id + formattedCategoryName);
+ categoryContainer.setAttribute("class","categoryContainer");
+
+ var categoryTitle = document.createElement("h3");
+ categoryTitle.setAttribute("class","head");
+ categoryTitle.innerHTML = this.categories[i];
+
+ categoryContainer.appendChild(categoryTitle);
+
+
+ if(this.values !== null && this.values[formattedCategoryName.toLowerCase()]){
+ for(var j=0; j<this.values[formattedCategoryName.toLowerCase()].length; j++){
+ var myVal = this.values[formattedCategoryName.toLowerCase()][j].value
+ var item = document.createElement("li");
+ item.setAttribute("id",formattedCategoryName.toLowerCase()+"-"+myVal);
+ item.setAttribute("class",this.id+"item item");
+ item.innerHTML = "<a><img class='close bank-item-img' id='close"+myVal.replace(/:/g,"colon")+"' title='Remove Layer' src='images/close-red-x.png' /></a>";
+ if(this.meta !== null && this.meta[myVal]){
+ if(myVal in this.hidden){
+ item.innerHTML += "<a class='hdanchor'><img class='hide hideReg bank-item-img' title='Show Layer' id='hide"+myVal.replace(/:/g,"colon")+"' src='images/invisible.png' /></a>";
+ }
+ else {
+ item.innerHTML += "<a class='hdanchor'><img class='hide hideReg bank-item-img' title='Hide Layer' id='hide"+myVal.replace(/:/g,"colon")+"' src='images/visible.png' /></a>";
+ }
+ item.innerHTML += "<h4>"+this.meta[myVal].label+"</h4>";
+ item.innerHTML += "<p>"+this.meta[myVal].sublabel+"</p>";
+ var m = this.meta[myVal];
+
+ if(m && m.palette){
+ var paletteString = "<div><span class='palette'><span class='p-min' style='margin-right:10px;'>"+m.min+"</span>" +
+ "<canvas class='colorBar' id='canvas"+this.values[formattedCategoryName.toLowerCase()][j].value+"' width=100px height=14px'></canvas>" +
+ "<span class='p-max' style='margin-left:10px;'>"+m.max+"</span>";
+ if(m.units && m.units != ""){
+ paletteString += "<span class='units' style='margin-left:3px;'>("+m.units+")</span></span></div>";
+ }
+ item.innerHTML += paletteString;
+ }
+
+ }
+ else{
+ item.innerHTML += "<h4>"+this.values[formattedCategoryName.toLowerCase()][j].value+"</h4>";
+ }
+ category.appendChild(item);
+ }
}
- item.innerHTML += paletteString;
+
+ categoryContainer.appendChild(category);
+ this.container.appendChild(categoryContainer);
+
}
-
- this.renderCanvases();*/
+ /*
+ var selectorbox = document.createElement("div");
+ selectorbox.setAttribute("id","selectorbox");
+ this.container.appendChild(selectorbox);*/
+
+ this.renderCanvases();
+ /*var accordionToggler = document.createElement("a");
+ accordionToggler.setAttribute("class","accordionToggler atcollapse");
+ accordionToggler.setAttribute("title","Hide Products");
+ this.isCollapsed = false;
+ this.container.appendChild(accordionToggler);
+ $('.accordionToggler').bind('click',{self:this},SOTE.widget.Bank.toggle);*/
+ $("#"+this.id).undelegate(".close" ,'click');
+ $("#"+this.id).undelegate(".hideReg" ,'click');
+ $("#"+this.id).undelegate(".hideSingle" ,'click');
+ $("#"+this.id).delegate(".close" ,'click',{self:this},SOTE.widget.Bank.removeValue);
+ $("#"+this.id).delegate(".hideReg" ,'click',{self:this},SOTE.widget.Bank.toggleValue);
+ $("#"+this.id).delegate(".hideSingle" ,'click',{self:this},SOTE.widget.Bank.toggleValue);
+ $( "." + this.id + "category" ).sortable({items: "li:not(.head)"});
+ if($(window).width() > 720)
+ {
+ if(this.jsp){
+ var api = this.jsp.data('jsp');
+ if(api) api.destroy();
+ }
+ this.jsp = $( "." + this.id + "category" ).jScrollPane({autoReinitialise: false, verticalGutter:0});
+ }
+ $( "." + this.id + "category li" ).disableSelection();
+ $( "." + this.id + "category" ).bind('sortstop',{self:this},SOTE.widget.Bank.handleSort);
+
+ setTimeout(SOTE.widget.Bank.adjustCategoryHeights,1,{self:this});
+ //this.hideAllRadioExceptTop();
+
+ /*$('#'+this.id).tabs();
+ //this.b = new SOTE.widget.Bank("products",{paletteWidget: window.palettes, dataSourceUrl:"ap_products.php",title:"My Layers",selected:{antarctic:"baselayers,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,antarctic_coastlines", arctic:"baselayers,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,arctic_coastlines",geographic:"baselayers,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,sedac_bound"},categories:["Base Layers","Overlays"],config:config});
+ this.s = new SOTE.widget.Selector("selectorbox",{dataSourceUrl:"ap_products.php",categories:["Base Layers","Overlays"]}); */
// Mark the component as ready in the registry if called via init()
if ((this.initRenderComplete === false) && REGISTRY) {
@@ -218,8 +304,48 @@ SOTE.widget.Bank.prototype.render = function(){
};
-SOTE.widget.Bank.handleFire = function(self){
- self.fire();
+SOTE.widget.Bank.adjustCategoryHeights = function(args){
+ var self = args.self;
+ var heights = new Array;
+ var container_height = $("#"+self.id).outerHeight(true);
+ var labelHeight = 0;
+ $('#'+self.id+' .head').each(function(){
+ labelHeight += $(this).outerHeight(true);
+ });
+ container_height -= labelHeight;
+ //console.log("This.id: " + container_height);
+ for(var i=0; i<self.categories.length; i++){
+ var formattedCategoryName = self.categories[i].replace(/\s/g, "");
+ var actual_height = 0;
+ var count = 0;
+ $('#' + formattedCategoryName.toLowerCase() + ' li').each(function(){
+ actual_height += $(this).outerHeight(true);
+ count++;
+ });
+
+ heights.push({name:formattedCategoryName.toLowerCase(),height:actual_height,count:count});
+ }
+
+ if(heights[0].height + heights[1].height > container_height){
+ if(heights[0].height > container_height/2) {
+ heights[0].height = container_height/2;
+ }
+
+ heights[1].height = container_height - heights[0].height;
+
+ }
+
+ $("#" + heights[0].name).css("height",heights[0].height+"px");
+ $("#" + heights[1].name).css("height",heights[1].height+"px");
+
+ SOTE.widget.Bank.reinitializeScrollbars({self:self});
+};
+
+SOTE.widget.Bank.reinitializeScrollbars = function(o) {
+ var pane = $("." + o.self.id + "category").each(function(){
+ var api = $(this).data('jsp');
+ if(api) api.reinitialise();
+ });
};
SOTE.widget.Bank.prototype.renderCanvases = function(){
@@ -265,6 +391,162 @@ SOTE.widget.Bank.prototype.renderCanvases = function(){
}
};
+SOTE.widget.Bank.toggle = function(e,ui){
+ var self = e.data.self;
+ if(self.isCollapsed){
+ $('.accordionToggler').removeClass('atexpand').addClass('atcollapse');
+ $('.accordionToggler').attr("title","Hide Products");
+ $('.bank').css('display','block');
+ self.isCollapsed = false;
+ }
+ else{
+ $('.accordionToggler').removeClass('atcollapse').addClass('atexpand');
+ $('.accordionToggler').attr("title","Show Products");
+ $('.bank').css('display','none');
+ self.isCollapsed = true;
+ }
+};
+
+SOTE.widget.Bank.handleSort = function(e,ui){
+ var self = e.data.self;
+ self.values = new Object;
+ for(var i=0; i<self.categories.length; i++){
+ var formatted = self.categories[i].replace(/\s/g, "");
+ formatted = formatted.toLowerCase();
+ self.values[formatted] = new Array();
+ jQuery('li[id|="'+formatted+'"]').each(function() {
+ var item = jQuery( this );
+ var id = item.attr("id");
+ var vals = id.split("-");
+ var val = vals.splice(0,1);
+ val = vals.join("-");
+ self.values[formatted].push({value:val});
+ });
+ }
+ self.fire();
+
+};
+
+SOTE.widget.Bank.removeValue = function(e){
+ var self = e.data.self;
+ var val = e.target.id.replace(/colon/g,":");
+ val = val.replace(/close/g,"");
+ for(var i=0; i<self.categories.length; i++){
+ var formatted = self.categories[i].replace(/\s/g, "");
+ formatted = formatted.toLowerCase();
+ for(var j=0; j<self.values[formatted].length; j++){
+ if(self.values[formatted][j].value == val){
+ self.values[formatted].splice(j,1);
+ }
+ }
+ }
+ var formattedVal = "close"+val.replace(/:/g,"colon");
+ //self.render();
+ $("#"+self.id+" #"+formattedVal).parent().parent().remove();
+ self.count--;
+ self.fire();
+};
+
+SOTE.widget.Bank.toggleValue = function(e){
+ var self = e.data.self;
+ var val = e.target.id.replace(/colon/g,":");
+ val = val.replace(/hide/g,"");
+ for(var i=0; i<self.categories.length; i++){
+ var formatted = self.categories[i].replace(/\s/g, "");
+ formatted = formatted.toLowerCase();
+ if(self.values[formatted]){
+ for(var j=0; j<self.values[formatted].length; j++){
+ if(self.values[formatted][j].value == val){
+ if(val in self.hidden){
+ delete self.hidden[val];
+ e.target.src = 'images/visible.png';
+ $("#"+e.target.id).attr("title","Hide Layer");
+ }
+ else {
+ self.hidden[val] = 1;
+ e.target.src = 'images/invisible.png';
+ $("#"+e.target.id).attr("title","Show Layer");
+ }
+
+
+ }
+ }
+ }
+ }
+ //var formattedVal = val.replace(/:/g,"colon");
+ //self.render();
+ //$("#"+self.id+" #"+formattedVal).parent().parent().remove();
+ self.fire();
+};
+
+SOTE.widget.Bank.prototype.hideAllRadioExceptTop = function(){
+ for(var i=0; i<this.categories.length - 1; i++){
+ var formatted = this.categories[i].replace(/\s/g, "");
+ formatted = formatted.toLowerCase();
+ for(var j=1; j<this.values[formatted].length; j++){
+
+ this.hidden[this.values[formatted][j].value] = 1;
+ $('#hide'+this.values[formatted][j].value).attr("src",'images/invisible.png');
+
+ }
+ }
+};
+
+SOTE.widget.Bank.radioToggleValue = function(e){
+ var self = e.data.self;
+ var val = e.target.id.replace(/colon/g,":");
+ var cat = -1;
+ var hidden = false;
+ val = val.replace(/hide/g,"");
+
+ for(var i=0; i<self.categories.length; i++){
+ var formatted = self.categories[i].replace(/\s/g, "");
+ formatted = formatted.toLowerCase();
+ if(self.values[formatted]){
+ for(var j=0; j<self.values[formatted].length; j++){
+ if(self.values[formatted][j].value == val){
+ if(val in self.hidden){
+ delete self.hidden[val];
+ e.target.src = 'images/visible.png';
+ for(var k=0; k<self.values[formatted].length; k++){
+ if(self.values[formatted][k].value != val){
+ self.hidden[self.values[formatted][k].value] = 1;
+ $('#hide'+self.values[formatted][k].value).attr("src",'images/invisible.png');
+ }
+ }
+ }
+ else {
+ self.hidden[val] = 1;
+ e.target.src = 'images/invisible.png';
+ if(j+1 < self.values[formatted].length){
+ if(self.hidden[self.values[formatted][j+1].value]){
+ delete self.hidden[self.values[formatted][j+1].value];
+ $('#hide'+self.values[formatted][j+1].value).attr("src",'images/visible.png');
+ }
+ }
+ else {
+ if(self.hidden[self.values[formatted][0].value]){
+ delete self.hidden[self.values[formatted][0].value];
+ $('#hide'+self.values[formatted][0].value).attr("src",'images/visible.png');
+
+ }
+ }
+ }
+
+ }
+ }
+ }
+ }
+
+
+ //var formattedVal = val.replace(/:/g,"colon");
+ //self.render();
+ //$("#"+self.id+" #"+formattedVal).parent().parent().remove();
+ self.fire();
+};
+
+
+
/**
* Fires an event to the registry when the state of the component is changed
*
@@ -272,6 +554,7 @@ SOTE.widget.Bank.prototype.renderCanvases = function(){
*
*/
SOTE.widget.Bank.prototype.fire = function(){
+ setTimeout(SOTE.widget.Bank.adjustCategoryHeights,1,{self:this});
$("#"+this.id).trigger("fire");
if(REGISTRY){
@@ -295,11 +578,18 @@ SOTE.widget.Bank.prototype.fire = function(){
*
*/
SOTE.widget.Bank.prototype.setValue = function(valString, selector){
- this.list.setValue(valString, selector);
+
+ this.values = this.unserialize(valString, selector);
+ var valid = true;
+ var self = this;
+
+ this.render();
+ this.fire();
+
};
SOTE.widget.Bank.prototype.currCount = function(){
- return this.list.count;
+ return this.count;
};
/**
@@ -312,12 +602,77 @@ SOTE.widget.Bank.prototype.currCount = function(){
*/
SOTE.widget.Bank.prototype.getValue = function(){
- return this.id + "=" + this.list.getValue();
+ var value = this.serialize(this.values);
+ return this.id + "=" + value;
};
SOTE.widget.Bank.prototype.value = function(){
- return this.list.getValue();
+ var value = this.serialize(this.values);
+ return value;
+};
+
+SOTE.widget.Bank.prototype.serialize = function(values){
+ var serialized = "";
+ for(var i=0; i<this.categories.length; i++){
+ if(i > 0){
+ serialized += "~";
+ }
+ var formatted = this.categories[i].replace(/\s/g, "");
+ formatted = formatted.toLowerCase();
+
+ serialized += formatted;
+ if(values[formatted]){
+ for(var j=0; j<values[formatted].length; j++){
+ if(!(values[formatted][j].value in this.hidden)){
+ serialized += "," + values[formatted][j].value;
+ }else {
+ serialized += "," + "!" + values[formatted][j].value;
+ }
+ }
+ }
+ }
+ return serialized;
+};
+
+SOTE.widget.Bank.prototype.unserialize = function(string, selector){
+ var unserialized = new Object;
+ var hideIndicator = /^!/;
+ var categories = string.split("~");
+ var values = [];
+ this.count = 0;
+ for(var i=0; i<categories.length; i++){
+ var items = categories[i].split(/[\.,]/);
+ unserialized[items[0]] = new Array;
+ for(var j=1; j<items.length; j++){
+ if ( this.meta && !this.meta[items[j]] && !hideIndicator.test(items[j]) ) {
+ this.log.warn("No such product: " + items[j]);
+ } else {
+ if(hideIndicator.test(items[j])){
+ items[j] = items[j].replace(/!/g, "");
+ this.hidden[items[j]] = 1;
+ }
+ else {
+ if(!selector){
+ delete this.hidden[items[j]];
+ }
+ }
+
+ unserialized[items[0]].push({"value":items[j]});
+ values.push(items[j]);
+ this.count++;
+ }
+ }
+
+ }
+
+ for(var key in this.hidden){
+ if( values.indexOf(key) < 0 ){
+ delete this.hidden[key];
+ }
+ }
+
+ return unserialized;
};
/**
@@ -330,6 +685,12 @@ SOTE.widget.Bank.prototype.value = function(){
*/
SOTE.widget.Bank.prototype.updateComponent = function(querystring){
var qs = (querystring === undefined)? "":querystring;
+ /*SOTE.util.getJSON(
+ this.dataSourceUrl+"?"+querystring,
+ {self:this,qs:querystring},
+ SOTE.widget.Bank.handleUpdateSuccess,
+ SOTE.widget.Bank.handleUpdateFailure
+ );*/
SOTE.widget.Bank.handleUpdateSuccess(this,qs);
};
@@ -354,7 +715,7 @@ SOTE.widget.Bank.handleUpdateSuccess = function(self,qs){
projection = self.VALID_PROJECTIONS[0];
}
if(projection == self.state){
- var vals = SOTE.util.extractFromQuery("selectorbox",qs);
+ var vals = SOTE.util.extractFromQuery("selectorbox",qs)
self.setValue(vals, "selector");
}
else {
@@ -394,16 +755,13 @@ SOTE.widget.Bank.prototype.loadFromQuery = function(qs){
this.updateComponent(qs);
}
else {
- SOTE.widget.Bank.loadValue({
- self: this,
- val: SOTE.util.extractFromQuery(this.id, qs)
- });
+ this.sleep(SOTE.util.extractFromQuery(this.id,qs));
}
};
SOTE.widget.Bank.prototype.sleep = function(v){
setTimeout(SOTE.widget.Bank.loadValue,100,{self:this,val:v});
-};
+}
SOTE.widget.Bank.loadValue = function(args){
if(args.self.buildMetaDone == true) {
diff --git a/src/js/products.js b/src/js/products.js
index 1dbca51a6..23c750761 100644
--- a/src/js/products.js
+++ b/src/js/products.js
@@ -3,12 +3,11 @@ SOTE.namespace("SOTE.widget.Products");
SOTE.widget.Products.prototype = new SOTE.widget.Component;
/**
- * A selection device classifying radio buttons/checkboxes into categories that are displayed in Accordion form.
+ * Instantiate the Products
+ *
+ * @class A selection device classifying radio buttons/checkboxes into categories that are displayed in Accordion form.
* Radio buttons allow single selection accross categories. Checkboxes allow multiple selections accross categories.
- * Radio selections cannot span multiple categories.
- *
- * @module SOTE.widget
- * @class Products
+ * Radio selections cannot span multiple categories.
* @constructor
* @this {Products}
* @param {String} containerId is the container id of the div in which to render the object
@@ -19,7 +18,7 @@ SOTE.widget.Products.prototype = new SOTE.widget.Component;
* @augments SOTE.widget.Component
*
*/
-SOTE.widget.Products = function(containerId, spec){
+SOTE.widget.Products = function(containerId, config){
this.log = Logging.getLogger("Worldview.Widget.Products");
//this.VALID_PROJECTIONS = ["geographic", "arctic", "antarctic"];
@@ -34,37 +33,36 @@ SOTE.widget.Products = function(containerId, spec){
this.containerId=containerId;
//Define an object for holding configuration
- if (spec===undefined){
- spec={};
+ if (config===undefined){
+ config={};
}
- if(spec.title === undefined){
- spec.title = "My Products";
+ if(config.title === undefined){
+ config.title = "My Products";
}
- if(spec.categories === undefined){
- spec.categories = ["Category 1","Category 2"];
+ if(config.categories === undefined){
+ config.categories = ["Category 1","Category 2"];
}
- if(spec.callback === undefined){
- spec.callback = null;
+ if(config.callback === undefined){
+ config.callback = null;
}
- if(spec.state === undefined || spec.state === ""){
- spec.state = "geographic";
+ if(config.state === undefined || config.state === ""){
+ config.state = "geographic";
}
- this.state = spec.state;
- this.selected = spec.selected;
+ this.state = config.state;
+ this.selected = config.selected;
this.isCollapsed = false;
- this.dataSourceUrl = spec.dataSourceUrl;
- this.categories = spec.categories;
+ this.dataSourceUrl = config.dataSourceUrl;
+ this.categories = config.categories;
+ this.config = config.config;
+ this.paletteWidget = config.paletteWidget;
+ this.events = Worldview.Events();
this.initRenderComplete = false;
- this.paletteWidget = spec.paletteWidget;
- this.config = spec.config;
- this.events = Worldview.Events();
-
this.init();
};
@@ -89,7 +87,7 @@ SOTE.widget.Products.HTML_TAB_DOWNLOAD_SELECTED =
SOTE.widget.Products.HTML_TAB_DOWNLOAD_UNSELECTED =
"<img class='productsIcon' src='images/missing-icon.svg' title='Download'>";
-
+
/**
* Displays all options in HTML in an Accordion format (see JQuery UI Accordion) with the selected states being indicated
* by radio button and checkbox selection. All callbacks should be set. The component UI should be rendered
@@ -128,9 +126,9 @@ SOTE.widget.Products.prototype.render = function(){
var tabs = document.createElement("ul");
tabs.setAttribute("id",this.id+"tabs");
- tabs.innerHTML =
+ tabs.innerHTML =
"<li class='layerPicker first'>" +
- "<a href='#products' class='activetab tab'></a>" +
+ "<a href='#products' class='activetab tab'></a>" +
"</li>" +
"<li class='layerPicker second'>" +
"<a class='addlayerstab tab' href='#selectorbox'></a>" +
@@ -139,8 +137,6 @@ SOTE.widget.Products.prototype.render = function(){
"<a class='tab' href='#DataDownload'></a>" +
"</li>";
this.container.appendChild(tabs);
- SOTE.widget.Products.change({data: {self: this}}, {index: 0});
-
//$('#'+this.id).addClass('products');
var toggleButtonHolder = document.createElement("div");
toggleButtonHolder.setAttribute("id",this.id+"toggleButtonHolder");
@@ -165,32 +161,32 @@ SOTE.widget.Products.prototype.render = function(){
this.container.appendChild(downloadBox);
//this.container.appendChild(productContainer);
- var self = this;
- $('#'+this.id).tabs({show: function(e, ui) {
- e.data = { self: self };
- SOTE.widget.Products.change(e, ui);
+ var self = this;
+ $('#'+this.id).tabs({show: function(e, ui) {
+ e.data = { self: self };
+ SOTE.widget.Products.change(e, ui);
}});
this.b = new SOTE.widget.Bank("products", {
+ paletteWidget: this.palettes,
dataSourceUrl: "ap_products.php",
title: "My Layers",
selected: {
antarctic: "baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,antarctic_coastlines",
- arctic:"baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,arctic_coastlines",
- geographic:"baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,sedac_bound"
+ arctic: "baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,arctic_coastlines",
+ geographic: "baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,sedac_bound"
},
- categories:["Base Layers","Overlays"],
- config: this.config,
- paletteWidget: this.paletteWidget
+ categories: ["Base Layers","Overlays"],
+ config:this.config
});
this.s = new SOTE.widget.Selector("selectorbox", {
dataSourceUrl: "ap_products.php",
- categories: ["Base Layers","Overlays"],
+ categories: ["Base Layers","Overlays"],
selected: {
- antarctic: "baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,antarctic_coastlines",
+ antarctic:"baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,antarctic_coastlines",
arctic:"baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,arctic_coastlines",
geographic:"baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,sedac_bound"
},
- config: this.config
+ config:this.config
});
//$('#'+this.id+"prods").on("tabsshow",SOTE.widget.Products.change);
@@ -210,8 +206,7 @@ SOTE.widget.Products.prototype.render = function(){
}
var self = this;
$(window).resize(function(){
- //self.b.render();
- self.b.resize(); self.b.adjustCategoryHeights({self: b});
+ self.b.render();
self.s.resize();
self.adjustAlignment();
});
@@ -245,13 +240,14 @@ SOTE.widget.Products.stopLink = function(e){
//e.stopPropagation();
};
-SOTE.widget.Products.change = function(e,ui) {
+SOTE.widget.Products.change = function(e,ui){
+ console.log(e);
var self = e.data.self;
if ( ui.index === 0 ) {
- $('.ui-tabs-nav')
- .addClass('firstselected')
- .removeClass('secondselected')
- .removeClass('thirdselected');
+ $('.ui-tabs-nav')
+ .addClass('firstselected')
+ .removeClass('secondselected')
+ .removeClass('thirdselected');
}
else if ( ui.index === 1 ) {
$('.ui-tabs-nav')
@@ -286,8 +282,8 @@ SOTE.widget.Products.change = function(e,ui) {
$('.ui-tabs-nav li.first a').html(tab1);
$('.ui-tabs-nav li.second a').html(tab2);
$('.ui-tabs-nav li.third a').html(tab3);
-
- return false;
+
+ return false;
};
SOTE.widget.Products.toggle = function(e,ui){
diff --git a/src/js/selector.js b/src/js/selector.js
index a30fb47e2..a1eceb34a 100644
--- a/src/js/selector.js
+++ b/src/js/selector.js
@@ -3,12 +3,11 @@ SOTE.namespace("SOTE.widget.Selector");
SOTE.widget.Selector.prototype = new SOTE.widget.Component;
/**
- * A selection device classifying radio buttons/checkboxes into categories that are displayed in Accordion form.
+ * Instantiate the Selector
+ *
+ * @class A selection device classifying radio buttons/checkboxes into categories that are displayed in Accordion form.
* Radio buttons allow single selection accross categories. Checkboxes allow multiple selections accross categories.
- * Radio selections cannot span multiple categories.
- *
- * @module SOTE.widget
- * @class Selector
+ * Radio selections cannot span multiple categories.
* @constructor
* @this {Selector}
* @param {String} containerId is the container id of the div in which to render the object
@@ -19,7 +18,7 @@ SOTE.widget.Selector.prototype = new SOTE.widget.Component;
* @augments SOTE.widget.Component
*
*/
-SOTE.widget.Selector = function(containerId, spec){
+SOTE.widget.Selector = function(containerId, config){
//Get the ID of the container element
this.container=document.getElementById(containerId);
if (this.container==null){
@@ -31,32 +30,29 @@ SOTE.widget.Selector = function(containerId, spec){
this.containerId=containerId;
//Define an object for holding configuration
- if (spec===undefined){
- spec={};
+ if (config===undefined){
+ config={};
}
- if(spec.categories === undefined){
- spec.categories = ["Category 1","Category 2"];
+ if(config.categories === undefined){
+ config.categories = ["Category 1","Category 2"];
}
- if(spec.state === undefined){
- spec.state = "geographic";
+ if(config.state === undefined){
+ config.state = "geographic";
}
- this.state = spec.state;
+ this.state = config.state;
- this.selected = spec.selected;
- //this.values = this.unserialize(this.selected[this.state]);
+ this.selected = config.selected;
+ this.values = this.unserialize(this.selected[this.state]);
this.meta = new Object;
- this.data = new Object;
- this.categories = spec.categories;
- this.cats = new Object;
+ this.categories = config.categories;
this.initRenderComplete = false;
- this.dataSourceUrl = spec.dataSourceUrl;
- this.config = spec.config;
- this.paletteWidget = spec.paletteWidget;
+ this.dataSourceUrl = config.dataSourceUrl;
this.statusStr = "";
+ this.config = config.config;
this.init();
//this.updateComponent(this.id+"=baselayers.MODIS_Terra_CorrectedReflectance_TrueColor-overlays.fires48.AIRS_Dust_Score.OMI_Aerosol_Index")
@@ -94,35 +90,7 @@ SOTE.widget.Selector.prototype.loadData = function(){
SOTE.widget.Selector.handleLoadSuccess = function(data,status,xhr,args){
var self = args.self;
- var dupes = new Object;
- var count = 0;
-
- for(var i in data){
- self.cats[i] = 1;
- if(i != "palettes") {
-
- for(var j=0; j<data[i].length; j++){
- if(!self.data[data[i][j].category]){
- self.data[data[i][j].category] = new Object;
- self.data[data[i][j].category].title = self.categories[count++];
- self.data[data[i][j].category].items = [];
- }
-
- if(! (data[i][j].value in dupes) ){
- var categories = new Object;
- categories[i] = 1;
- self.data[data[i][j].category].items.push({label:data[i][j].label,sublabel:data[i][j].sublabel,value:data[i][j].value,categories:categories});
- dupes[data[i][j].value] = self.data[data[i][j].category].items.length - 1;
- }
- else {
- var tmp = dupes[data[i][j].value];
- var items = self.data[data[i][j].category].items;
- items[tmp].categories[i]=1;
- }
- }
- }
- }
-
+ self.data = data;
self.render();
};
@@ -143,23 +111,19 @@ SOTE.widget.Selector.prototype.render = function(){
$('#'+this.id).height($('#'+this.id).parent().outerHeight() - tabs_height);
- this.list = new SOTE.widget.List(this.id,{
- data: this.data,
- selected: this.selected[this.state],
- hide: false,
- checkbox: true,
- close: false,
- filter: false,
- search: true,
- defaultCategory: "All",
- categories: this.cats,
- onchange: SOTE.widget.Selector.handleFire,
- args: this,
- paletteWidget: this.paletteWidget,
- config: this.config
- });
+ var catList = document.createElement("ul");
+ catList.setAttribute("class","toplevel");
+
+//<div id="selectorbox"><h1>Choose Your Interest Area</h1><ul><li><a>Text 1</a></li></ul><a>Skip this step</a></div>
+ var titleContainer = document.createElement("div");
+ var title = document.createElement("h2");
+ title.innerHTML = "Choose Your Interest Area";
+ titleContainer.appendChild(title);
+ this.container.appendChild(titleContainer);
+ var count = 0;
+
+ SOTE.widget.Selector.loadCategory({ data: {self:this,category:"All"}, back: false });
- //$("#"+this.id).bind("listchange", {self:this}, SOTE.widget.Selector.handleFire);
// Mark the component as ready in the registry if called via init()
if ((this.initRenderComplete === false) && REGISTRY) {
@@ -171,13 +135,376 @@ SOTE.widget.Selector.prototype.render = function(){
};
-SOTE.widget.Selector.handleFire = function(self){
+SOTE.widget.Selector.prototype.resize = function (){
+ var tabs_height = $(".ui-tabs-nav").outerHeight(true);
+ $('#'+this.id).height($('#'+this.id).parent().outerHeight() - tabs_height);
+ setTimeout(SOTE.widget.Selector.adjustCategoryHeights,1,{self:this});
+};
+
+SOTE.widget.Selector.callRender = function (e){
+ e.data.self.openCat = null;
+ e.data.self.render();
+};
+
+SOTE.widget.Selector.prototype.reloadCategory = function(){
+ var e = new Object;
+ e.data = new Object;
+ e.data.self = this;
+ e.data.category = this.openCat;
+ SOTE.widget.Selector.loadCategory(e);
+};
+
+SOTE.widget.Selector.loadCategory = function(e){
+
+ var self = e.data.self;
+ var cat = e.data.category;
+ self.openCat = cat;
+ var back = false;
+
+
+ var categories = new Object;
+ //self.container.innerHTML = "";
+ $("#"+self.id).empty();
+
+ var form = document.createElement("div");
+ form.setAttribute("class","facetedSearch");
+ form.setAttribute("id",self.id+"facetedSearch");
+
+ var select = document.createElement("select");
+ select.setAttribute("id",self.id+"select");
+ select.setAttribute("class","select");
+ for (var c in self.data){
+ if(c != 'palettes'){
+ var opt = document.createElement("option");
+ opt.setAttribute("value",c);
+ opt.text = c;
+ select.add(opt);
+ }
+ }
+
+ form.appendChild(select);
+
+
+ var search = document.createElement("input");
+ search.setAttribute("type","text");
+ search.setAttribute("name","search");
+ search.setAttribute("id",self.id+"search");
+ search.setAttribute("class","search");
+ search.setAttribute("placeholder","ex. modis, terra, fire");
+ search.setAttribute("autocomplete","off");
+
+ form.appendChild(search);
+
+ var content = document.createElement("div");
+ content.setAttribute("id",self.id+"content");
+
+ var categoryTitles = [];
+
+ for(var i=0; i<self.categories.length; i++){
+ var formattedCategoryName = self.categories[i].replace(/\s/g, "");
+
+
+ var categoryTitle = document.createElement("h3");
+ categoryTitle.setAttribute("class","head");
+ categoryTitle.innerHTML = self.categories[i];
+ categoryTitles.push(categoryTitle);
+
+ categories[formattedCategoryName.toLowerCase()] = document.createElement("ul");
+ categories[formattedCategoryName.toLowerCase()].setAttribute("id",self.id + formattedCategoryName.toLowerCase());
+ categories[formattedCategoryName.toLowerCase()].setAttribute("class",self.id + "category category scroll-pane");
+
+ }
+
+
+ for(var i=0; i< self.data[cat].length; i++){
+ var item = self.data[cat][i];
+ var subItem = document.createElement("li");
+ subItem.setAttribute("class","selectorItem item");
+ var itemHead = document.createElement("h4");
+ var formatted = item.value.replace(/:/g,"colon");
+ itemHead.innerHTML = item.label;
+ var itemP = document.createElement("p");
+ itemP.innerHTML = item.sublabel;
+ var itemInput = document.createElement("input");
+ if(item.type === "single"){
+ itemInput.setAttribute("type","checkbox");
+ itemInput.setAttribute("name",cat);
+ }
+ else {
+ itemInput.setAttribute("type","checkbox");
+ }
+ itemInput.setAttribute("id",formatted);
+ itemInput.setAttribute("value",item.value);
+ subItem.appendChild(itemInput);
+ subItem.appendChild(itemHead);
+ subItem.appendChild(itemP);
+
+ categories[item.category].appendChild(subItem);
+ $("#"+self.id).undelegate("#" + formatted,'click');
+ $("#"+self.id).delegate("#" + formatted,'click',{self:self},SOTE.widget.Selector.toggleValue);
+ }
+
+ for(var i=0; i<self.categories.length; i++){
+ var formattedCategoryName = self.categories[i].replace(/\s/g, "");
+ var catContainer = document.createElement("div");
+ catContainer.setAttribute("id",self.id+formattedCategoryName);
+ catContainer.setAttribute("class","categoryContainer");
+ catContainer.appendChild(categoryTitles[i]);
+ catContainer.appendChild(categories[formattedCategoryName.toLowerCase()]);
+ content.appendChild(catContainer);
+ }
+
+ self.container.appendChild(form);
+ self.container.appendChild(content);
+ //self.renderCanvases(cat);
+ if(back){
+ var subBack = document.createElement("a");
+ subBack.setAttribute("id","subback");
+ subBack.setAttribute("class","flowbutton");
+ subBack.setAttribute("href","javascript:void(0);");
+ subBack.innerHTML = "<< <b>go back</b> and reselect my interest area";
+ self.container.appendChild(subBack);
+ $("#"+self.id).undelegate("#" + "subback",'click');
+ $("#"+self.id).delegate("#" + "subback",'click',{self:self},SOTE.widget.Selector.callRender);
+ }
+
+ //$("#"+self.id+"search").undelegate('keypress');
+ $("#"+self.id+"select").on('change',{self:self,select:true},SOTE.widget.Selector.selectCat);
+ $('#'+self.id+"select").val("All");
+
+ $("#"+self.id+"search").on('keyup',{self:self,select:false},SOTE.widget.Selector.search);
+ $("#"+self.id+"search").focus();
+
+ if($(window).width() > 720){
+ if(self.jsp){
+ var api = self.jsp.data('jsp');
+ if(api) {api.destroy()};
+ }
+ self.jsp = $( ".category" ).jScrollPane({autoReinitialise: false, verticalGutter:0});
+ }
+ setTimeout(SOTE.widget.Selector.adjustCategoryHeights,1,{self:self});
+
+ self.adjustSelected();
+
+
+};
+
+SOTE.widget.Selector.reinitializeScrollbars = function(o) {
+ var pane = $(".category").each(function(){
+ var api = $(this).data('jsp');
+ if(api) api.reinitialise();
+ });
+};
+
+SOTE.widget.Selector.selectCat = function(e){
+ e.data.self.openCat = e.target.value;
+ $("#"+e.data.self.id+"search").keyup();
+};
+
+SOTE.widget.Selector.search = function(e){
+ var self = e.data.self;
+ var cat = self.openCat;
+ var val = e.target.value.toUpperCase();
+ val = val.replace(/[\(\)\"\'!\$\%\&\?\+\*\\\@\=]/g,"");
+ var valArr = val.split(/\s/);
+ //var re = new RegExp(val);
+ var content = document.getElementById(self.id+"content");
+ content.innerHTML = "";
+
+ var categories = new Object;
+
+ var categoryTitles = [];
+
+ for(var i=0; i<self.categories.length; i++){
+ var formattedCategoryName = self.categories[i].replace(/\s/g, "");
+
+
+ var categoryTitle = document.createElement("h3");
+ categoryTitle.setAttribute("class","head");
+ categoryTitle.innerHTML = self.categories[i];
+ categoryTitles.push(categoryTitle);
+
+ categories[formattedCategoryName.toLowerCase()] = document.createElement("ul");
+ categories[formattedCategoryName.toLowerCase()].setAttribute("id",self.id + formattedCategoryName.toLowerCase());
+ categories[formattedCategoryName.toLowerCase()].setAttribute("class",self.id + "category category scroll-pane");
+
+ }
+
+
+ for(var i=0; i< self.data[cat].length; i++){
+ var item = self.data[cat][i];
+
+ //var matched = false;
+ var count = 0;
+ for(var j=0; j<valArr.length; ++j){
+ var myVal = new RegExp(valArr[j]);
+ if(item.label.toUpperCase().match(myVal) || item.sublabel.toUpperCase().match(myVal) || item.tags && item.tags.toUpperCase().match(myVal)) {
+ count++;
+ }
+ }
+
+ if(count == valArr.length) { //item.label.toUpperCase().match(val) || item.sublabel.toUpperCase().match(val)){
+
+ var subItem = document.createElement("li");
+ subItem.setAttribute("class","selectorItem item");
+ var itemHead = document.createElement("h4");
+ var formatted = item.value.replace(/:/g,"colon");
+ itemHead.innerHTML = item.label;
+ var itemP = document.createElement("p");
+ itemP.innerHTML = item.sublabel;
+ var itemInput = document.createElement("input");
+ if(item.type === "single"){
+ itemInput.setAttribute("type","checkbox");
+ itemInput.setAttribute("name",cat);
+ }
+ else {
+ itemInput.setAttribute("type","checkbox");
+ }
+ itemInput.setAttribute("class","css-checkbox");
+ itemInput.setAttribute("id",formatted);
+ itemInput.setAttribute("value",item.value);
+ subItem.appendChild(itemInput);
+ subItem.appendChild(itemHead);
+ subItem.appendChild(itemP);
+
+ categories[item.category].appendChild(subItem);
+ //ul.appendChild(subItem);
+ $("#"+self.id).undelegate("#" + formatted,'click');
+ $("#"+self.id).delegate("#" + formatted,'click',{self:self},SOTE.widget.Selector.toggleValue);
+ }
+ }
+
+ for(var i=0; i<self.categories.length; i++){
+ var formattedCategoryName = self.categories[i].replace(/\s/g, "");
+ var catContainer = document.createElement("div");
+ catContainer.setAttribute("id",self.id+formattedCategoryName);
+ catContainer.setAttribute("class","categoryContainer");
+ catContainer.appendChild(categoryTitles[i]);
+ catContainer.appendChild(categories[formattedCategoryName.toLowerCase()]);
+ content.appendChild(catContainer);
+ }
+
+ if($(window).width() > 720){
+ if(self.jsp){
+ var api = self.jsp.data('jsp');
+ if(api) api.destroy();
+ }
+ self.jsp = $( ".category" ).jScrollPane({autoReinitialise: false, verticalGutter:0});
+ }
+ setTimeout(SOTE.widget.Selector.adjustCategoryHeights,1,{self:self});
+
+ self.adjustSelected();
+
+ //content.appendChild(ul);
+
+};
+
+SOTE.widget.Selector.prototype.renderCanvases = function(cat){
+ for(var i=0; i< this.data[cat].length; i++){
+ var item = this.data[cat][i];
+ if(this.data.palettes[item.value]){
+ var p = this.data.palettes[item.value];
+ var width = 100/p.palette.length;
+ var canvas = document.getElementById("canvas"+this.id+item.value);
+ var context = canvas.getContext('2d');
+ for(var k=0; k<p.palette.length; ++k){
+ context.fillStyle = "rgba("+ p.palette[k] +")";
+ context.fillRect (width*k,0,width,14);
+ }
+ }
+ }
+
+};
+
+SOTE.widget.Selector.adjustCategoryHeights = function(args){
+ var self = args.self;
+ var heights = new Array;
+ var facets_height = $("#"+self.id+"facetedSearch").outerHeight(true);
+ var container_height = $("#"+self.id).outerHeight() - facets_height;
+ $('#'+self.id+"content").height(container_height);
+ var labelHeight = 0;
+ $('#'+self.id+'content .head').each(function(){
+ labelHeight += $(this).outerHeight(true);
+ });
+ container_height -= labelHeight;
+ //console.log("This.id: " + container_height);
+ for(var i=0; i<self.categories.length; i++){
+ var formattedCategoryName = self.categories[i].replace(/\s/g, "");
+ var actual_height = 0;
+ var count = 0;
+ $('#' + self.id + formattedCategoryName.toLowerCase() + ' li').each(function(){
+ //console.log(document.getElementById(", " + $(this).outerHeight()));
+ actual_height += $(this).outerHeight();
+ count++;
+ });
+
+ heights.push({name:self.id + formattedCategoryName.toLowerCase(),height:actual_height,count:count});
+ }
+
+ if(heights[0].height + heights[1].height > container_height){
+ if(heights[0].height > container_height/2) {
+ heights[0].height = container_height/2;
+ }
+
+ heights[1].height = container_height - heights[0].height;
+
+ }
+
+ $("#" + heights[0].name).css("height",heights[0].height+"px");
+ $("#" + heights[1].name).css("height",heights[1].height+"px");
+
+ SOTE.widget.Selector.reinitializeScrollbars({self:self});
+
+};
+
+SOTE.widget.Selector.prototype.adjustSelected = function(){
+ var inputs = document.getElementsByTagName("input");
+ for(var i=0; i<inputs.length; i++){
+ inputs[i].checked = "";
+ }
+ for(var j=0; j<this.categories.length; j++){
+ var formatted = this.categories[j].replace(/\s/g, "");
+ formatted = formatted.toLowerCase();
+ if(this.values[formatted]){
+ for(var k=0; k < this.values[formatted].length; k++){
+ var val = this.values[formatted][k].value.replace(/:/g,"colon");
+ var el = document.getElementById(val);
+ if(el)
+ el.checked = "checked";
+ }
+ }
+ }
+};
+
+SOTE.widget.Selector.toggleValue = function(e){
+ var self = e.data.self;
+ var targetEl = e.target;
+ var category = $("#"+targetEl.id).parents('.category').attr("id");
+ category = category.replace(self.id,"");
+ var value = $("#"+targetEl.id).attr("value");
+ value = value.replace(/colon/,":");
+ var checked = $("#"+targetEl.id).attr("checked");
+
+ if(!self.values[category]){
+ self.values[category] = new Array();
+ }
+ if(checked !== undefined && checked == "checked"){
+ self.removeItem(category,value);
+ self.values[category].unshift({"value":value});
+ }
+ else{
+ self.removeItem(category,value);
+ }
+
self.fire();
};
-SOTE.widget.Selector.prototype.resize = function (){
- var tabs_height = $(".ui-tabs-nav").outerHeight(true);
- $('#'+this.id).height($('#'+this.id).parent().outerHeight() - tabs_height);
+SOTE.widget.Selector.prototype.removeItem = function(cat,val){
+ for(var i=0; i<this.values[cat].length; i++){
+ if(this.values[cat][i].value == val){
+ this.values[cat].splice(i,1);
+ }
+ }
};
/**
@@ -207,7 +534,10 @@ SOTE.widget.Selector.prototype.fire = function(){
*
*/
SOTE.widget.Selector.prototype.setValue = function(valString){
- this.list.setValue(valString);
+
+ this.values = this.unserialize(valString);
+ return this.validate();
+
};
/**
@@ -218,10 +548,48 @@ SOTE.widget.Selector.prototype.setValue = function(valString){
* representing the key(s) of the currently selected option(s)
*
*/
-SOTE.widget.Selector.prototype.getValue = function(){
- return this.id + "=" + this.list.getValue();
+SOTE.widget.Selector.prototype.getValue = function(){
+
+ var value = this.serialize(this.values);
+ return this.id + "=" + value;
};
+SOTE.widget.Selector.prototype.serialize = function(values){
+ var serialized = "";
+ for(var i=0; i<this.categories.length; i++){
+ if(i > 0){
+ serialized += "~";
+ }
+ var formatted = this.categories[i].replace(/\s/g, "");
+ formatted = formatted.toLowerCase();
+
+ serialized += formatted;
+ if(values[formatted]){
+ for(var j=0; j<values[formatted].length; j++){
+ serialized += "," + values[formatted][j].value;
+ }
+ }
+ }
+ return serialized;
+};
+
+SOTE.widget.Selector.prototype.unserialize = function(string){
+ var unserialized = new Object;
+ var hideIndicator = /^!/;
+ var categories = string.split("~");
+ for(var i=0; i<categories.length; i++){
+ var items = categories[i].split(/[\.,]/);
+ unserialized[items[0]] = new Array;
+ for(var j=1; j<items.length; j++){
+ if(hideIndicator.test(items[j])){
+ items[j] = items[j].replace(/!/g,"");
+ }
+ unserialized[items[0]].push({"value":items[j]});
+ }
+
+ }
+ return unserialized;
+};
/**
* Change the component based on dependencies (i.e. Available Options, Selected)
@@ -255,7 +623,10 @@ SOTE.widget.Selector.handleUpdateSuccess = function(self,qs){
data.selected = (data.selected === undefined || data.selected === "")? SOTE.util.extractFromQuery(args.self.id,args.self.getValue()):data.selected;*/
if(SOTE.util.extractFromQuery("switch",qs) == self.state){
var vals = SOTE.util.extractFromQuery("products",qs);
- self.values = self.setValue(vals);
+ self.values = self.unserialize(vals);
+ if(self.openCat !== undefined && self.openCat !== null){
+ self.adjustSelected();
+ }
}
else {
self.state = SOTE.util.extractFromQuery("switch",qs);