Author: ivol37 at gmail.com
Date: Fri Nov 12 16:25:38 2010
New Revision: 422
Log:
[AMDATU-169] Moved REST calls to separate JS, the hooks however must still be
removed from the dashboard plugin
Added:
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/gadgets_appdata.js
Modified:
trunk/amdatu-opensocial/dashboard/src/main/resources/jsp/dashboard.jsp
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/dashboard.js
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/lib/jquery.dashboard.js
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 12 16:25:38 2010
@@ -16,9 +16,10 @@
<script type="text/javascript"
src="/dashboard/static/js/lib/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript"
src="/dashboard/static/js/lib/jquery.dashboard.js"></script>
<script type="text/javascript"
src="/dashboard/static/js/lib/themeroller.js"></script>
+ <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">')
@@ -82,7 +83,7 @@
</div>
<div id="footer">
- Amdatu 0.0.4 - 2010 - <a href="http://amdatu.org">http://amdatu.org</a>
+ Amdatu 0.0.6 - 2010 - <a href="http://amdatu.org">http://amdatu.org</a>
</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 12 16:25:38 2010
@@ -133,7 +133,7 @@
});
dashboard.element.live('dashboardAddWidget',function(e, obj){
- dashboard.addWidgetToAppData(obj, startId++);
+ addWidgetToAppData(obj, startId++, dashboard);
});
dashboard.init();
Added:
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/gadgets_appdata.js
==============================================================================
--- (empty file)
+++
trunk/amdatu-opensocial/dashboard/src/main/resources/static/js/gadgets_appdata.js
Fri Nov 12 16:25:38 2010
@@ -0,0 +1,80 @@
+// Retrieves the gadgets stored in the AppData of the current user
+retrieveCurrentWidgetsInAppData = function(securetoken) {
+ var currentGadgets;
+ var url = "/social/rest/appdata/@me/@self?&st=" + securetoken;
+ jQuery.ajax({
+ url: url,
+ type: "GET",
+ contentType: "application/json",
+ dataType: "json",
+ async:false,
+ success: function(response) {
+ $.each(response.entry, function(i, item){
+ currentGadgets = item["registeredgadgets"];
+ });
+ },
+ error: function(request, textStatus, errorThrown) {
+ alert("Could not find AppData for this user");
+ }
+ });
+ return currentGadgets;
+}
+
+// Adds a gadget to the AppData of the current user
+addWidgetToAppData = function(obj, startId, dashboard) {
+ var currentGadgets = retrieveCurrentWidgetsInAppData(obj.securetoken);
+
+ // use appData opensocial call to add this gadget to the users appData
+ var postdata = '{"registeredgadgets":"';
+ if (currentGadgets == "" || !currentGadgets) {
+ postdata += obj.id + '"}';
+ } else {
+ postdata += currentGadgets + " " + obj.id + '"}';
+ }
+
+ var url = "/social/rest/appdata/@me/@self/" + obj.id +
"?fields=registeredgadgets&st=" + obj.securetoken;
+ jQuery.ajax({
+ url: url,
+ type: "PUT",
+ data: postdata,
+ contentType: "application/json",
+ dataType: "json",
+ async:false,
+ success: function(response) {
+ dashboard.addWidget({
+ "id":startId,
+ "title":obj.title,
+ "url":obj.url,
+ "securetoken":obj.securetoken,
+ "metadata":obj.metadata
+ }, dashboard.element.find('.column:first'));
+ },
+ error: function(request, textStatus, errorThrown) {
+ alert("Gadget could not be added to user profile. Error: " +
textStatus);
+ }
+ });
+}
+
+// Removes a gadget from the AppData of the current user
+removeWidgetFromAppData = function(gadgetId, securetoken, dashboard) {
+ var currentGadgets = retrieveCurrentWidgetsInAppData(securetoken);
+ currentGadgets = currentGadgets.replace(gadgetId, "");
+
+ var postdata = '{"registeredgadgets":"' + currentGadgets + '"}';
+
+ var url = "/social/rest/appdata/@me/@self/?fields=registeredgadgets&st=" +
securetoken;
+ jQuery.ajax({
+ url: url,
+ type: "PUT",
+ data: postdata,
+ contentType: "application/json",
+ dataType: "json",
+ async:false,
+ success: function(response) {
+ dashboard.getWidget(gadgetId).remove();
+ },
+ error: function(request, textStatus, errorThrown) {
+ alert("Gadget could not be removed from user profile.");
+ }
+ });
+}
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 12 16:25:38 2010
@@ -144,84 +144,6 @@
}
};
- dashboard.retrieveCurrentWidgetsInAppData = function(securetoken) {
- // First retrieve current appData
- var currentGadgets;
- var url = "/social/rest/appdata/@me/@self?&st=" +
securetoken;
- jQuery.ajax({
- url: url,
- type: "GET",
- contentType: "application/json",
- dataType: "json",
- async:false,
- success: function(response) {
- $.each(response.entry,
function(i, item){
- currentGadgets
= item["registeredgadgets"];
- });
- },
- error: function(request,
textStatus, errorThrown) {
- alert("Could
not find AppData for this user");
- }
- });
- return currentGadgets;
- }
-
- dashboard.addWidgetToAppData = function(obj, startId) {
- var currentGadgets =
dashboard.retrieveCurrentWidgetsInAppData(obj.securetoken);
-
- // use appData opensocial call to add this gadget to the users appData
- var postdata = '{"registeredgadgets":"';
- if (currentGadgets == "" || !currentGadgets) {
- postdata += obj.id + '"}';
- } else {
- postdata += currentGadgets + " " + obj.id +
'"}';
- }
-
- var url = "/social/rest/appdata/@me/@self/" + obj.id +
"?fields=registeredgadgets&st=" + obj.securetoken;
- jQuery.ajax({
- url: url,
- type: "PUT",
- data: postdata,
- contentType: "application/json",
- dataType: "json",
- async:false,
- success: function(response) {
- dashboard.addWidget({
- "id":startId,
-
"title":obj.title,
- "url":obj.url,
-
"securetoken":obj.securetoken,
-
"metadata":obj.metadata
- },
dashboard.element.find('.column:first'));
- },
- error: function(request, textStatus,
errorThrown) {
- alert("Gadget could not be
added to user profile. Error: " + textStatus);
- }
- });
- }
-
- dashboard.removeWidgetFromAppData = function(gadgetId,
securetoken) {
- var currentGadgets =
dashboard.retrieveCurrentWidgetsInAppData(securetoken);
- currentGadgets = currentGadgets.replace(gadgetId, "");
-
- var postdata = '{"registeredgadgets":"' +
currentGadgets + '"}';
-
- var url =
"/social/rest/appdata/@me/@self/?fields=registeredgadgets&st=" + securetoken;
- jQuery.ajax({
- url: url,
- type: "PUT",
- data: postdata,
- contentType: "application/json",
- dataType: "json",
- async:false,
- success: function(response) {
- dashboard.getWidget(gadgetId).remove();
- },
- error: function(request, textStatus,
errorThrown) {
- alert("Gadget could not be
removed from user profile.");
- }
- });
- }
dashboard.addWidget = function(obj, column) {
// add the widget to the column
@@ -262,13 +184,13 @@
}
dashboard.appDataDone = function(data) {
- if (data.get('set_data').hadError()) {
- alert("Gadget could not be added");
- } else {
- alert("Gadget added to appData");
- }
- }
-
+ if (data.get('set_data').hadError()) {
+ alert("Gadget could not be added");
+ } else {
+ alert("Gadget added to appData");
+ }
+ }
+
dashboard.loadWidgets = function(data) {
dashboard.element.find('.' + opts.columnClass).empty();
@@ -492,10 +414,9 @@
$('.' + opts.widgetClass).live('widgetdelete',function() {
if (confirm(opts.deleteConfirmMessage)) {
-
- // Remove the widget from the AppData of the Person in the OpenSocial
container
- var securetoken = dashboard.getWidget($(this).attr("id")).securetoken;
- dashboard.removeWidgetFromAppData($(this).attr("id"), securetoken);
+ // Remove the widget from the AppData of the Person in the OpenSocial
container
+ var securetoken = dashboard.getWidget($(this).attr("id")).securetoken;
+ removeWidgetFromAppData($(this).attr("id"), securetoken, dashboard);
}
});