Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 36 additions & 65 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,75 +1,46 @@
<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title ng-bind="title"></title>

<link rel="stylesheet" href="css/bootstrap.css"/>
<style>
h1 { color: darkred }
h1 { weight: bolder }
h1 { margin: 20px; display: block; opacity: 80%; }
h1:hover { opacity:1; }
</style>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title ng-bind="title"></title>

<link rel="stylesheet" href="css/bootstrap.css" />

<style>
h1 {
color: darkred
}
h1 {
weight: bolder
}
h1 {
margin: 20px;
display: block;
opacity: 80%;
}
h1:hover {
opacity: 1;
}
</style>

<!--[if lte IE 7]>
<!--[if lte IE 7]>
<script src="js/vendor/json3.js"></script>
<![endif]-->

<script src="js/vendor/angular.min.js"></script>
<script src="js/vendor/angular-route.min.js"></script>
<script src="js/app.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<h1>The User Interface Developer Test</h1>
</div>
<div class="well">
<div class="well">
<ul>
<li>This Page and results.html should be converted to AngularJS templates.</li>
<li>Add a select-all toggle for the checkbox list.</li>
<li>Select-all should be checked if all fields are checked, unchecked if all fields are unchecked and indeterminate if some are checked.</li>
<li>Sor the checkboxes by name</l>
<li>When submitting the form, if only "Language" is checked, then an error should appear stating &quot; Please choose more items! &quot;</li>
<li>Successfully submitting the form takes us to results.html and shows what the user submitted.</li>
<li>Maybe the page can look a little better?</li>
<p>Read the README.md</p>
</ul>
</div>
</div>
<form role="form">
<div class="form-group">
<input type="checkbox">Select All
</div>
<div class="form-group">
<label class="checkbox">
<input type="checkbox" name="fields" value="Abstract">Abstract
</label>
<label class="checkbox">
<input type="checkbox" name="fields" value="Abstract">Publication
</label>
<label class="checkbox">
<input type="checkbox" value="Abstract">Inventor
</label>
<label class="checkbox">
<input type="checkbox" name="fields" value="Abstract">Language
</label>
<label class="checkbox">
<input type="checkbox" name="field" value="Abstract">Source
</label>
<label class="checkbox">
<input type="checkbox" name="fields" value="Abstract">Priority
</label>

</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<script>console.log('page loaded');</script>
</head>

<body ng-app="TestMe">
<div class="container">
<div ng-view></div>
</div>
<script src="js/vendor/angular.min.js"></script>
<script src="js/vendor/angular-route.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>

</html>
114 changes: 113 additions & 1 deletion js/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,113 @@
angular.module('TestMe', []);
angular.module('TestMe', ['ngTest.cbSelector', 'ngTest.results', 'ngRoute'])
.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: '/testForm.html',
controller: 'CheckBoxController'
}).
when('/results', {
templateUrl: '/results.html',
controller: 'ResultsController'
}).
otherwise({
redirectTo: '/'
});
}
]);

