Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>

<head>
   <title>Welcome | Fame Cinema</title>
</head>

<body ng-app="fameCinemaApp" ng-controller="BehaviourController as bController" ng-init="bController.init()">

   <div class="jumbotron">
      <div class="container">

         <h1 ng-show="bController.showWelcomeText">Fame Cinema Official Ticketing App</h1>
         <p>{{bController.mainText}}</p>
         <form ng-submit="bController.nextStep()">
            <div class="jumbotron-input">
               <div class="input-group padding5px" ng-show="bController.showNameInput">
                  <span class="input-group-addon" id="basic-addon1">@</span>
                  <input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1" ng-model="bController.name">
               </div>

               <div class="input-group" ng-show="bController.showTicketQtyInput">
                  <span class="input-group-addon" id="basic-addon1"> * </span>
                  <input type="text" class="form-control" placeholder="Number of tickets" aria-describedby="basic-addon1" ng-model="bController.count">
               </div>
               
            </div>

            <button type="submit" class="btn btn-primary">
               {{bController.buttonText}}
            </button>
         </form>
         <div ng-show="bController.showCategories">
            You have selected
            <span class="selected" ng-repeat="s in bController.selected">{{s}}</span>
         </div>
      </div>


   </div>
   </div>

   <div class="container">
      <nav class="navbar navbar-inverse navbar-fixed-top">
         <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
               <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                  <span class="sr-only">Toggle navigation</span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
               </button>
               <a class="navbar-brand" href="">Fame Cinema</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
               

            </div>
            <!-- /.navbar-collapse -->
         </div>
         <!-- /.container-fluid -->
      </nav>
      <div class="row">
         <div class="col-md-9">
            <div class="tile-group" ng-show="bController.showCategories">
               <span ng-repeat="seat in bController.seats">
               <div ng-class="{selected:seat.reserved, old:seat.old}" ng-click="bController.select(seat.name)">
                  <a href="#" class="tile-group-item">
                     {{seat.name}}
                   </a>
               </div>
               <div style="width:100%;background:transparent;border:0;" ng-if="seat.newLine"></div>
               </span>

            </div>

            
         </div>
         <div class="col-md-3" ng-show="bController.showCategories">
          <table class="table table-bordered legend">
             <tr>
                <td style="background:red"></td>
                <td>Reserved</td>
             </tr>
             <tr>
                <td style="background:#563d7c"></td>
                <td>Selected</td>
             </tr>
             <tr>
                <td style="background:#f9f9f9"></td>
                <td>Empty</td>
             </tr>
</table>
         </div>
      </div>
      <div class="row">
         <div class="col-md-12">
            <fieldset ng-show="bController.showReservationList()">
               <legend>Reservations</legend>
            <table class="table table-striped">
               <thead>
                  <tr>
                     <th>#</th>
                     <th>Name</th>
                     <th># of Seats</th>
                     <th>Seat Nos.</th>
                  </tr>
               </thead>
               <tbody>
                  <tr ng-repeat="seat in bController.persistedSelections">
                     <th scope="row">{{$index+1}}</th>
                     <td>{{seat.name}}</td>
                     <td>{{seat.count}}</td>
                     <td>
                        <span class="selected" ng-repeat="s in seat.seats">{{s}}</span>
                     </td>
                  </tr>
               </tbody>
            </table>
               </fieldset>
         </div>
      </div>   
   </div>

</body>

</html>
              
            
!

CSS

              
                body {
  padding-top:3%;
}
@media (min-width: 768px)
.tile-group div a{
  width: 12.5%;
  font-size: 12px;
}
div.tile-group li{
  list-style:none;
  float:left;
}
.tile-group div{
  float: left;
  width: 8%;
  height: 7%;
  padding: 10px;
  font-size: 10px;
  line-height: 1.4;
  text-align: center;
  background-color: #f9f9f9;
  border: 1px solid #fff;
}
.tile-group div:hover {
   color:#000;
   border: 1px solid #563d7c;
}
.tile-group div.selected{
  color: #fff;
  background-color: #563d7c;
}
.tile-group div.selected.old{
   background-color: red;
}
.tile-group div a.tile-group-item {
  color:#000;
  text-decoration:none;
  display: block;
  text-align: center;
  word-wrap: break-word;
  font-size:large;
}
.tile-group div.selected a.tile-group-item{
  color: #fff;
}
.jumbotron-input {
  width:40%;  
  line-height:1.4;
  padding-bottom:1%;
}
span.selected {
  padding: 2px;
  border: 1px solid grey;
}
.padding5px{
   padding: 5px;
}
table.legend tr td:first-child{
   width:50%;
}
              
            
!

