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);
}
this.div = opt.jQueryDiv[0];
opt.map.controls[opt.controlPositions].push(this.div);
},
getDiv: function() {
/* Allow to edit everything start from div level by returning div jquery object */
@ -38,6 +37,14 @@ var ControlPanel = Class.extend({
if (div) {
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) {
this._super(options);
this.initCopyRight();
this.addToMap();
},
initCopyRight: function() {
var me = this;

View file

@ -75,7 +75,7 @@ var ErrorDisplayWidget = Class.extend({
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>"
}

View file

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

View file

@ -1,13 +1,41 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
var ScimapWidget = Class.extend({
init: function(map, sliderControl) {
init: function(map) {
var me = this;
me.activeManager = null;
me.isUnloaded = true;
me.map = map;
me.sliderControl = sliderControl;
me.initView();
},
initView: function(){
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,
@ -21,19 +49,13 @@ var ScimapWidget = Class.extend({
}
}
});
me.initView();
},
initView: function(){
var me = this;
}
/* Display labels if checked */
me.disciplineLabelsControl.addToMap();
if (me.disciplineLabelsControl.isChecked()) {
me.labelsMarkerManager.showMarkers();
}
me.initMarkerManagers();
me.sliderControl.setChangeEventHandler(function(event, ui) {
me.updateDisplayedMarkers(ui.value);
});
me.show(SCIMAP_TYPE.SUBDISCIPLINE);
},
initMarkerManagers: function() {
if (this.keyToMarkerManagers == null) {
@ -146,23 +168,29 @@ var ScimapWidget = Class.extend({
hide: function(key) {
var manager = this.getMarkerManager(key);
if (this.activeManager == manager) {
this.cleanup();
this._cleanupMarkers();
}
},
_switchActiveManager: function(manager) {
if (this.activeManager != manager) {
this.cleanUp();
this._cleanUpMarkers();
manager.addMarkersToMap();
this.activeManager = manager;
this.updateMap();
}
},
cleanUp: function() {
_cleanUpMarkers: function() {
if (this.activeManager) {
this.activeManager.removeMarkersFromMap();
INFO_WINDOW.close();
}
},
cleanup: function() {
var me = this;
me._cleanUpMarkers();
me.sliderControl.RemoveFromMap();
me.disciplineLabelsControl.RemoveFromMap();
},
updateDisplayedMarkers: function(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$ */
var ENTITY_VIS_MODE = "ENTITY";
var COMPARISON_VIS_MODE = "COMPARISON";
var EntityVisModeController = Class.extend({
init: function(map, sliderControl) {
var VisModeController = Class.extend({
init: function(map) {
this.visMode = ENTITY_VIS_MODE;
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();
},
initFilter: function() {
@ -39,21 +74,13 @@ var EntityVisModeController = Class.extend({
/* Init default filter */
$("#" + dom.subdisciplinesFilterID).trigger('click');
},
initWidgets: function(map, sliderControl) {
initWidgets: function(map) {
var widgets = {};
widgets['scimap'] = new ScimapWidget(map, sliderControl);
widgets['scimap'] = new ScimapWidget(map);
widgets['sci_area_table'] = new DataTableWidget(widgets['scimap']);
this.widgets = widgets;
},
needLoaded: function() {
return this.isUnloaded;
},
initView: function() {
$.each(this.widgets, function(i, widget) {
widget.initView();
});
},
loadData: function(url, sync) {
// 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
show: function(key) {
$.each(this.widgets, function(i, widget) {
widget.show(key);
initFilter: function() {
var widgets = this.widgets;
var dom = {
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);
});
},
hide: function(key) {
$.each(this.widgets, function(i, widget) {
widget.hide(key);
} 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');
},
cleanUp: function() {
$.each(this.widgets, function(i, widget) {
widget.cleanUp(key);
initWidgets: function(map) {
var widgets = {};
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();
},
initToolTipInfo: function() {
$('.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'
}
});
});
}
});