Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. .circle {
  2. width: 13px;
  3. height: 13px;
  4. border-radius: 50%;
  5. font-size: 8px;
  6. font-weight: bold;
  7. color: #fff;
  8. line-height: 13px;
  9. text-align: center;
  10. cursor:pointer;
  11. }
  12. .spawn {
  13. border:1px dashed #666;
  14. background:#324148;
  15. padding:5px;
  16. }
  17. #plan {
  18. width:1200px;
  19. height:540px;
  20. margin:auto;
  21. background:white;
  22. border: 3px solid rgba(0,0,0,.125);
  23. -webkit-box-shadow: inset 0 0.25rem 0.125rem 0 rgba(0, 0, 0, 0.05) !important;
  24. background-repeat: no-repeat;
  25. background-size: contain;
  26. background-position: center;
  27. }
  28. .move { float:left; }
  29.  
  30. <div id="toolbar" class="container-fluid">
  31. <div class="row">
  32. <div class="col-sm-4 p-1">
  33. <div class="buttons">
  34. <button onclick="createStation('PE')" class="nbtn pe">PE</button>
  35. <button onclick="createStation('PM')" class="nbtn pm">PM</button>
  36. <button class="nbtn ins">INS</button>
  37. <button class="nbtn det">DET</button>
  38. </div>
  39. </div>
  40. <div class="col-sm-4 spawn"></div>
  41. <div class="col-sm-4 text-right"></div>
  42. </div>
  43. </div>
  44.  
  45. <?php
  46. $stations = $con->query('SELECT * FROM zapp_clt_station WHERE zone = ?', $zId)->fetchAll();
  47.  
  48. foreach ($stations as $station) {
  49. $id = $station['type']."".$station['num'];
  50. echo "<div id='".$id."' class='move circle pe context-menu-one'>".$station['num']."</div>";
  51. }
  52.  
  53. echo "<script>";
  54. foreach ($stations as $station) {
  55. $id = $station['type']."".$station['num'];
  56. echo"
  57. $('#".$id."').offset({
  58. left: ".$station['xCord'].",
  59. top: ".$station['yCord']."
  60. });
  61. ";
  62. }
  63. echo "</script>";
  64.  
  65.  
  66. ?>
  67.  
  68. function createStation(type) {
  69. swal.mixin({
  70. input: 'text',
  71. confirmButtonText: 'Confirmar',
  72. cancelButtonText: 'Cancelar',
  73. showCancelButton: true,
  74. inputClass: 'form-control',
  75. confirmButtonClass: 'nbtn pm p-1',
  76. cancelButtonClass: 'nbtn pe p-1',
  77. progressSteps: ['1', '2']
  78. }).queue([{
  79. title: 'Escolha o nΓΊmero do posto',
  80. inputPlaceholder: '# do posto'
  81. },
  82. {
  83. title: 'Posto de Interior ou Exterior',
  84. input: 'select',
  85. inputOptions: {
  86. 'Int': 'Interior',
  87. 'Ext': 'Exterior'
  88. },
  89. inputPlaceholder: 'Escolha',
  90. inputClass: 'form-control',
  91. }
  92. ]).then(function(result) {
  93. if (result.value) {
  94. $.ajax({
  95. type: 'POST',
  96. url: 'add-station.php',
  97. data: {
  98. id: result.value,
  99. zone: zone,
  100. company: company,
  101. branch: branch,
  102. type: type
  103. },
  104. dataType: 'json',
  105. success: function(response) {
  106. if (response.codigo == 1) {
  107.  
  108. var type = response.type.toLowerCase();
  109. $(".spawn").append("<div id='" + response.id + "' class='move circle "+ type +" context-menu-one'>" + response.num + "</div>");
  110.  
  111. // On every new item..
  112. dragger();
  113. }
  114. if (response.codigo == 0) {
  115. Swal.fire({
  116. type: 'error',
  117. title: 'Oops...',
  118. text: response.mensagem
  119. })
  120. }
  121. },
  122. error: function() {
  123. Swal.fire({
  124. type: 'error',
  125. title: 'Oops...',
  126. text: 'Erro a processar o pedido!'
  127. })
  128. }
  129. });
  130. }
  131. });
  132.  
  133. }
  134.  
  135. function dragger() {
  136. $('.move').draggable({
  137. containment: '#plan',
  138. stop: function(e, ui) {
  139. element = $(this);
  140. var y = element.position().top;
  141. var x = element.position().left;
  142. var x = Math.round(x - 86);
  143. var y = Math.round(y - 89);
  144. num = ($("#"+ element.attr("id")).html());
  145. // ##### [AJAX TO UPDATE THE STATIONS COORDS] #####
  146. alert (x+'-'+y); //just for debug
  147. $.ajax({
  148. type: 'POST',
  149. url: 'update-station.php',
  150. data: {
  151. zone: zone,
  152. num: num,
  153. x: x,
  154. y: y
  155. },
  156. dataType: 'json',
  157. success: function(response) {
  158. if (response.codigo == 1) {
  159. // DEBUG
  160. }
  161. if (response.codigo == 0) {
  162. Swal.fire({
  163. type: 'error',
  164. title: 'Oops...',
  165. text: response.mensagem
  166. })
  167. }
  168. },
  169. error: function() {
  170. Swal.fire({
  171. type: 'error',
  172. title: 'Oops...',
  173. text: 'Erro a processar o pedido!'
  174. })
  175. }
  176. });
  177. // ##### [AJAX TO UPDATE THE STATIONS COORDS] #####
  178. }
  179. });
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement