Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Added now and today buttons #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
50 changes: 47 additions & 3 deletions dist/mdPickers.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ function DatePickerCtrl($scope, $mdDialog, $mdMedia, $timeout, currentDate, opti
this.showCalendar = function() {
self.selectingYear = false;
};

/**
* Set the date component to today
*/
this.today = function() {
var now = moment();
this.date.year(now.year());
this.date.month(now.month());
this.date.date(now.date());
};

this.cancel = function() {
$mdDialog.cancel();
Expand Down Expand Up @@ -158,6 +168,7 @@ function DatePickerCtrl($scope, $mdDialog, $mdMedia, $timeout, currentDate, opti
module.provider("$mdpDatePicker", function() {
var LABEL_OK = "OK",
LABEL_CANCEL = "Cancel",
LABEL_TODAY = "Today",
DISPLAY_FORMAT = "ddd, MMM DD";

this.setDisplayFormat = function(format) {
Expand Down Expand Up @@ -202,6 +213,7 @@ module.provider("$mdpDatePicker", function() {
'<mdp-calendar ng-if="!datepicker.selectingYear" class="mdp-animation-zoom" date="datepicker.date" min-date="datepicker.minDate" date-filter="datepicker.dateFilter" max-date="datepicker.maxDate"></mdp-calendar>' +
'<md-dialog-actions layout="row">' +
'<span flex></span>' +
'<md-button ng-click="datepicker.today()" aria-label="' + LABEL_TODAY + '">' + LABEL_TODAY + '</md-button>' +
'<md-button ng-click="datepicker.cancel()" aria-label="' + LABEL_CANCEL + '">' + LABEL_CANCEL + '</md-button>' +
'<md-button ng-click="datepicker.confirm()" class="md-primary" aria-label="' + LABEL_OK + '">' + LABEL_OK + '</md-button>' +
'</md-dialog-actions>' +
Expand Down Expand Up @@ -606,6 +618,13 @@ function TimePickerCtrl($scope, $mdDialog, time, autoSwitch, $mdMedia) {
self.time.hour(self.time.hour() + 12);
};

this.now = function() {
var now = moment();
this.time.hour(now.hour());
this.time.minute(now.minute());
this.time.second(now.second());
};

this.cancel = function() {
$mdDialog.cancel();
};
Expand Down Expand Up @@ -689,21 +708,44 @@ function ClockCtrl($scope) {
case TYPE_HOURS:
for(var i = 1; i <= 12; i++)
self.steps.push(i);
self.selected = self.time.hours() || 0;
if(self.selected > 12) self.selected -= 12;

break;
case TYPE_MINUTES:
for(var i = 5; i <= 55; i+=5)
self.steps.push(i);
self.steps.push(0);
self.selected = self.time.minutes() || 0;

break;
}
refresh();
};

this.init();

/**
* Respond to changes in the selected date/time.
*/
$scope.$watch(function() { return self.time.unix() }, function(newVal, oldVal) {
refresh();
});

/**
* Refresh the value shown in the current clock
*/
function refresh() {
self.type = self.type || "hours";
switch(self.type) {
case TYPE_HOURS:
self.selected = self.time.hours() || 0;
if(self.selected > 12) self.selected -= 12;

break;
case TYPE_MINUTES:
self.selected = self.time.minutes() || 0;

break;
}
}
}

module.directive("mdpClock", ["$animate", "$timeout", function($animate, $timeout) {
Expand Down Expand Up @@ -761,6 +803,7 @@ module.directive("mdpClock", ["$animate", "$timeout", function($animate, $timeou

module.provider("$mdpTimePicker", function() {
var LABEL_OK = "OK",
LABEL_NOW = "Now",
LABEL_CANCEL = "Cancel";

this.setOKButtonLabel = function(label) {
Expand Down Expand Up @@ -800,6 +843,7 @@ module.provider("$mdpTimePicker", function() {

'<md-dialog-actions layout="row">' +
'<span flex></span>' +
'<md-button ng-click="timepicker.now()" aria-label="' + LABEL_NOW + '">' + LABEL_NOW + '</md-button>' +
'<md-button ng-click="timepicker.cancel()" aria-label="' + LABEL_CANCEL + '">' + LABEL_CANCEL + '</md-button>' +
'<md-button ng-click="timepicker.confirm()" class="md-primary" aria-label="' + LABEL_OK + '">' + LABEL_OK + '</md-button>' +
'</md-dialog-actions>' +
Expand Down
2 changes: 1 addition & 1 deletion dist/mdPickers.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/mdPickers.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mdPickers.min.js.map

Large diffs are not rendered by default.

Loading