diff --git a/opensocial/shindig_example_gadgets.sql b/opensocial/shindig_example_gadgets.sql index e2441adc5..afad1dc44 100644 --- a/opensocial/shindig_example_gadgets.sql +++ b/opensocial/shindig_example_gadgets.sql @@ -9,21 +9,23 @@ INSERT INTO `orng_apps` (`appid`, `name`, `url`, `PersonFilterID`, `enabled`, `c (102, 'Faculty Mentor', 'http://dev-profiles.ucsf.edu/orng/Mentor.xml', NULL, 0, NULL), (103, 'Websites', 'http://dev-profiles.ucsf.edu/orng/Links.xml', NULL, 1, NULL), (104, 'Profile List', 'http://dev-profiles.ucsf.edu/orng/ProfileListTool.xml', NULL, 1, 'JSONPersonIds'), -(106, 'RDF Test Gadget', 'http://dev-profiles.ucsf.edu/orng/RDFTest.xml', NULL, 1, NULL); +(106, 'RDF Test Gadget', 'http://dev-profiles.ucsf.edu/orng/RDFTest.xml', NULL, 1, NULL), +(112, 'Twitter', 'http://dev-profiles.ucsf.edu/ORNG/Twitter.xml', NULL, 1, NULL); DELETE FROM `orng_app_views`; -INSERT INTO `orng_app_views` (`appid`, `viewer_req`, `owner_req`, `page`, `view`, `closed_width`, `open_width`, `start_closed`, `chromeId`, `display_order`) VALUES -(100, NULL, NULL, 'search', NULL, 600, 600, 1, 'gadgets-search', NULL), -(101, NULL, 'R', 'individual', 'profile', 290, 600, 1, 'gadgets-view', 3), -(101, NULL, NULL, 'individual-EDIT-MODE', 'home', 700, 700, 1, 'gadgets-edit', NULL), -(102, NULL, 'R', 'individual', 'profile', 290, 600, 1, 'gadgets-view', 2), -(102, NULL, NULL, 'individual-EDIT-MODE', 'home', 700, 700, 1, 'gadgets-edit', NULL), -(103, NULL, NULL, 'individual-EDIT-MODE', 'home', 700, 700, 1, 'gadgets-edit', NULL), -(103, NULL, 'R', 'individual', 'profile', 290, 600, 0, 'gadgets-view', 1), -(104, 'U', NULL, 'search', 'small', 160, 160, 0, 'gadgets-tools', NULL), -(104, 'U', NULL, 'gadgetDetails', 'canvas', 700, 700, 0, 'gadgets-detail', NULL), -(104, 'U', NULL, 'SimilarPeople.aspx', 'small', 160, 160, 0, 'gadgets-tools', NULL), -(104, 'U', NULL, 'individual', 'small', 290, 290, 0, 'gadgets-view', NULL), -(104, 'U', NULL, 'CoAuthors.aspx', 'small', 160, 160, 0, 'gadgets-tools', NULL), -(106, NULL, NULL, 'individual-EDIT-MODE', 'home', 700, 700, 1, 'gadgets-edit', NULL); +INSERT INTO `orng_app_views` (`appid`, `viewer_req`, `owner_req`, `page`, `view`, `chromeId`, `opt_params`, `display_order`) VALUES +(100, NULL, NULL, 'search', NULL, 'gadgets-search', NULL, NULL), +(101, NULL, 'R', 'individual', 'profile', 'gadgets-view', '{''gadget_class'':''ORNGToggleGadget'', ''start_closed'':1, ''closed_width'':290}', 4), +(101, NULL, NULL, 'individual-EDIT-MODE', 'home', 'gadgets-edit', '{''gadget_class'':''ORNGToggleGadget'', ''start_closed'':1, ''closed_width'':700}', 4), +(102, NULL, 'R', 'individual', 'profile', 'gadgets-view', '{''gadget_class'':''ORNGToggleGadget'', ''start_closed'':1, ''closed_width'':290}', 3), +(102, NULL, NULL, 'individual-EDIT-MODE', 'home', 'gadgets-edit', '{''gadget_class'':''ORNGToggleGadget'', ''start_closed'':1, ''closed_width'':700}', 3), +(103, NULL, NULL, 'individual-EDIT-MODE', 'home', 'gadgets-edit', '{''gadget_class'':''ORNGToggleGadget'', ''start_closed'':1, ''closed_width'':700}', NULL), +(103, NULL, 'R', 'individual', 'profile', 'gadgets-view', '{''gadget_class'':''ORNGToggleGadget'', ''start_closed'':0, ''closed_width'':290}', 1), +(104, 'U', NULL, 'search', 'small', 'gadgets-tools', NULL, NULL), +(104, 'U', NULL, 'gadgetDetails', 'canvas', 'gadgets-detail', NULL, NULL), +(104, 'U', NULL, 'individual', 'small', 'gadgets-view', NULL, NULL), +(106, NULL, NULL, 'individual-EDIT-MODE', 'home', 'gadgets-edit', '{''gadget_class'':''ORNGToggleGadget'', ''start_closed'':1, ''closed_width'':700}', NULL), +(112, NULL, 'R', 'individual', 'profile', 'gadgets-view', '{''gadget_class'':''ORNGToggleGadget'', ''start_closed'':0, ''closed_width'':290}', 2), +(112, NULL, NULL, 'individual-EDIT-MODE', 'home', 'gadgets-edit', '{''gadget_class'':''ORNGToggleGadget'', ''start_closed'':1, ''closed_width'':700}', 2); + diff --git a/opensocial/shindig_orng_tables.sql b/opensocial/shindig_orng_tables.sql index a94db1d67..d73764a8a 100644 --- a/opensocial/shindig_orng_tables.sql +++ b/opensocial/shindig_orng_tables.sql @@ -1,145 +1,153 @@ - --- --- Table structure for table `orng_activity` --- - -CREATE TABLE IF NOT EXISTS `orng_activity` ( - `activityId` int(11) NOT NULL AUTO_INCREMENT, - `userId` varchar(255) default NULL, - `appId` int(11) default NULL, - `createdDT` datetime default NULL, - `activity` text, - PRIMARY KEY (`activityId`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- -------------------------------------------------------- - --- --- Table structure for table `orng_appdata` --- - -CREATE TABLE IF NOT EXISTS `orng_appdata` ( - `userId` varchar(255) NOT NULL, - `appId` int(11) NOT NULL, - `keyname` varchar(255) NOT NULL, - `value` varchar(4000) default NULL, - `createdDT` datetime default NULL, - `updatedDT` datetime default NULL, - KEY `userId` (`userId`,`appId`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- -------------------------------------------------------- - --- --- Table structure for table `orng_apps` --- - -CREATE TABLE IF NOT EXISTS `orng_apps` ( - `appid` int(11) NOT NULL, - `name` varchar(255) NOT NULL, - `url` varchar(255) NOT NULL, - `PersonFilterID` int(11) default NULL, - `enabled` tinyint(1) NOT NULL default '1', - `channels` varchar(255) default NULL, - PRIMARY KEY (`appid`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- -------------------------------------------------------- - --- --- Table structure for table `orng_app_registry` --- - -CREATE TABLE IF NOT EXISTS `orng_app_registry` ( - `appid` int(11) NOT NULL, - `personId` varchar(255) NOT NULL, - `createdDT` datetime NOT NULL, - PRIMARY KEY (`appid`, `personId` ) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- -------------------------------------------------------- - --- --- Table structure for table `orng_app_views` --- - -CREATE TABLE IF NOT EXISTS `orng_app_views` ( - `appid` int(11) NOT NULL, - `viewer_req` char(1) default NULL, - `owner_req` char(1) default NULL, - `page` varchar(50) default NULL, - `view` varchar(50) default NULL, - `closed_width` int(11) default NULL, - `open_width` int(11) default NULL, - `start_closed` tinyint(1) default NULL, - `chromeId` varchar(50) default NULL, - `display_order` int(11) default NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- -------------------------------------------------------- - --- --- Table structure for table `orng_messages` --- - -CREATE TABLE IF NOT EXISTS `orng_messages` ( - `msgId` varchar(255) NOT NULL, - `senderId` varchar(255) default NULL, - `recipientId` varchar(255) default NULL, - `coll` varchar(255) default NULL, - `title` varchar(255) default NULL, - `body` varchar(4000) default NULL, - `createdDT` datetime default NULL, - PRIMARY KEY (`msgId`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- -------------------------------------------------------- - - -DELIMITER // -CREATE PROCEDURE orng_registerAppPerson (uid varchar(255), aid INT, v BOOL) -BEGIN - IF (v) - THEN - INSERT INTO orng_app_registry (appId, personId, createdDT) values (aid, uid, now()); - ELSE - DELETE FROM orng_app_registry where appId = aid AND personId = uid; - END IF; -END // -DELIMITER ; - -DELIMITER // -CREATE PROCEDURE orng_upsertAppData(uid varchar(255), aid INT, kn varchar(255),v varchar(4000)) -BEGIN - DECLARE cnt int; - SELECT count(*) FROM orng_appdata WHERE userId = uid AND appId = aid and keyname = kn INTO cnt; - IF (cnt > 0) - THEN - UPDATE orng_appdata set `value` = v, updatedDT = NOW() WHERE userId = uid AND appId = aid and keyname = kn; - ELSE - INSERT INTO orng_appdata (userId, appId, keyname, `value`) values (uid, aid, kn, v); - END IF; - -- if keyname is VISIBLE, do more - IF (kn = 'VISIBLE' AND v = 'Y') - THEN - CALL orng_registerAppPerson(uid, aid, 1); - ELSEIF (kn = 'VISIBLE' ) - THEN - CALL orng_registerAppPerson(uid, aid, 0); - END IF; -END // -DELIMITER ; - -DELIMITER // -CREATE PROCEDURE orng_deleteAppData(uid varchar(255),aid INT, kn varchar(255)) -BEGIN - DELETE FROM orng_appdata WHERE userId = uid AND appId = aid and keyname = kn; - -- if keyname is VISIBLE, do more - IF (kn = 'VISIBLE' ) - THEN - CALL orng_registerAppPerson(uid, aid, 0); - END IF; -END // -DELIMITER ; - - + +-- +-- Table structure for table `orng_activity` +-- + +DROP TABLE IF EXISTS `orng_activity`; +CREATE TABLE `orng_activity` ( + `activityId` int(11) NOT NULL AUTO_INCREMENT, + `userId` varchar(255) default NULL, + `appId` int(11) default NULL, + `createdDT` datetime default NULL, + `activity` text, + PRIMARY KEY (`activityId`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `orng_appdata` +-- + +DROP TABLE IF EXISTS `orng_appdata`; +CREATE TABLE `orng_appdata` ( + `userId` varchar(255) NOT NULL, + `appId` int(11) NOT NULL, + `keyname` varchar(255) NOT NULL, + `value` varchar(4000) default NULL, + `createdDT` datetime default NULL, + `updatedDT` datetime default NULL, + KEY `userId` (`userId`,`appId`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `orng_apps` +-- + +DROP TABLE IF EXISTS `orng_apps`; +CREATE TABLE `orng_apps` ( + `appid` int(11) NOT NULL, + `name` varchar(255) NOT NULL, + `url` varchar(255) NOT NULL, + `PersonFilterID` int(11) default NULL, + `enabled` tinyint(1) NOT NULL default '1', + `channels` varchar(255) default NULL, + PRIMARY KEY (`appid`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `orng_app_registry` +-- + +DROP TABLE IF EXISTS `orng_app_registry`; +CREATE TABLE `orng_app_registry` ( + `appid` int(11) NOT NULL, + `personId` varchar(255) NOT NULL, + `createdDT` datetime NOT NULL, + PRIMARY KEY (`appid`, `personId` ) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `orng_app_views` +-- + +DROP TABLE IF EXISTS `orng_app_views`; +CREATE TABLE `orng_app_views` ( + `appid` int(11) NOT NULL, + `viewer_req` char(1) default NULL, + `owner_req` char(1) default NULL, + `page` varchar(50) default NULL, + `view` varchar(50) default NULL, + `chromeId` varchar(50) default NULL, + `display_order` int(11) default NULL, + `opt_params` varchar(255) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `orng_messages` +-- + +DROP TABLE IF EXISTS `orng_messages`; +CREATE TABLE `orng_messages` ( + `msgId` varchar(255) NOT NULL, + `senderId` varchar(255) default NULL, + `recipientId` varchar(255) default NULL, + `coll` varchar(255) default NULL, + `title` varchar(255) default NULL, + `body` varchar(4000) default NULL, + `createdDT` datetime default NULL, + PRIMARY KEY (`msgId`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + + +DROP PROCEDURE IF EXISTS `orng_registerAppPerson`; +DROP PROCEDURE IF EXISTS `orng_upsertAppData`; +DROP PROCEDURE IF EXISTS `orng_deleteAppData`; + +DELIMITER // +CREATE PROCEDURE orng_registerAppPerson (uid varchar(255), aid INT, v BOOL) +BEGIN + IF (v) + THEN + INSERT INTO orng_app_registry (appId, personId, createdDT) values (aid, uid, now()); + ELSE + DELETE FROM orng_app_registry where appId = aid AND personId = uid; + END IF; +END // +DELIMITER ; + +DELIMITER // +CREATE PROCEDURE orng_upsertAppData(uid varchar(255), aid INT, kn varchar(255),v varchar(4000)) +BEGIN + DECLARE cnt int; + SELECT count(*) FROM orng_appdata WHERE userId = uid AND appId = aid and keyname = kn INTO cnt; + IF (cnt > 0) + THEN + UPDATE orng_appdata set `value` = v, updatedDT = NOW() WHERE userId = uid AND appId = aid and keyname = kn; + ELSE + INSERT INTO orng_appdata (userId, appId, keyname, `value`) values (uid, aid, kn, v); + END IF; + -- if keyname is VISIBLE, do more + IF (kn = 'VISIBLE' AND v = 'Y') + THEN + CALL orng_registerAppPerson(uid, aid, 1); + ELSEIF (kn = 'VISIBLE' ) + THEN + CALL orng_registerAppPerson(uid, aid, 0); + END IF; +END // +DELIMITER ; + +DELIMITER // +CREATE PROCEDURE orng_deleteAppData(uid varchar(255), aid INT, kn varchar(255)) +BEGIN + DELETE FROM orng_appdata WHERE userId = uid AND appId = aid and keyname = kn; + -- if keyname is VISIBLE, do more + IF (kn = 'VISIBLE' ) + THEN + CALL orng_registerAppPerson(uid, aid, 0); + END IF; +END // +DELIMITER ; + + diff --git a/opensocial/shindigorng.properties.template b/opensocial/shindigorng.properties.template index d62afd24f..dffadf448 100644 --- a/opensocial/shindigorng.properties.template +++ b/opensocial/shindigorng.properties.template @@ -159,9 +159,6 @@ shindig.json-rpc.result-field=result shindig.accelerate.remapInternalServerError=true shindig.proxy.remapInternalServerError=true -shindig.signing.key-file=@TOKEN_KEY_FILE@ -shindig.signing.key-name=mykey - ##################################################################################### # # Open Research Networking Gadgets Items diff --git a/opensocial/shindigorng.war b/opensocial/shindigorng.war index ab466ebf5..bc54c356c 100644 Binary files a/opensocial/shindigorng.war and b/opensocial/shindigorng.war differ diff --git a/webapp/src/edu/ucsf/vitro/opensocial/GadgetSpec.java b/webapp/src/edu/ucsf/vitro/opensocial/GadgetSpec.java index 6b9666662..38ff92277 100644 --- a/webapp/src/edu/ucsf/vitro/opensocial/GadgetSpec.java +++ b/webapp/src/edu/ucsf/vitro/opensocial/GadgetSpec.java @@ -37,7 +37,7 @@ public class GadgetSpec { ResultSet rset = null; try { - String sqlCommand = "select page, viewer_req, owner_req, view, closed_width, open_width, start_closed, chromeId, display_order from orng_app_views where appId = " + String sqlCommand = "select page, viewer_req, owner_req, view, chromeId, opt_params, display_order from orng_app_views where appId = " + appId; conn = ds.getConnection(); stmt = conn.createStatement(); @@ -47,9 +47,8 @@ public class GadgetSpec { rset.getString(1), new GadgetViewRequirements(rset.getString(1), rset .getString(2), rset.getString(3), rset - .getString(4), rset.getInt(5), rset - .getInt(6), rset.getBoolean(7), rset - .getString(8), rset.getInt(9))); + .getString(4), rset.getString(5), rset + .getString(6), rset.getInt(7))); } } finally { try { diff --git a/webapp/src/edu/ucsf/vitro/opensocial/GadgetViewRequirements.java b/webapp/src/edu/ucsf/vitro/opensocial/GadgetViewRequirements.java index d482e3585..7378fecaa 100644 --- a/webapp/src/edu/ucsf/vitro/opensocial/GadgetViewRequirements.java +++ b/webapp/src/edu/ucsf/vitro/opensocial/GadgetViewRequirements.java @@ -4,31 +4,24 @@ public class GadgetViewRequirements { private char viewerReq; // U for User or null for no requirement private char ownerReq; // R for Registered or null for no requirement private String view; - private int closedWidth; - private int openWidth; - private boolean startClosed; private String chromeId; + private String optParams; private int display_order; public GadgetViewRequirements(char viewerReq, char ownerReq, - String view, int closedWidth, int openWidth, boolean startClosed, - String chromeId, int display_order) { + String view, String chromeId, String optParams, int display_order) { this.viewerReq = viewerReq; this.ownerReq = ownerReq; this.view = view; - this.closedWidth = closedWidth; - this.openWidth = openWidth; - this.startClosed = startClosed; this.chromeId = chromeId; + this.optParams = optParams; this.display_order = display_order; } public GadgetViewRequirements(String page, String viewerReq, - String ownerReq, String view, int closedWidth, int openWidth, - boolean startClosed, String chromeId, int display_order) { + String ownerReq, String view, String chromeId, String optParams, int display_order) { this(viewerReq != null ? viewerReq.charAt(0) : ' ', - ownerReq != null ? ownerReq.charAt(0) : ' ', view, closedWidth, - openWidth, startClosed, chromeId, display_order); + ownerReq != null ? ownerReq.charAt(0) : ' ', view, chromeId, optParams, display_order); } public char getViewerReq() { @@ -43,22 +36,14 @@ public class GadgetViewRequirements { return view; } - public int getClosedWidth() { - return closedWidth; - } - - public int getOpenWidth() { - return openWidth; - } - - public boolean getStartClosed() { - return startClosed; - } - public String getChromeId() { return chromeId; } + public String getOptParams() { + return optParams != null && optParams.trim().length() > 0 ? optParams : "{}"; + } + int getDisplayOrder() { return display_order; } diff --git a/webapp/src/edu/ucsf/vitro/opensocial/OpenSocialManager.java b/webapp/src/edu/ucsf/vitro/opensocial/OpenSocialManager.java index c5447bf7c..f7794812c 100644 --- a/webapp/src/edu/ucsf/vitro/opensocial/OpenSocialManager.java +++ b/webapp/src/edu/ucsf/vitro/opensocial/OpenSocialManager.java @@ -353,15 +353,13 @@ public class OpenSocialManager { public String getGadgetJavascript() { String lineSeparator = System.getProperty("line.separator"); String gadgetScriptText = "var my = {};" + lineSeparator - + "my.gadgetSpec = function(appId, name, url, secureToken, view, closed_width, open_width, start_closed, chrome_id, visible_scope) {" + + "my.gadgetSpec = function(appId, name, url, secureToken, view, chrome_id, opt_params, visible_scope) {" + lineSeparator + "this.appId = appId;" + lineSeparator + "this.name = name;" + lineSeparator + "this.url = url;" + lineSeparator + "this.secureToken = secureToken;" + lineSeparator + "this.view = view || 'default';" - + lineSeparator + "this.closed_width = closed_width;" - + lineSeparator + "this.open_width = open_width;" - + lineSeparator + "this.start_closed = start_closed;" - + lineSeparator + "this.chrome_id = chrome_id;" + lineSeparator + + lineSeparator + "this.chrome_id = chrome_id;" + + lineSeparator + "this.opt_params = opt_params;" + lineSeparator + "this.visible_scope = visible_scope;" + lineSeparator + "};" + lineSeparator + "my.pubsubData = {};" + lineSeparator; for (String key : getPubsubData().keySet()) { @@ -377,10 +375,7 @@ public class OpenSocialManager { gadgetScriptText += "new my.gadgetSpec(" + gadget.getAppId() + ",'" + gadget.getName() + "','" + gadget.getGadgetURL() + "','" + gadget.getSecurityToken() + "','" + gadget.getView() - + "'," + gadget.getClosedWidth() + "," - + gadget.getOpenWidth() + "," - + (gadget.getStartClosed() ? "1" : "0") + ",'" - + gadget.getChromeId() + "','" + + "','" + gadget.getChromeId() + "'," + gadget.getOptParams() + ",'" + gadget.getGadgetSpec().getVisibleScope() + "'), "; } gadgetScriptText = gadgetScriptText.substring(0, diff --git a/webapp/src/edu/ucsf/vitro/opensocial/PreparedGadget.java b/webapp/src/edu/ucsf/vitro/opensocial/PreparedGadget.java index caab0b18b..db13259f4 100644 --- a/webapp/src/edu/ucsf/vitro/opensocial/PreparedGadget.java +++ b/webapp/src/edu/ucsf/vitro/opensocial/PreparedGadget.java @@ -73,23 +73,6 @@ public class PreparedGadget implements Comparable { } } - public int getOpenWidth() { - GadgetViewRequirements reqs = getGadgetViewRequirements(); - return reqs != null ? reqs.getOpenWidth() : 0; - } - - public int getClosedWidth() { - GadgetViewRequirements reqs = getGadgetViewRequirements(); - return reqs != null ? reqs.getClosedWidth() : 0; - } - - public boolean getStartClosed() { - GadgetViewRequirements reqs = getGadgetViewRequirements(); - // if the page specific reqs are present, honor those. Otherwise defaut - // to true for regular gadgets, false for sandbox gadgets - return reqs != null ? reqs.getStartClosed() : !gadgetSpec.fromSandbox(); - } - public String getChromeId() { GadgetViewRequirements reqs = getGadgetViewRequirements(); if (reqs != null) { @@ -112,6 +95,11 @@ public class PreparedGadget implements Comparable { } } + public String getOptParams() { + GadgetViewRequirements reqs = getGadgetViewRequirements(); + return reqs != null ? reqs.getOptParams() : "{}"; + } + public String getCanvasURL() throws UnsupportedEncodingException { return "~/gadget?appId=" + getAppId() + "&Person=" + URLEncoder.encode(helper.getOwnerId(), "UTF-8"); diff --git a/webapp/web/js/openSocial/orng.js b/webapp/web/js/openSocial/orng.js index e85076fe0..6140493c1 100644 --- a/webapp/web/js/openSocial/orng.js +++ b/webapp/web/js/openSocial/orng.js @@ -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, '&').replace(/'); + } + else { + continuation( + '
' + + ' ' + + this.getTitleHtml(this.title) + '
'); } - } - 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(''); - } - else { - continuation( - ''); - } +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 '' + + (title ? title.replace(/&/g, '&').replace(/'; +}; + + +ORNGToggleGadget.prototype.getTitleBarContent = function(continuation) { + if (my.gadgets[this.id].view == 'canvas') { + ORNGGadgetService.setCanvasTitle(title); + continuation(''); + } else { + continuation('
' + + ' ' + this.getTitleHtml(this.title) + + '
'); + } +}; + +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); -}; \ No newline at end of file