Advertisement
Guest User

Untitled

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