Guest User

Untitled

a guest
Jun 23rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <head>
  2.     <style>
  3.         td {
  4.             background: #EEE;
  5.             padding: 4px;
  6.             cursor: pointer;
  7.             border: 1px solid transparent;
  8.             min-width: 50px;
  9.         }
  10.         td:hover {
  11.             background: #777;
  12.             color: #FFF;
  13.         }
  14.         .dashed-cell {
  15.             border: 1px dashed #555;
  16.         }
  17.         .hour {
  18.             width: 60px;
  19.         }
  20.         .mini {
  21.             width: 20px;
  22.         }
  23.         #modal {
  24.             border: 1px solid #AAA;
  25.             background: #FFF;
  26.             display: none;
  27.             padding: 10px;
  28.             width: 200px;
  29.             top: 100px;
  30.             left: 100px;
  31.             position: absolute;
  32.         }
  33.  
  34.     </style>
  35. </head>
  36. <body>
  37.     <table id="myTable"></table>
  38.     <div id="modal">
  39.         <form action="#">
  40.             Enter a company name:
  41.             <br/>
  42.             <input id="modalInput" type="text" />
  43.             <br/>
  44.             <button id="modalBtn">
  45.                 Done
  46.             </button>
  47.         </form>
  48.     </div>
  49. </body>
  50. <script src="jquery-1.7.1.min.js" type="text/javascript"></script>
  51. <script type="text/javascript">
  52.     var hours = [1, 2, 3, 4, 5, 6, 7], increment = 15, current = {};
  53.  
  54.     get('modalBtn').addEventListener('click', closeModal, false);
  55.  
  56.     var modal = get('modal'), myTable = get('myTable'), input = get('modalInput'), l = hours.reverse().length, temp = [];
  57.  
  58.     temp[0] = document.createElement('tr');
  59.     temp[1] = temp[0].appendChild(document.createElement('td'));
  60.     temp[1].setAttribute('class', 'mini');
  61.     temp[2] = temp[0].appendChild(temp[1].cloneNode(true));
  62.     temp[3] = temp[0].appendChild(temp[1].cloneNode(true));
  63.     temp[1].setAttribute('class', 'hour');
  64.     temp[2].innerHTML = '+';
  65.     temp[3].innerHTML = '-';
  66.     temp.length = 1;
  67.     while(l--) {
  68.         temp[1] = temp[0].cloneNode(true);
  69.         temp[2] = temp[1].children;
  70.         temp[2][0].innerHTML = hours[l] + ':00';
  71.         //temp[2][1].addEventListener('click',showModal,false);
  72.         temp[2][1].addEventListener('click', addCell, false);
  73.         temp[2][2].addEventListener('click', removeSlot, false);
  74.         myTable.appendChild(temp[1]);
  75.     }
  76.  
  77.     temp.length = 0;
  78.  
  79.     function addCell() {
  80.         var elems = this.parentNode.children, l = elems.length, tar = elems[l - 3];
  81.         insert = tar.cloneNode(true);
  82.         insert.innerHTML = '';
  83.         tar.setAttribute('class', '');
  84.         insert.setAttribute('class', 'dashed-cell');
  85.         this.parentNode.insertBefore(insert, elems[l - 2]);
  86.     }
  87.  
  88.     function closeModal() {
  89.         $.post("/", {
  90.             method_to_handle_request : "value"
  91.         }, function(data) {
  92.             // do something with data
  93.         });
  94.         var elems = current.parent.children, l = elems.length, tar = elems[l - 3];
  95.         insert = tar.cloneNode(true);
  96.         insert.innerHTML = input.value;
  97.         current.parent.insertBefore(insert, elems[l - 2]);
  98.         modal.style.display = 'none';
  99.         input.value = '';
  100.     }
  101.  
  102.     function removeSlot() {
  103.         var parent = this.parentNode, elems = parent.children, l = elems.length, tar = elems[l - 3];
  104.         if(elems.length > 3)
  105.             parent.removeChild(tar);
  106.     }
  107.  
  108.     function getDiaryId() (
  109.  
  110.     (
  111.     )() {
  112.  
  113.         var path = document.location.href;
  114.         //href  = "/Cannock/2012-02-11"
  115.         var a = path.split('/');
  116.         //Split the path
  117.  
  118.         var id = a[1];
  119.         //The array is the result of the split
  120.  
  121.         //If href is a full url, then we get a wrong id here
  122.         if(a[0] != "") {
  123.             id = a[3];
  124.             //If element is is empty then set the id variable to the 3 element being the site_id = Cannock
  125.         }
  126.         return id;
  127.     }
  128.  
  129.    
  130.    
  131.     function getSlotDayId() (
  132.     )()) {
  133.         var path = document.location.href;
  134.         var a = path.split('/');
  135.  
  136.         var id = a[3];
  137.  
  138.         // If href is a full url, then we get a wrong id here
  139.         if(a[0] != "") {
  140.             id = a[5];
  141.         }
  142.         return id;
  143.         alert("Returned id");
  144.     }
  145.  
  146.     /* you count the elements of array, you can see the date
  147.      *
  148.      *(and the id is what we need) is right to the diary id, by two element.
  149.      * So, you need add 2 to every place,
  150.      where you want to take element into "id" variable. */
  151.  
  152.     function get(a) {
  153.         return document.getElementById(a);
  154.     });
  155.     }
  156.    
  157.     $.post("/" + getDiaryId() + "/slot_days/" + getSlotDayId(),
  158.    
  159. </script>
Add Comment
Please, Sign In to add comment