dmilosavleski

5 -2

Dec 25th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.99 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html>
  4. <head lang="en">
  5. <meta charset="UTF-8">
  6. <title>Втора задача</title>
  7. <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  8. <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  9. <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  10. <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
  11. <style>
  12. body
  13. {
  14. font-size: 62.5%;
  15. }
  16. label, input
  17. {
  18. display:block;
  19. }
  20. input.text
  21. {
  22. margin-bottom:12px;
  23. width:95%;
  24. padding: .4em;
  25. }
  26. fieldset
  27. {
  28. padding:0;
  29. border:0;
  30. margin-top:25px;
  31. }
  32. h1
  33. {
  34. font-size: 1.2em;
  35. margin: .6em 0;
  36. }
  37. div#letovi-contain
  38. {
  39. width: 350px;
  40. margin: 20px 0;
  41. }
  42. div#letovi-contain table
  43. {
  44. margin: 1em 0;
  45. border-collapse: collapse;
  46. width: 100%;
  47. }
  48. div#letovi-contain table td, div#letovi-contain table th
  49. {
  50. border: 1px solid #eee;
  51. padding: .6em 10px;
  52. text-align: left;
  53. }
  54. .ui-dialog .ui-state-error
  55. {
  56. padding: .3em;
  57. }
  58. .validateTips
  59. {
  60. border: 1px solid transparent;
  61. padding: 0.3em;
  62. }
  63. .ui-autocomplete-category
  64. {
  65. font-weight: bold;
  66. padding: .2em .4em;
  67. margin: .8em 0 .2em;
  68. line-height: 1.5;
  69. }
  70. </style>
  71. <script>
  72. $(function() {
  73. $("#kalendarche1").datepicker({
  74. onClose: function(selectedDate){
  75. $("#kalendarche2").datepicker("option","minDate",selectedDate);
  76. }
  77. });
  78. $("#kalendarche2").datepicker({
  79. onClose: function(selectedDate){
  80. $("#kalendarche1").datepicker("option","maxDate",selectedDate);
  81. }
  82. });
  83. });
  84. </script>
  85. <script>
  86.  
  87. $.widget( "custom.catcomplete", $.ui.autocomplete, {
  88.  
  89. _renderMenu: function( ul, items ) {
  90. var that = this,
  91. currentCategory = "";
  92. $.each( items, function( index, item ) {
  93. var li;
  94. if ( item.category != currentCategory ) {
  95. ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
  96. currentCategory = item.category;
  97. }
  98. li = that._renderItemData( ul, item );
  99. });
  100. }
  101. });
  102.  
  103.  
  104.  
  105. $(function() {
  106. var dialog, form,
  107.  
  108. // From http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-%28type=email%29
  109. shifra = $("#shifra"),
  110. avioprevoznik = $("#avioprevoznik"),
  111. dest = $("#dest"),
  112. kategorija = $("#kategorija"),
  113. datumOd = $("#kalendarche1"),
  114. datumDo = $("#kalendarche2"),
  115. allFields = $([]).add(shifra).add(avioprevoznik).add(dest).add(kategorija).add(datumOd).add(datumDo),
  116. tips = $(".validateTips");
  117.  
  118. function updateTips(t) {
  119. tips
  120. .text(t)
  121. .addClass("ui-state-highlight");
  122. setTimeout(function () {
  123. tips.removeClass("ui-state-highlight", 1500);
  124. }, 500);
  125. }
  126.  
  127. function checkRegexp(o, regexp, n) {
  128. if (!( regexp.test(o.val()) )) {
  129. o.addClass("ui-state-error");
  130. updateTips(n);
  131. return false;
  132. } else {
  133. return true;
  134. }
  135. }
  136.  
  137. function addFlight() {
  138. var valid = true;
  139. allFields.removeClass("ui-state-error");
  140.  
  141. valid = valid && checkRegexp(shifra, /^([0-9])+$/, "Шифрата мора да содржи само цифри");
  142. if (valid) {
  143. $("#letovi tbody").append("<tr>" +
  144. "<td>" + shifra.val() + "</td>" +
  145. "<td>" + avioprevoznik.val() + "</td>" +
  146. "<td>" + dest.val() + "</td>" +
  147. "<td>" + kategorija.val() + "</td>" +
  148. "<td>" + datumOd.val() + "</td>" +
  149. "<td>" + datumDo.val() + "</td>" +
  150. "</tr>");
  151. dialog.dialog("close");
  152. }
  153.  
  154. $(function () {
  155.  
  156. pole = [];
  157. $.each($("#letovi tr").not(".ui-widget-header"), function (i, o) {
  158. var t2 = $(o).find("td:nth-child(2)");
  159. var t3 = $(o).find("td:nth-child(3)");
  160. var t4 = $(o).find("td:nth-child(4)");
  161. pole.push({label: t3.html() + " - " + t2.html(), category: t4.html()});
  162.  
  163. });
  164. $("#prebaraj").catcomplete({
  165. delay: 0,
  166. source: pole
  167. });
  168. });
  169.  
  170. return valid;
  171. }
  172.  
  173. dialog = $("#dialog-form").dialog({
  174. autoOpen: false,
  175. height: 330,
  176. width: 350,
  177. modal: true,
  178. buttons: {
  179. "Додади": addFlight,
  180. "Откажи": function () {
  181. dialog.dialog("close");
  182. }
  183. },
  184. close: function () {
  185. form[0].reset();
  186. allFields.removeClass("ui-state-error");
  187. }
  188. });
  189.  
  190. form = dialog.find("form").on("submit", function (event) {
  191. event.preventDefault();
  192. addFlight();
  193. });
  194.  
  195. $("#create-flight").button().on("click", function () {
  196. dialog.dialog("open");
  197. });
  198. });
  199.  
  200. $(function() {
  201.  
  202. pole=[];
  203. $.each($(" #letovi tr").not(".ui-widget-header"),function(i,o){
  204. var t2=$(o).find("td:nth-child(2)");
  205. var t3=$(o).find("td:nth-child(3)");
  206. var t4=$(o).find("td:nth-child(4)");
  207. pole.push({label:t3.html()+" - "+t2.html(),category:t4.html()});
  208.  
  209. });
  210. $( "#prebaraj" ).catcomplete({
  211. delay: 0,
  212. source: pole
  213. });
  214.  
  215. });
  216. </script>
  217. <script>
  218. $(function() {
  219.  
  220. $( "#dialog" ).dialog({
  221. autoOpen: false,
  222. modal: true,
  223. buttons: {
  224. ok: function(){
  225. console.log("OK");
  226. $( "#dialog" ).dialog("close");
  227. },
  228. cancel:function(){
  229. console.log("cancel");
  230. $( "#dialog" ).dialog("close");
  231. }
  232. }
  233. });
  234.  
  235. $( "#opener" ).click(function() {
  236. $( "#dialog" ).dialog( "open" );
  237. });
  238. });
  239. </script>
  240. </head>
  241. <body>
  242. <div id="dialog-form" title="Create new flight">
  243. <p class="validateTips">Сите полиња се задолжителни.</p>
  244.  
  245. <form>
  246. <fieldset>
  247. <label for="shifra">Шифра</label>
  248. <input type="text" name="shifra" id="shifra" value="" class="text ui-widget-content ui-corner-all">
  249. <label for="avioprevoznik">Авиопревозник</label>
  250. <input type="text" name="avioprevoznik" id="avioprevoznik" value="" class="text ui-widget-content ui-corner-all">
  251. <label for="dest">До</label>
  252. <input type="text" name="dest" id="dest" value="" class="text ui-widget-content ui-corner-all">
  253. <label for="kategorija">Категорија</label>
  254. <select name="kategorija" id="kategorija" class="text ui-widget-content ui-corner-all">
  255. <option value="Бизнис">Бизнис</option>
  256. <option value="Класа А">Прва Класа</option>
  257. <option value="Економска">Економска</option>
  258. </select>
  259. <!-- Allow form submission with keyboard without duplicating the dialog button -->
  260. <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
  261. </fieldset>
  262. </form>
  263. </div>
  264.  
  265. <label for="prebaraj">Пребарај: </label>
  266. <input id="prebaraj">
  267. <p>
  268. Датум од:
  269. <input type="text" id="kalendarche1">
  270. </p>
  271. <p>
  272. Датум до:
  273. <input type="text" id="kalendarche2">
  274. </p>
  275.  
  276. <button id="create-flight">Резервирај лет</button>
  277.  
  278. <div id="letovi-contain" class="ui-widget">
  279. <h1>Летови:</h1>
  280. <table id="letovi" class="ui-widget ui-widget-content">
  281. <thead>
  282. <tr class="ui-widget-header ">
  283. <th>Шифра</th>
  284. <th>Авиопревозник</th>
  285. <th>До</th>
  286. <th>Класа</th>
  287. <th>Датум од</th>
  288. <th>Датум до</th>
  289. </tr>
  290. </thead>
  291. <tbody>
  292. <tr>
  293. <td>12331</td>
  294. <td>Wizz Air</td>
  295. <td>London</td>
  296. <td>Бизнис</td>
  297. <td>11/11/2015</td>
  298. <td>11/23/2015</td>
  299. </tr>
  300. </tbody>
  301. </table>
  302. </div>
  303. </body>
  304. </html>
Add Comment
Please, Sign In to add comment