-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from qjd2413/service_hour_date
Service hour date
- Loading branch information
Showing
9 changed files
with
468 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
(function() { | ||
var months = [ | ||
{ id: 1, name: 'January' }, { id: 2, name: 'February' }, | ||
{ id: 3, name: 'March' }, { id: 4, name: 'April' }, | ||
{ id: 5, name: 'May' }, { id: 6, name: 'June' }, | ||
{ id: 7, name: 'July' }, { id: 8, name: 'August' }, | ||
{ id: 9, name: 'September' }, { id: 10, name: 'October' }, | ||
{ id: 11, name: 'November' }, { id: 12, name: 'December' } | ||
]; | ||
|
||
var monthToDays = function(month, year) { | ||
if(month === 2) { | ||
return (year % 4) ? 28 : 29; | ||
} else if(month < 8) { | ||
return 30 + month % 2; | ||
} else { | ||
return 30 + (month+1) % 2; | ||
} | ||
}; | ||
|
||
var verifyDate = function(date) { | ||
date.min = parseInt(date.min); | ||
var validHour = date.hour <= 12 && date.hour >= 1; | ||
var validMin = date.min <=59 && date.min >= 0; | ||
var validDay = date.day < monthToDays(date.month, date.year); | ||
var currentDate = new Date(); | ||
return (currentDate >= revParseDate(date)) && validHour && validMin && validDay; | ||
}; | ||
|
||
var revParseDate = function(date) { | ||
return new Date(date.year, date.month-1, date.day, date.hour, date.min); | ||
}; | ||
|
||
var dateInputDirective = function() { | ||
return { | ||
restrict: 'E', | ||
replace: false, | ||
scope: { | ||
date: '=', | ||
notify: '=', | ||
changeFn: '&' | ||
}, | ||
templateUrl: 'app/directives/templates/dateInput.html', | ||
link: function(scope) { | ||
scope.months = months; | ||
scope.changeFunction = function() { | ||
scope.notify = {}; | ||
if(!verifyDate(scope.date)) { | ||
scope.notify.error = 'Invalid Date.'; | ||
return; | ||
} | ||
if(scope.changeFn) scope.notify.error = scope.changeFn(); | ||
}; | ||
|
||
} | ||
} | ||
}; | ||
|
||
angular.module('KDRPoints') | ||
.directive('dateInput', dateInputDirective); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="date-input"> | ||
<select ng-model="date.month" ng-options="s_month.id as s_month.name for s_month in months" ng-change="changeFunction()" > | ||
</select> | ||
<input type="number" ng-model="date.day" placeholder="Day" max="31" ng-change="changeFunction()" /> | ||
<input type="number" ng-model="date.year" placeholder="Year" max="2020" ng-change="changeFunction()" /><br /> | ||
<input type="text" ng-model="date.hour" maxlength="2" ng-change="changeFunction()" /> | ||
: | ||
<input type="text" ng-model="date.min" maxlength="2" ng-change="changeFunction()" /> | ||
<select ng-model="date.cycle" ng-change="changeFunction()" > | ||
<option value="AM">AM</option> | ||
<option value="PM">PM</option> | ||
</select> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,53 @@ | ||
<div id="submit-service"> | ||
<select ng-model="type"> | ||
<select ng-model="type" ng-change="calculateDuration(); calculateEquivalent()" > | ||
<option>Hour</option> | ||
<option>Donation</option> | ||
</select> | ||
<br /> | ||
|
||
Description: | ||
<input type="text" ng-model="hour.description" /> | ||
|
||
<div ng-show="type === 'Hour'"> | ||
Start Time: <input type="text" ng-model="hour.startTime" /><br /> | ||
End Time: <input type="text" ng-model="hour.endTime" /><br /> | ||
</div> | ||
<form name="hourForm"> | ||
Description: | ||
<input type="text" ng-model="hour.description" /> | ||
|
||
<div ng-show="type === 'Donation'"> | ||
Amount: <input type="text" ng-model="hour.amount" /> | ||
</div> | ||
<div ng-show="type === 'Hour'"> | ||
Start: | ||
<datepicker date-format="MMMM d, yyyy" date-typer="true" > | ||
<input ng-model="hour.start.date" type="text" ng-change="calculateDuration()" /> | ||
</datepicker><br /> | ||
<select ng-model="hour.start.hour" ng-options="hr for hr in hours"></select> | ||
: | ||
<select ng-model="hour.start.min" ng-options="min for min in minutes"></select> | ||
<select ng-model="hour.start.cycle" ng-change="changeFunction()" > | ||
<option value="AM">AM</option> | ||
<option value="PM">PM</option> | ||
</select><br /> | ||
|
||
End: | ||
<datepicker date-format="MMMM d, yyyy" date-typer="true" > | ||
<input ng-model="hour.end.date" type="text" ng-change="calculateDuration()" /> | ||
</datepicker><br /> | ||
<select ng-model="hour.end.hour" ng-options="hr for hr in hours"></select> | ||
: | ||
<select ng-model="hour.end.min" ng-options="min for min in minutes"></select> | ||
<select ng-model="hour.end.cycle" ng-change="changeFunction()" > | ||
<option value="AM">AM</option> | ||
<option value="PM">PM</option> | ||
</select><br /> | ||
|
||
<button ng-click="submit()">Submit</button> | ||
<div class="duration"> | ||
Duration: {{hour.duration.hours}}:{{hour.duration.minutes}} | ||
</div> | ||
</div> | ||
|
||
<div ng-show="success">Hour successfully submitted.</div> | ||
<div ng-show="type === 'Donation'"> | ||
Amount: $<input type="number" ng-model="hour.amount" ng-change="calculateEquivalent()" /><br /> | ||
Hour Equivalent: {{hour.equivalent.hours}}:{{hour.equivalent.minutes}} | ||
</div> | ||
|
||
<button ng-click="submit()">Submit</button> | ||
|
||
<div ng-show="notify.success">{{type}} successfully submitted.</div> | ||
<div ng-show="notify.error">{{notify.error}}</div> | ||
|
||
</form> | ||
</div> |
Oops, something went wrong.