Advertisement
Guest User

Untitled

a guest
Feb 29th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.99 KB | None | 0 0
  1. var app = angular.module('shipmentApp', [])
  2. app.controller('shipmentsCtrl', function ($scope) {
  3. //variables:
  4. $scope.shipments = [
  5. {id: 1, name: "shipment1", transportMode: "Air"},
  6. {id: 2, name: 'shipment2', transportMode: 'Sea'}
  7. ];
  8. var addresses = [
  9. {
  10. id: 1,
  11. postcode: "2700",
  12. country: "HUN",
  13. city: "Cegléd",
  14. street: "Kossuth Ferenc",
  15. houseNumber: "2",
  16. type: "Consignee",
  17. shipment: 1
  18. },
  19. {
  20. id: 2,
  21. postcode: "1111",
  22. country: "HUN",
  23. city: "Bp",
  24. street: "Móricz",
  25. houseNumber: "10",
  26. type: "Shipper",
  27. shipment: 1
  28. },
  29. {
  30. id: 3,
  31. postcode: "1111",
  32. country: "HUN",
  33. city: "Bp",
  34. street: "Bakony",
  35. houseNumber: "10",
  36. type: "Consignee",
  37. shipment: 2
  38. },
  39. {
  40. id: 4,
  41. postcode: "1111",
  42. country: "HUN",
  43. city: "Bp",
  44. street: "Széchenyi",
  45. houseNumber: "10",
  46. type: "Shipper",
  47. shipment: 1
  48. },
  49. {
  50. id: 5,
  51. postcode: "1111",
  52. country: "HUN",
  53. city: "Bp",
  54. street: "Sasadi",
  55. houseNumber: "10",
  56. type: "Shipper",
  57. shipment: 1
  58. },
  59. {
  60. id: 6,
  61. postcode: "1111",
  62. country: "HUN",
  63. city: "Bp",
  64. street: "Karolina",
  65. houseNumber: "10",
  66. type: "Shipper",
  67. shipment: 2
  68. }
  69. ];
  70. var statuses = [
  71. {
  72. id: 1,
  73. estimatedDateTime: new Date().toDateString(),
  74. actualDateTime: new Date().toDateString(),
  75. generatedDateTime: new Date().toDateString(),
  76. shipment: 1
  77. },
  78. {
  79. id: 2,
  80. estimatedDateTime: new Date().toDateString(),
  81. actualDateTime: new Date().toDateString(),
  82. generatedDateTime: new Date().toDateString(),
  83. shipment: 2
  84. },
  85. {
  86. id: 3,
  87. estimatedDateTime: new Date().toDateString(),
  88. actualDateTime: new Date().toDateString(),
  89. generatedDateTime: new Date().toDateString(),
  90. shipment: 1
  91. },
  92. {
  93. id: 4,
  94. estimatedDateTime: new Date().toDateString(),
  95. actualDateTime: new Date().toDateString(),
  96. generatedDateTime: new Date().toDateString(),
  97. shipment: 2
  98. },
  99. {
  100. id: 5,
  101. estimatedDateTime: new Date().toDateString(),
  102. actualDateTime: new Date().toDateString(),
  103. generatedDateTime: new Date().toDateString(),
  104. shipment: 1
  105. },
  106. {
  107. id: 6,
  108. estimatedDateTime: new Date().toDateString(),
  109. actualDateTime: new Date().toDateString(),
  110. generatedDateTime: new Date().toDateString(),
  111. shipment: 2
  112. },
  113. {
  114. id: 7,
  115. estimatedDateTime: new Date().toDateString(),
  116. actualDateTime: new Date().toDateString(),
  117. generatedDateTime: new Date().toDateString(),
  118. shipment: 1
  119. },
  120. {
  121. id: 8,
  122. estimatedDateTime: new Date().toDateString(),
  123. actualDateTime: new Date().toDateString(),
  124. generatedDateTime: new Date().toDateString(),
  125. shipment: 2
  126. }
  127. ];
  128.  
  129. var items = [
  130. {id: 1, type: "type", length: 10, weight: 20, height: 40, numberOfPieces: 50, shipment: 1},
  131. {id: 2, type: "type", length: 10, weight: 20, height: 40, numberOfPieces: 50, shipment: 2},
  132. {id: 3, type: "type", length: 10, weight: 20, height: 40, numberOfPieces: 50, shipment: 1},
  133. {id: 4, type: "type", length: 10, weight: 20, height: 40, numberOfPieces: 50, shipment: 2},
  134. {id: 5, type: "type", length: 10, weight: 20, height: 40, numberOfPieces: 50, shipment: 1},
  135. {id: 6, type: "type", length: 10, weight: 20, height: 40, numberOfPieces: 50, shipment: 2},
  136. {id: 7, type: "type", length: 10, weight: 20, height: 40, numberOfPieces: 50, shipment: 1},
  137. {id: 8, type: "type", length: 10, weight: 20, height: 40, numberOfPieces: 50, shipment: 1},
  138. {id: 9, type: "type", length: 10, weight: 20, height: 40, numberOfPieces: 50, shipment: 1}
  139. ];
  140.  
  141. $scope.selected = "";
  142. $scope.returnAddresses = [];
  143. $scope.returnItems = [];
  144. $scope.returnStatuses = [];
  145. $scope.addressesLength = addresses.length;
  146. $scope.itemsLength = items.length;
  147. $scope.statusesLength = statuses.length;
  148. $scope.shipmentsLength = $scope.shipments.length;
  149. $scope.selectedShipmentId = 0;
  150. //---------end variables
  151.  
  152. $scope.getSelected = function (shipment) {
  153. console.log(shipment.id);
  154. setSelected(shipment);
  155. getShipmentAddressesById(shipment.id);
  156. getShipmentItemsById(shipment.id);
  157. getShipmentStatusesById(shipment.id);
  158. $scope.selectedShipmentId = shipment.id;
  159. };
  160.  
  161. var setSelected = function (shipment) {
  162. $scope.selected = "Shipment (id: " + shipment.id + " Name: " + shipment.name + " Transport mode: " + shipment.transportMode + ")";
  163. console.log("Set selected to: " + shipment);
  164. };
  165.  
  166.  
  167. var getShipmentAddressesById = function (shipmentId) {
  168. $scope.returnAddresses = [];
  169. for (var i = 0; i < addresses.length; i++) {
  170. console.log(addresses[i].id);
  171. if (shipmentId == addresses[i].shipment) {
  172. console.log("Push: " + addresses[i]);
  173. $scope.returnAddresses.push(addresses[i]);
  174. }
  175. }
  176. if ($scope.returnAddresses == 0 || $scope.returnAddresses == null) {
  177. console.log("null");
  178. }
  179. console.log($scope.returnAddresses);
  180. };
  181.  
  182. var getShipmentItemsById = function (shipmentId) {
  183. $scope.returnItems = [];
  184.  
  185. items.forEach(function (item) {
  186. if (shipmentId == item.shipment) {
  187. $scope.returnItems.push(item);
  188. }
  189. });
  190. }
  191.  
  192. var getShipmentStatusesById = function (shipmentId) {
  193. $scope.returnStatuses = [];
  194. statuses.forEach(function (status) {
  195. if (shipmentId == status.shipment) {
  196. $scope.returnStatuses.push(status);
  197. }
  198. });
  199. };
  200.  
  201. $scope.update = function (returnAddresses) {
  202. console.log(returnAddresses);
  203. $scope.returnAddresses = angular.copy(returnAddresses);
  204. $scope.selected = "";
  205. };
  206.  
  207. $scope.update = function (returnItems) {
  208. console.log(returnItems);
  209. $scope.returnItems = angular.copy(returnItems);
  210. $scope.selected = "";
  211. };
  212.  
  213. $scope.update = function (returnStatuses) {
  214. console.log(returnStatuses);
  215. $scope.returnStatuses = angular.copy(returnStatuses);
  216. $scope.selected = "";
  217. };
  218.  
  219.  
  220. $scope.addShipment = function (shipment) {
  221. var object = {id: $scope.shipments.length + 1, name: shipment.name, transportMode: shipment.transportMode};
  222. console.log(object);
  223. $scope.shipments.push(object);
  224. $scope.shipments.forEach(function (shipment) {
  225. console.log(shipment);
  226. });
  227.  
  228. };
  229.  
  230. /* $scope.reset = function () {
  231. $scope.getSelected($scope.shipments.length + 1);
  232. };*/
  233. /*
  234. var isEmpty = function (obj) {
  235. if (obj == null) return true;
  236. if (obj.length > 0) return false;
  237. if (obj.length === 0) return true;
  238. return true;
  239. };*/
  240.  
  241.  
  242. $scope.addAddress = function (address) {
  243. var object = {};
  244. object.id = addresses.length + 1;
  245. object.postcode = address.postcode;
  246. object.country = address.country;
  247. object.city = address.city;
  248. object.street = address.street;
  249. object.houseNumber = address.houseNumber;
  250. object.type = address.type;
  251. object.shipment = $scope.selectedShipmentId;
  252. console.log(object);
  253. addresses.push(object);
  254. addresses.forEach(function (myAddress) {
  255. console.log(myAddress);
  256. });
  257. var frm = document.getElementsByName('myForm')[0];
  258. frm.reset();
  259. $scope.selected = "";
  260. };
  261.  
  262. $scope.addItem = function (item) {
  263. item.shipment = $scope.selectedShipmentId;
  264. item.id = items.length + 1;
  265. var itemObject = {};
  266.  
  267. itemObject.id = items.length + 1;
  268. itemObject.type = item.type;
  269. itemObject.length = item.length;
  270. itemObject.weight = item.weight;
  271. itemObject.height = item.height;
  272. itemObject.numberOfPieces = item.numberOfPieces;
  273. itemObject.shipment = $scope.selectedShipmentId;
  274.  
  275. console.log(itemObject);
  276. items.push(itemObject);
  277. items.forEach(function (myAddress) {
  278. console.log(myAddress);
  279. });
  280. var frm = document.getElementsByName('myForm')[0];
  281. frm.reset();
  282. $scope.selected = "";
  283. };
  284.  
  285. $scope.addStatus = function (status) {
  286. status.id = statuses.length + 1;
  287. status.shipment = $scope.selectedShipmentId;
  288. var statusObject = {};
  289.  
  290. statusObject.id = statuses.length + 1;
  291. statusObject.estimatedDateTime = status.estimatedDateTime;
  292. statusObject.actualDateTime = status.actualDateTime;
  293. statusObject.generatedDateTime = status.generatedDateTime;
  294. statusObject.shipment = $scope.selectedShipmentId;
  295.  
  296. console.log(statusObject);
  297. statuses.push(statusObject);
  298. var frm = document.getElementsByName('myForm')[0];
  299. frm.reset();
  300. $scope.selected = "";
  301. };
  302.  
  303.  
  304. })
  305. ;
  306.  
  307.  
  308. app.directive("formDirective", function () {
  309. return {
  310. restrict: 'E',
  311. //controller: 'shipmentsCtrl',
  312. templateUrl: 'form.html'
  313. };
  314. });
  315.  
  316.  
  317.  
  318. //html
  319.  
  320. <!DOCTYPE html>
  321. <html lang="en">
  322. <head>
  323. <meta charset="UTF-8">
  324. <title>Transport-demo app</title>
  325. <meta name="viewport" content="width=device-width, initial-scale=1">
  326. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  327. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  328. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  329. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  330. <script src="indexWithBootstrapController.js"></script>
  331. <link href="styles.css" rel="stylesheet" type="text/css">
  332. -
  333. <style>
  334. .highlight {
  335. background-color: aqua;
  336. }
  337. .highlighted {
  338. color: #261F1D !important;
  339. background-color: #E5C37E !important;
  340. }
  341. .member tr.selected {
  342. background-color: rgba(41, 103, 182, 0.89);
  343. color: #FFF;
  344. }
  345.  
  346. /*
  347. tr:hover, tr.selected {
  348. background-color: #FFCF8B
  349. }*/
  350. </style>
  351.  
  352. </head>
  353.  
  354.  
  355. <body ng-app="shipmentApp" ng-controller="shipmentsCtrl">
  356. <ul class="nav nav-pills">
  357. <li class="active"><a data-toggle="tab" href="#home">Shipments</a></li>
  358. <li><a data-toggle="tab" href="#createShipment">Create Shipment</a></li>
  359. </ul>
  360.  
  361. <div class="tab-content">
  362. <div id="home" class="tab-pane fade in active">
  363. <table class="table table-hover" id="shipmentTable" style="float:left">
  364. <thead>
  365. <tr>
  366. <th>shipment id</th>
  367. <th>shipment name</th>
  368. <th>shipment transport mode</th>
  369. </tr>
  370. </thead>
  371. <tbody class="member">
  372. <tr class="shipmentRow" ng-click="getSelected(shipment);" ng-repeat="shipment in shipments">
  373. <td>{{shipment.id}}</td>
  374. <td>{{shipment.name}}</td>
  375. <td>{{shipment.transportMode}}</td>
  376. </tr>
  377. </tbody>
  378. </table>
  379. <div class="importForm" ng-hide="selected == ''" ng-model="selected">
  380. <h5>{{selected}}</h5>
  381. <form-directive></form-directive>
  382. </div>
  383. </div>
  384.  
  385. <div id="createShipment" class="tab-pane fade">
  386. <form class="navbar-form">
  387. <div class="form-group" ng-model="shipment">
  388. <input type="text" class="form-control" placeholder="Shipment name" ng-model="shipment.name"><br>
  389. <input type="text" class="form-control" placeholder="Shipment transport mode"
  390. ng-model="shipment.transportMode"><br>
  391. <input id="checkbox" type="checkbox" ng-model="formData"> With details
  392. </div>
  393. <div class="importForm" ng-show="formData">
  394. <h5>Shipment({{shipment.name}} , {{shipment.transportMode}})</h5>
  395. <form-directive ng-init="shipment.id=$scope.shipments.length+1"></form-directive>
  396.  
  397.  
  398. </div>
  399.  
  400. <button id="addShipmentBtn" type="submit" class="btn btn-default" ng-click="addShipment(shipment)">Add
  401. shipment
  402. </button>
  403. </form>
  404.  
  405. </div>
  406. </div>
  407.  
  408.  
  409. <script>
  410. $(document).ready(function () {
  411. /*
  412. $("#shipmentTable tr").click(function () {
  413. var selected = $(this).hasClass("highlight");
  414. $("#shipmentTable tr").removeClass("highlight");
  415. if (!selected)
  416. $(this).addClass("highlight");
  417. });*/
  418.  
  419.  
  420. /* $("tbody tr").click(function() {
  421. $("table tr").css("background", "blue"); //reset to original color
  422. $(this).css("background", "red"); //apply the new color
  423. });*/
  424. $("#shipmentTable tr").click(function(){
  425. $(this).addClass("selected").siblings().removeClass("selected");
  426. });
  427.  
  428. });
  429.  
  430.  
  431.  
  432. </script>
  433. </body>
  434. </html>
  435.  
  436.  
  437.  
  438. //form
  439.  
  440. <!DOCTYPE html>
  441. <html lang="en">
  442. <head>
  443. <meta charset="UTF-8">
  444. <meta name="viewport" content="width=device-width, initial-scale=1">
  445. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  446. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  447. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  448. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  449. <script src="indexWithBootstrapController.js"></script>
  450. <link href="styles.css" rel="stylesheet" type="text/css">
  451. </head>
  452. <body>
  453. <form name="myForm">
  454.  
  455. <ul class="nav nav-tabs">
  456. <li class="active"><a data-toggle="tab" href="#addresses">Addresses</a></li>
  457. <li><a data-toggle="tab" href="#items">Items</a></li>
  458. <li><a data-toggle="tab" href="#statuses">Statuses</a></li>
  459. </ul>
  460.  
  461. <div class="tab-content" style="width:450px;">
  462. <div id="addresses" class="tab-pane fade in active">
  463. <table class="table table-hover">
  464. <thead>
  465. <tr>
  466. <th>id</th>
  467. <th>postcode</th>
  468. <th>country</th>
  469. <th>city</th>
  470. <th>street</th>
  471. <th>house number</th>
  472. <th>type</th>
  473. <th>shipment</th>
  474. <th></th>
  475. </tr>
  476. </thead>
  477. <tbody>
  478.  
  479. <div>
  480. <tr ng-repeat="address in returnAddresses">
  481. <td>{{address.id}}</td>
  482. <td>
  483. <input maxlength="4" size="4" type="text" width="10px" ng-model="address.postcode"/>
  484. </td>
  485. <td>
  486. <input maxlength="20" size="10" type="text" ng-model="address.country"/>
  487. </td>
  488. <td>
  489. <input maxlength="20" size="10" type="text" ng-model="address.city"/>
  490. </td>
  491. <td>
  492. <input maxlength="20" size="20" type="text" ng-model="address.street"/>
  493. </td>
  494. <td>
  495. <input maxlength="4" size="4" type="text" ng-model="address.houseNumber"/>
  496. </td>
  497. <td>
  498. <input maxlength="9" size="10" type="text" ng-model="address.type"/>
  499. </td>
  500. <td>
  501. {{address.shipment}}
  502. </td>
  503. <td></td>
  504. </tr>
  505. </div>
  506.  
  507. <div ng-model="address">
  508. <tr>
  509. <td>
  510. {{address.id}}
  511. </td>
  512. <td>
  513. <input maxlength="4" size="4" type="text" width="10px" ng-model="address.postcode"/>
  514. </td>
  515. <td>
  516. <input maxlength="20" size="10" type="text" ng-model="address.country"/>
  517. </td>
  518. <td>
  519. <input maxlength="20" size="10" type="text" ng-model="address.city"/>
  520. </td>
  521. <td>
  522. <input maxlength="20" size="20" type="text" ng-model="address.street"/>
  523. </td>
  524. <td>
  525. <input maxlength="4" size="4" type="text" ng-model="address.houseNumber"/>
  526. </td>
  527. <td>
  528. <input maxlength="9" size="10" type="text" ng-model="address.type"/>
  529. </td>
  530. <td>
  531. {{address.shipment}}
  532. </td>
  533. <td>
  534. <button id="addressAddButton" ng-click="addAddress(address)" type="button"
  535. class="btn btn-default">Add Address
  536. </button>
  537. </td>
  538. </tr>
  539. </div>
  540.  
  541. </tbody>
  542. </table>
  543.  
  544. <button id="addressesButton" ng-click="update(returnAddresses)" type="button" class="btn btn-default">Modify
  545. addresses
  546. </button>
  547. </div>
  548. <div id="items" class="tab-pane fade">
  549. <table class="table table-hover">
  550. <thead>
  551. <tr>
  552. <th>id</th>
  553. <th>length</th>
  554. <th>weight</th>
  555. <th>height</th>
  556. <th>numberOfPieces</th>
  557. <th>type</th>
  558. <th>shipment</th>
  559. <th></th>
  560. </tr>
  561. </thead>
  562. <tbody>
  563. <div>
  564. <tr ng-repeat="item in returnItems">
  565. <td> {{item.id}}</td>
  566. <td>
  567. <input maxlength="6" size="6" type="text" ng-model="item.length"/>
  568. </td>
  569. <td>
  570. <input maxlength="6" size="6" type="text" ng-model="item.weight"/>
  571. </td>
  572. <td>
  573. <input maxlength="6" size="6" type="text" ng-model="item.height"/>
  574. </td>
  575. <td>
  576. <input maxlength="5" size="5" type="text" ng-model="item.numberOfPieces"/>
  577. </td>
  578. <td>
  579. <input maxlength="20" size="10" type="text" ng-model="item.type"/>
  580. </td>
  581. <td>{{item.shipment}}</td>
  582. <td></td>
  583. </tr>
  584. </div>
  585. <div ng-model="item">
  586. <tr>
  587. <td ng-model="item.id"></td>
  588. <td>
  589. <input maxlength="6" size="6" type="text" ng-model="item.length"/>
  590. </td>
  591. <td>
  592. <input maxlength="6" size="6" type="text" ng-model="item.weight"/>
  593. </td>
  594. <td>
  595. <input maxlength="6" size="6" type="text" ng-model="item.height"/>
  596. </td>
  597. <td>
  598. <input maxlength="5" size="5" type="text" ng-model="item.numberOfPieces"/>
  599. </td>
  600. <td>
  601. <input maxlength="20" size="10" type="text" ng-model="item.type"/>
  602. </td>
  603. <td ng-model="item.shipment"></td>
  604. <td>
  605. <button id="itemAddButton" ng-click="addItem(item)" type="button" class="btn btn-default">
  606. Add Item
  607. </button>
  608. </td>
  609. </tr>
  610. </div>
  611. </tbody>
  612. </table>
  613. <button id="itemsButton" ng-click="update(returnItems)" type="button" class="btn btn-default">Modify items
  614. </button>
  615.  
  616. </div>
  617. <div id="statuses" class="tab-pane fade">
  618. <table class="table table-hover">
  619. <thead>
  620. <tr>
  621. <th>id</th>
  622. <th>estimatedDateTime</th>
  623. <th>actualDateTime</th>
  624. <th>generatedDateTime</th>
  625. <th>shipment</th>
  626. <th></th>
  627. </tr>
  628. </thead>
  629. <tbody>
  630. <div>
  631. <tr ng-repeat="status in returnStatuses">
  632. <td>{{status.id}}</td>
  633. <td>
  634. <input type="text" ng-model="status.estimatedDateTime"/>
  635. </td>
  636. <td>
  637. <input type="text" ng-model="status.actualDateTime"/>
  638. </td>
  639. <td>
  640. <input type="text" ng-model="status.generatedDateTime"/>
  641. </td>
  642. <td>{{status.shipment}}</td>
  643. <td></td>
  644. </tr>
  645. </div>
  646. <div>
  647. <tr ng-model="status">
  648. <td ng-model="status.id"></td>
  649. <td>
  650. <input type="text" ng-model="status.estimatedDateTime"/>
  651. </td>
  652. <td>
  653. <input type="text" ng-model="status.actualDateTime"/>
  654. </td>
  655. <td>
  656. <input type="text" ng-model="status.generatedDateTime"/>
  657. </td>
  658. <td ng-model="status.shipment"></td>
  659. <td>
  660. <button id="statusAddButton" ng-click="addStatus(status)" type="button"
  661. class="btn btn-default">Add Status
  662. </button>
  663. </td>
  664. </tr>
  665. </div>
  666. </tbody>
  667. </table>
  668. <button id="statusesButton" ng-click="update(returnStatuses)" type="button" class="btn btn-default">Modify statuses
  669. </button>
  670. </div>
  671. </div>
  672. </form>
  673. </body>
  674. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement