You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ms...@apache.org on 2014/12/03 16:01:28 UTC
[03/11] portals-pluto git commit: Added helper functions to
PortletParameters & PortletState objects. Began adapting demo to use the
helper functions.
Added helper functions to PortletParameters & PortletState objects. Began adapting demo to use the helper functions.
Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/30e5bbf7
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/30e5bbf7
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/30e5bbf7
Branch: refs/heads/PortletHub
Commit: 30e5bbf7d94c6ae4e9a7819d457e506e613e94ca
Parents: 71a19e1
Author: Scott Nicklous <ms...@apache.org>
Authored: Mon Dec 1 16:48:50 2014 +0100
Committer: Scott Nicklous <ms...@apache.org>
Committed: Mon Dec 1 16:48:50 2014 +0100
----------------------------------------------------------------------
.../src/main/webapp/WEB-INF/jsp/view-csp.jsp | 2 +-
.../src/main/webapp/WEB-INF/jsp/view-isp.jsp | 6 +-
pluto-portal/src/main/webapp/portlet.js | 205 +++++++++++++++++--
3 files changed, 189 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/30e5bbf7/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp
index 7ce9442..ecc389d 100644
--- a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-csp.jsp
@@ -118,7 +118,7 @@ limitations under the License.
if ((newColor === undefined) || (newColor === null) || !newColor.match("^#(?:[A-Fa-f0-9]{3}){1,2}$")) {
document.getElementById(msgdiv).innerHTML = 'Bad color. Enter #xxxxxx or #xxx.';
} else {
- newState = portletInit.cloneState(currState);
+ newState = currState.clone();
newState.parameters.color = [newColor];
portletInit.setPortletState(newState);
}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/30e5bbf7/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp
index 92b4cd6..40bbfa6 100644
--- a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view-isp.jsp
@@ -59,7 +59,7 @@ limitations under the License.
console.log("ISP: image selected (radio): " + this.value);
if (currState.parameters.imgName !== this.value) {
- var newState = portletInit.cloneState(currState);
+ var newState = currState.clone();
newState.parameters.imgName = [this.value];
portletInit.setPortletState(newState);
}
@@ -70,7 +70,7 @@ limitations under the License.
console.log("ISP: image selected (dropdown): " + this.value);
if (currState.parameters.imgName !== this.value) {
- var newState = portletInit.cloneState(currState);
+ var newState = currState.clone();
newState.parameters.imgName = [this.value];
portletInit.setPortletState(newState);
}
@@ -134,7 +134,7 @@ limitations under the License.
handleST = function () {
console.log("ISP: select display type clicked: " + this.value);
if (currState.parameters.selType !== this.value) {
- var newState = portletInit.cloneState(currState);
+ var newState = currState.clone();
newState.parameters.selType = [this.value];
portletInit.setPortletState(newState);
}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/30e5bbf7/pluto-portal/src/main/webapp/portlet.js
----------------------------------------------------------------------
diff --git a/pluto-portal/src/main/webapp/portlet.js b/pluto-portal/src/main/webapp/portlet.js
index 98b898f..5abdd2d 100644
--- a/pluto-portal/src/main/webapp/portlet.js
+++ b/pluto-portal/src/main/webapp/portlet.js
@@ -47,17 +47,56 @@
* To represent the parameter having a <code>null</code> value, the
* property value must equal [null].
* <p>
- * @typedef PortletParameter
+ * PortletParameters objects obtained from the Portlet Hub define some helper
+ * functions for accessing the parameter values.
+ * <p>
+ * @typedef PortletParameters
* @property {string[]} {string} The parameters object may have
* multiple properties.
+ * @property {function} clone() Returns a new copy of this object
+ * @property {function} setValue(n,v) Sets a parameter with name n and value v.
+ * The value v may be a string or an array.
+ * @property {function} setValues(n,v) Sets a parameter with name n and value v.
+ * The value v may be a string or an array.
+ * @property {function} getValue(n) Gets the string parameter value for the name n.
+ * If n designates a multi-valued parameter, this function returns the first value in the values array.
+ * @property {function} getValues(n) Gets the string array parameter value for the name n.
+ * @property {function} remove(n) Removes the parameter with name n.
*/
/**
* Represents the portlet state.
+ * <p>
+ * PortletState objects obtained from the Portlet Hub define some helper
+ * functions for accessing the parameter values.
+ * <p>
* @typedef PortletState
- * @property {PortletParameter} parameters The portlet parameters
+ * @property {PortletParameters} parameters The portlet parameters
+ * @property {PortletParameters} p an alias for the 'parameters' property
* @property {string} portletMode The portlet mode
* @property {string} windowState The window state
+ * @property {function} clone() Returns a new copy of this object
+ * @property {function} setPortletMode(pm) Sets the portlet mode to the specified value.
+ * The strings defined by the {@link PortletConstants} object should be used to specify the portlet mode.
+ * @property {function} getPortletMode() Returns the current portlet mode
+ * @property {function} setWindowState(ws) Sets the window state to the specified value
+ * @property {function} getWindowState() Returns the current window state
+ * The strings defined by the {@link PortletConstants} object should be used to specify the window state.
+ */
+
+/**
+ * Provides defined values for some commonly-used portlet constants
+ * <p>
+ * @typedef PortletConstants
+ * @property {string} VIEW Specifies portlet mode 'VIEW'
+ * @property {string} EDIT Specifies portlet mode 'EDIT'
+ * @property {string} HELP Specifies portlet mode 'HELP'
+ * @property {string} NORMAL Specifies window state 'NORMAL'
+ * @property {string} MINIMIZED Specifies window state 'MINIMIZED'
+ * @property {string} MAXIMIZED Specifies window state 'MAXIMIZED'
+ * @property {string} FULL Specifies resource URL cacheability 'FULL'
+ * @property {string} PORTLET Specifies resource URL cacheability 'PORTLET'
+ * @property {string} PAGE Specifies resource URL cacheability 'PAGE'
*/
/**
@@ -305,8 +344,94 @@ var portlet = portlet || {};
return;
}
+
+ // ~~~~~~~~~~~~~~~~ Helper classes for parameters & state ~~~~~~~~~~~~~~~~~~~
+
+ function Parameters(p) {
+ var n;
+ if (p) {
+ for (n in p) {
+ if (p.hasOwnProperty(n) && Array.isArray(p[n])) {
+ this[n] = p[n].slice(0);
+ }
+ }
+ }
+ }
+ Parameters.prototype.clone = function () {
+ return new Parameters(this);
+ };
+ Parameters.prototype.setValue = function (name, value) {
+ var val = value;
+ if (!Array.isArray(value)) {
+ val = [value];
+ }
+ this[name] = val;
+ };
+ Parameters.prototype.setValues = Parameters.prototype.setValue;
+ Parameters.prototype.remove = function (name) {
+ if (this[name] !== undefined) {
+ delete this[name];
+ }
+ };
+ Parameters.prototype.getValue = function (name) {
+ var res = this[name];
+ if (res) {
+ res = res[0];
+ }
+ return res;
+ };
+ Parameters.prototype.getValues = function (name) {
+ return this[name];
+ };
+
+ function State (s) {
+ if (s) {
+ this.portletMode = s.portletMode;
+ this.windowState = s.windowState;
+ this.parameters = new Parameters(s.parameters);
+ } else {
+ this.portletMode = 'VIEW';
+ this.windowState = 'NORMAL';
+ this.parameters = new Parameters();
+ }
+ this.p = this.parameters;
+ }
+ State.prototype.clone = function () {
+ return new State(this);
+ };
+ State.prototype.setPortletMode = function (pm) {
+ this.portletMode = pm;
+ };
+ State.prototype.getPortletMode = function () {
+ return this.portletMode;
+ };
+ State.prototype.setWindowState = function (ws) {
+ this.windowState = ws;
+ };
+ State.prototype.getWindowState = function () {
+ return this.windowState;
+ };
+
+ var portletConstants = {
+
+ // Portlet mode
+ "VIEW" : "VIEW",
+ "EDIT" : "EDIT",
+ "HELP" : "HELP",
+
+ // window state
+ "NORMAL" : "NORMAL",
+ "MINIMIZED" : "MINIMIZED",
+ "MAXIMIZED" : "MAXIMIZED",
+
+ // Resource URL cacheability
+ "FULL" : "cacheLevelFull",
+ "PAGE" : "cacheLevelPage",
+ "PORTLET" : "cacheLevelPortlet"
+ },
+
// variable declarations
- var portletRegex = "^portlet[.].*",
+ portletRegex = "^portlet[.].*",
/**
* Portlet Hub Mockup internal structure defining the data held
@@ -623,7 +748,7 @@ var portlet = portlet || {};
pi = _registeredPortlets[p];
- state = _clone(pi.getState());
+ state = new State(pi.getState());
data = pi.getRenderData();
callback = oscListeners[p].callback;
@@ -809,7 +934,7 @@ var portlet = portlet || {};
* To represent a <code>null</code> value, the property value must equal
* [null].
*
- * @param {PortletParameter} parms The parameters to check
+ * @param {PortletParameters} parms The parameters to check
* @private
* @throws {IllegalArgumentException}
* Thrown if the parameters are incorrect
@@ -958,6 +1083,10 @@ var portlet = portlet || {};
setPageState = function (pid, ustr) {
var pi;
+ // Perform some checks on the update string. allow null string.
+ if ((ustr === undefined) || ((ustr !== null) && (typeof ustr !== 'string'))) {
+ throwIllegalArgumentException("Invalid update string: " + ustr);
+ }
// convert page state into an object.
// update each affected portlet client. Makes use of a
// mockup-specific function for decoding.
@@ -976,6 +1105,8 @@ var portlet = portlet || {};
};
+ // ~~~~~~~~~~~~~~~~ Register function ~~~~~~~~~~~~~~~~~~~
+
/**
* Registers a portlet client with the portlet hub.
* <p>
@@ -1249,15 +1380,6 @@ var portlet = portlet || {};
/**
- * Utility function to perform a deep copy of the state object.
- *
- * @param {PortletState} state The state to be cloned
- *
- * @memberOf PortletInit
- */
- cloneState : _clone,
-
- /**
* Returns a promise for a resource URL with parameters set appropriately
* for the page state according to the resource parameters
* and cacehability option provided.
@@ -1272,7 +1394,7 @@ var portlet = portlet || {};
* <p>
* The resource parameters must be an object containing properties
* representing parameter names whose values must be an array of string
- * values, as described under {@link PortletParameter}.
+ * values, as described under {@link PortletParameters}.
* All of the resource parameters will be attached to the URL.
* Use of resource parameters is optional.
* <p>
@@ -1315,7 +1437,8 @@ var portlet = portlet || {};
*
* @param {PortletParameters} resParams Resource parameters to be
* added to the URL
- * @param {string} cache Cacheability option
+ * @param {string} cache Cacheability option. The strings defined
+ * under {@link PortletConstants} should be used to specifiy cacheability.
*
* @returns {Promise} A Promise object. Returns a string representing the
* resource URL on successful resolution.
@@ -1400,7 +1523,7 @@ var portlet = portlet || {};
* <p>
* The action parameters must be an object containing properties
* representing parameter names whose values must be an array of string
- * values, as described under {@link PortletParameter}.
+ * values, as described under {@link PortletParameters}.
* All of the action parameters will be attached to the URL.
* Use of action parameters is optional.
* <p>
@@ -1513,7 +1636,7 @@ var portlet = portlet || {};
* <p>
* The action parameters must be an object containing properties
* representing parameter names whose values must be an array of string
- * values, as described under {@link PortletParameter}.
+ * values, as described under {@link PortletParameters}.
* All of the action parameters will be attached to the URL.
* Use of action parameters is optional.
* <p>
@@ -1689,10 +1812,52 @@ var portlet = portlet || {};
}
return cnt;
- }
+ },
+
+ /**
+ * Creates and returns a new PortletParameters object.
+ * <p>
+ * If no argument is provided, an empty PortletParameters object will be
+ * returned. If an existing PortletParameters object is provided as argument,
+ * a clone of the input object will be returned.
+ *
+ * @param {PortletParameters} p An optional PortletParameters object to be copied
+ *
+ * @returns {PortletParameters} The new parameters object
+ *
+ * @memberOf PortletInit
+ */
+ newParameters : function (p) {
+ return new Parameters (p);
+ },
+
+ /**
+ * Creates and returns a new PortletState object.
+ * <p>
+ * If no argument is provided, an empty PortletState object will be
+ * returned. If an existing PortletState object is provided as argument,
+ * a clone of the input object will be returned.
+ *
+ * @param {PortletState} s An optional PortletState object to be copied
+ *
+ * @returns {PortletState} The new PortletState object
+ *
+ * @memberOf PortletInit
+ */
+ newState : function (s) {
+ return new State(s);
+ },
+
+ /**
+ * The {@link PortletConstants} object that provides useful field definitions for
+ * portlet mode, window state, and resource URL cacheability settings.
+ *
+ * @memberOf PortletInit
+ */
+ constants : portletConstants
};
});
};
-})();
+}());