-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
124 lines (99 loc) · 4.26 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// I think in the spirit of the assignment this code follows what the requirements were.
// One thing I took a little liberty with. One change I made was to update the border
// of the input box before the user presses the "Check If Too Much" button.
// That and I changed/added more info for the status messages presented to users.
// Also I had one version that updated the user message about too much or enjoy in
// realtime, but the assignment was to have a button, I beleive to specifically see/use
// the ng-click Angular's version for onclick() thus the auto fail if you used the HTML default...
// If desired just uncomment the call to DisplayMessage() in the UpdateBorder()...
//
// FYI: This was tested with the minify, and it worked fine... ie. the ctrlr.$inject...
//
//
// CSS on-line helper -- http://enjoycss.com/start#border
//
(function()
{
'use strict';
var app = angular.module('TxtBoxApp',[]);
app.controller( 'TxtBoxController',TxtBoxController);
//
// Defend again minification errors...
//
TxtBoxController.$inject = ['$scope','$filter'];
function TxtBoxController($scope)
{
$scope.textBox = ""; // input text box for user input
$scope.userMessage = ""; // status message when the user presses teh check box.
$scope.inputBoxCSS = "normalBorder"; // css variably for dynamicaly updating the border color.
$scope.UpdateBorder=function()
{
//
// Sprint user input (textBox) into an array.
//
var items = splitAndFilterStrings($scope.textBox,',');
$scope.userMessage = ""; // Always clear previous message to avoid confusing UI state.
// Determine the corrct border color...
//
// Borders
// [ normalBorder | redBorder | greenBoarder]
//
if( items.length <1)
{
$scope.inputBoxCSS = "normalBorder";
}
else if( items.length < 4 )
{
$scope.inputBoxCSS = "greenBoarder";
}
else
{
$scope.inputBoxCSS = "redBorder";
}
// Uncomment this as we don't need the user to even press the button...
// $scope.DisplayMessage();
}; // end -- $scope.UpdateBorder=function()
$scope.DisplayMessage=function()
{
var items = splitAndFilterStrings($scope.textBox,',');
if( items.length <1 )
{
$scope.userMessage = "Please enter data first -- Don't let Yaakov starve... Don't be mean!";
}
else if ( items.length <4 )
{
$scope.userMessage = "Enjoy! -- Yaakov says \"Thank-You\"";
}
else
{
$scope.userMessage = "\"Too much!\" -- Yaakov needs to stay in shape!!!";
}
}; // end -- $scope.DisplayMessage=function()
function splitAndFilterStrings(stringToSplit, separator)
{
//
// Trim off trailing whitespace and commas.
//
var arrayOfStrings = stringToSplit.replace(/[ ,]+$/,"").split(',');
if( arrayOfStrings.length == 1 && arrayOfStrings[0].length ==0 )
{
//
// if we get a valid string, the split will result in a one element array with an
// empty string. So see if in fact arrayOfStrings is like this and return an
// array with zero items.
//
return [];
}
var returnStrings = [];
for(var i=0; i < arrayOfStrings.length; ++i)
{
var tmpStr = arrayOfStrings[i].trim();
if( tmpStr.length > 0 )
{
returnStrings.push(tmpStr);
}
}
return returnStrings;
}; // end -- splitString(stringToSplit, separator)
} // end -- TxtBoxController($scope)
})(); // end -- IIFEE()