admin-markdown-delete.html 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <link rel="import" href="../../../bower_components/polymer/polymer.html">
  2. <link rel="import" href="../../../bower_components/iron-ajax/iron-ajax.html">
  3. <link rel="import" href="../../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
  4. <link rel="import" href="../../../bower_components/paper-button/paper-button.html">
  5. <link rel="import" href="../../../bower_components/paper-input/paper-input.html">
  6. <link rel="import" href="../../../bower_components/paper-material/paper-material.html">
  7. <link rel="import" href="../../../bower_components/paper-toast/paper-toast.html">
  8. <link rel="import" href="../../../bower_components/vaadin-combo-box/vaadin-combo-box.html">
  9. <dom-module id="admin-markdown-delete">
  10. <template>
  11. <style is="custom-style" include="iron-flex iron-positioning"></style>
  12. <style>
  13. paper-material {
  14. padding: 8px;
  15. margin: 8px;
  16. }
  17. .separator {
  18. margin: 0 4px;
  19. }
  20. .button {
  21. color: white;
  22. background-color: var(--paper-blue-300);
  23. }
  24. .markdown-container {
  25. margin: 8px;
  26. }
  27. .toast {
  28. }
  29. .success {
  30. background: var(--paper-green-300);
  31. border: 1px solid var(--paper-green-500);
  32. }
  33. .failure {
  34. background: var(--paper-red-300);
  35. border: 1px solid var(--paper-red-500);
  36. }
  37. </style>
  38. <paper-material class="header">
  39. This form removes an item from the markdown list
  40. </paper-material>
  41. <paper-material class="options horizontal layout">
  42. <vaadin-combo-box id="toolList" label="Tool" class="flex" items="[[tools]]"></vaadin-combo-box>
  43. <div class="separator"></div>
  44. <vaadin-combo-box id="sectionList" label="Sections" class="flex"
  45. items="{{sectionNames}}" value="About">
  46. </vaadin-combo-box>
  47. <paper-input id="itemNum" label="Item #" type="number"></paper-input>
  48. <paper-button id="save" class="button primary flex" on-tap="_deleteMarkdown" raised>ADD</paper-button>
  49. </paper-material>
  50. <paper-toast id="successToast" class="toast success" text="{{message.success}}"></paper-toast>
  51. <paper-toast id="failureToast" class="toast failure" text="{{message.failure}}"></paper-toast>
  52. </template>
  53. <script>
  54. Polymer({
  55. is: 'admin-markdown-delete',
  56. properties: {
  57. /**
  58. * Object for storing success/failure messages
  59. */
  60. message: {
  61. type: Object,
  62. value: {
  63. failure: "Failed to add tool!",
  64. success: "Markdown added successfully!"
  65. }
  66. },
  67. /**
  68. * Names of the sections that can be deleted
  69. */
  70. sectionNames: {
  71. type: Array,
  72. value: ['About', 'Training', 'Links']
  73. },
  74. /**
  75. * Array for storing the names of the tools
  76. */
  77. tools: {
  78. type: Array,
  79. }
  80. },
  81. ready: function () {
  82. var me = this;
  83. //Load in the tools to populate the <vaadin-combo-box>
  84. me.tools = me._getTools();
  85. },
  86. /**
  87. * Helper method for getting the names of the tools
  88. * @private
  89. */
  90. _getTools: function () {
  91. var me = this;
  92. var tools_ajax = document.createElement('iron-ajax');
  93. tools_ajax.auto = true;
  94. tools_ajax.method = "GET";
  95. tools_ajax.url = "/api/tools/info";
  96. tools_ajax.addEventListener("response", function (e) {
  97. //Grab the tools from the response
  98. var tools = e.detail.response;
  99. //We need to transform the array to fit to <vaadin-combo-box> requirements
  100. me.tools = tools.map(function (obj) {
  101. return rObj = {
  102. value: obj.id,
  103. label: obj.name
  104. };
  105. });
  106. });
  107. },
  108. /**
  109. * Helper method for deleting an item from the tool section
  110. * @private
  111. */
  112. _deleteMarkdown: function () {
  113. var me = this;
  114. var toolListVal = me.$.toolList.value;
  115. var sectionListVal = me.$.sectionList.value;
  116. var itemNumVal = me.$.itemNum.value;
  117. var successToast = me.$.successToast;
  118. var failureToast = me.$.failureToast;
  119. //Only procced if all of these were supplied
  120. if (toolListVal && sectionListVal && itemNumVal) {
  121. }
  122. },
  123. });
  124. </script>
  125. </dom-module>