jira-create-issue-form.html 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <link rel="import" href="../../../bower_components/polymer/polymer.html">
  2. <link rel="import" href="../../../bower_components/iron-autogrow-textarea/iron-autogrow-textarea.html">
  3. <link rel="import" href="../../../bower_components/iron-ajax/iron-ajax.html">
  4. <link rel="import" href="../../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
  5. <link rel="import" href="../../../bower_components/iron-form/iron-form.html">
  6. <link rel="import" href="../../../bower_components/paper-button/paper-button.html">
  7. <link rel="import" href="../../../bower_components/paper-dialog/paper-dialog.html">
  8. <link rel="import" href="../../../bower_components/paper-icon-button/paper-icon-button.html">
  9. <link rel="import" href="../../../bower_components/paper-input/paper-input.html">
  10. <link rel="import" href="../../../bower_components/paper-material/paper-material.html">
  11. <link rel="import" href="../../../bower_components/paper-spinner/paper-spinner.html">
  12. <link rel="import" href="../../../bower_components/vaadin-combo-box/vaadin-combo-box.html">
  13. <!--
  14. An element for creating an issue on JIRA
  15. -->
  16. <dom-module id="jira-create-issue-form">
  17. <template>
  18. <style is="custom-style" include="iron-flex iron-positioning iron-flex-alignment"></style>
  19. <style>
  20. .container {
  21. margin: 16px;
  22. background-color: white;
  23. }
  24. form {
  25. margin: 8px;
  26. }
  27. .separator {
  28. margin: 8px 0;
  29. }
  30. iron-autogrow-textarea {
  31. width: 100%;
  32. }
  33. .button {
  34. color: white;
  35. }
  36. .submit {
  37. background-color: var(--zebra-blue);
  38. }
  39. </style>
  40. <paper-material class="layout vertical container">
  41. <div class="layout horizontal end-justified">
  42. <paper-icon-button id="help" icon="help" on-tap="_openHelp"></paper-icon-button>
  43. </div>
  44. <form id="issueForm" is="iron-form" method="post" action="/api/jira/issue">
  45. <vaadin-combo-box id="issueType" class="flex" items="[[issueTypes]]"
  46. label="Issue Type" required></vaadin-combo-box>
  47. <vaadin-combo-box id="tool" class="flex" items="[[tools]]" label="Tool" required></vaadin-combo-box>
  48. <paper-input id="summary" class="flex" label="Summary" required></paper-input>
  49. <div class="separator"></div>
  50. <span>Description</span>
  51. <div class="layout horizontal">
  52. <iron-autogrow-textarea id="description" class="flex" rows="5" required></iron-autogrow-textarea>
  53. </div>
  54. <div class="separator"></div>
  55. <div class="layout horizontal">
  56. <paper-button id="submit" class="button submit" on-tap="submit" raised>Submit</paper-button>
  57. </div>
  58. </form>
  59. </paper-material>
  60. <paper-dialog id="dialog" modal>
  61. <paper-spinner id="spinner"></paper-spinner>
  62. </paper-dialog>
  63. <paper-dialog id="helpDialog" no-overlap horizontal-align="right" vertical-align="top">
  64. <h2>Request vs Change</h2>
  65. </paper-dialog>
  66. </template>
  67. <script>
  68. Polymer({
  69. is: 'jira-create-issue-form',
  70. properties: {
  71. /**
  72. * The state of the request (i.e. is it in flight or not).
  73. * Has an observer to disable the form if it is in flight.
  74. */
  75. inFlight: {
  76. type: Boolean,
  77. value: false,
  78. observer: '_inFlight'
  79. },
  80. /**
  81. * The issue types that can be accepted by JIRA.
  82. * NOTE: The structure of the Objects in the array is intended (to comply with <vaadin-combo-box>
  83. */
  84. issueTypes: {
  85. type: Array,
  86. value: [
  87. {value: 11200, label: "Request"},
  88. {value: 11201, label: "Change"}
  89. ]
  90. },
  91. /**
  92. * The array of tools (tool names/ids)
  93. */
  94. tools: {
  95. type: Array
  96. }
  97. },
  98. /**
  99. * When this element is attached to the DOM, do some setup tasks.
  100. */
  101. attached: function () {
  102. var me = this;
  103. //Get the tools info (tool ids and names)
  104. me._getToolsInfo();
  105. //Grab a handle on all of our elements (form elements, etc)
  106. var dialog = me.$.dialog;
  107. var form = me.$.issueForm;
  108. var issueType = me.$.issueType;
  109. var tool = me.$.tool;
  110. var summary = me.$.summary;
  111. var description = me.$.description;
  112. //Before the form is submitted, get the value of all the inputs and pack them into the request body
  113. //Also pack the cookie into the request body
  114. form.addEventListener('iron-form-presubmit', function (event) {
  115. this.request.contentType = 'application/json';
  116. this.request.body = {
  117. cookie: Cookies.get("JSESSIONID"),
  118. issueType: issueType.value,
  119. toolId: tool.value,
  120. summary: summary.value,
  121. description: description.value
  122. };
  123. });
  124. //Once the form is submitted, notify that the request is in flight and open the dialog containing the spinner
  125. form.addEventListener('iron-form-submit', function (event) {
  126. me.inFlight = true;
  127. dialog.open();
  128. });
  129. //Once a response is received, notify that the response is not in flight and close the dialog
  130. form.addEventListener('iron-form-response', function (event) {
  131. me.inFlight = false;
  132. dialog.close();
  133. //Fire an event containing a link to the issue
  134. var response = event.detail.response;
  135. me.fire('jira-issue-created', {issueUrl: response.issue.link});
  136. });
  137. //Once an error is encountered, notify that the response is not in flight and close the dialog
  138. form.addEventListener('iron-form-error', function (event) {
  139. me.inFlight = false;
  140. dialog.close();
  141. //Fire an event containing the error message received
  142. var response = event.detail.request.response;
  143. me.fire('jira-issue-failure', {errorMsg: response.error});
  144. });
  145. },
  146. //Helper function to submit the form
  147. submit: function () {
  148. this.$.issueForm.submit();
  149. },
  150. /**
  151. * Helper function to retrieve the info about the tools from the DB.
  152. * @private
  153. */
  154. _getToolsInfo: function () {
  155. var me = this;
  156. var ajax = document.createElement('iron-ajax');
  157. ajax.auto = true;
  158. ajax.method = "GET";
  159. ajax.url = "/api/tools/info";
  160. //Once we receive a response from the server, we need to update the 'tools' prop.
  161. ajax.addEventListener("response", function (e) {
  162. var temp = e.detail.response;
  163. //Map to conform with <vaadin-combo-box>
  164. //label = name | value = id
  165. me.tools = temp.map(function (obj) {
  166. var rObj = {};
  167. rObj.label = obj.name;
  168. rObj.value = obj.id;
  169. return rObj;
  170. })
  171. });
  172. },
  173. /**
  174. * Helper method for opening the help dialog and positioning it next to the calling element.
  175. * @private
  176. */
  177. _openHelp: function () {
  178. this.$.helpDialog.positionTarget = this.$.help;
  179. this.$.helpDialog.open();
  180. },
  181. /**
  182. * Helper method that disables the form elements if the request is mid flight.
  183. * Also enables/disables the spinner.
  184. * @private
  185. */
  186. _inFlight: function () {
  187. var me = this;
  188. var inFlight = me.inFlight;
  189. me.$.spinner.active = inFlight;
  190. me.$.issueType.disabled = inFlight;
  191. me.$.tool.disabled = inFlight;
  192. me.$.summary.disabled = inFlight;
  193. me.$.description.disabled = inFlight;
  194. }
  195. });
  196. </script>
  197. </dom-module>