angular.module('ngTest.cbSelector', [])
.controller('CheckBoxController', ['$scope', '$rootScope','$location', function($scope, $rootScope, $location){
$scope.cbSelectedByVal = {
abstract: false,
publication: false,
inventor: false,
language: false,
source: false,
priority: false
};
$scope.cbSelectAll = false;

$scope.getKeys = function(Obj,order){
return Object.keys(Obj).sort(); //ensures that checkboxes are sorted by name.
}

//checks for the indeterminate condition.
var checkIndeterminate = function(selectObject){
var keys = $scope.getKeys(selectObject);
var counter = 0; max_limit = keys.length, t = true;
var elm = document.getElementById('selectAllChkBox');
keys.forEach(function(el, i){
t = t && selectObject[el];
if(selectObject[el]){counter++;}
});
if(counter<max_limit && counter!==0){
if(elm!==null){
elm.indeterminate = true;
}
}
else{
elm.indeterminate = false;
}
};

$scope.testSelectAll = function(){
var isAllSelected = true;
for(var key in $scope.cbSelectedByVal){
if($scope.cbSelectedByVal.hasOwnProperty(key)){
if($scope.cbSelectedByVal[key] == false){
isAllSelected = false;
}
}
}
if(isAllSelected){
$scope.cbSelectAll = true;
}else{
$scope.cbSelectAll = false;
}
checkIndeterminate($scope.cbSelectedByVal);

};

$scope.selectAllCheckBoxes = function(){
if($scope.cbSelectAll){
for(var key in $scope.cbSelectedByVal){
if($scope.cbSelectedByVal.hasOwnProperty(key)){
$scope.cbSelectedByVal[key] = true;
}
}
}else{
$scope.testSelectAll();
}
};

$scope.submit = function(){
var selectedItems = [];
for(var key in $scope.cbSelectedByVal){
if($scope.cbSelectedByVal.hasOwnProperty(key)){
if($scope.cbSelectedByVal[key] == true){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use === to specifically test the boolean true. Otherwise, "if ($scope.cbSelectedByVal[key])" is sufficient for testing if the value is "truthy"

selectedItems.push(key);
}
}
}
if(selectedItems && selectedItems.length==1 && selectedItems.indexOf("language")!= -1){
alert('Please select more items!');
}else{
$rootScope.selectedItems = selectedItems;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extraneous console.log() statements need to be removed.

$location.url('/results'); //prevents page change when only language is selected.
}
};



}]);



angular.module('ngTest.results', [])
.controller('ResultsController', ['$scope', '$rootScope', function($scope, $rootScope){
$scope.results = [];
if($rootScope.selectedItems){
$scope.results = $rootScope.selectedItems;
}
}]);
38 changes: 13 additions & 25 deletions results.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TestMe_lite results!</title>
<link rel="stylesheet" href="css/bootstrap.css"/>
<!--[if IE 7]>
<!--[if IE 7]>
<script>
// Attach additional stylesheets and JS for ie.
//TODO: json3 not working??
Expand All @@ -16,22 +10,16 @@
json3.appendChild(document.getElementsByTagName('head')[0]);
</script>
<![endif]-->
<script src="js/vendor/jquery.min.js"></script>
<script src="js/vendor/bootstrap.js"></script>

</head>
<body>
<div class="container">
<div class="row">
<h1>You made it to the results page!</h1>
</div>
<div class="well">
<p>On this page you will:</p>
<ul>
<li>Tastefully display the selections the user made .</li>
<li>Fix the json3 and css includes for IE7.</li>
</ul>

</div>
</body>
</html>
<div class="container" ng-controller="ResultsController">
<div class="row">
<h1>You made it to the results page!</h1>
</div>
<div class="well">
<p>Selected Items:</p>
<ul>
<li ng-repeat="item in results">{{item}}</li>
</ul>
<a href="index.html">Return to Form</a>
</div>
</div>
34 changes: 34 additions & 0 deletions testForm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div ng-controller="CheckBoxController">
<div class="row">
<h1>The User Interface Developer Test</h1>
</div>
<div class="well">
<ul>
<li>This Page and results.html should be converted to AngularJS templates.</li>
<li>Add a select-all toggle for the checkbox list.</li>
<li>Select-all should be checked if all fields are checked, unchecked if all fields are unchecked and indeterminate if some are checked.</li>
<li>Sor the checkboxes by name</li>
<li>When submitting the form, if only "Language" is checked, then an error should appear stating &quot; Please choose more items! &quot;</li>
<li>Successfully submitting the form takes us to results.html and shows what the user submitted.</li>
<li>Maybe the page can look a little better?</li>
<p>Read the README.md</p>
</ul>
</div>
<form role="form" ng-submit="submit()">
<div class="form-group">
<input type="checkbox" ng-model="cbSelectAll" ng-change="selectAllCheckBoxes()" id="selectAllChkBox">Select All
</div>
<div class="form-group col-md-6">
<div ng-repeat-start="item in getKeys(cbSelectedByVal)| orderBy:item">
<input type="checkbox" name="fields" value="{{item}}" ng-model="cbSelectedByVal[item]" ng-change="testSelectAll()">
<label>
{{item}}
</label>
</div>
<div ng-repeat-end></div>
<button type="submit" class="btn btn-primary" ng-click="submit()">Submit</button>
</div>
</form>
<script>
</script>
</div>