Merge from 1.5 branch: NIHVIVO-3977 Incorporate improvements in OpenSocial for 1.5.1. Also, make shinding_orng_tables.sql re-runnable.

This commit is contained in:
j2blake 2012-10-01 16:53:43 +00:00
parent b9cd04f0fa
commit e0a255c8b2
9 changed files with 443 additions and 351 deletions

View file

@ -118,6 +118,9 @@ gadgets.pubsubrouter.init(function(id) {
_gaq.push(['_trackEvent', my.gadgets[moduleId].name, 'go_to_profile', message]);
document.location.href = '/' + location.pathname.split('/')[1] + '/display/n' + message;
}
else if (channel == 'hide') {
document.getElementById(sender).parentNode.parentNode.style.display = 'none';
}
else if (channel == 'JSONPersonIds' || channel == 'JSONPubMedIds') {
// do nothing, no need to alert
}
@ -222,23 +225,31 @@ my.requestGadgetMetaData = function(view, opt_callback) {
my.renderableGadgets = [];
my.generateGadgets = function(metadata) {
my.generateGadgets = function (metadata) {
// put them in moduleId order
for (var i = 0; i < metadata.gadgets.length; i++) {
var moduleId = metadata.gadgets[i].moduleId;
// Notes by Eric. Not sure if I should have to calculate this myself, but I will.
var height = metadata.gadgets[i].height;
var width = metadata.gadgets[i].width;
var viewPrefs = metadata.gadgets[i].views[my.gadgets[moduleId].view];
if (viewPrefs) {
height = viewPrefs.preferredHeight || height;
width = viewPrefs.preferredWidth || width;
}
my.renderableGadgets[moduleId] = shindig.container.createGadget({'specUrl': metadata.gadgets[i].url, 'secureToken': my.gadgets[moduleId].secureToken,
'title': metadata.gadgets[i].title, 'userPrefs': metadata.gadgets[i].userPrefs,
'height': height, 'width': width, 'debug': my.debug});
// set the metadata for easy access
my.renderableGadgets[moduleId].setMetadata(metadata.gadgets[i]);
var moduleId = metadata.gadgets[i].moduleId;
// Notes by Eric. Not sure if I should have to calculate this myself, but I will.
var height = metadata.gadgets[i].height;
var width = metadata.gadgets[i].width;
var viewPrefs = metadata.gadgets[i].views[my.gadgets[moduleId].view];
if (viewPrefs) {
height = viewPrefs.preferredHeight || height;
width = viewPrefs.preferredWidth || width;
}
var opt_params = { 'specUrl': metadata.gadgets[i].url, 'secureToken': my.gadgets[moduleId].secureToken,
'title': metadata.gadgets[i].title, 'userPrefs': metadata.gadgets[i].userPrefs,
'height': height, 'width': width, 'debug': my.debug};
// do a shallow merge of the opt_params from the database. This will overwrite anything with the same name, and we like that
for (var attrname in my.gadgets[moduleId].opt_params) {
opt_params[attrname] = my.gadgets[moduleId].opt_params[attrname];
}
my.renderableGadgets[moduleId] = shindig.container.createGadget(opt_params);
// set the metadata for easy access
my.renderableGadgets[moduleId].setMetadata(metadata.gadgets[i]);
}
// this will be called multiple times, only render when all gadgets have been processed
var ready = my.renderableGadgets.length == my.gadgets.length;
@ -247,23 +258,27 @@ my.generateGadgets = function(metadata) {
ready = false;
}
}
if (ready) {
shindig.container.addGadgets(my.renderableGadgets );
shindig.container.addGadgets(my.renderableGadgets);
shindig.container.renderGadgets();
}
};
my.init = function() {
shindig.container.gadgetClass = OrngGadget;
shindig.container.layoutManager = new OrngLayoutManager();
shindig.container.setNoCache(my.noCache);
shindig.container.gadgetService = new OrngGadgetService();
// overwrite this RPC function. Do it at this level so that rpc.f (this.f) is accessible for getting module ID
// gadgets.rpc.register('requestNavigateTo', doProfilesNavigation);
shindig.container = new ORNGContainer();
// since we render multiple views, we need to do somethign fancy by swapping out this value in getIframeUrl
shindig.container.setView('REPLACE_THIS_VIEW');
// do multiple times as needed if we have multiple views
shindig.container.gadgetService = new ORNGGadgetService();
shindig.container.layoutManager = new ORNGLayoutManager();
shindig.container.setNoCache(my.noCache);
// since we render multiple views, we need to do somethign fancy by swapping out this value in getIframeUrl
shindig.container.setView('REPLACE_THIS_VIEW');
// do multiple times as needed if we have multiple views
// find out what views are being used and call requestGadgetMetaData for each one
var views = {};
for (var moduleId = 0; moduleId < my.gadgets.length; moduleId++) {
@ -275,34 +290,83 @@ my.init = function() {
}
};
// OrngGadgetService
//ORNGContainer
ORNGContainer = function() {
shindig.IfrContainer.call(this);
};
OrngGadgetService = function() {
ORNGContainer.inherits(shindig.IfrContainer);
ORNGContainer.prototype.createGadget = function (opt_params) {
if (opt_params.gadget_class) {
return new window[opt_params.gadget_class](opt_params);
}
else {
return new ORNGGadget(opt_params);
}
}
//ORNGLayoutManager.
ORNGLayoutManager = function() {
shindig.LayoutManager.call(this);
};
ORNGLayoutManager.inherits(shindig.LayoutManager);
ORNGLayoutManager.prototype.getGadgetChrome = function(gadget) {
var layoutRoot = document.getElementById(my.gadgets[gadget.id].chrome_id);
if (layoutRoot) {
var chrome = document.createElement('div');
chrome.className = 'gadgets-gadget-chrome';
layoutRoot.appendChild(chrome);
return chrome;
} else {
return null;
}
};
//ORNGGadgetService
ORNGGadgetService = function() {
shindig.IfrGadgetService.call(this);
};
OrngGadgetService.inherits(shindig.IfrGadgetService);
ORNGGadgetService.inherits(shindig.IfrGadgetService);
OrngGadgetService.prototype.requestNavigateTo = function(view, opt_params) {
var viewConfig = gadgets.config.get('views')[view];
var url = '/' + location.pathname.split('/')[1] + '/' + viewConfig.urlTemplate;
ORNGGadgetService.prototype.setTitle = function (title) {
var moduleId = shindig.container.gadgetService.getGadgetIdFromModuleId(this.f);
if (my.gadgets[moduleId].view == 'canvas') {
ORNGGadgetService.setCanvasTitle(title);
}
else {
var element = document.getElementById(this.f + '_title');
element.innerHTML = my.renderableGadgets[moduleId].getTitleHtml(title);
}
};
ORNGGadgetService.setCanvasTitle = function (title) {
document.getElementById("gadgets-title").innerHTML = title.replace(/&/g, '&amp;').replace(/</g, '&lt;');
}
ORNGGadgetService.prototype.requestNavigateTo = function(view, opt_params) {
var urlTemplate = gadgets.config.get('views')[view].urlTemplate;
var url = urlTemplate || 'OpenSocial.aspx?';
url += window.location.search.substring(1);
// remove appId if present
url = my.removeParameterFromURL(url, 'appId');
// Add appId if isOnlyVisible is TRUE for this view
if (viewConfig.isOnlyVisible) {
// Add appId if the URL Template begins with the word 'Gadget'
if (urlTemplate.indexOf('Gadget') == 0) {
var moduleId = shindig.container.gadgetService.getGadgetIdFromModuleId(this.f);
var appId = my.gadgets[moduleId].appId;
url += (url.indexOf('?') != url.length - 1 ? '&' : '') + 'appId=' + appId;
url += '&appId=' + appId;
}
if (opt_params) {
var paramStr = gadgets.json.stringify(opt_params);
if (paramStr.length > 0) {
url += (url.indexOf('?') != url.length - 1 ? '&' : '') + 'appParams=' + encodeURIComponent(paramStr);
url += '&appParams=' + encodeURIComponent(paramStr);
}
}
if (url && document.location.href.indexOf(url) == -1) {
@ -310,10 +374,9 @@ OrngGadgetService.prototype.requestNavigateTo = function(view, opt_params) {
}
};
// OrngGadget
OrngGadget = function(opt_params) {
shindig.Gadget.call(this, opt_params);
//ORNGGadget
ORNGGadget = function(opt_params) {
shindig.BaseIfrGadget.call(this, opt_params);
this.debug = my.debug;
this.serverBase_ = my.openSocialURL + "/gadgets/";
var gadget = this;
@ -330,13 +393,13 @@ OrngGadget = function(opt_params) {
}
};
OrngGadget.inherits(shindig.BaseIfrGadget);
ORNGGadget.inherits(shindig.BaseIfrGadget);
OrngGadget.prototype.setMetadata = function(metadata) {
ORNGGadget.prototype.setMetadata = function(metadata) {
this.metadata = metadata;
};
OrngGadget.prototype.hasFeature = function(feature) {
ORNGGadget.prototype.hasFeature = function(feature) {
for (var i = 0; i < this.metadata.features.length; i++) {
if (this.metadata.features[i] == feature) {
return true;
@ -345,7 +408,7 @@ OrngGadget.prototype.hasFeature = function(feature) {
return false;
};
OrngGadget.prototype.getAdditionalParams = function() {
ORNGGadget.prototype.getAdditionalParams = function() {
var params = '';
for (var key in my.gadgets[this.id].additionalParams) {
params += '&' + key + '=' + my.gadgets[this.id].additionalParams[key];
@ -353,107 +416,162 @@ OrngGadget.prototype.getAdditionalParams = function() {
return params;
};
OrngGadget.prototype.finishRender = function(chrome) {
window.frames[this.getIframeId()].location = this.getIframeUrl();
if (my.gadgets[this.id].start_closed) {
this.handleToggle();
}
else if (chrome) {
// set the gadget box width, and remember that we always render as open
chrome.style.width = (my.gadgets[this.id].open_width || 600) + 'px';
}
};
OrngGadget.prototype.getIframeUrl = function() {
ORNGGadget.prototype.getIframeUrl = function() {
var url = this.originalGetIframeUrl();
return url.replace('REPLACE_THIS_VIEW', my.gadgets[this.id].view);
};
OrngGadget.prototype.handleToggle = function() {
var gadgetIframe = document.getElementById(this.getIframeId());
if (gadgetIframe) {
var gadgetContent = gadgetIframe.parentNode;
var gadgetImg = document.getElementById('gadgets-gadget-title-image-' + this.id);
if (gadgetContent.style.display) {
//OPEN
gadgetContent.parentNode.style.width = (my.gadgets[this.id].open_width || 600) + 'px';
gadgetContent.style.display = '';
gadgetImg.src = '/' + location.pathname.split('/')[1] + '/themes/wilma/images/green_minus_sign.gif';
// refresh if certain features require so
//if (this.hasFeature('dynamic-height')) {
if (my.gadgets[this.id].chrome_id == 'gadgets-search') {
this.refresh();
document.getElementById(this.getIframeId()).contentWindow.location.reload(true);
}
if (my.gadgets[this.id].view == 'home') {
// record in google analytics
_gaq.push(['_trackEvent', my.gadgets[this.id].name, 'OPEN_IN_EDIT', 'profile_edit_view']);
}
else {
// find out whose page we are on, if any
var userId = gadgets.util.getUrlParameters()['uri'] || document.URL.replace('/display/', '/individual/');
osapi.activities.create(
{ 'userId': userId,
'appId': my.gadgets[this.id].appId,
'activity': {'postedTime': new Date().getTime(), 'title': 'gadget viewed', 'body': my.gadgets[this.id].name + ' gadget was viewed' }
}).execute(function(response){});
// record in google analytics
_gaq.push(['_trackEvent', my.gadgets[this.id].name, 'OPEN']);
ORNGGadget.prototype.getTitleHtml = function(title) {
return title ? title.replace(/&/g, '&amp;').replace(/</g, '&lt;') : 'Gagdget';
};
ORNGGadget.prototype.getTitleBarContent = function(continuation) {
if (my.gadgets[this.id].view == 'canvas') {
ORNGGadgetService.setCanvasTitle(this.title);
continuation('<span class="gadgets-gadget-canvas-title"></span>');
}
else {
continuation(
'<div id="' + this.cssClassTitleBar + '-' + this.id +
'" class="' + this.cssClassTitleBar + '"><span class="' +
this.cssClassTitleButtonBar + '">' +
'</span> <span id="' +
this.getIframeId() + '_title" class="' + this.cssClassTitle + '">' +
this.getTitleHtml(this.title) + '</span><span id="' +
this.getIframeId() + '_status" class="gadgets-gadget-status"></span></div>');
}
}
else {
//CLOSE
gadgetContent.parentNode.style.width = (my.gadgets[this.id].closed_width || 600) + 'px';
gadgetContent.style.display = 'none';
gadgetImg.src = '/' + location.pathname.split('/')[1] + '/themes/wilma/images/green_plus_sign.gif';
if (my.gadgets[this.id].view == 'home') {
// record in google analytics
_gaq.push(['_trackEvent', my.gadgets[this.id].name, 'CLOSE_IN_EDIT', 'profile_edit_view']);
}
else {
// record in google analytics
_gaq.push(['_trackEvent', my.gadgets[this.id].name, 'CLOSE']);
}
}
}
};
OrngGadget.prototype.getTitleBarContent = function(continuation) {
if (my.gadgets[this.id].view == 'canvas') {
document.getElementById("gadgets-title").innerHTML = (this.title ? this.title : 'Gadget');
continuation('<span class="gadgets-gadget-canvas-title"></span>');
}
else {
continuation(
'<div id="' + this.cssClassTitleBar + '-' + this.id +
'" class="' + this.cssClassTitleBar + '"><span class="' +
this.cssClassTitleButtonBar + '">' +
'<a href="#" onclick="shindig.container.getGadget(' + this.id +
').handleToggle();return false;" class="' + this.cssClassTitleButton +
'"><img id="gadgets-gadget-title-image-' + this.id + '" src="/' + location.pathname.split('/')[1] + '/themes/wilma/images/green_minus_sign.gif"/></a></span> <span id="' +
this.getIframeId() + '_title" class="' + this.cssClassTitle + '">' +
'<a href="#" onclick="shindig.container.getGadget(' + this.id + ').handleToggle();return false;">' +
(this.title ? this.title : 'Gadget') + '</a>' + '</span><span id="' +
this.getIframeId() + '_status" class="gadgets-gadget-status"></span></div>');
}
ORNGGadget.prototype.finishRender = function(chrome) {
window.frames[this.getIframeId()].location = this.getIframeUrl();
if (chrome && this.width) {
// set the gadget box width, and remember that we always render as open
chrome.style.width = this.width + 'px';
}
};
// OrngLayoutManager. Creates a FloatLeftLayoutManager for every chromeId in our gadgets
OrngLayoutManager = function() {
shindig.LayoutManager.call(this);
// find out what chromeId's are being used, create a FloatLeftLayoutManager for each
this.layoutManagers = {};
for (var moduleId = 0; moduleId < my.gadgets.length; moduleId++) {
var chromeId = my.gadgets[moduleId].chrome_id;
if (!this.layoutManagers[chromeId]) {
this.layoutManagers[chromeId] = new shindig.FloatLeftLayoutManager(chromeId);
// ORNGToggleGadget
ORNGToggleGadget = function(opt_params) {
ORNGGadget.call(this, opt_params);
};
ORNGToggleGadget.inherits(ORNGGadget);
ORNGToggleGadget.prototype.handleToggle = function (track) {
var gadgetIframe = document.getElementById(this.getIframeId());
if (gadgetIframe) {
var gadgetContent = gadgetIframe.parentNode;
var gadgetImg = document.getElementById('gadgets-gadget-title-image-'
+ this.id);
if (gadgetContent.style.display) {
//OPEN
if (this.width) {
gadgetContent.parentNode.style.width = this.width + 'px';
}
gadgetContent.style.display = '';
gadgetImg.src = '/' + location.pathname.split('/')[1] + '/themes/wilma/images/green_minus_sign.gif'
// refresh if certain features require so
//if (this.hasFeature('dynamic-height')) {
if (my.gadgets[this.id].chrome_id == 'gadgets-search') {
this.refresh();
document.getElementById(this.getIframeId()).contentWindow.location
.reload(true);
}
if (my.gadgets[this.id].view == 'home') {
if (track) {
// record in google analytics
_gaq.push(['_trackEvent', my.gadgets[this.id].name,
'OPEN_IN_EDIT', 'profile_edit_view']);
}
} else {
// only do this for user centric activities
if (gadgets.util.getUrlParameters()['Person'] != undefined) {
osapi.activities
.create(
{
'userId': gadgets.util
.getUrlParameters()['Person'],
'appId': my.gadgets[this.id].appId,
'activity': {
'postedTime': new Date().getTime(),
'title': 'gadget was viewed',
'body': my.gadgets[this.id].name
+ ' gadget was viewed'
}
}).execute(function (response) {
});
}
if (track) {
// record in google analytics
_gaq.push(['_trackEvent', my.gadgets[this.id].name, 'OPEN']);
}
}
} else {
//CLOSE
if (this.closed_width) {
gadgetContent.parentNode.style.width = this.closed_width + 'px';
}
gadgetContent.style.display = 'none';
gadgetImg.src = '/' + location.pathname.split('/')[1] + '/themes/wilma/images/green_plus_sign.gif'
if (track) {
if (my.gadgets[this.id].view == 'home') {
// record in google analytics
_gaq.push(['_trackEvent', my.gadgets[this.id].name,
'CLOSE_IN_EDIT', 'profile_edit_view']);
} else {
// record in google analytics
_gaq.push(['_trackEvent', my.gadgets[this.id].name, 'CLOSE']);
}
}
}
}
}
};
OrngLayoutManager.inherits(shindig.LayoutManager);
ORNGToggleGadget.prototype.getTitleHtml = function(title) {
return '<a href="#" onclick="shindig.container.getGadget('
+ this.id + ').handleToggle(true);return false;">'
+ (title ? title.replace(/&/g, '&amp;').replace(/</g, '&lt;') : 'Gadget') + '</a>';
};
ORNGToggleGadget.prototype.getTitleBarContent = function(continuation) {
if (my.gadgets[this.id].view == 'canvas') {
ORNGGadgetService.setCanvasTitle(title);
continuation('<span class="gadgets-gadget-canvas-title"></span>');
} else {
continuation('<div id="'
+ this.cssClassTitleBar
+ '-'
+ this.id
+ '" class="'
+ this.cssClassTitleBar
+ '"><span class="'
+ this.cssClassTitleButtonBar
+ '">'
+ '<a href="#" onclick="shindig.container.getGadget('
+ this.id
+ ').handleToggle(true);return false;" class="'
+ this.cssClassTitleButton
+ '"><img id="gadgets-gadget-title-image-'
+ this.id
+ '" src="/' + location.pathname.split('/')[1] + '/themes/wilma/images/green_minus_sign.gif"/></a></span> <span id="'
+ this.getIframeId() + '_title" class="' + this.cssClassTitle
+ '">' + this.getTitleHtml(this.title)
+ '</span><span id="' + this.getIframeId()
+ '_status" class="gadgets-gadget-status"></span></div>');
}
};
ORNGToggleGadget.prototype.finishRender = function(chrome) {
window.frames[this.getIframeId()].location = this.getIframeUrl();
if (this.start_closed) {
this.handleToggle(false);
}
else if (chrome && this.width) {
chrome.style.width = this.width + 'px';
}
};
OrngLayoutManager.prototype.getGadgetChrome = function(gadget) {
return this.layoutManagers[my.gadgets[gadget.id].chrome_id].getGadgetChrome(gadget);
};