Guest User

Untitled

a guest
Nov 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. @Component({
  2. selector: 'bol-form',
  3. template: `
  4. <table class="styledTable" id="CommoditySection"
  5. (handlingDeleteEvent) =
  6. "removeHandlingUnits(handlingUnitsCount)">
  7. <thead><th>Commodities</th></thead>
  8. <tr><td>
  9. <div id="commodities">
  10.  
  11. <h5><a id="addHandlingUnits"
  12. (click)="addHandlingUnits(handlingUnitsCount, 0)">Add More Handling Units</a></h5>
  13.  
  14. <dynamic-handling-component
  15. [componentHandlingData]="componentHandlingData"
  16. [removeComponent]="removeComponent">
  17. </dynamic-handling-component>
  18.  
  19. </div>
  20. </td></tr>
  21. </table>
  22. `
  23. })
  24.  
  25. export class App implements AfterContentInit {
  26.  
  27. private handlingUnitsCount: number;
  28. private componentHandlingData = null;
  29. private componentCommoditiesData = null;
  30. private removeCommoditiesComponent = null;
  31. private removeComponent = null;
  32.  
  33.  
  34. constructor() {
  35. this.handlingUnitsCount = 0;
  36. }
  37.  
  38. addHandlingUnits(unita, unitb) {
  39.  
  40. if (unita == undefined ) {
  41. unita = this.handlingUnitsCount;
  42. unitb = 0;
  43. }
  44.  
  45. this.sleep(unita * 50 + 10).then(() => {
  46.  
  47. this.componentHandlingData = {
  48. component: HandlingComponent,
  49. inputs: {
  50. handlingUnitsCount: unita,
  51. }
  52. };
  53.  
  54. this.handlingUnitsCount += 1;
  55. });
  56.  
  57. }
  58.  
  59. removeHandlingUnits(id) {
  60.  
  61. if (id == 0) {
  62.  
  63. this.sleep(10).then(() => {
  64. this.removeComponent = {
  65. toDelete: id,
  66. allDelete: true,
  67. };
  68. });
  69.  
  70. this.handlingUnitsCount = this.handlingUnitsCount - 1;
  71. this.componentHandlingData = null;
  72. this.componentCommoditiesData = null;
  73.  
  74. } else {
  75.  
  76. this.sleep(10).then(() => {
  77. this.removeComponent = {
  78. toDelete: id,
  79. allDelete: false,
  80. };
  81. });
  82.  
  83. this.handlingUnitsCount = 0;
  84. this.componentHandlingData = null;
  85. this.componentCommoditiesData = null;
  86.  
  87. }
  88.  
  89. }
  90.  
  91. ngAfterContentInit() {
  92.  
  93. this.addHandlingUnits(0,0);
  94.  
  95. }
  96.  
  97. sleep (time) {
  98. return new Promise((resolve) => setTimeout(resolve, time));
  99. }
  100.  
  101. }
Add Comment
Please, Sign In to add comment