/Ringify/Ringify.Web/Scripts/storage.permissions.js

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