Advertisement
Guest User

index

a guest
Apr 25th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.09 KB | None | 0 0
  1. <%--
  2.  Created by IntelliJ IDEA.
  3.  User: jsardoy
  4.  Date: 2019-04-24
  5.  Time: 11:24
  6. --%>
  7.  
  8. <%@ page contentType="text/html;charset=UTF-8" %>
  9. <html>
  10. <head>
  11.     <meta name="layout" content="main"/>
  12.     <title></title>
  13.  
  14.     <script type="text/javascript">
  15.         function getCategories(site){
  16.             var URL = "${createLink(controller: 'Client', action: 'showCategories', params: ['site': ""])}"+site
  17.             $.ajax({
  18.                 url: URL,
  19.                 success: function(resp){
  20.                     var cat_head = document.getElementById("category_head");
  21.                     console.log(site)
  22.                     cat_head.innerText = resp.name
  23.                     var subcats_element = document.getElementById("subcategories");
  24.                     while(subcats_element.firstChild){
  25.                         subcats_element.removeChild(subcats_element.firstChild);
  26.                     }
  27.                     var col_div = document.createElement("div");
  28.                     col_div.setAttribute("class", "col-md-2");
  29.                     resp.forEach(function(category){
  30.                         var button_element = document.createElement("button");
  31.                         button_element.innerText = category.name;
  32.                         button_element.style = "display: block; width:100%; font-size: 10px";
  33.                         console.log(category.id);
  34.                         var function_call = "getSubCategories(this, '"+category.id+ "')";
  35.                         button_element.setAttribute("onclick", function_call);
  36.                         col_div.appendChild(button_element)
  37.                     })
  38.                     subcats_element.appendChild(col_div)
  39.                 }
  40.             })
  41.         };
  42.         function getSubCategories(element, category_id){
  43.  
  44.             var URL = "${createLink(controller: 'Client', action: 'showSubCategories', params: ['category_id': ""])}"+category_id;
  45.             $.ajax({
  46.                 url: URL,
  47.                 success: function(resp){
  48.                     if (resp.children_categories.length > 0){
  49.                         var current_section = element.parentElement;
  50.                         var subcats_element = document.getElementById("subcategories");
  51.                         while(subcats_element.lastChild !== current_section){
  52.                             subcats_element.removeChild(subcats_element.lastChild);
  53.                         }
  54.                         var col_div = document.createElement("div");
  55.                         col_div.setAttribute("class", "col-md-2");
  56.                         resp.children_categories.forEach(function(category){
  57.                             var button_element = document.createElement("button");
  58.                             button_element.innerText = category.name;
  59.                             button_element.style = "display: block; width:100%; font-size: 10px";
  60.                             console.log(category.id);
  61.                             var function_call = "getSubCategories(this, '"+category.id+ "')";
  62.                             button_element.setAttribute("onclick", function_call);
  63.                             col_div.appendChild(button_element)
  64.                         })
  65.                         subcats_element.appendChild(col_div)
  66.  
  67.                     }
  68.                     else{
  69.                         console.log("CAVIPOOOOOO")
  70.                         alert(resp.id)
  71.  
  72.                     }
  73.                 }
  74.             })
  75.  
  76.         };
  77.     </script>
  78. </head>
  79.  
  80. <body>
  81.  
  82. <div class="dropdown">
  83.     <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  84.         Sites
  85.     </button>
  86.     <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
  87.         <g:each var="site" in="${result}">
  88.             <button class="dropdown-item" onclick="getCategories('${site.id}')">${site.name}</button>
  89.         </g:each>
  90.     </div>
  91. </div>
  92.  
  93. <div class="container-fluid">
  94.     <h2 id="category_head"></h2>
  95.     <div class="row" id="subcategories">
  96.     </div>
  97. </div>
  98.  
  99.  
  100.  
  101. </body>
  102. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement