Refactor before integrate with new comparison code

This commit is contained in:
kongchinhua 2011-11-02 01:04:53 +00:00
parent 5158aaa913
commit b4263c3176
5 changed files with 228 additions and 55 deletions

View file

@ -21,7 +21,6 @@ var ControlPanel = Class.extend({
opt.jQueryDiv.addClass(opt.divClass); opt.jQueryDiv.addClass(opt.divClass);
} }
this.div = opt.jQueryDiv[0]; this.div = opt.jQueryDiv[0];
opt.map.controls[opt.controlPositions].push(this.div);
}, },
getDiv: function() { getDiv: function() {
/* Allow to edit everything start from div level by returning div jquery object */ /* Allow to edit everything start from div level by returning div jquery object */
@ -38,6 +37,14 @@ var ControlPanel = Class.extend({
if (div) { if (div) {
div.style.display = "block"; div.style.display = "block";
} }
},
addToMap: function() {
var opt = this.options;
opt.map.controls[opt.controlPositions].push(this.div);
},
removeFromMap: function() {
var opt = this.options;
opt.map.controls[opt.controlPositions].pop();
} }
}); });
@ -141,6 +148,7 @@ var CopyrightPanel = ControlPanel.extend({
init: function(options) { init: function(options) {
this._super(options); this._super(options);
this.initCopyRight(); this.initCopyRight();
this.addToMap();
}, },
initCopyRight: function() { initCopyRight: function() {
var me = this; var me = this;

View file

@ -75,7 +75,7 @@ var ErrorDisplayWidget = Class.extend({
var publicationsText = (responseData.pubsWithNoJournals > 1) ? "publications" : "publication"; var publicationsText = (responseData.pubsWithNoJournals > 1) ? "publications" : "publication";
newErrorMessage += "<li>" + responseData.pubsWithNoJournals + " " + publicationsText + " with no journal" newErrorMessage += "<li>" + responseData.pubsWithNoJournals + " " + publicationsText + " have no journal"
+ " information.</li>" + " information.</li>"
} }

View file

@ -1,7 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
var map; var map;
var downloader; var downloader;
var sliderControl;
var currentVisMode; var currentVisMode;
var currentController; var currentController;
var visModeControllers = {}; var visModeControllers = {};
@ -64,17 +63,12 @@ function initMap() {
createScimapType(map, mapName); createScimapType(map, mapName);
map.setMapTypeId(mapName); map.setMapTypeId(mapName);
sliderControl = new SliderControlPanel({
map:map,
controlPositions: google.maps.ControlPosition.RIGHT_BOTTOM
});
downloader = new DownloadManager(); downloader = new DownloadManager();
} }
function initVisModeController() { function initVisModeController() {
var controller = new EntityVisModeController(map, sliderControl); var controller = new EntityVisModeController(map);
visModeControllers[controller.visMode] = controller; visModeControllers[controller.visMode] = controller;
switchVisMode(controller.visMode); switchVisMode(controller.visMode);
currentController.loadData(scienceMapDataURL, false); currentController.loadData(scienceMapDataURL, false);

View file

@ -1,39 +1,61 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
var ScimapWidget = Class.extend({ var ScimapWidget = Class.extend({
init: function(map, sliderControl) { init: function(map) {
var me = this; var me = this;
me.activeManager = null; me.activeManager = null;
me.isUnloaded = true; me.isUnloaded = true;
me.map = map; me.map = map;
me.sliderControl = sliderControl;
me.labelsMarkerManager = new DisciplineLabelsMarkerManager(map);
me.disciplineLabelsControl = new CheckBoxPanel({
map: map,
checked: true,
text: "Show discipline labels",
click: function() {
if($(this).attr('checked')) {
me.labelsMarkerManager.showMarkers();
} else {
me.labelsMarkerManager.hideMarkers();
}
}
});
me.initView(); me.initView();
}, },
initView: function(){ initView: function(){
var me = this; var me = this;
me.initControlPanels();
me.initMarkerManagers();
me.show(SCIMAP_TYPE.SUBDISCIPLINE);
},
initControlPanels: function() {
var me = this;
/* Create slider control panel */
if (me.sliderControl == null) {
me.sliderControl = new SliderControlPanel({
map:me.map,
controlPositions: google.maps.ControlPosition.RIGHT_BOTTOM
});
}
/* Register event */
me.sliderControl.addToMap();
me.sliderControl.setChangeEventHandler(function(event, ui) {
if (me.keyToMarkerManagers) {
me.updateDisplayedMarkers(ui.value);
}
});
/* create */
if (me.disciplineLabelsControl == null) {
me.labelsMarkerManager = new DisciplineLabelsMarkerManager(map);
me.disciplineLabelsControl = new CheckBoxPanel({
map: map,
checked: true,
text: "Show discipline labels",
click: function() {
if($(this).attr('checked')) {
me.labelsMarkerManager.showMarkers();
} else {
me.labelsMarkerManager.hideMarkers();
}
}
});
}
/* Display labels if checked */ /* Display labels if checked */
me.disciplineLabelsControl.addToMap();
if (me.disciplineLabelsControl.isChecked()) { if (me.disciplineLabelsControl.isChecked()) {
me.labelsMarkerManager.showMarkers(); me.labelsMarkerManager.showMarkers();
} }
me.initMarkerManagers();
me.sliderControl.setChangeEventHandler(function(event, ui) {
me.updateDisplayedMarkers(ui.value);
});
me.show(SCIMAP_TYPE.SUBDISCIPLINE);
}, },
initMarkerManagers: function() { initMarkerManagers: function() {
if (this.keyToMarkerManagers == null) { if (this.keyToMarkerManagers == null) {
@ -146,23 +168,29 @@ var ScimapWidget = Class.extend({
hide: function(key) { hide: function(key) {
var manager = this.getMarkerManager(key); var manager = this.getMarkerManager(key);
if (this.activeManager == manager) { if (this.activeManager == manager) {
this.cleanup(); this._cleanupMarkers();
} }
}, },
_switchActiveManager: function(manager) { _switchActiveManager: function(manager) {
if (this.activeManager != manager) { if (this.activeManager != manager) {
this.cleanUp(); this._cleanUpMarkers();
manager.addMarkersToMap(); manager.addMarkersToMap();
this.activeManager = manager; this.activeManager = manager;
this.updateMap(); this.updateMap();
} }
}, },
cleanUp: function() { _cleanUpMarkers: function() {
if (this.activeManager) { if (this.activeManager) {
this.activeManager.removeMarkersFromMap(); this.activeManager.removeMarkersFromMap();
INFO_WINDOW.close(); INFO_WINDOW.close();
} }
}, },
cleanup: function() {
var me = this;
me._cleanUpMarkers();
me.sliderControl.RemoveFromMap();
me.disciplineLabelsControl.RemoveFromMap();
},
updateDisplayedMarkers: function(numberOfMarkers) { updateDisplayedMarkers: function(numberOfMarkers) {
this.activeManager.display(numberOfMarkers); this.activeManager.display(numberOfMarkers);
}, },

View file

@ -1,11 +1,46 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
var ENTITY_VIS_MODE = "ENTITY"; var ENTITY_VIS_MODE = "ENTITY";
var COMPARISON_VIS_MODE = "COMPARISON";
var EntityVisModeController = Class.extend({ var VisModeController = Class.extend({
init: function(map, sliderControl) { init: function(map) {
this.visMode = ENTITY_VIS_MODE; this.visMode = ENTITY_VIS_MODE;
this.isUnloaded = true; this.isUnloaded = true;
this.initWidgets(map, sliderControl); this.initWidgets(map);
},
initWidgets: function(map) {
this.widgets = {};
},
needLoaded: function() {
return this.isUnloaded;
},
initView: function() {
$.each(this.widgets, function(i, widget) {
widget.initView();
});
},
// key can be discippline or subdiscipline
show: function(key) {
$.each(this.widgets, function(i, widget) {
widget.show(key);
});
},
hide: function(key) {
$.each(this.widgets, function(i, widget) {
widget.hide(key);
});
},
cleanUp: function() {
$.each(this.widgets, function(i, widget) {
widget.cleanUp(key);
});
}
});
var EntityVisModeController = VisModeController.extend({
init: function(map) {
this._super(map);
this.visMode = ENTITY_VIS_MODE;
this.initFilter(); this.initFilter();
}, },
initFilter: function() { initFilter: function() {
@ -39,21 +74,13 @@ var EntityVisModeController = Class.extend({
/* Init default filter */ /* Init default filter */
$("#" + dom.subdisciplinesFilterID).trigger('click'); $("#" + dom.subdisciplinesFilterID).trigger('click');
}, },
initWidgets: function(map, sliderControl) { initWidgets: function(map) {
var widgets = {}; var widgets = {};
widgets['scimap'] = new ScimapWidget(map, sliderControl); widgets['scimap'] = new ScimapWidget(map);
widgets['sci_area_table'] = new DataTableWidget(widgets['scimap']); widgets['sci_area_table'] = new DataTableWidget(widgets['scimap']);
this.widgets = widgets; this.widgets = widgets;
}, },
needLoaded: function() {
return this.isUnloaded;
},
initView: function() {
$.each(this.widgets, function(i, widget) {
widget.initView();
});
},
loadData: function(url, sync) { loadData: function(url, sync) {
// Download data from server and add to markerManager if not gotten already // Download data from server and add to markerManager if not gotten already
@ -139,21 +166,137 @@ var EntityVisModeController = Class.extend({
} }
}); });
}); });
}
});
var ComparisonVisModeController = Class.extend({
init: function(map) {
this._super(map);
this.visMode = COMPARISON_VIS_MODE;
this.initFilter();
}, },
// key can be discippline or subdiscipline initFilter: function() {
show: function(key) { var widgets = this.widgets;
$.each(this.widgets, function(i, widget) { var dom = {
widget.show(key); disciplineFilterID: "discipline-filter",
subdisciplinesFilterID: "subdisciplines-filter",
filterOptionClass: "filter-option",
activeFilterClass: "active-filter"
};
$("." + dom.filterOptionClass).live('click', function() {
if (!$(this).hasClass(dom.activeFilterClass)) {
if ($(this).attr('id') === dom.subdisciplinesFilterID) {
$("#" + dom.disciplineFilterID).removeClass(dom.activeFilterClass);
$.each(widgets, function(i, widget) {
widget.changeFilter(SCIMAP_TYPE.SUBDISCIPLINE);
});
} else if ($(this).attr('id') === dom.disciplineFilterID) {
$("#" + dom.subdisciplinesFilterID).removeClass(dom.activeFilterClass);
$.each(widgets, function(i, widget) {
widget.changeFilter(SCIMAP_TYPE.DISCIPLINE);
});
}
$(this).addClass('active-filter');
}
}); });
/* Init default filter */
$("#" + dom.subdisciplinesFilterID).trigger('click');
}, },
hide: function(key) { initWidgets: function(map) {
$.each(this.widgets, function(i, widget) { var widgets = {};
widget.hide(key); widgets['scimap'] = new ScimapWidget(map);
widgets['sci_area_table'] = new DataTableWidget(widgets['scimap']);
this.widgets = widgets;
},
loadData: function(url, sync) {
// Download data from server and add to markerManager if not gotten already
var me = this;
if (me.isUnloaded) {
if (sync) {
downloader.downloadAndWait(url, function(data) {
me.loadJsonData(me, data);
});
} else {
downloader.download(url, function(data) {
me.loadJsonData(me, data);
});
}
} // end if
},
loadJsonData: function(me, data) {
$("#" + responseContainerID).unblock();
if (ERROR_DISPLAY_WIDGET.isErrorConditionTriggered(data)) {
$("#map-of-science-response").hide();
ERROR_DISPLAY_WIDGET.show(ENTITY_TYPE, data);
return;
}
data = data[0];
$.each(me.widgets, function(i, widget) {
widget.loadJsonData(data);
}); });
me.isUnloaded = false;
me.initToolTipInfo();
}, },
cleanUp: function() { initToolTipInfo: function() {
$.each(this.widgets, function(i, widget) {
widget.cleanUp(key); $('.filterInfoIcon').each(function () {
var me = $(this);
var tipText;
var tipLocation = "topLeft";
if (me.attr('id') == 'imageIconOne') {
tipText = $('#toolTipOne').html();
} else if (me.attr('id') == 'imageIconTwo') {
tipText = $('#toolTipTwo').html();
} else if (me.attr('id') == 'searchInfoIcon') {
tipText = $('#searchInfoTooltipText').html();
} else {
tipText = $('#toolTipThree').html();
tipLocation = "topRight";
}
me.qtip({
content: {
text: tipText
},
position: {
corner: {
target: 'center',
tooltip: tipLocation
}
},
show: {
when: {
event: 'mouseover'
}
},
hide: {
fixed: true // Make it fixed so it can be hovered over
},
style: {
padding: '6px 6px',
// Give it some extra padding
width: 500,
textAlign: 'left',
backgroundColor: '#ffffc0',
fontSize: '.7em',
padding: '6px 10px 6px 10px',
lineHeight: '14px'
}
});
}); });
} }
}); });