Author: ivol37 at gmail.com
Date: Fri Nov 26 11:43:09 2010
New Revision: 447
Log:
[AMDATU-76] Updated jquery dashboard plugin. Only modification left is adding
the 'securetoken' field to the widget (should be moved to metadata). However,
in IE8 I still get a JS error.
Added:
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/lib/jquery.dashboard.min.js
Modified:
trunk/amdatu-opensocial/dashboard/src/main/resources/jsp/dashboard.jsp
trunk/amdatu-opensocial/dashboard/src/main/resources/static/css/dashboardui.css
trunk/amdatu-opensocial/dashboard/src/main/resources/static/html/templates.html
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/dashboard.js
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/gadgets_appdata.js
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/lib/jquery.dashboard.js
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/service/GadgetManagementServiceImpl.java
Modified: trunk/amdatu-opensocial/dashboard/src/main/resources/jsp/dashboard.jsp
==============================================================================
--- trunk/amdatu-opensocial/dashboard/src/main/resources/jsp/dashboard.jsp
(original)
+++ trunk/amdatu-opensocial/dashboard/src/main/resources/jsp/dashboard.jsp
Fri Nov 26 11:43:09 2010
@@ -19,17 +19,7 @@
<script type="text/javascript"
src="/dashboard/static/js/gadgets_appdata.js"></script>
<script type="text/javascript"
src="/gadgets/js/shindig-container:pubsub-2.js?c=1&debug=1"></script>
-
- <script type="text/javascript">
- $(function() {
- $("body").append('<div id="templates" style="display:none">')
- $("#templates").load("/dashboard/static/html/templates.html");
-
- $('#switcher').themeswitcher();
-
- });
- </script>
-
+
<script type="text/javascript"
src="/dashboard/static/js/dashboard.js"></script>
<link rel="stylesheet" type="text/css"
href="/dashboard/static/css/dashboardui.css" />
@@ -44,7 +34,7 @@
<div id="switcher"></div>
</div>
<div class="headerlinks">
- <a class="add-gadget headerlink" href="#">Add Gadget</a> <span
class="headerlink">|</span>
+ <a class="openaddwidgetdialog headerlink" href="#">Add
Gadget</a> <span class="headerlink">|</span>
<a class="editlayout headerlink" href="#">Edit layout</a>
</div>
</div>
@@ -58,30 +48,6 @@
</div>
</div>
- <!-- Definition for the dialogs -->
- <div class="dialog" id="add-gadget-dialog" title="Gadget Directory">
- <ul style="height: 614px;" class="page-menu categorylist">
- </ul>
-
- <div class="page-body">
- <div style="height: 624px; display: block;" class="panel-body">
- <ol id="category-all" class="macro-list">
- </ol>
- </div>
- </div>
- <div class="button-panel">
- </div>
- </div>
-
-
- <div class="dialog" id="editLayout" title="Edit layout">
- <div class="panel-body" id="layout-dialog">
- <p><strong>Choose dashboard layout</strong></p>
- <ul class="layoutSelection">
- </ul>
- </div>
- </div>
-
<div id="footer">
Amdatu 0.0.6 - 2010 - <a href="http://amdatu.org">http://amdatu.org</a>
</div>
Modified:
trunk/amdatu-opensocial/dashboard/src/main/resources/static/css/dashboardui.css
==============================================================================
---
trunk/amdatu-opensocial/dashboard/src/main/resources/static/css/dashboardui.css
(original)
+++
trunk/amdatu-opensocial/dashboard/src/main/resources/static/css/dashboardui.css
Fri Nov 26 11:43:09 2010
@@ -5,7 +5,7 @@
cursor:move;
}
.column {
- min-height:600px;
+ min-height:1500px;
}
#layout-dialog .selected {
@@ -41,7 +41,7 @@
.ui-icon {
float:left;
}
-.content {
+.widgetcontent {
padding:2px 2px 5px 5px;
}
.widget {
@@ -54,47 +54,44 @@
width:47.5%;
}
-.layout-a .column, .layout-a div.gadget {
+.layout-a .column {
width:98%;
}
.layout-a .column.second, .layout-a .column.third {
display:none;
}
-.layout-aa .column, .layout-aa div.gadget {
+.layout-aa .column {
width:47.5%;
}
.layout-aa .third {
display:none;
}
-.layout-ba .column, .layout-ba div.gadget {
+.layout-ba .column {
width:68%;
}
-.layout-ba .first, .layout-ba div.gadget.first {
+.layout-ba .first {
width:27%;
}
.layout-ba .third {
display:none;
}
-.layout-ab .column, .layout-ab div.gadget {
+.layout-ab .column {
width:27%;
}
-.layout-ab .first, .layout-ab div.gadget.first {
+.layout-ab .first {
width:68%;
}
.layout-ab .third {
display:none;
}
-.layout-aaa .column, .layout-aaa div.gadget {
+.layout-aaa .column {
width:30.9%;
}
-#tabs {
- margin-left:5px;
- margin-right:5px;
-}
-
body {
margin:0;
+ color:#333333;
+ font:12px/1.4 arial,FreeSans,Helvetica,sans-serif;
}
.header_tile_image {
background:url("../img/lake.png") repeat-x scroll center top transparent;
@@ -114,10 +111,6 @@
height:148px;
}
-.gadget {
- width:100%;
-}
-
.ui-widget-overlay {
opacity:0.5;
}
@@ -129,41 +122,33 @@
}
-
-body {
-color:#333333;
-font:12px/1.4 arial,FreeSans,Helvetica,sans-serif;
-}
-
-
-
#layout-dialog ul {
-margin:0;
-padding:0;
+ margin:0;
+ padding:0;
}
#layout-dialog ul li a, #layout-dialog ul li a:link, #layout-dialog ul li
a:visited {
-border:1px solid #BBBBBB;
-display:block;
-float:left;
-margin:0 1em 1em 0;
-outline:medium none;
-padding:0.35em;
-width:auto;
+ border:1px solid #BBBBBB;
+ display:block;
+ float:left;
+ margin:0 1em 1em 0;
+ outline:medium none;
+ padding:0.35em;
+ width:auto;
}
.hidden {
display:none;
}
-.aui-dropdown {
+.controls {
border:1px solid #BBBBBB;
float:none;
margin:0;
padding:4px 0;
}
-.aui-dropdown {
+.controls {
width:100px;
background:none repeat scroll 0 0 #dddddd;
border:1px solid #6A8EB3;
@@ -175,43 +160,40 @@
z-index:2003;
}
-.aui-dropdown li {
-float:none;
-margin:0;
-padding:0;
-list-style-type:none;
-margin:0 0 0 0.2em;
-width:auto;
-position:static;
-}
-
-.aui-dropdown li a {
-color:#000000;
-font-weight:normal;
-float:none;
-margin:0;
-text-decoration:none;
-width:auto;
-padding-left:5px;
+.controls li {
+ float:none;
+ margin:0;
+ padding:0;
+ list-style-type:none;
+ margin:0 0 0 0.2em;
+ width:auto;
+ position:static;
+}
+
+.controls li a {
+ color:#000000;
+ font-weight:normal;
+ float:none;
+ margin:0;
+ text-decoration:none;
+ width:auto;
+ padding-left:5px;
}
.hiddenmenu {
position:relative;
}
-
-
-
-
-.dialog .page-menu {
-list-style:none outside none;
+.dialog .categories {
+ list-style:none outside none;
+ height: 414px;
}
-.dialog .page-menu li.selected button {
-color:#FFFFFF;
-font-weight:800;
+.dialog .categories li.selected button {
+ color:#FFFFFF;
+ font-weight:800;
}
-.dialog .page-menu li button {
+.dialog .categories li button {
background:none repeat scroll 0 0 transparent;
border:medium none;
color:#666666;
@@ -221,64 +203,63 @@
text-align:left;
width:100%;
}
-ul.page-menu button {
+ul.categories button {
cursor:pointer;
}
+.widgetitem {
+ border:2px none white;
+ float:left;
+ font-size:0.77em;
+ height:142px;
+ margin:0;
+ overflow:hidden;
+ padding:0 20px 0 142px;
+ width:152px;
+}
-.macro-list-item {
-border:2px none white;
-float:left;
-font-size:0.77em;
-height:142px;
-margin:0;
-overflow:hidden;
-padding:0 20px 0 142px;
-width:152px;
-}
-
-ol.macro-list {
-float:left;
-list-style:none outside none;
-margin:-10px;
-padding:0;
-width:auto;
+ol.widgets {
+ float:left;
+ list-style:none outside none;
+ margin:-10px;
+ padding:0;
+ width:auto;
}
.dialog .panel-body {
-overflow:auto;
-padding:10px;
+ overflow:auto;
+ padding:10px;
}
-.dialog .page-menu {
-background:none repeat scroll 0 0 #FFFFFF;
-border-right:1px solid #F0F0F0;
-float:left;
-height:100%;
-list-style:none outside none;
-margin:0 1.17em 0 0;
-padding:10px 0 0;
-width:25%;
+.dialog .categories {
+ background:none repeat scroll 0 0 #FFFFFF;
+ border-right:1px solid #F0F0F0;
+ float:left;
+ height:100%;
+ list-style:none outside none;
+ margin:0 1.17em 0 0;
+ padding:10px 0 0;
+ width:25%;
}
-.dialog .page-menu li.selected {
-background:none repeat scroll 0 0 #6699CC;
-color:#FFFFFF;
+.dialog .categories li.selected {
+ background:none repeat scroll 0 0 #6699CC;
+ color:#FFFFFF;
}
-.macro-list-item .add-button {
-float:left;
-margin:81px 0 0 -131px;
-width:auto;
+.widgetitem .add-button {
+ float:left;
+ margin:81px 0 0 -131px;
+ width:auto;
}
-.macro-list-item h3 {
-margin:11px 0 0;
-padding:0;
+.widgetitem h3 {
+ margin:11px 0 0;
+ padding:0;
}
-.macro-list-item img {
-border:1px solid #999999;
-float:left;
-margin:10px 0 0 -132px;
+.widgetitem img {
+ border:1px solid #999999;
+ float:left;
+ margin:10px 0 0 -132px;
}
\ No newline at end of file
Modified:
trunk/amdatu-opensocial/dashboard/src/main/resources/static/html/templates.html
==============================================================================
---
trunk/amdatu-opensocial/dashboard/src/main/resources/static/html/templates.html
(original)
+++
trunk/amdatu-opensocial/dashboard/src/main/resources/static/html/templates.html
Fri Nov 26 11:43:09 2010
@@ -5,13 +5,13 @@
<script type="text/html" id="widgettemplate">
<div class="ui-widget ui-corner-all ui-widget-content widget" id="<%=
id %>" title="<%= title %>">
- <div class="ui-widget-header ui-corner-all ui-helper-clearfix
widgetheader">
+ <div class="ui-widget-header ui-corner-all widgetheader">
<span class="widgettitle"><%= title %></span>
- <span class="right gadget-menu">
+ <span class="right icons hidden">
<span class="ui-icon ui-icon-newwin
widgetopenfullscreen"></span>
<span class="ui-icon ui-icon-arrowthickstop-1-s
menutrigger"></span>
<span class="hiddenmenu">
- <ul style="top: 13px;"
class="aui-dropdown menu hidden controls">
+ <ul style="top: 13px;" class="hidden
controls ui-widget-header">
<li class="widgetclose">
<span class="ui-icon
ui-icon-minus"></span>
<a class="minimization"
href="#">Minimize</a>
@@ -30,10 +30,9 @@
</li>
</ul>
</span>
-
</span>
</div>
- <div class="content dashboard-item-content">
+ <div class="widgetcontent">
</div>
</div>
</script>
@@ -44,17 +43,36 @@
<script type="text/html" id="addwidgettemplate">
- <li id="macro-ActivityStream" class="macro-list-item">
+ <li class="widgetitem">
<img src="<%= screenshot %>" alt="" height="60" width="120">
<div class="add-button">
<input class="macro-button-add addwidget"
id="addwidget<%= id %>" value="Add it Now" type="button"><br>
<input class="macro-hidden-uri" value="<%= url
%>" type="hidden">
</div>
<!-- // .add-button -->
- <h3 class="macro-title"><a href="<%= title_url %>"
target="_new"><%= title %></a></h3>
- <p class="macro-author">By <%= author %></p>
+ <h3><a href=""><%= title %></a></h3>
- <p class="macro-desc"><%= description %></p>
+ <p>By <%= author %></p>
+ <p><%= description %></p>
</li>
</script>
+
+<div class="dialog" id="addwidgetdialog" title="Widget Directory">
+ <ul class="categories">
+ </ul>
+
+ <div class="panel-body">
+ <ol id="category-all" class="widgets">
+ </ol>
+ </div>
+</div>
+
+
+<div class="dialog" id="editLayout" title="Edit layout">
+ <div class="panel-body" id="layout-dialog">
+ <p><strong>Choose dashboard layout</strong></p>
+ <ul class="layoutselection">
+ </ul>
+ </div>
+</div>
Modified:
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/dashboard.js
==============================================================================
--- trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/dashboard.js
(original)
+++ trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/dashboard.js
Fri Nov 26 11:43:09 2010
@@ -1,148 +1,161 @@
$(document).ready(function() {
- var startId = 100;
- // Documentation:
- // When using the layoutClass, it is possible to change layout using only
another class. In this case
- // you don't need the html property in the layout
-
- var dashboard = $('#dashboard').dashboard({
- layoutClass: 'layout',
- loadingHtml: '<div class="loading"><img alt="Loading, please wait"
src="/dashboard/static/img/loading.gif" /><p>Loading</p></div>',
- json_data : {
- url: "/rest/services/gadgetstore/gadgetstore/gadgets/mine"
- },
- addWidgetSettings: {
- widgetDirectoryUrl:"/rest/services/gadgetstore/gadgetstore/categories"
- },
- layouts :
- [
- { title: "Layout1",
- id: "layout1",
- image: "/dashboard/static/img/layout1.png",
- class: 'layout-a'
- },
- { title: "Layout2",
- id: "layout2",
- image: "/dashboard/static/img/layout2.png",
- class: 'layout-aa'
- },
- { title: "Layout3",
- id: "layout3",
- image: "/dashboard/static/img/layout3.png",
- class: 'layout-ba'
- },
- { title: "Layout4",
- id: "layout4",
- image: "/dashboard/static/img/layout4.png",
- class: 'layout-ab'
- },
- { title: "Layout5",
- id: "layout5",
- image: "/dashboard/static/img/layout5.png",
- class: 'layout-aaa'
- }
- ]
-
- }); // end dashboard call
+ $('body').append('<div id="templates"></div>');
+ $("#templates").hide();
+ $("#templates").load("/dashboard/static/html/templates.html", initDashboard);
+
+ $('#switcher').themeswitcher();
+
+
+ function initDashboard() {
+
+ var startId = 100;
+
+ // Documentation:
+ // When using the layoutClass, it is possible to change layout using only
another class. In this case
+ // you don't need the html property in the layout
+
+ var dashboard = $('#dashboard').dashboard({
+ debuglevel:1,
+ layoutClass: 'layout',
+ loadingHtml: '<div class="loading"><img alt="Loading, please wait"
src="/dashboard/static/img/loading.gif" /><p>Loading</p></div>',
+ json_data : {
+ url: "/rest/services/gadgetstore/gadgetstore/gadgets/mine"
+ },
+ addWidgetSettings: {
+ widgetDirectoryUrl:"/rest/services/gadgetstore/gadgetstore/categories"
+ },
+ layouts :
+ [
+ { title: "Layout1",
+ id: "layout1",
+ image: "/dashboard/static/img/layout1.png",
+ classname: 'layout-a'
+ },
+ { title: "Layout2",
+ id: "layout2",
+ image: "/dashboard/static/img/layout2.png",
+ classname: 'layout-aa'
+ },
+ { title: "Layout3",
+ id: "layout3",
+ image: "/dashboard/static/img/layout3.png",
+ classname: 'layout-ba'
+ },
+ { title: "Layout4",
+ id: "layout4",
+ image: "/dashboard/static/img/layout4.png",
+ classname: 'layout-ab'
+ },
+ { title: "Layout5",
+ id: "layout5",
+ image: "/dashboard/static/img/layout5.png",
+ classname: 'layout-aaa'
+ }
+ ]
+
+ }); // end dashboard call
- var my = {};
- my.widgets = dashboard.widgets;
+ var my = {};
+ my.widgets = dashboard.widgets;
- /*
- * Implement our own layoutmanager, because we have a different layout
- */
-
- // FIXME: move this to another js file
- my.LayoutManager = function() {
- shindig.LayoutManager.call(this);
- };
+ /*
+ * Implement our own layoutmanager, because we have a different layout
+ */
+
+ // FIXME: move this to another js file
+ my.LayoutManager = function() {
+ shindig.LayoutManager.call(this);
+ };
- my.LayoutManager.inherits(shindig.LayoutManager);
+ my.LayoutManager.inherits(shindig.LayoutManager);
- my.LayoutManager.prototype.getGadgetChrome = function(gadget) {
-
- var w = my.widgets[gadget.serviceName];
-
- var chrome = w.element.find('.dashboard-item-content').get(0);
- return chrome;
- };
-
- my.init = function() {
- shindig.container.layoutManager = new my.LayoutManager();
- };
- my.init();
-
- my.renderGadget = function(widget) {
- startId = startId + 1;
- var metadata = widget.metadata;
- if (typeof metadata != 'undefined' && typeof metadata.gadgeturl !=
'undefined') {
- var gadget = shindig.container.createGadget(
- {serviceName: widget.id, specUrl: metadata.gadgeturl, width: "100%",
secureToken: widget.securetoken});
- shindig.container.addGadget(gadget);
-
- var chrome = shindig.container.layoutManager.getGadgetChrome(gadget);
-
- // Don't render the header div
- if (chrome) {
- getMainContent(gadget, function(content) {
- chrome.innerHTML = content;
- window.frames[gadget.getIframeId()].location =
this.getIframeUrl(gadget);
- });
- }
+ my.LayoutManager.prototype.getGadgetChrome = function(widget) {
+ var chrome = widget.element.find('.widgetcontent').get(0);
+ return chrome;
};
- };
- // The src attribute for the iframe is added, because when you drag and drop
a iframe, it is reloaded by the browser
- getMainContent = function(gadget, continuation) {
- var iframeId = gadget.getIframeId();
- gadgets.rpc.setRelayUrl(iframeId, gadget.serverBase_ + gadget.rpcRelay);
- gadgets.rpc.setAuthToken(iframeId, gadget.rpcToken);
- continuation('<iframe id="' +
- iframeId + '" src="about:blank" name="' + iframeId + '" class="' +
gadget.cssClassGadget +
- '" src="about:blank' +
- '" frameborder="no" scrolling="no"' +
- (gadget.height ? ' height="' + gadget.height + '"' : '') +
- (gadget.width ? ' width="' + gadget.width + '"' : '') +
- '></iframe>');
- };
-
- getIframeUrl = function(gadget) {
- return gadget.serverBase_ + 'ifr?' +
- 'container=' + gadget.CONTAINER +
- '&mid=' + gadget.id +
- '&nocache=' + shindig.container.nocache_ +
- '&country=' + shindig.container.country_ +
- '&lang=' + shindig.container.language_ +
- '&view=' + shindig.container.view_ +
- (gadget.specVersion ? '&v=' + gadget.specVersion : '') +
- (shindig.container.parentUrl_ ? '&parent=' +
encodeURIComponent(shindig.container.parentUrl_) : '') +
- (gadget.debug ? '&debug=1' : '') +
- gadget.getAdditionalParams() +
- gadget.getUserPrefsParams() +
- (gadget.secureToken ? '&st=' + gadget.secureToken : '') +
- '&url=' + encodeURIComponent(gadget.specUrl) +
- '#rpctoken=' + gadget.rpcToken +
- (gadget.viewParams ?
- '&view-params=' +
encodeURIComponent(gadgets.json.stringify(gadget.viewParams)) : '') +
- (gadget.hashData ? '&' + gadget.hashData : '');
- }
+ my.init = function() {
+ shindig.container.layoutManager = new my.LayoutManager();
+ };
+ my.init();
- $('.widget').live('widgetLoaded',function(e, obj){
- my.renderGadget(obj);
- });
-
- $('.widget').live('widgetDeleted',function(e, obj){
- removeWidgetFromAppData(obj, dashboard);
- });
-
- dashboard.element.live('dashboardAddWidget',function(e, obj){
- addWidgetToAppData(obj, startId++, dashboard);
- });
-
- dashboard.init();
+ my.renderGadget = function(widget) {
+ startId = startId + 1;
+ var metadata = widget.metadata;
+ if (typeof metadata != 'undefined' && typeof metadata.gadgeturl !=
'undefined') {
+ var gadget = shindig.container.createGadget(
+ {serviceName: widget.id, specUrl: metadata.gadgeturl, width:
"100%", secureToken: widget.securetoken});
+ shindig.container.addGadget(gadget);
+
+ var chrome = shindig.container.layoutManager.getGadgetChrome(widget);
+
+ // Don't render the header div
+ if (chrome) {
+ getMainContent(gadget, function(content) {
+ chrome.innerHTML = content;
+ var iframe = widget.element.find('.gadgets-gadget').get(0);
+ iframe.src = this.getIframeUrl(gadget);
+
+ // The line below doesn't work for some reason
+ // window.frames[gadget.getIframeId()].location =
this.getIframeUrl(gadget);
+ });
+ }
+ };
+ };
+
+ // The src attribute for the iframe is added, because when you drag and
drop a iframe, it is reloaded by the browser
+ getMainContent = function(gadget, continuation) {
+ var iframeId = gadget.getIframeId();
+ gadgets.rpc.setRelayUrl(iframeId, gadget.serverBase_ + gadget.rpcRelay);
+ gadgets.rpc.setAuthToken(iframeId, gadget.rpcToken);
+ continuation('<iframe id="' +
+ iframeId + '" src="about:blank" name="' + iframeId + '" class="' +
gadget.cssClassGadget +
+ '" src="about:blank' +
+ '" frameborder="no" scrolling="no"' +
+ (gadget.height ? ' height="' + gadget.height + '"' : '') +
+ (gadget.width ? ' width="' + gadget.width + '"' : '') +
+ '></iframe>');
+ };
+
+ getIframeUrl = function(gadget) {
+ return gadget.serverBase_ + 'ifr?' +
+ 'container=' + gadget.CONTAINER +
+ '&mid=' + gadget.id +
+ '&nocache=' + shindig.container.nocache_ +
+ '&country=' + shindig.container.country_ +
+ '&lang=' + shindig.container.language_ +
+ '&view=' + shindig.container.view_ +
+ (gadget.specVersion ? '&v=' + gadget.specVersion : '') +
+ (shindig.container.parentUrl_ ? '&parent=' +
encodeURIComponent(shindig.container.parentUrl_) : '') +
+ (gadget.debug ? '&debug=1' : '') +
+ gadget.getAdditionalParams() +
+ gadget.getUserPrefsParams() +
+ (gadget.secureToken ? '&st=' + gadget.secureToken : '') +
+ '&url=' + encodeURIComponent(gadget.specUrl) +
+ '#rpctoken=' + gadget.rpcToken +
+ (gadget.viewParams ?
+ '&view-params=' +
encodeURIComponent(gadgets.json.stringify(gadget.viewParams)) : '') +
+ (gadget.hashData ? '&' + gadget.hashData : '');
+ }
+
+ $('.widget').live('widgetLoaded',function(e, obj){
+ my.renderGadget(obj);
+ });
+
+ $('.widget').live('widgetDeleted',function(e, obj){
+ removeWidgetFromAppData(obj, dashboard);
+ });
+
+ dashboard.element.live('dashboardAddWidget',function(e, obj){
+ addWidgetToAppData(obj, startId++, dashboard);
+ });
+ dashboard.init();
+
+ }
});
function log(msg) {
Modified:
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/gadgets_appdata.js
==============================================================================
---
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/gadgets_appdata.js
(original)
+++
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/gadgets_appdata.js
Fri Nov 26 11:43:09 2010
@@ -45,7 +45,7 @@
dashboard.addWidget({
"id":gadgetId,
"title":obj.title,
- "url":obj.url,
+ "url":"",
"securetoken":obj.securetoken,
"metadata":obj.metadata
}, dashboard.element.find('.column:first'));
Modified:
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/lib/jquery.dashboard.js
==============================================================================
---
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/lib/jquery.dashboard.js
(original)
+++
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/lib/jquery.dashboard.js
Fri Nov 26 11:43:09 2010
@@ -1,24 +1,20 @@
-/**
- * @file
- * Defines the jQuery.dashboard() plugin.
+/*
+ * dashboard 1.0
+ * http://www.gxdeveloperweb.com/dashboard/
+ *
+ * Copyright (c) 2010 Mark Machielsen
+ *
+ * Dual licensed under the MIT and GPL licenses (same as jQuery):
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
*
*/
// TODO:
//
-// Small
-// - minimizing CSS
-// - minimizing HTML and add it to the plugin
-// - name conventions for classes
-// - hover icons for the icons in the widget header
-// - make space when dragging between widgets
-
-// Large(r):
// - cleaner solution for the widget menu (and pluggable ala jstree
contextmenu)
// - edit settings option
-// - check on all browsers (IE7, IE8, FF3, Chrome, Safari)
// - check if there is a memory leak (use destroy function??)
-// - adding gadget: service servlet who handles the add
// Later:
// - documentation
@@ -26,16 +22,13 @@
// - add more examples
// - plugin for shortcuts
// - check with google pagespeed for efficient CSS selectors and unused CSS
-// - offer the minimized variant
// - check directory structure
// - moving a widget from one tab to the other
// - check review comments from William Breuer
// - check solution for fullscreen
// Known bugs:
-// - when dragging a widget from column1 to column2, the widget is closed:
this is cause because it also is a click event for toggle
// - multitabs: select theme frog: you see that the content of the tab is too
small: this is cause by the float:left of the column class
-// - when dragging a widget from column2 to column1 sometimes the widget
disappears
(function($) { // Create closure.
@@ -47,16 +40,18 @@
var widgetDirectoryUrl;
dashboard.layout;
dashboard.element = this;
- dashboard.widgets = new Object();
- dashboard.widgetsToAdd = new Object();
- dashboard.widgetCategories = new Object();
+ dashboard.widgets = {};
+ dashboard.widgetsToAdd = {};
+ dashboard.widgetCategories = {};
dashboard.initialized = false;
// Public methods
- dashboard.serialize = function() {
+ dashboard.serialize = function() {
+ dashboard.log('entering serialize function',1);
var r = '{"layout": "' + dashboard.layout.id + '", "data" : [';
// add al widgets in the right order
var i=0;
+ if ($('.' + opts.columnClass).length == 0)
dashboard.log(opts.columnClass + ' class not found',5);
$('.' + opts.columnClass).each(function() {
$(this).children().each(function() {
if ($(this).hasClass(opts.widgetClass)) {
@@ -69,22 +64,34 @@
r+= ']}';
return r;
}
+
+ dashboard.log = function(msg, level) {
+ if (level >= opts.debuglevel && typeof console != 'undefined') {
+ var l = '';
+ if (level == 1) l = 'INFO';
+ if (level == 2) l = 'EVENT';
+ if (level == 3) l = 'WARNING';
+ if (level == 5) l = 'ERROR';
+ console.log(l + ' - ' + msg);
+ }
+ }
dashboard.setLayout = function(layout) {
+ dashboard.log('entering setLayout function with layout' + layout,1);
dashboard.layout = layout;
loading.remove();
if (typeof opts.layoutClass != 'undefined') {
- this.element.find('.' +
opts.layoutClass).addClass(dashboard.layout.class);
+ this.element.find('.' +
opts.layoutClass).addClass(dashboard.layout.classname);
} else {
this.element.html(dashboard.layout.html);
}
- // make the columns sortable
+ // make the columns sortable, see http://jqueryui.com/demos/sortable/
for explaination
$('.' + opts.columnClass).sortable({
connectWith: $('.' + opts.columnClass),
- placeholder: 'placeholder',
opacity: opts.opacity,
+ handle: '.' + opts.widgetHeaderClass,
over: function(event, ui) {
$(this).addClass("selectedcolumn");
},
@@ -96,9 +103,11 @@
var w = dashboard.getWidget(ui.item.attr("id"));
w.setColumn(getColumnIdentifier($(this).attr("class")));
},
- deactivate: function(event, ui) {
+ deactivate: function(event, ui) {
+ dashboard.log('dropping the widget',1);
var childLength = $(this).children().length;
if (childLength == 0) {
+ dashboard.log('adding the empty text to the column',1);
$(this).html('<div class="emptycolumn">' + opts.emptyColumnHtml +
'</div>');
} else {
if (childLength == 2) {
@@ -106,16 +115,37 @@
$(this).find('.emptycolumn').remove();
}
}
+ },
+ start: function(event, ui) {
+ ui.item.find('.' + opts.widgetTitleClass).addClass('noclick');
+ },
+ stop: function(event, ui) {
+ //sorting changed (within one list)
+ setTimeout(function(){
+ ui.item.find('.' + opts.widgetTitleClass).removeClass('noclick');
+ }, 300);
}
});
+ fixSortableColumns();
+
// trigger the dashboardLayoutLoaded event
+ dashboard.log('dashboardLayoutLoaded event thrown',2);
dashboard.element.trigger("dashboardLayoutLoaded");
}
+ // This is a workaround for the following problem: when I drag a widget
from column2 to column1, sometimes the widget is
+ // moved to column3, which is not visible
+ function fixSortableColumns() {
+ dashboard.log('entering fixSortableColumns function',1);
+
$('.nonsortablecolumn').removeClass('nonsortablecolumn').addClass(opts.columnClass);
+ $('.' + opts.columnClass).filter(function() {return
$(this).css("display") ==
'none'}).addClass('nonsortablecolumn').removeClass(opts.columnClass);
+ }
+
// FIXME: private function
function getColumnIdentifier(classes) {
+ dashboard.log('entering getColumnIdentifier function',1);
var r;
var s = classes.split(" ");
for (var i = 0;i < s.length;i++) {
@@ -125,12 +155,14 @@
}
dashboard.loadLayout = function() {
+ dashboard.log('entering loadLayout function',1);
if (opts.json_data.url.length > 0) {
// ajax option
+ dashboard.log('Getting JSON feed : ' + opts.json_data.url,1);
$.getJSON(opts.json_data.url, function(json) {
// FIXME: can this be solved?
if (json == null) {
- alert('Unable to get json. If you are using chrome: there is an
issue with loading json with local files. It works on a server :-)');
+ alert('Unable to get json. If you are using chrome: there is an
issue with loading json with local files. It works on a server :-)',5);
return;
}
// set the layout
@@ -144,8 +176,8 @@
}
};
-
dashboard.addWidget = function(obj, column) {
+ dashboard.log('entering addWidget function',1);
// add the widget to the column
var wid = obj.id;
@@ -155,6 +187,8 @@
column = dashboard.widgets[wid].column;
} else {
// build the widget
+ dashboard.log('Applying template : ' + opts.widgetTemplate,1);
+ if ($('#' + opts.widgetTemplate).length == 0) dashboard.log('Template
"' + opts.widgetTemplate + ' not found',5);
var widgetStr = tmpl($('#' + opts.widgetTemplate).html(), obj);
var wi = $(widgetStr);
@@ -169,29 +203,21 @@
securetoken: obj.securetoken,
metadata: obj.metadata
});
- }
-
- // add it to the column
- wi.appendTo(column);
+ }
- var addedWidget = dashboard.widgets[wid];
- // open the widget
- if (addedWidget.open) {
- addedWidget.openContent();
+ // add it to the column
+ wi.appendTo(column);
+ dashboard.log('widgetAdded event thrown for widget ' + wid,2);
+ dashboard.widgets[wid].element.trigger("widgetAdded",
dashboard.widgets[wid]);
+
+ if (dashboard.initialized) {
+ dashboard.log('dashboardStateChange event thrown for widget ' +
wid,2);
+
dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetAdded","widget":wi});
}
+ }
- if (dashboard.initialized)
dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetAdded","widget":wi});
- }
-
- dashboard.appDataDone = function(data) {
- if (data.get('set_data').hadError()) {
- alert("Gadget could not be added");
- } else {
- alert("Gadget added to appData");
- }
- }
-
dashboard.loadWidgets = function(data) {
+ dashboard.log('entering loadWidgets function',1);
dashboard.element.find('.' + opts.columnClass).empty();
@@ -223,17 +249,16 @@
});
dashboard.initialized = true;
- dashboard.element.trigger("widgetsLoaded")
};
-
-
dashboard.init = function() {
+ dashboard.log('entering init function',1);
// load the widgets as fast as we can. After that add the binding
dashboard.loadLayout();
}
dashboard.getWidget = function(id) {
+ dashboard.log('entering getWidget function',1);
return dashboard.widgets[id];
}
@@ -252,11 +277,13 @@
* Constructor starts
*/
function widget(widget) {
+ dashboard.log('entering widget constructor',1);
// Merge default options with the options defined for this widget.
widget = $.extend({}, $.fn.dashboard.widget.defaults, widget);
// public functions
widget.openContent = function() {
+ dashboard.log('entering openContent function',1);
widget.open = true;
if (!widget.loaded) {
// load the content in the widget if the state == open
@@ -264,48 +291,86 @@
// add the loading
$(opts.loadingHtml).appendTo(widget.element.find('.' +
opts.widgetContentClass));
- widget.element.find('.' + opts.widgetContentClass).load(this.url,
function() {
+
+ widget.element.find('.' + opts.widgetContentClass).load(this.url,
function(response, status, xhr) {
+ if (status == "error") {
+ widget.element.find('.' +
opts.widgetContentClass).html(opts.widgetNotFoundMessage);
+ }
widget.loaded = true;
- widget.element.find('.' + opts.widgetContentClass).show();
+ widget.element.find('.' + opts.widgetContentClass).show();
+ dashboard.log('widgetLoaded event thrown for widget ' +
widget.id,2);
widget.element.trigger("widgetLoaded", widget);
});
} else {
+ dashboard.log('widgetLoaded event thrown',2);
widget.element.trigger("widgetLoaded", widget);
}
} else {
widget.element.find('.' + opts.widgetContentClass).show();
}
- if (dashboard.initialized)
dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetOpened","widget":widget});
+ if (dashboard.initialized) {
+ dashboard.log('dashboardStateChange event thrown for widget ' +
widget.id,2);
+
dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetOpened","widget":widget});
+ }
};
widget.setColumn = function(column) {
+ dashboard.log('entering setColumn function and setting widget ' +
widget.id + ' into column ' + column,1);
widget.column = column;
+ dashboard.log('dashboardStateChange event thrown for widget ' +
widget.id,2);
dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetMoved","widget":widget});
},
widget.refreshContent = function() {
+ dashboard.log('entering refreshContent function',1);
widget.loaded = false;
if (widget.open) {
widget.openContent();
}
}
+ widget.setTitle = function(newTitle){
+ dashboard.log('entering setTitle function',1);
+ widget.title=newTitle;
+ widget.element.find('.' + opts.widgetTitleClass).html(newTitle);
+ if (dashboard.initialized) {
+ dashboard.log('dashboardStateChange event thrown for widget ' +
widget.id,2);
+
dashboard.element.trigger("dashboardStateChange",{"stateChange":"titleChanged","widget":widget});
+ }
+ }
widget.closeContent = function() {
+ dashboard.log('entering closeContent function',1);
widget.open = false;
widget.element.find('.' + opts.widgetContentClass).hide();
+ dashboard.log('dashboardStateChange event thrown for widget ' +
widget.id,2);
dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetClosed","widget":widget});
};
+ widget.setMetadata = function(name, value) {
+ dashboard.log('entering setMetadata function',1);
+ if (typeof widget.metadata == 'undefined') {
+ widget.metadata = {};
+ }
+ widget.metadata[name] = value;
+ dashboard.log('dashboardStateChange event thrown for widget ' +
widget.id,2);
+
dashboard.element.trigger("dashboardStateChange",{"stateChange":"metadataChanged","widget":widget});
+ };
widget.openMenu = function() {
+ dashboard.log('entering openMenu function',1);
widget.element.find('.' + opts.menuClass).show();
};
widget.closeMenu = function() {
+ dashboard.log('entering closeMenu function',1);
widget.element.find('.' + opts.menuClass).hide();
};
widget.remove = function() {
+ dashboard.log('entering remove function',1);
widget.element.remove();
+ dashboard.log('widgetDeleted event thrown for widget ' + widget.id,2);
widget.element.trigger('widgetDeleted', widget);
+ dashboard.log('dashboardStateChange event thrown for widget ' +
widget.id,2);
dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetRemoved","widget":widget});
};
widget.serialize = function() {
+ dashboard.log('entering serialize function',1);
var r = '{"title" : "' + widget.title + '", "id" : "' + widget.id +
'", "column" : "' + widget.column + '","editurl" : "' + widget.editurl +
'","open" : ' + widget.open + ',"url" : "' + widget.url + '"';
if (typeof widget.metadata != 'undefined') {
@@ -327,6 +392,7 @@
return r;
};
widget.openFullscreen = function() {
+ dashboard.log('entering openFullscreen function',1);
widget.fullscreen = true;
// create a clone
@@ -346,6 +412,7 @@
};
widget.closeFullscreen = function() {
+ dashboard.log('entering closeFullscreen function',1);
widget.fullscreen = false;
// FIXME: this is not multiple dashboard proof
@@ -359,15 +426,22 @@
};
widget.openSettings = function() {
+ dashboard.log('entering openSettings function',1);
widget.element.find('.' +
opts.widgetContentClass).load(widget.editurl);
};
+ // called when widget is initialized
+ if (widget.open) {
+ widget.openContent();
+ }
+
return widget;
};
// FIXME: can this be done easier??
function getLayout(id) {
+ dashboard.log('entering getLayout function',1);
var r = null;
var first;
$.each(opts.layouts,function(i, item) {
@@ -382,6 +456,7 @@
$('.menutrigger').live('click', function() {
+ dashboard.log('widgetOpenMenu event thrown for widget ' + widget.id,2);
$(this).closest('.' + opts.widgetClass).trigger('widgetOpenMenu');
return false;
});
@@ -390,30 +465,38 @@
// add event handlers to the menu
$('.widgetopenfullscreen').live('click',function(e) {
// close the menu
+ dashboard.log('widgetCloseMenu event thrown for widget ' + widget.id,2);
$(this).closest('.' + opts.widgetClass).trigger('widgetCloseMenu');
+ dashboard.log('widgetOpenFullScreen event thrown for widget ' +
widget.id,2);
$(this).closest('.' + opts.widgetClass).trigger('widgetOpenFullScreen');
return false;
});
$('.controls li').live('click',function(e) {
// close the menu
+ dashboard.log('widgetCloseMenu event thrown for widget ' + widget.id,2);
$(this).closest('.' + opts.widgetClass).trigger('widgetCloseMenu');
+
// use the class on the li to determine what action to trigger
+ dashboard.log($(this).attr('class') + ' event thrown for widget ' +
widget.id,2);
$(this).closest('.' + opts.widgetClass).trigger($(this).attr('class'));
return false;
});
- // add the menu events
+ // add the menu events (by default triggers are connected in
dashboard_jsonfeed)
$('.' + opts.widgetClass).live('widgetCloseMenu',function() {
+ dashboard.log("Closing menu " + $(this).attr("id"),1);
dashboard.getWidget($(this).attr("id")).closeMenu();
});
$('.' + opts.widgetClass).live('widgetOpenMenu',function() {
+ dashboard.log("Opening menu " + $(this).attr("id"),1);
dashboard.getWidget($(this).attr("id")).openMenu();
});
$('.' + opts.widgetClass).live('widgetdelete',function() {
if (confirm(opts.deleteConfirmMessage)) {
+ dashboard.log("Removing widget " + $(this).attr("id"),1);
dashboard.getWidget($(this).attr("id")).remove();
}
});
@@ -421,28 +504,53 @@
$('.' + opts.widgetClass).live('widgetreload',function() {
dashboard.getWidget($(this).attr("id")).refreshContent();
});
+
+ $('.' + opts.widgetClass).live('widgetTitleChange',function(event, title) {
+ dashboard.getWidget($(this).attr("id")).setTitle(title);
+ });
$('.' + opts.widgetClass).live('widgetClose',function() {
+ dashboard.log("Closing widget " + $(this).attr("id"),1);
dashboard.getWidget($(this).attr("id")).closeContent();
});
$('.' + opts.widgetClass).live('widgetOpen',function() {
+ dashboard.log("Opening widget " + $(this).attr("id"),1);
dashboard.getWidget($(this).attr("id")).openContent();
});
+ $('.' + opts.widgetClass).live('metadataChange',function(object, name,
value) {
+ dashboard.log("Changing metadata for widget " + $(this).attr("id") + ",
metadata name: " + name + ", value: " + value, 1);
+ dashboard.getWidget($(this).attr("id")).setMetadata(name, value);
+ });
+
// Define a toggle event when clicking at the header
- $('.' + opts.widgetTitleClass).live('click',function() {
- wiObj = $(this).closest('.' + opts.widgetClass);
- var wi = dashboard.getWidget(wiObj.attr("id"));
- if (wi.open) {
- wiObj.trigger('widgetClose');
- } else {
- wiObj.trigger('widgetOpen');
+ $('.' + opts.widgetTitleClass).live('click',function(e) {
+ dashboard.log("Click on the header detected for widget " +
$(this).attr("id"),1);
+ if (!$(this).hasClass('noclick')) {
+ wiObj = $(this).closest('.' + opts.widgetClass);
+ var wi = dashboard.getWidget(wiObj.attr("id"));
+ if (wi.open) {
+ dashboard.log('widgetClose event thrown for widget ' + wi,2);
+ wiObj.trigger('widgetClose');
+ } else {
+ dashboard.log('widgetOpen event thrown for widget ' + wi,2);
+ wiObj.trigger('widgetOpen');
+ }
}
});
+
+ $("." + opts.widgetHeaderClass).live('mouseover',function () {
+ $(this).find('.' + opts.iconsClass).removeClass("hidden");
+ });
+ $("." + opts.widgetHeaderClass).live('mouseout', function () {
+ $(this).find('.' + opts.iconsClass).addClass("hidden");
+ });
+
$('#fullscreenclose').live('click', function(){
// find the widget and throw a high level event
+ dashboard.log('widgetCloseFullScreen event thrown',2);
dashboard.element.find('.' +
opts.widgetClass).trigger('widgetCloseFullScreen');
});
@@ -458,6 +566,7 @@
dashboard.getWidget($(this).attr("id")).openSettings();
});
+ if ($('#' + addOpts.dialogId).length == 0) dashboard.log('Unable to find '
+ addOpts.dialogId,5);
$('#' + addOpts.dialogId).dialog({
autoOpen: false,
height: 414,
@@ -473,6 +582,7 @@
}
});
+ if ($('#' + layoutOpts.dialogId).length == 0) dashboard.log('Unable to
find ' + layoutOpts.dialogId,5);
$('#' + layoutOpts.dialogId).dialog({
autoOpen: false,
height: 300,
@@ -481,16 +591,21 @@
});
$('.' + layoutOpts.editLayoutClass).live('click', function(){
+ dashboard.log('dashboardOpenLayoutDialog event thrown',2);
dashboard.element.trigger("dashboardOpenLayoutDialog");
});
dashboard.element.live('dashboardOpenLayoutDialog', function(){
+ dashboard.log('Opening dialog ' + layoutOpts.dialogId,5);
$('#' + layoutOpts.dialogId).dialog('open');
// add the layout images
var h = $('#' + layoutOpts.dialogId).find('.' + layoutOpts.layoutClass);
if (h.children().length == 0) {
+ dashboard.log('Number of layouts : ' + opts.layouts.length,1);
$.each(opts.layouts,function(i, item) {
+ dashboard.log('Applying template : ' + layoutOpts.layoutTemplate,1);
+ if ($('#' + layoutOpts.layoutTemplate).length == 0)
dashboard.log('Template "' + layoutOpts.layoutTemplate + ' not found',5);
h.append(tmpl($('#' + layoutOpts.layoutTemplate).html(), item));
});
}
@@ -504,8 +619,27 @@
dashboard.element.live('dashboardStateChange', function(){
- if (typeof opts.stateChangeUrl != 'undefined' && opts.stateChangeUrl !=
null) {
- $.post(opts.stateChangeUrl, { dashboard: dashboard.element.attr("id"),
settings: dashboard.serialize() } );
+ if (typeof opts.stateChangeUrl != 'undefined' && opts.stateChangeUrl !=
null) {
+ $.ajax({type: 'POST',
+ url: opts.stateChangeUrl,
+ data: { dashboard: dashboard.element.attr("id"), settings:
dashboard.serialize() },
+ success: function(data){
+ if (data == "NOK" || data.indexOf('<response>NOK</response>') !=
-1){
+ dashboard.log(opts.saveFailedMessage, 5);
+ dashboard.log('dashboardSaveFailed event thrown',2);
+ dashboard.element.trigger("dashboardSaveFailed");
+ } else {
+ dashboard.log('dashboardSuccessfulSaved event thrown',2);
+ dashboard.element.trigger("dashboardSuccessfulSaved");
+ }
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown){
+ dashboard.log(opts.saveFailedMessage, 5);
+ dashboard.log('dashboardSaveFailed event thrown',2);
+ dashboard.element.trigger("dashboardSaveFailed");
+ },
+ dataType: "text"
+ });
}
});
@@ -517,9 +651,11 @@
// FIXME: why doesn't the live construct work in this case
function bindSelectLayout() {
+ if ($('.' + layoutOpts.selectLayoutClass).length == 0)
dashboard.log('Unable to find ' + layoutOpts.selectLayoutClass,5);
$('.' + layoutOpts.selectLayoutClass).bind('click', function(e){
var currentLayout = dashboard.layout;
+ dashboard.log('dashboardCloseLayoutDialog event thrown',2);
dashboard.element.trigger('dashboardCloseLayoutDialog');
// Now set the new layout
@@ -528,9 +664,12 @@
// remove the class of the old layout
if (typeof opts.layoutClass != 'undefined') {
- dashboard.element.find('.' +
opts.layoutClass).removeClass(currentLayout.class).addClass(newLayout.class);
+ dashboard.element.find('.' +
opts.layoutClass).removeClass(currentLayout.classname).addClass(newLayout.classname);
+
+ fixSortableColumns();
// check if there are widgets in hidden columns, move them to the
first column
+ if ($('.' + opts.columnClass).length == 0) dashboard.log('Unable to
find ' + opts.columnClass,5);
dashboard.element.find('.' + opts.columnClass).each(function() {
if ($(this).css("display") == "none") {
// move the widgets to the first column
@@ -562,12 +701,14 @@
// FIXME: before or after dashboard.init(); ?
// throw an event upon changing the layout.
+ dashboard.log('dashboardChangeLayout event thrown',2);
$("body").trigger('dashboardChangeLayout');
});
}
$('.' + addOpts.selectCategoryClass).live('click', function(){
+ dashboard.log('selectCategory event thrown',2);
dashboard.element.trigger('selectCategory', $(this));
});
@@ -584,28 +725,36 @@
// get the widgets
url = dashboard.widgetCategories[$(obj).attr("id")];
+ dashboard.log('Getting JSON feed : ' + url,1);
$.getJSON(url, {"cache":true}, function(json) {
// load the widgets from the category
+ if (json.data == 0) dashboard.log('Empty data returned',3);
$.each(json.data, function(i,item){
dashboard.widgetsToAdd[item.id] = item;
+ dashboard.log('Applying template : ' + addOpts.widgetTemplate,1);
+ if ($('#' + addOpts.widgetTemplate).length == 0)
dashboard.log('Template "' + addOpts.widgetTemplate + ' not found',5);
var html = tmpl($('#' + addOpts.widgetTemplate).html(), item);
$('#' + addOpts.dialogId).find('.' +
addOpts.widgetClass).append(html);
});
});
+ dashboard.log('addWidgetDialogWidgetsLoaded event thrown',2);
dashboard.element.trigger('addWidgetDialogWidgetsLoaded');
});
$('.' + addOpts.addWidgetClass).live('click', function(){
var obj =
dashboard.widgetsToAdd[$(this).attr("id").replace('addwidget','')];
+ dashboard.log('dashboardAddWidget event thrown',2);
dashboard.element.trigger('dashboardAddWidget', obj);
+ dashboard.log('dashboardCloseWidgetDialog event thrown',2);
dashboard.element.trigger('dashboardCloseWidgetDialog');
});
$('.' + addOpts.openDialogClass).live('click', function(){
+ dashboard.log('dashboardOpenWidgetDialog event thrown',2);
dashboard.element.trigger('dashboardOpenWidgetDialog');
});
@@ -620,63 +769,73 @@
$('#' + addOpts.dialogId).find('.' + addOpts.categoryClass).empty();
$('#' + addOpts.dialogId).find('.' + addOpts.widgetClass).empty();
+ dashboard.log('Opening dialog ' + addOpts.dialogId,5);
$('#' + addOpts.dialogId).dialog('open');
+ dashboard.log('Getting JSON feed : ' + addOpts.widgetDirectoryUrl,1);
$.getJSON(addOpts.widgetDirectoryUrl, function(json) {
+ if (json.category == 0) dashboard.log('Empty data returned',3);
$.each(json.category, function(i,item){
// Add the categories to the dashboard
dashboard.widgetCategories[item.id] = item.url;
+ dashboard.log('Applying template : ' + addOpts.categoryTemplate,1);
+ if ($('#' + addOpts.categoryTemplate).length == 0)
dashboard.log('Template "' + addOpts.categoryTemplate + ' not found',5);
var html = tmpl($('#' + addOpts.categoryTemplate).html(),item);
$('#' + addOpts.dialogId).find('.' +
addOpts.categoryClass).append(html);
});
+ dashboard.log('addWidgetDialogCategoriesLoaded event thrown',2);
dashboard.element.trigger('addWidgetDialogCategoriesLoaded');
+ dashboard.log('selectCategory event thrown',2);
dashboard.element.trigger('selectCategory', $('#' +
addOpts.dialogId).find('.' + addOpts.categoryClass + '>li:first'));
});
});
-
+
return dashboard;
};
// Public static properties of dashboard. Default settings.
$.fn.dashboard.defaults = {
+ debuglevel: 3,
json_data: {},
fullscreenHeaderInner: '<img alt="Close this widget"
src="images/close.gif" /> Return to Dashboard',
loadingHtml: '<div class="loading"><img alt="Loading, please wait"
src="../themes/default/loading.gif" /><p>Loading...</p></div>',
- emptyColumnHtml: 'Drag your gadgets here',
+ emptyColumnHtml: 'Drag your widgets here',
tempDashboard: 'tempDashboard',
widgetTemplate: 'widgettemplate',
columnPrefix: 'column-',
opacity:"0.2",
deleteConfirmMessage: "Are you sure you want to delete this widget?",
-
+ saveFailedMessage: "Saving failed. Please reload the page.",
+ widgetNotFoundMessage: "The content of this widget is not available
anymore. You may remove this widget.",
columnClass: 'column',
widgetClass: 'widget',
- hoverClass: 'gadget-hover',
- menuClass: 'menu',
- widgetContentClass: 'dashboard-item-content',
+ menuClass: 'controls',
+ widgetContentClass: 'widgetcontent',
widgetTitleClass: 'widgettitle',
+ widgetHeaderClass: 'widgetheader',
+ iconsClass: 'icons',
addWidgetSettings: {
- openDialogClass: 'add-gadget',
+ openDialogClass: 'openaddwidgetdialog',
addWidgetClass: 'addwidget',
selectCategoryClass: 'selectcategory',
selectedCategoryClass: 'selected',
- categoryClass: 'categorylist',
- widgetClass: 'macro-list',
+ categoryClass: 'categories',
+ widgetClass: 'widgets',
- dialogId: 'add-gadget-dialog',
+ dialogId: 'addwidgetdialog',
categoryTemplate: 'categorytemplate',
widgetTemplate: 'addwidgettemplate'
},
editLayoutSettings: {
dialogId: 'editLayout',
- layoutClass: 'layoutSelection',
+ layoutClass: 'layoutselection',
selectLayoutClass: 'layoutchoice',
selectedLayoutClass: 'selected',
editLayoutClass: 'editlayout',
@@ -692,18 +851,11 @@
open: true,
fullscreen: false,
loaded: false,
- url: ''
+ url: '',
+ metadata: {}
}
};
-
- function log(msg) {
- if (typeof console != 'undefined') {
- console.log(msg);
- }
- }
-
-
})(jQuery); // end of closure
Added:
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/lib/jquery.dashboard.min.js
==============================================================================
--- (empty file)
+++
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/lib/jquery.dashboard.min.js
Fri Nov 26 11:43:09 2010
@@ -0,0 +1 @@
+(function(a){a.fn.dashboard=function(m){var k={};var f;var
j;k.layout;k.element=this;k.widgets={};k.widgetsToAdd={};k.widgetCategories={};k.initialized=false;k.serialize=function(){k.log("entering
serialize function",1);var o='{"layout": "'+k.layout.id+'", "data" : [';var
n=0;if(a("."+b.columnClass).length==0){k.log(b.columnClass+" class not
found",5)}a("."+b.columnClass).each(function(){a(this).children().each(function(){if(a(this).hasClass(b.widgetClass)){if(n>0){o+=","}o+=(k.getWidget(a(this).attr("id"))).serialize();n++}})});o+="]}";return
o};k.log=function(o,p){if(p>=b.debuglevel&&typeof console!="undefined"){var
n="";if(p==1){n="INFO"}if(p==2){n="EVENT"}if(p==3){n="WARNING"}if(p==5){n="ERROR"}console.log(n+"
- "+o)}};k.setLayout=function(n){k.log("entering setLayout function with
layout"+n,1);k.layout=n;f.remove();if(typeof
b.layoutClass!="undefined"){this.element.find("."+b.layoutClass).addClass(k.layout.classname)}else{this.element.html(k.layout.html)}a("."+b.columnClass).sortable({connectWith:a("."+b.columnClass),opacity:b.opacity,handle:"."+b.widgetHeaderClass,over:function(o,p){a(this).addClass("selectedcolumn")},out:function(o,p){a(this).removeClass("selectedcolumn")},receive:function(p,q){var
o=k.getWidget(q.item.attr("id"));o.setColumn(e(a(this).attr("class")))},deactivate:function(p,q){k.log("dropping
the widget",1);var o=a(this).children().length;if(o==0){k.log("adding the
empty text to the column",1);a(this).html('<div
class="emptycolumn">'+b.emptyColumnHtml+"</div>")}else{if(o==2){a(this).find(".emptycolumn").remove()}}},start:function(o,p){p.item.find("."+b.widgetTitleClass).addClass("noclick")},stop:function(o,p){setTimeout(function(){p.item.find("."+b.widgetTitleClass).removeClass("noclick")},300)}});g();k.log("dashboardLayoutLoaded
event thrown",2);k.element.trigger("dashboardLayoutLoaded")};function
g(){k.log("entering fixSortableColumns
function",1);a(".nonsortablecolumn").removeClass("nonsortablecolumn").addClass(b.columnClass);a("."+b.columnClass).filter(function(){return
a(thi!
s).css("
display")=="none"}).addClass("nonsortablecolumn").removeClass(b.columnClass)}function
e(o){k.log("entering getColumnIdentifier function",1);var q;var p=o.split("
");for(var
n=0;n<p.length;n++){if(p[n].indexOf(b.columnPrefix)===0){q=p[n]}}return
q.replace(b.columnPrefix,"")}k.loadLayout=function(){k.log("entering loadLayout
function",1);if(b.json_data.url.length>0){k.log("Getting JSON feed :
"+b.json_data.url,1);a.getJSON(b.json_data.url,function(n){if(n==null){alert("Unable
to get json. If you are using chrome: there is an issue with loading json with
local files. It works on a server
:-)",5);return}k.setLayout(c(n.layout));k.loadWidgets(n.data)})}else{k.setLayout(c(b.json_data.layout));k.loadWidgets(b.json_data.data)}};k.addWidget=function(r,p){k.log("entering
addWidget function",1);var q=r.id;if(typeof
k.widgets[q]!="undefined"&&a("#"+q).length>0){var
n=a("#"+q);p=k.widgets[q].column}else{k.log("Applying template :
"+b.widgetTemplate,1);if(a("#"+b.widgetTemplate).length==0){k.log('Template
"'+b.widgetTemplate+" not found",5)}var
o=tmpl(a("#"+b.widgetTemplate).html(),r);var
n=a(o);k.widgets[q]=h({id:q,element:n,column:r.column,url:(typeof
r.url!="undefined"?r.url:null),editurl:r.editurl,title:r.title,open:r.open,metadata:r.metadata})}n.appendTo(p);k.log("widgetAdded
event thrown for widget
"+q,2);k.widgets[q].element.trigger("widgetAdded",k.widgets[q]);if(k.initialized){k.log("dashboardStateChange
event thrown for widget
"+q,2);k.element.trigger("dashboardStateChange",{stateChange:"widgetAdded",widget:n})}};k.loadWidgets=function(n){k.log("entering
loadWidgets
function",1);k.element.find("."+b.columnClass).empty();a(n).each(function(){var
o=this.column;k.addWidget(this,k.element.find("."+b.columnPrefix+o))});a("#"+b.tempDashboard).find("."+b.widgetClass).each(function(){var
o=k.element.find("."+b.columnClass+":first");a(this).appendTo(o);k.getWidget(a(this).attr("id")).column=o.attr("id")});a("#"+b.tempDashboard).remove();a("."+b.columnClass).each(function(){if(a(this).children().length==0){a(this).html!
('<div c
lass="emptycolumn">'+b.emptyColumnHtml+"</div>")}});k.initialized=true};k.init=function(){k.log("entering
init function",1);k.loadLayout()};k.getWidget=function(n){k.log("entering
getWidget function",1);return k.widgets[n]};var
b=a.extend({},a.fn.dashboard.defaults,m);var
l=a.extend({},a.fn.dashboard.defaults.addWidgetSettings,m.addWidgetSettings);var
d=a.extend({},a.fn.dashboard.defaults.editLayoutSettings,m.editLayoutSettings);var
f=a(b.loadingHtml).appendTo(k.element);function h(n){k.log("entering widget
constructor",1);n=a.extend({},a.fn.dashboard.widget.defaults,n);n.openContent=function(){k.log("entering
openContent
function",1);n.open=true;if(!n.loaded){if(this.url!=""&&this.url!=null&&typeof
this.url!="undefined"){a(b.loadingHtml).appendTo(n.element.find("."+b.widgetContentClass));n.element.find("."+b.widgetContentClass).load(this.url,function(p,o,q){if(o=="error"){n.element.find("."+b.widgetContentClass).html(b.widgetNotFoundMessage)}n.loaded=true;n.element.find("."+b.widgetContentClass).show();k.log("widgetLoaded
event thrown for widget
"+n.id,2);n.element.trigger("widgetLoaded",n)})}else{k.log("widgetLoaded event
thrown",2);n.element.trigger("widgetLoaded",n)}}else{n.element.find("."+b.widgetContentClass).show()}if(k.initialized){k.log("dashboardStateChange
event thrown for widget
"+n.id,2);k.element.trigger("dashboardStateChange",{stateChange:"widgetOpened",widget:n})}};n.setColumn=function(o){k.log("entering
setColumn function and setting widget "+n.id+" into column
"+o,1);n.column=o;k.log("dashboardStateChange event thrown for widget
"+n.id,2);k.element.trigger("dashboardStateChange",{stateChange:"widgetMoved",widget:n})},n.refreshContent=function(){k.log("entering
refreshContent
function",1);n.loaded=false;if(n.open){n.openContent()}};n.setTitle=function(o){k.log("entering
setTitle
function",1);n.title=o;n.element.find("."+b.widgetTitleClass).html(o);if(k.initialized){k.log("dashboardStateChange
event thrown for widget
"+n.id,2);k.element.trigger("dashboardStateChange",{stateChange:"titleC!
hanged",
widget:n})}};n.closeContent=function(){k.log("entering closeContent
function",1);n.open=false;n.element.find("."+b.widgetContentClass).hide();k.log("dashboardStateChange
event thrown for widget
"+n.id,2);k.element.trigger("dashboardStateChange",{stateChange:"widgetClosed",widget:n})};n.setMetadata=function(o,p){k.log("entering
setMetadata function",1);if(typeof
n.metadata=="undefined"){n.metadata={}}n.metadata[o]=p;k.log("dashboardStateChange
event thrown for widget
"+n.id,2);k.element.trigger("dashboardStateChange",{stateChange:"metadataChanged",widget:n})};n.openMenu=function(){k.log("entering
openMenu
function",1);n.element.find("."+b.menuClass).show()};n.closeMenu=function(){k.log("entering
closeMenu
function",1);n.element.find("."+b.menuClass).hide()};n.remove=function(){k.log("entering
remove function",1);n.element.remove();k.log("widgetDeleted event thrown for
widget
"+n.id,2);n.element.trigger("widgetDeleted",n);k.log("dashboardStateChange
event thrown for widget
"+n.id,2);k.element.trigger("dashboardStateChange",{stateChange:"widgetRemoved",widget:n})};n.serialize=function(){k.log("entering
serialize function",1);var q='{"title" : "'+n.title+'", "id" : "'+n.id+'",
"column" : "'+n.column+'","editurl" : "'+n.editurl+'","open" : '+n.open+',"url"
: "'+n.url+'"';if(typeof n.metadata!="undefined"){q+=',"metadata":{';var
s=n.metadata;var o=0;for(var p in
s){if(o>0){q+=","}q+='"'+p+'":"'+s[p]+'"';o++}q+="}"}q+="}";return
q};n.openFullscreen=function(){k.log("entering openFullscreen
function",1);n.fullscreen=true;var q=n.element.clone();var p=a('<div
style="display:none"
id="tempdashboard"></div>');p.appendTo(a("body"));k.element.children().appendTo(p);var
o=a('<a id="fullscreenclose">Back</a><p /><ul
id="fullscreen"></ul>');o.appendTo(k.element);q.appendTo(a("#fullscreen"))};n.closeFullscreen=function(){k.log("entering
closeFullscreen
function",1);n.fullscreen=false;a("#fullscreenclose").remove();a("#fullscreen").remove();a("#tempdashboard").children().appendTo(k.element);a("#tempdashboard").remove()};n!
.openSet
tings=function(){k.log("entering openSettings
function",1);n.element.find("."+b.widgetContentClass).load(n.editurl)};if(n.open){n.openContent()}return
n}function c(p){k.log("entering getLayout function",1);var n=null;var
o;a.each(b.layouts,function(q,r){if(q==0){o=r}if(r.id==p){n=r}});if(n==null){n=o}return
n}a(".menutrigger").live("click",function(){k.log("widgetOpenMenu event thrown
for widget
"+h.id,2);a(this).closest("."+b.widgetClass).trigger("widgetOpenMenu");return
false});a(".widgetopenfullscreen").live("click",function(n){k.log("widgetCloseMenu
event thrown for widget
"+h.id,2);a(this).closest("."+b.widgetClass).trigger("widgetCloseMenu");k.log("widgetOpenFullScreen
event thrown for widget
"+h.id,2);a(this).closest("."+b.widgetClass).trigger("widgetOpenFullScreen");return
false});a(".controls li").live("click",function(n){k.log("widgetCloseMenu
event thrown for widget
"+h.id,2);a(this).closest("."+b.widgetClass).trigger("widgetCloseMenu");k.log(a(this).attr("class")+"
event thrown for widget
"+h.id,2);a(this).closest("."+b.widgetClass).trigger(a(this).attr("class"));return
false});a("."+b.widgetClass).live("widgetCloseMenu",function(){k.log("Closing
menu
"+a(this).attr("id"),1);k.getWidget(a(this).attr("id")).closeMenu()});a("."+b.widgetClass).live("widgetOpenMenu",function(){k.log("Opening
menu
"+a(this).attr("id"),1);k.getWidget(a(this).attr("id")).openMenu()});a("."+b.widgetClass).live("widgetdelete",function(){if(confirm(b.deleteConfirmMessage)){k.log("Removing
widget
"+a(this).attr("id"),1);k.getWidget(a(this).attr("id")).remove()}});a("."+b.widgetClass).live("widgetreload",function(){k.getWidget(a(this).attr("id")).refreshContent()});a("."+b.widgetClass).live("widgetTitleChange",function(n,o){k.getWidget(a(this).attr("id")).setTitle(o)});a("."+b.widgetClass).live("widgetClose",function(){k.log("Closing
widget
"+a(this).attr("id"),1);k.getWidget(a(this).attr("id")).closeContent()});a("."+b.widgetClass).live("widgetOpen",function(){k.log("Opening
widget "+a(this).attr("id"),1);k.getWidget(a(!
this).at
tr("id")).openContent()});a("."+b.widgetClass).live("metadataChange",function(o,n,p){k.log("Changing
metadata for widget "+a(this).attr("id")+", metadata name: "+n+", value:
"+p,1);k.getWidget(a(this).attr("id")).setMetadata(n,p)});a("."+b.widgetTitleClass).live("click",function(o){k.log("Click
on the header detected for widget
"+a(this).attr("id"),1);if(!a(this).hasClass("noclick")){wiObj=a(this).closest("."+b.widgetClass);var
n=k.getWidget(wiObj.attr("id"));if(n.open){k.log("widgetClose event thrown for
widget "+n,2);wiObj.trigger("widgetClose")}else{k.log("widgetOpen event thrown
for widget
"+n,2);wiObj.trigger("widgetOpen")}}});a("."+b.widgetHeaderClass).live("mouseover",function(){a(this).find("."+b.iconsClass).removeClass("hidden")});a("."+b.widgetHeaderClass).live("mouseout",function(){a(this).find("."+b.iconsClass).addClass("hidden")});a("#fullscreenclose").live("click",function(){k.log("widgetCloseFullScreen
event
thrown",2);k.element.find("."+b.widgetClass).trigger("widgetCloseFullScreen")});a("."+b.widgetClass).live("widgetOpenFullScreen",function(){k.getWidget(a(this).attr("id")).openFullscreen()});a("."+b.widgetClass).live("widgetCloseFullScreen",function(){k.getWidget(a(this).attr("id")).closeFullscreen()});a("."+b.widgetClass).live("widgetedit",function(){k.getWidget(a(this).attr("id")).openSettings()});if(a("#"+l.dialogId).length==0){k.log("Unable
to find
"+l.dialogId,5)}a("#"+l.dialogId).dialog({autoOpen:false,height:414,width:550,modal:true,buttons:{Cancel:function(){a(this).dialog("close")}},close:function(){}});if(a("#"+d.dialogId).length==0){k.log("Unable
to find
"+d.dialogId,5)}a("#"+d.dialogId).dialog({autoOpen:false,height:300,width:600,modal:true});a("."+d.editLayoutClass).live("click",function(){k.log("dashboardOpenLayoutDialog
event
thrown",2);k.element.trigger("dashboardOpenLayoutDialog")});k.element.live("dashboardOpenLayoutDialog",function(){k.log("Opening
dialog "+d.dialogId,5);a("#"+d.dialogId).dialog("open");var
n=a("#"+d.dialogId).find("."+d.layoutClass);if(n.children().!
length==
0){k.log("Number of layouts :
"+b.layouts.length,1);a.each(b.layouts,function(o,p){k.log("Applying template :
"+d.layoutTemplate,1);if(a("#"+d.layoutTemplate).length==0){k.log('Template
"'+d.layoutTemplate+" not
found",5)}n.append(tmpl(a("#"+d.layoutTemplate).html(),p))})}a("."+d.selectLayoutClass).removeClass(d.selectedLayoutClass);a("#"+k.layout.id).addClass(d.selectedLayoutClass);i()});k.element.live("dashboardStateChange",function(){if(typeof
b.stateChangeUrl!="undefined"&&b.stateChangeUrl!=null){a.ajax({type:"POST",url:b.stateChangeUrl,data:{dashboard:k.element.attr("id"),settings:k.serialize()},success:function(n){if(n=="NOK"||n.indexOf("<response>NOK</response>")!=-1){k.log(b.saveFailedMessage,5);k.log("dashboardSaveFailed
event
thrown",2);k.element.trigger("dashboardSaveFailed")}else{k.log("dashboardSuccessfulSaved
event
thrown",2);k.element.trigger("dashboardSuccessfulSaved")}},error:function(n,p,o){k.log(b.saveFailedMessage,5);k.log("dashboardSaveFailed
event
thrown",2);k.element.trigger("dashboardSaveFailed")},dataType:"text"})}});k.element.live("dashboardCloseLayoutDialog",function(){a("#"+d.dialogId).dialog("close")});function
i(){if(a("."+d.selectLayoutClass).length==0){k.log("Unable to find
"+d.selectLayoutClass,5)}a("."+d.selectLayoutClass).bind("click",function(q){var
o=k.layout;k.log("dashboardCloseLayoutDialog event
thrown",2);k.element.trigger("dashboardCloseLayoutDialog");var
p=c(a(this).attr("id"));k.layout=p;if(typeof
b.layoutClass!="undefined"){k.element.find("."+b.layoutClass).removeClass(o.classname).addClass(p.classname);g();if(a("."+b.columnClass).length==0){k.log("Unable
to find
"+b.columnClass,5)}k.element.find("."+b.columnClass).each(function(){if(a(this).css("display")=="none"){a(this).children().appendTo(k.element.find("."+b.columnClass+":first"))}a(".emptycolumn").remove();a("."+b.columnClass).each(function(){if(a(this).children().length==0){a(this).html('<div
class="emptycolumn">'+b.emptyColumnHtml+"</div>")}})})}else{var n=a('<div
style="display:none" id="'+b.tempDashb!
oard+'">
</div>');n.appendTo(a("body"));k.element.children().appendTo(n);k.init()}k.log("dashboardChangeLayout
event
thrown",2);a("body").trigger("dashboardChangeLayout")})}a("."+l.selectCategoryClass).live("click",function(){k.log("selectCategory
event
thrown",2);k.element.trigger("selectCategory",a(this))});k.element.live("selectCategory",function(o,n){a("."+l.selectCategoryClass).removeClass(l.selectedCategoryClass);a("#"+l.dialogId).find("."+l.widgetClass).empty();a(n).addClass(l.selectedCategoryClass);url=k.widgetCategories[a(n).attr("id")];k.log("Getting
JSON feed :
"+url,1);a.getJSON(url,{cache:true},function(p){if(p.data==0){k.log("Empty data
returned",3)}a.each(p.data,function(r,s){k.widgetsToAdd[s.id]=s;k.log("Applying
template :
"+l.widgetTemplate,1);if(a("#"+l.widgetTemplate).length==0){k.log('Template
"'+l.widgetTemplate+" not found",5)}var
q=tmpl(a("#"+l.widgetTemplate).html(),s);a("#"+l.dialogId).find("."+l.widgetClass).append(q)})});k.log("addWidgetDialogWidgetsLoaded
event
thrown",2);k.element.trigger("addWidgetDialogWidgetsLoaded")});a("."+l.addWidgetClass).live("click",function(){var
n=k.widgetsToAdd[a(this).attr("id").replace("addwidget","")];k.log("dashboardAddWidget
event
thrown",2);k.element.trigger("dashboardAddWidget",n);k.log("dashboardCloseWidgetDialog
event
thrown",2);k.element.trigger("dashboardCloseWidgetDialog")});a("."+l.openDialogClass).live("click",function(){k.log("dashboardOpenWidgetDialog
event
thrown",2);k.element.trigger("dashboardOpenWidgetDialog")});k.element.live("dashboardCloseWidgetDialog",function(){a("#"+l.dialogId).dialog("close")});k.element.live("dashboardOpenWidgetDialog",function(){a("#"+l.dialogId).find("."+l.categoryClass).empty();a("#"+l.dialogId).find("."+l.widgetClass).empty();k.log("Opening
dialog "+l.dialogId,5);a("#"+l.dialogId).dialog("open");k.log("Getting JSON
feed :
"+l.widgetDirectoryUrl,1);a.getJSON(l.widgetDirectoryUrl,function(n){if(n.category==0){k.log("Empty
data
returned",3)}a.each(n.category,function(p,q){k.widgetCategories[q.id]=q.url;k.log("!
Applying
template :
"+l.categoryTemplate,1);if(a("#"+l.categoryTemplate).length==0){k.log('Template
"'+l.categoryTemplate+" not found",5)}var
o=tmpl(a("#"+l.categoryTemplate).html(),q);a("#"+l.dialogId).find("."+l.categoryClass).append(o)});k.log("addWidgetDialogCategoriesLoaded
event
thrown",2);k.element.trigger("addWidgetDialogCategoriesLoaded");k.log("selectCategory
event
thrown",2);k.element.trigger("selectCategory",a("#"+l.dialogId).find("."+l.categoryClass+">li:first"))})});return
k};a.fn.dashboard.defaults={debuglevel:3,json_data:{},fullscreenHeaderInner:'<img
alt="Close this widget" src="images/close.gif" /> Return to
Dashboard',loadingHtml:'<div class="loading"><img alt="Loading, please wait"
src="../themes/default/loading.gif"
/><p>Loading...</p></div>',emptyColumnHtml:"Drag your widgets
here",tempDashboard:"tempDashboard",widgetTemplate:"widgettemplate",columnPrefix:"column-",opacity:"0.2",deleteConfirmMessage:"Are
you sure you want to delete this widget?",saveFailedMessage:"Saving failed.
Please reload the page.",widgetNotFoundMessage:"The content of this widget is
not available anymore. You may remove this
widget.",columnClass:"column",widgetClass:"widget",menuClass:"controls",widgetContentClass:"widgetcontent",widgetTitleClass:"widgettitle",widgetHeaderClass:"widgetheader",iconsClass:"icons",addWidgetSettings:{openDialogClass:"openaddwidgetdialog",addWidgetClass:"addwidget",selectCategoryClass:"selectcategory",selectedCategoryClass:"selected",categoryClass:"categories",widgetClass:"widgets",dialogId:"addwidgetdialog",categoryTemplate:"categorytemplate",widgetTemplate:"addwidgettemplate"},editLayoutSettings:{dialogId:"editLayout",layoutClass:"layoutselection",selectLayoutClass:"layoutchoice",selectedLayoutClass:"selected",editLayoutClass:"editlayout",layoutTemplate:"selectlayouttemplate"}};a.fn.dashboard.widget={defaults:{open:true,fullscreen:false,loaded:false,url:"",metadata:{}}}})(jQuery);(function(){var
b={};this.tmpl=function a(e,d){var
c=!/\W/.test(e)?b[e]=b[e]||a(document.getElementById(e).in!
nerHTML)
:new Function("obj","var
p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+e.replace(/[\r\t\n]/g,"
").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return
p.join('');");return d?c(d):c}})();
\ No newline at end of file
Modified:
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/service/GadgetManagementServiceImpl.java
==============================================================================
---
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/service/GadgetManagementServiceImpl.java
(original)
+++
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/service/GadgetManagementServiceImpl.java
Fri Nov 26 11:43:09 2010
@@ -220,7 +220,7 @@
}
if (!skip) {
// Be sure to add the security token
- addSecurityToken(gadgetDefinition.getUrl(), gadget,
request);
+ addSecurityToken(gadget, request);
gadgets.add(gadget);
}
}
@@ -328,7 +328,7 @@
gadget =
retrieveGadget(gadgetId.substring(gadgetId.indexOf("-") + 1));
}
if (gadget != null) {
- addSecurityToken(gadgetId, gadget, request);
+ addSecurityToken(gadget, request);
// FIXME: for now handle layout here
if (column == 1) {
gadget.put("column", "first");
@@ -617,7 +617,7 @@
}
// Adds a security token
- private void addSecurityToken(String gadgetUrl, JSONObject gadget,
HttpServletRequest request)
+ private void addSecurityToken(JSONObject gadget, HttpServletRequest
request)
throws BlobCrypterException, JSONException {
// TODO: This is the same key as in securitytokenkey.txt file of the
shindig application bundle
// But we are too lazy to load that key from the file
@@ -625,7 +625,7 @@
String hostName = request.getServerName();
BasicBlobCrypter blobCrypter = new BasicBlobCrypter(key.getBytes());
BlobCrypterSecurityToken st = new
BlobCrypterSecurityToken(blobCrypter, "default", hostName);
- st.setAppUrl(gadgetUrl);
+ st.setAppUrl(gadget.getJSONObject("metadata").getString("gadgeturl"));
Authorization auth = (Authorization)
BasicHttpSession.getSession(request).getValue("authorization");
if (auth != null) {
@@ -636,7 +636,7 @@
st.setViewerId("anonymous");
st.setOwnerId("anonymous");
}
-
+
String securityToken = Utf8UrlCoder.encode(st.encrypt());
gadget.put("securetoken", securityToken);
}