portal-tools.html 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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-drawer-panel/paper-drawer-panel.html">
  5. <link rel="import" href="../../bower_components/paper-header-panel/paper-header-panel.html">
  6. <link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
  7. <link rel="import" href="../../bower_components/paper-item/paper-item.html">
  8. <link rel="import" href="../../bower_components/paper-item/paper-item-body.html">
  9. <link rel="import" href="../../bower_components/paper-menu/paper-menu.html">
  10. <link rel="import" href="../../bower_components/paper-menu/paper-submenu.html">
  11. <link rel="import" href="../paper-card-list.html">
  12. <!--
  13. Wrapper' for the 'Tools' section of the Portal
  14. Loads in the information about the tools ('About', 'Training', 'Useful Links')
  15. -->
  16. <dom-module id="portal-tools">
  17. <style is="custom-style" include="iron-flex iron-positioning"></style>
  18. <style>
  19. paper-item {
  20. font-size: 14px;
  21. }
  22. .sublist paper-item {
  23. padding-left: 32px;
  24. }
  25. </style>
  26. <template>
  27. <paper-drawer-panel>
  28. <paper-header-panel drawer>
  29. <paper-menu selected="{{toolSelected}}">
  30. <template is="dom-repeat" items="{{toolNames}}">
  31. <paper-submenu>
  32. <paper-item class="menu-trigger">
  33. <paper-item-body>
  34. <div>{{item}}</div>
  35. </paper-item-body>
  36. <paper-icon-button icon="arrow-drop-down"></paper-icon-button>
  37. </paper-item>
  38. <paper-menu class="menu-content sublist" selected="{{sectionSelected}}">
  39. <paper-item>About</paper-item>
  40. <paper-item>Training</paper-item>
  41. <paper-item>Useful Links</paper-item>
  42. </paper-menu>
  43. </paper-submenu>
  44. </template>
  45. </paper-menu>
  46. </paper-header-panel>
  47. <paper-header-panel main>
  48. <paper-icon-button icon="menu" paper-drawer-toggle></paper-icon-button>
  49. <paper-card-list items="{{sectionItems}}"></paper-card-list>
  50. </paper-header-panel>
  51. </paper-drawer-panel>
  52. </template>
  53. <script>
  54. Polymer({
  55. is: 'portal-tools',
  56. properties: {
  57. /**
  58. * The items for the particular tool section (i.e. the array of 'about' items).
  59. */
  60. sectionItems: {
  61. type: Array
  62. },
  63. /**
  64. * The particular section that is selected.
  65. * Has an observer for detecting when the user clicks on a different section in the sidebar.
  66. */
  67. sectionSelected: {
  68. type: Number,
  69. //value: 0,
  70. observer: '_sectionChanged'
  71. },
  72. /**
  73. * Tool selected in the sidebar
  74. */
  75. toolSelected: {
  76. type: Number,
  77. //value: 0
  78. },
  79. /**
  80. * Array of tools to be loaded from DB
  81. */
  82. tools: {
  83. type: Array
  84. },
  85. /**
  86. * Names of tools to be loaded from the DB
  87. */
  88. toolNames: {
  89. type: Array
  90. }
  91. },
  92. /**
  93. * When this element is attached to the DOM, load in the tools and tool names by calling the appropriate helper methods
  94. */
  95. attached: function () {
  96. this.getTools();
  97. this.getToolNames();
  98. },
  99. /**
  100. * Helper method for retrieving the tools from the DB
  101. */
  102. getTools: function () {
  103. var me = this;
  104. var ajax = document.createElement('iron-ajax');
  105. ajax.auto = true;
  106. ajax.method = "GET";
  107. ajax.url = "/api/tools/";
  108. ajax.addEventListener("response", function (e) {
  109. me.tools = e.detail.response;
  110. });
  111. },
  112. /**
  113. * Helper method for retrieving the tool names from the DB
  114. */
  115. getToolNames: function () {
  116. var me = this;
  117. //GET the tool names
  118. var ajax = document.createElement('iron-ajax');
  119. ajax.auto = true;
  120. ajax.method = "GET";
  121. ajax.url = "/api/tools/names";
  122. //When we get a response from our AJAX call
  123. ajax.addEventListener("response", function (e) {
  124. me.toolNames = e.detail.response;
  125. });
  126. },
  127. /**
  128. * Observer for detecting when the section changes in the sidebar.
  129. * Loads in a new tool section item array.
  130. * @private
  131. */
  132. _sectionChanged: function () {
  133. var me = this;
  134. //Get the tool and section that was selected (via the <paper-menu> or <paper-submenu>).
  135. var toolSelected = me.toolSelected;
  136. var sectionSelected = me.sectionSelected;
  137. //Check that there was an actual selection
  138. if (toolSelected != undefined && sectionSelected != undefined) {
  139. var temp;
  140. //Number <=> Section
  141. //Need a switch/case statement to decide which section to load
  142. switch (sectionSelected) {
  143. case 0:
  144. temp = me.tools[toolSelected].about;
  145. break;
  146. case 1:
  147. temp = me.tools[toolSelected].training;
  148. break;
  149. case 2:
  150. temp = me.tools[toolSelected].links;
  151. break;
  152. }
  153. //Set the items = current selection
  154. me.sectionItems = temp;
  155. }
  156. }
  157. });
  158. </script>
  159. </dom-module>