JS

              
                var app = angular.module("fameCinemaApp", []);
app.controller("BehaviourController", function($scope) {
   this.persistedSelections = [];
   this.seats = [];
   this.row = 5;
   this.col = 5;
	
   var self = this;
   this.init = function() {
      this.showWelcomeText = true;
      this.showCategories = false;
      this.showNameInput = false;
      this.showTicketQtyInput = false;
      this.mainText = "Welcome! Would you like to book a ticket?";
      this.buttonText = "Yes!";
      this.name = undefined;
      this.count = undefined;
      this.selected = [];
      
      this.buildSeatMap();
   };

   this.nextStep = function() {
      this.buttonText = "Next";
      if (undefined === this.name) {
         this.mainText = "Okay, please tell us your name";
         toggleInput(self, "name");			
      } else if (undefined === this.count) {
         // user has already input name. Show greeting
         this.mainText = "Hi " + this.name + "! Please enter the number of tickets you wish to buy";
         toggleInput(self, "count");
         this.buttonText = "Show me seats!";
      } else if (0 == this.selected.length) {

         this.showWelcomeText = false;
         this.mainText = "Fantastic! Now " + this.name + ", Please choose your seats";
         toggleInput(self);
         if (!this.showCategories) {
            this.showCategories = true;
         } else {
            this.showCategories = false;
         }
         this.buttonText = "Confirm my booking!";
      } else if (this.count >= this.selected.length) {
         // save and flush
         var saveSelectionObject = {
            "name": this.name,
            "count": this.selected.length,
            "seats": this.selected
         };
         for (var i = 0; i < this.selected.length; i++) {
            var seat = this.selected[i];
            var seatIndex = this.getSeatIndex(seat);
            this.seats[seatIndex].old = true;
         }
         this.persistedSelections.push(saveSelectionObject);
         this.init();
      }

   };
   var toggleInput = function(self, input) {
      self.showNameInput = false;
      self.showTicketQtyInput = false;
      if ("name" === input) {
         self.showNameInput = true;
      } else if ("count" === input) {
         self.showTicketQtyInput = true;
      }
   };
   this.getSeatIndex = function(seat) {
      var seatIndex = _.findIndex(this.seats, {
         'name': seat
      });
      return seatIndex;
   };
   this.deSelect = function(seat) {
      var seatIndex = this.getSeatIndex(seat);
      this.seats[seatIndex].reserved = false;
      //var buffer = this.selected;
      //this.selected = [];
      var index;
      for (var i = 0; i < this.selected.length; i++) {
         if (this.selected[i] == seat) {
            index = i;
         }
      }
      this.selected.splice(index, 1);
   };
   this.select = function(seat) {
      var flag = false;
      if (undefined != this.selected.length) {
         if (this.selected.length < this.count) {
            flag = true;
         }
         for (var i = 0; i < this.selected.length; i++) {
            if (this.selected[i] == seat) {
               flag = false;
               this.deSelect(seat);
               break;
            }
         }
      } else {
         flag = true;
      }
      var seatIndex = this.getSeatIndex(seat);
      if (this.seats[seatIndex].reserved) {
         flag = false;
      }
      if (flag) {
         this.selected.push(seat);
         this.seats[seatIndex].reserved = true;
      }
   };
   this.buildSeatMap = function() {
      if (this.seats.length == 0) {

         for (var i = 1; i <= this.row; i++) {
            for (var j = 1; j <= this.col; j++) {
               var newLine = (j == this.col);
               var name = "S" + i + j;
               var seat = {
                  "id": i + j,
                  "name": name,
                  "reserved": false,
                  "old": false,
                  "newLine": newLine
               };
               this.seats.push(seat);
            }
         }
      }
   };
   this.showReservationList = function(){
     return this.persistedSelections.length>0;
   };
});
              
            
!
999px

Console