PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/WP7.1/Templates/VB/WPCloud.SQL.ACS/WindowsPhoneCloud.Web/Scripts/storage.permissions.js

#
JavaScript | 150 lines | 129 code | 21 blank | 0 comment | 23 complexity | 69dce78ae04a126752b475aaaaa53aa0 MD5 | raw file
  1. function EnableContent(userId, actionUrl) {
  2. var useTables = $("[id='Tables_" + userId + "']:checked").val() !== undefined;
  3. var useBlobs = $("[id='Blobs_" + userId + "']:checked").val() !== undefined;
  4. var useQueues = $("[id='Queues_" + userId + "']:checked").val() !== undefined;
  5. var useSql = $("[id='Sql_" + userId + "']:checked").val() !== undefined;
  6. actionUrl = actionUrl.replace("_user_", encodeURIComponent(userId));
  7. actionUrl = actionUrl.replace("_useTables_", encodeURIComponent(useTables));
  8. actionUrl = actionUrl.replace("_useBlobs_", encodeURIComponent(useBlobs));
  9. actionUrl = actionUrl.replace("_useQueues_", encodeURIComponent(useQueues));
  10. actionUrl = actionUrl.replace("_useSql_", encodeURIComponent(useSql));
  11. $.ajax({ url: actionUrl, cache: false, type: "POST" });
  12. }
  13. function SetPublic(storage, actionUrl) {
  14. var isPublic = $("[id='Public_" + storage + "']").val() == "false";
  15. actionUrl = actionUrl.replace("_storage_", encodeURIComponent(storage));
  16. actionUrl = actionUrl.replace("_isPublic_", encodeURIComponent(isPublic));
  17. if (isPublic) {
  18. $("[id='Public_" + storage + "']").val("true");
  19. $("[id='Public_" + storage + "_Public']").removeClass("hidden");
  20. $("[id='Public_" + storage + "_Private']").addClass("hidden");
  21. $("[id='Public_" + storage + "_SetPublic']").addClass("hidden");
  22. $("[id='Public_" + storage + "_SetPrivate']").removeClass("hidden");
  23. } else {
  24. $("[id='Public_" + storage + "']").val("false");
  25. $("[id='Public_" + storage + "_Public']").addClass("hidden");
  26. $("[id='Public_" + storage + "_Private']").removeClass("hidden");
  27. $("[id='Public_" + storage + "_SetPublic']").removeClass("hidden");
  28. $("[id='Public_" + storage + "_SetPrivate']").addClass("hidden");
  29. }
  30. $("input[name^='" + storage + "'][type='checkbox']").each(function (ix, el) {
  31. el.disabled = isPublic;
  32. });
  33. $.ajax({ url: actionUrl, cache: false, type: "POST" });
  34. }
  35. function SetPermission(containerId, userId, storage, addPermissionActionUrl, removePermissionActionUrl) {
  36. var hasAccess = $("[id='" + storage + "_" + containerId + "']:checked").val() !== undefined;
  37. actionUrl = hasAccess ? addPermissionActionUrl : removePermissionActionUrl;
  38. actionUrl = actionUrl.replace("_storage_", encodeURIComponent(storage));
  39. actionUrl = actionUrl.replace("_user_", encodeURIComponent(userId));
  40. $.ajax({ url: actionUrl, cache: false, type: "POST" });
  41. }
  42. function SendMicrosoftNotification(containerId, userId, actionUrl) {
  43. var message = $("[id='Push_" + containerId + "_Message']").val();
  44. actionUrl = actionUrl.replace("_user_", encodeURIComponent(userId));
  45. actionUrl = actionUrl.replace("_message_", encodeURIComponent(message));
  46. SetMicrosoftPushNotificationImageStatus(containerId, "Sending");
  47. $.ajax({
  48. url: actionUrl,
  49. cache: false,
  50. type: "POST",
  51. success: function (data) {
  52. if (typeof data == "string") {
  53. var msg = "<img src=\"/Content/images/error_small.png\" alt=\"An error has ocurred while sending the push notification.\" title=\"An error has ocurred while sending the push notification.\" />";
  54. msg += " " + data;
  55. SetMicrosoftPushNotificationImageStatus(containerId, "Result", msg);
  56. } else {
  57. var msg = "";
  58. $.each(data, function (i, e) {
  59. if (e.Status != "Success") {
  60. msg += "<img src=\"/Content/images/error_small.png\" alt=\"An error has ocurred while sending the push notification.\" title=\"An error has ocurred while sending the push notification.\" />"
  61. msg += " Device " + (i + 1) + " / " + data.length + " failed: " + e.Description + "<br />";
  62. } else {
  63. msg += "<img src=\"/Content/images/success_small.png\" alt=\"Notification successfully sent.\" title=\"Notification successfully sent.\" />"
  64. msg += " Device " + (i + 1) + " / " + data.length + " success. <br />";
  65. }
  66. });
  67. SetMicrosoftPushNotificationImageStatus(containerId, "Result", msg);
  68. }
  69. },
  70. error: function (data) {
  71. SetMicrosoftPushNotificationImageStatus(containerId, "Result", "Error accessing Push Notification Service.");
  72. }
  73. });
  74. }
  75. function SendAppleNotification(actionUrl) {
  76. var deviceId = $("#appleDeviceId").val();
  77. var message = $("#appleMessage").val();
  78. actionUrl = actionUrl.replace("_deviceId_", encodeURIComponent(deviceId));
  79. actionUrl = actionUrl.replace("_message_", encodeURIComponent(message));
  80. SetApplePushNotificationImageStatus("Sending");
  81. $.ajax({
  82. url: actionUrl,
  83. cache: false,
  84. type: "POST",
  85. success: function (data) {
  86. if ((typeof data == "string") && (data.toLowerCase() == "success")) {
  87. SetApplePushNotificationImageStatus("Success", "Notification successfully sent.");
  88. } else {
  89. SetApplePushNotificationImageStatus("Failed", data);
  90. }
  91. },
  92. error: function (data) {
  93. SetApplePushNotificationImageStatus("Failed", "Error accessing Apple Push Notification Service.");
  94. }
  95. });
  96. }
  97. function SetMicrosoftPushNotificationImageStatus(containerId, status, tooltip) {
  98. if (status == "Sending") {
  99. $("[id='Push_" + containerId + "_Sending']").show();
  100. $("[id='Push_" + containerId + "_Result']").html("");
  101. }
  102. else {
  103. $("[id='Push_" + containerId + "_Sending']").hide();
  104. $("[id='Push_" + containerId + "_Result']").html(tooltip);
  105. }
  106. }
  107. function SetApplePushNotificationImageStatus(status, tooltip) {
  108. if (status == "Sending") {
  109. $("#sendingNotificationStatus").show();
  110. $("#successNotificationStatus").hide();
  111. $("#failedNotificationStatus").hide();
  112. $("#messageStatus").hide();
  113. $("#messageStatus").html("");
  114. }
  115. else if (status == "Success") {
  116. $("#sendingNotificationStatus").hide();
  117. $("#successNotificationStatus").show();
  118. $("#failedNotificationStatus").hide();
  119. $("#messageStatus").html(tooltip);
  120. $("#messageStatus").show();
  121. }
  122. else {
  123. $("#sendingNotificationStatus").hide();
  124. $("#successNotificationStatus").hide();
  125. $("#failedNotificationStatus").show();
  126. $("#messageStatus").html(tooltip);
  127. $("#messageStatus").show();
  128. }
  129. }