Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** Car list component */
  2. let carListComponent = {
  3.     bindings: {
  4.         profile: '<'
  5.     },
  6.     controller: function () {
  7.         let $ctrl = this;
  8.     },
  9.     template: `
  10.         <div class="profile-block">
  11.             <div class="header">Cars</div>
  12.             <div class="car-block" ng-repeat="car in $ctrl.profile.Cars">
  13.                 <car car="car"></car>
  14.             </div>
  15.             <div>
  16.                 <a ui-sref="addCar">
  17.                     <i class="fa fa-plus-circle ico-add" aria-hidden="true"></i> <span class="add">Add Car</span>
  18.                 </a>
  19.             </div>
  20.         </div>
  21.     `
  22. };
  23.  
  24. export default carListComponent;
  25.  
  26. /** Car component */
  27. let carComponent = {
  28.     bindings: {
  29.         car: '<'
  30.     },
  31.     controller: function ($state, CarsService) {
  32.         let $ctrl = this;
  33.  
  34.         $ctrl._$state = $state;
  35.         $ctrl.CarsService = CarsService;
  36.  
  37.         $ctrl.getCarPic = function (carId) {
  38.             return $ctrl.CarsService
  39.                 .getCarPicture(carId)
  40.                 .then((res) => {
  41.                     let img = btoa(String.fromCharCode.apply(null, new Uint8Array(res)));
  42.                     document.querySelector(`#car_${carId}`).src = `data:image/jpeg;base64,${img}`;
  43.                 }, err => console.log(err));
  44.         };
  45.  
  46.         $ctrl.deleteCar = function (carId) {
  47.             let val = confirm('Are you sure you want to delete the car?');
  48.             if (val) {
  49.                 return $ctrl.CarsService
  50.                     .deleteCar(carId)
  51.                     .then(res => $ctrl._$state.reload(), err => console.log(err));
  52.             }
  53.         }
  54.     },
  55.     template: `
  56.          <img src="" ng-init="$ctrl.getCarPic($ctrl.car.CarId)" ng-attr-id="{{'car_' + $ctrl.car.CarId}}" class="img-responsive">
  57.          <div class="block-part">
  58.             <div class="name"><p>{{$ctrl.car.CarMakeEntity.Make}} {{$ctrl.car.CarModelEntity.Model}}</p></div>
  59.             <div class="property"><p>Number of seats: {{$ctrl.car.Seats}}</p></div>
  60.             <div class="property">
  61.                 Color: <div class="car-color" ng-style="{'background': $ctrl.car.Color}"></div>
  62.             </div>
  63.             <div uib-dropdown dropdown-append-to-body>
  64.                 <i class="fa fa-ellipsis-v" aria-hidden="true" uib-dropdown-toggle="" id={{$ctrl.car.CarId}}></i>
  65.                 <ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby={{$ctrl.car.CarId}}>
  66.                     <li role="menuitem">
  67.                         <a href="#">Edit</a>
  68.                     </li>
  69.                     <li role="menuitem">
  70.                         <a href="#" ng-click="$ctrl.deleteCar($ctrl.car.CarId)">Delete</a>
  71.                      </li>
  72.                 </ul>
  73.             </div>
  74.          </div>
  75.     `
  76. };
  77.  
  78. export default carComponent;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement