-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
7 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
59 changes: 59 additions & 0 deletions
59
app/assets/javascripts/components/datetime-delay-picker.js
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,59 @@ | ||
ManageIQ.angular.app.component('datetimeDelayPicker', { | ||
bindings: { | ||
model: '=', | ||
start_date: '<', | ||
}, | ||
|
||
controllerAs: 'vm', | ||
|
||
controller: ['$scope', '$element', function($scope, $element) { | ||
$scope.__ = __; | ||
|
||
this.months = 0; | ||
this.weeks = 0; | ||
this.days = 0; | ||
this.hours = 0; | ||
|
||
this.setRetirementDate = function() { | ||
this.model = moment(this.start_date) | ||
.add(this.months, 'month') | ||
.add(this.weeks, 'week') | ||
.add(this.days, 'day') | ||
.add(this.hours, 'hour') | ||
.toDate(); | ||
}; | ||
|
||
this.$onInit = function() { | ||
if (! this.start_date) { | ||
this.start_date = new Date(); | ||
} | ||
}; | ||
|
||
this.$postLink = function() { | ||
var commonAttrs = {min: 0, verticalbuttons: true, buttondown_class: "btn btn-link", buttonup_class: "btn btn-link"}; | ||
var attrs = {months: __('Months'), weeks: __('Weeks'), days: __('Days'), hours: __('Hours')} | ||
|
||
for (var key in attrs) { | ||
$element.find('input[name=' + key + ']').TouchSpin(Object.assign({}, commonAttrs, {'prefix': attrs[key]})); | ||
} | ||
}; | ||
}], | ||
|
||
template: [ | ||
'<div class="form-group">', | ||
' <label class="control-label col-md-2">{{ __("Time Delay:") }}</label>', | ||
' <div class="col-md-2">', | ||
' <input class="form-control" name="months" type="text" ng-model="vm.months" ng-change="vm.setRetirementDate()">', | ||
' </div>', | ||
' <div class="col-md-2">', | ||
' <input class="form-control" name="weeks" type="text" ng-model="vm.weeks" ng-change="vm.setRetirementDate()">', | ||
' </div>', | ||
' <div class="col-md-2">', | ||
' <input class="form-control" name="days" type="text" ng-model="vm.days" ng-change="vm.setRetirementDate()">', | ||
' </div>', | ||
' <div class="col-md-2">', | ||
' <input class="form-control" name="hours" type="text" ng-model="vm.hours" ng-change="vm.setRetirementDate()">', | ||
' </div>', | ||
'</div>', | ||
].join('\n'), | ||
}); |
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