Skip to content

Commit d76631d

Browse files
committed
add datetimepicker
1 parent 40f89b3 commit d76631d

File tree

6 files changed

+106
-1
lines changed

6 files changed

+106
-1
lines changed

Gruntfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ module.exports = function (grunt) {
128128
'lib/bootstrap/dist/js/bootstrap.js',
129129
'lib/bootstrap-combobox/js/bootstrap-combobox.js',
130130
'lib/bootstrap-datepicker/dist/js/bootstrap-datepicker.js',
131+
'lib/moment/moment.js',
132+
'lib/eonasdan-bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js',
131133
'lib/bootstrap-select/js/bootstrap-select.js',
132134
'lib/patternfly-bootstrap-treeview/src/js/bootstrap-treeview.js',
133135
'lib/c3/c3.js',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"karma-jasmine": "0.2.2",
4141
"karma-junit-reporter": "0.2.2",
4242
"karma-ng-html2js-preprocessor": "~0.1",
43-
"karma-phantomjs-launcher": "0.1.4",
43+
"karma-phantomjs-launcher": "^1.0.0",
4444
"matchdep": "0.3.0"
4545
},
4646
"scripts": {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @ngdoc directive
3+
* @name patternfly.form.directive:pfDateTimepicker
4+
*
5+
* @description
6+
* Angular directive to wrap the bootstrap datetimepicker http://eonasdan.github.io/bootstrap-datetimepicker/
7+
*
8+
* @param {object} date date and time moment object
9+
* @param {string} options the configuration options for the date picker
10+
*
11+
* @example
12+
<example module="patternfly.form">
13+
<file name="index.html">
14+
<form class="form" ng-controller="FormDemoCtrl">
15+
<span>Date and Time: <span ng-bind="date"></span></span>
16+
<div pf-date-timepicker options="options" date="date"></div>
17+
</form>
18+
</file>
19+
20+
<file name="script.js">
21+
angular.module( 'patternfly.form' ).controller( 'FormDemoCtrl', function( $scope ) {
22+
$scope.options = {
23+
format: 'HH:mm'
24+
};
25+
$scope.date = moment();
26+
});
27+
</file>
28+
</example>
29+
*/
30+
angular.module('patternfly.form').directive('pfDateTimepicker', function () {
31+
'use strict';
32+
33+
return {
34+
replace: true,
35+
restrict: 'A',
36+
require: '^form',
37+
templateUrl: 'form/datetimepicker/datetimepicker.html',
38+
scope: {
39+
options: '=',
40+
date: '='
41+
},
42+
link: function ($scope, element) {
43+
//Make sure the date picker is set with the correct options
44+
element.datetimepicker($scope.options);
45+
46+
//Set the initial value of the date picker
47+
element.datetimepicker('date', $scope.date || null);
48+
49+
//Change happened on the date picker side. Update the underlying date model
50+
element.on('dp.change', function (elem) {
51+
$scope.$apply(function () {
52+
$scope.date = elem.date;
53+
});
54+
});
55+
}
56+
};
57+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="input-group time-picker-pf">
2+
<input type="text" class="form-control"/>
3+
<span class="input-group-addon btn btn-default">
4+
<span class="fa fa-clock-o"></span>
5+
</span>
6+
</div>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
describe('Directive: pfDateTimepicker', function() {
2+
var $scope, $compile, $timeout, element, datepicker, dateInput, dateElement;
3+
4+
beforeEach(module('patternfly.form', 'form/datetimepicker/datetimepicker.html'));
5+
6+
beforeEach(inject(function(_$compile_, _$rootScope_) {
7+
$compile = _$compile_;
8+
$scope = _$rootScope_;
9+
}));
10+
11+
var compileDateTimepicker = function(markup, $scope) {
12+
var el = $compile(markup)($scope);
13+
$scope.$apply();
14+
return el;
15+
};
16+
17+
it("should set the date and time picker input", function() {
18+
$scope.options = {format: 'HH:mm'};
19+
$scope.date = moment("2016-01-01 11:31:23");
20+
21+
datepicker = compileDateTimepicker('<form><div pf-date-timepicker options="options" date="date"></div></form>', $scope);
22+
dateInput = angular.element(datepicker).find('input');
23+
24+
expect(dateInput.val()).toBe('11:31');
25+
});
26+
27+
it("should set the angular model", function() {
28+
$scope.options = {format: 'HH:mm'};
29+
30+
datepicker = compileDateTimepicker('<form><div pf-date-timepicker options="options" date="date"></div></form>', $scope);
31+
dateInput = angular.element(datepicker).find('input');
32+
dateElement = angular.element(datepicker).find('div');
33+
dateElement.datetimepicker('date', moment("2016-01-01 11:31:23"));
34+
35+
expect(dateInput.val()).toBe('11:31');
36+
});
37+
38+
});

test/karma.conf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module.exports = function(config) {
1010
files: [
1111
'lib/jquery/dist/jquery.js',
1212
'lib/bootstrap-datepicker/dist/js/bootstrap-datepicker.js',
13+
'lib/moment/moment.js',
14+
'lib/eonasdan-bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js',
1315
'lib/bootstrap-select/js/bootstrap-select.js',
1416
'lib/d3/d3.js',
1517
'lib/c3/c3.js',

0 commit comments

Comments
 (0)