Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.11 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html ng-app="BrentonApp">
  3. <head>
  4.     <meta charset="utf-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1">
  6.     <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  7. <!-- Just a lame style to showcase save within tabular view -->
  8.  
  9.  
  10. <title>Brent's AngularJS Demo</title>
  11.  
  12. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js"></script>
  13.                             <!-- Needed reference for ngRoute -->
  14. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular-route.min.js"></script>
  15.                             <!-- Needed references for css and responsive design -->
  16. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  17. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  18.  <!-- The below script reference version does not work with this angularjs implementation -->
  19.  <!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js"></script>-->
  20.  
  21. <script type="text/javascript">
  22.     //Used for records / faking identity-like pid
  23.     var uid = 1;
  24.    
  25.     //Your localhost route to match up with endpoints
  26.     var homeRoute = 'http://localhost:8080'
  27.    
  28.     //Define an angular module for our app
  29.     var myApp = angular.module('BrentonApp', ['ngRoute']);
  30.        
  31.        
  32. //Define Routing for app
  33. //Uri /EmbeddedPartialView -> template EmbeddedPartialView.html and Controller PartialController
  34. //Uri /ShowContacts -> template ShowContacts.html and Controller ContactController
  35.        
  36.     myApp.config(['$routeProvider', function($routeProvider) {
  37.         $routeProvider.when('/AddNewOrder', {
  38.             templateUrl: 'AddFakeHtmlPageHere',
  39.             controller: 'PartialController'
  40.         });
  41.         /*when('/ShowOrders', {
  42.             templateUrl: 'templates/show_orders.html',
  43.             controller: 'ShowOrdersController'
  44.         }).
  45.         otherwise({
  46.             redirectTo: '/AddNewOrder'
  47.         }); */
  48.     }]);
  49.        
  50.     myApp.controller('PartialController', function($scope) {
  51.      
  52.         $scope.message = 'This is PartialView for Contact';
  53.      
  54.     });
  55.        
  56.        
  57.     myApp.controller('ContactController', ['$scope', function($scope) {
  58.    
  59.         $scope.contacts = [{
  60.             id:0, 'name': 'Brenton Bates',
  61.             'email':'brentonbates@gmail.com',
  62.             'phone': '614-999-9999'
  63.         }];
  64.          
  65.         $scope.saveContact = function() {
  66.             //if this is new contact, add it in contacts array
  67.             if($scope.newcontact.id == null) {
  68.                 $scope.newcontact.id = uid++;
  69.                 $scope.contacts.push($scope.newcontact);
  70.             } else {
  71.             //For an existing contact, find by contact id
  72.             //and update it.
  73.                 for(i in $scope.contacts) {
  74.                     if($scope.contacts[i].id == $scope.newcontact.id) {
  75.                     $scope.contacts[i] = $scope.newcontact;
  76.                     }
  77.                 }                
  78.             }
  79.              
  80.             //clear the add contact form
  81.             $scope.newcontact = {};
  82.         }
  83.          
  84.         $scope.delete = function(id) {
  85.              
  86.             //search for contact by id and delete it
  87.             for(i in $scope.contacts) {
  88.                 if($scope.contacts[i].id == id) {
  89.                     $scope.contacts.splice(i,1);
  90.                     $scope.newcontact = {};
  91.                 }
  92.             }            
  93.         }
  94.          
  95.         $scope.edit = function(id) {
  96.         //search for contact by id and update it
  97.             for(i in $scope.contacts) {
  98.                 if($scope.contacts[i].id == id) {
  99.                     //we use angular.copy() method to create
  100.                     //copy of original object
  101.                     $scope.newcontact = angular.copy($scope.contacts[i]);
  102.                 }
  103.             }
  104.         }
  105.     }]);   
  106. </script>
  107.  
  108. </head>
  109.     <body>
  110.         <div class="container-fluid" ng-controller="ContactController">
  111.             <form class="form-inline" role="form">
  112.             <div class="form-group">
  113.                 <label class="sr-only" for="nameInput"><strong>Name:</strong></label>
  114.                     <input id="nameInput" class="form-control" type="text" name="name" ng-model="newcontact.name" placeholder="Enter Name"/>
  115.                     <br/><br/>
  116.                 <label class="sr-only" for="emailInput"><strong>Email:</strong></label>
  117.                     <input class="form-control" type="text" name="email" ng-model="newcontact.email" placeholder="YourEmail@example.com"/>
  118.                     <br/><br/>
  119.                 <label class="sr-only" for="phoneInput"><strong>Phone:</strong></label>
  120.                     <input class="form-control" type="text" name="phone" ng-model="newcontact.phone" placeholder="Enter Phone Number"/>
  121.                     <br/><br/>
  122.                     <input class="form-control" type="hidden" ng-model="newcontact.id" />                  
  123.                     <br/>
  124.                     <input class="btn btn-primary form-control" type="button" value="Save" ng-click="saveContact()" />
  125.             </div>
  126.             </form>
  127.             <br/>
  128.             <table class="table table-hover table-bordered table-condensed table-striped" width="300px">
  129.                 <thead>
  130.                 <tr>
  131.                     <th class="active">Name</th>
  132.                     <th class="success">Email</th>
  133.                     <th class="warning">Phone</th>
  134.                     <th class="danger">Action</th>
  135.                 </tr>
  136.                 </thead>
  137.                     <tbody>
  138.                         <tr ng-repeat="contact in contacts">
  139.                             <td>{{ contact.name }}</td>
  140.                             <td>{{ contact.email }}</td>
  141.                             <td>{{ contact.phone }}</td>
  142.                             <td>
  143.                                 <a href="#" ng-click="edit(contact.id)">edit</a> |
  144.                                 <a href="#" ng-click="delete(contact.id)">delete</a> |
  145.                                 <a href="#" ng-click="addEvent/ControllerCallByScope">view</a>
  146.                             </td>
  147.                         </tr>
  148.                     </tbody>
  149.             </table>    
  150.         </div>
  151.     </body>
  152. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement