Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <base target="_top" />
  5. <link
  6. rel="stylesheet"
  7. href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"
  8. />
  9. <!-- The CSS package above applies Google styling to buttons and other elements. -->
  10. <style>
  11. .branding-below {
  12. bottom: 54px;
  13. top: 0;
  14. }
  15. .branding-text {
  16. left: 7px;
  17. position: relative;
  18. top: 3px;
  19. }
  20. .logo {
  21. vertical-align: middle;
  22. }
  23. .width-100 {
  24. width: 100%;
  25. box-sizing: border-box;
  26. -webkit-box-sizing: border-box;
  27. -moz-box-sizing: border-box;
  28. }
  29. label {
  30. font-weight: bold;
  31. }
  32. #seta-options,
  33. #setb-options {
  34. background-color: #eee;
  35. border-color: #eee;
  36. border-width: 5px;
  37. border-style: solid;
  38. display: none;
  39. }
  40. #seta-text,
  41. #setb-text,
  42. #button-bar,
  43. #submit-subject {
  44. margin-bottom: 10px;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <div class="sidebar branding-below">
  50. <form>
  51. <div class="block">
  52. <input type="checkbox" id="setting-a" />
  53. <label for="setting-a">Collect generated document urls in spreadsheet?</label>
  54. </div>
  55. <div class="block form-group" id="seta-options">
  56. <label for="seta-text">
  57. Spreadsheet to write to (URL)
  58. </label>
  59. <input type="text" class="width-100" id="seta-text" />
  60. <!-- more options -->
  61. </div>
  62.  
  63. <div class="block" id="button-bar">
  64. <button class="action" id="save-settings">Save</button>
  65. </div>
  66. </form>
  67. </div>
  68.  
  69. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  70. <script>
  71. /**
  72. * On document load, assign required handlers to each element,
  73. * and attempt to load any saved settings.
  74. */
  75. $(function() {
  76. $("#save-settings").click(saveSettingsToServer);
  77. $("#setting-a").click(toggleexportToSheet);
  78. google.script.run
  79. .withSuccessHandler(loadSettings)
  80. .withFailureHandler(showStatus)
  81. .withUserObject($("#button-bar").get())
  82. .getSettings();
  83. });
  84.  
  85. /**
  86. * Callback function that populates the notification options using
  87. * previously saved values.
  88. *
  89. * @param {Object} settings The saved settings from the client.
  90. */
  91. function loadSettings(settings) {
  92. $("#seta-text").val(settings.sheetURL);
  93.  
  94. if (settings.exportToSheet === "true") {
  95. $("#setting-a").prop("checked", true);
  96. $("#seta-options").show();
  97. }
  98. }
  99.  
  100. /**
  101. * Toggles the visibility of the setting a options.
  102. */
  103. function toggleexportToSheet() {
  104. $("#status").remove();
  105. if ($("#setting-a").is(":checked")) {
  106. $("#seta-options").show();
  107. } else {
  108. $("#seta-options").hide();
  109. }
  110. }
  111.  
  112. /**
  113. * Collects the options specified in the add-on sidebar and sends them to
  114. * be saved as Properties on the server.
  115. */
  116. function saveSettingsToServer() {
  117. this.disabled = true;
  118. $("#status").remove();
  119. var exportToSheet = $("#setting-a").is(":checked");
  120. var settings = {
  121. 'exportToSheet': exportToSheet
  122. };
  123.  
  124. // Only save if export selected
  125. if (exportToSheet) {
  126. settings.sheetURL = $("#seta-text")
  127. .val()
  128. .trim();
  129. }
  130.  
  131. // Save the settings on the server
  132. google.script.run
  133. .withSuccessHandler(function(msg, element) {
  134. showStatus("Saved settings", $("#button-bar"));
  135. element.disabled = false;
  136. })
  137. .withFailureHandler(function(msg, element) {
  138. showStatus(msg, $("#button-bar"));
  139. // showStatus("failed", $("#button-bar"));
  140. element.disabled = false;
  141. })
  142. .withUserObject(this)
  143. .saveSettings(settings);
  144. }
  145.  
  146. /**
  147. * Inserts a div that contains an status message after a given element.
  148. *
  149. * @param {String} msg The status message to display.
  150. * @param {Object} element The element after which to display the Status.
  151. */
  152. function showStatus(msg, element) {
  153. var div = $("<div>")
  154. .attr("id", "status")
  155. .attr("class", "error")
  156. .text(msg);
  157. $(element).after(div);
  158. }
  159. </script>
  160. </body>
  161. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement