Skip to content

Commit

Permalink
built files
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Zirilli committed Feb 17, 2015
1 parent f36763b commit b9db40e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 169 deletions.
172 changes: 4 additions & 168 deletions dist/follett-angular-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@
restrict:'A',
controller: angular.noop,
link: function ($scope, element, attrs, modelCtrl) {
var USER_FRIENDLY_FORMAT, USER_FRIENDLY_PARSING_FORMAT, ISO_FORMAT, canUseDatePicker;
var USER_FRIENDLY_FORMAT, USER_FRIENDLY_PARSING_FORMAT, ISO_FORMAT, RFD_FORMAT, canUseDatePicker;
USER_FRIENDLY_FORMAT = 'MM/DD/YYYY';
USER_FRIENDLY_PARSING_FORMAT = 'M/D/YYYY';
ISO_FORMAT = 'YYYY-MM-DD';
RFD_FORMAT = 'ddd MMM DD YYYY HH:mm:ss';
canUseDatePicker = $window.Modernizr.inputtypes.date;

if (canUseDatePicker) {
Expand All @@ -120,9 +121,9 @@

if (modelValue) {
if (canUseDatePicker) {
dateString = $moment(modelValue).format(ISO_FORMAT);
dateString = $moment(modelValue, RFD_FORMAT).format(ISO_FORMAT);
} else {
dateString = $moment(modelValue).format(USER_FRIENDLY_FORMAT);
dateString = $moment(modelValue, RFD_FORMAT).format(USER_FRIENDLY_FORMAT);
}
}
return dateString;
Expand Down Expand Up @@ -198,163 +199,6 @@
};
}]);
}(angular));
/*
* FSS Angular component library
* Copyright 2013, Follett School Solutions, Inc.
*Licensed under the MIT license http://opensource.org/licenses/MIT
*/

(function () {
'use strict';
/**
*
* Date shim creates a date entry field that will utilize the browser's native date picker.
* If the browser does not support the datepicker, then it becomes a text entry field that requires
* mm/dd/yyyy. In either case, ng-model associated with the directive will store the date in the ISO8601
* format (yyyy-mm-dd). For the case of browsers which do not support the native date picker, the model will
* remain null until a valid date has been entered.
*/
angular.module('fss.directives.dateshim', ['fss.services.datetime'])
.directive('fssDateShim', ['DateTimeService', function (dts) {
return {
restrict: 'A',
replace: false,
//create an iso scope, and setup bi-di binding between scope.model and the ng-model of the parent scope
scope: {model: "=ngModel"},
templateUrl: 'directives/dateshim/dateshim.html',
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
var dateField = element.find('input[name="dateShimNativePicker"]'),
modelValue = null,
startingDate = null,
startingDateFormatted = null,
nativePicker = true;
//hack to keep the ngModel from the parent scope in sync with our copy of the ngModel on our isolate scope
//see http://stackoverflow.com/questions/15269737/why-is-ngmodel-setviewvalue-not-working-from
scope.$watch('model', function () {
scope.$eval(attrs.ngModel + "= model");
});
scope.$watch(attrs.ngModel, function (val) {
scope.model = val;
});

//Determine whether we have native date picker support
if (attrs.nativePicker && attrs.nativePicker === 'false') {
nativePicker = false;
}
scope.pickerSupported = nativePicker;

//initialize the models that hold the user input
scope.unclean = {text: null};
scope.clean = {text: null};

//Check to see if the model is set initially. If so, convert it to the displayable date
//and set the input fields with the initial values in the formats they expect them
modelValue = scope.model;
if (modelValue) {
startingDate = dts.parseDateISO8601(modelValue);
startingDateFormatted = dts.formatDate(startingDate);
scope.unclean.text = startingDateFormatted;
scope.clean.text = modelValue;
}
/**
* Watch the unclean model. This is input from the text input field expecting
* input in the mm/dd/yyyy format
* Changes are tested to see if it is a valid date. If so, then we format it in ISO8601
* and set the model with the ISO8601 date string
*/
scope.$watch('unclean.text', function (newVal) {
var d;
if (dts.isValidDate(newVal)) {
d = new Date(newVal);
ngModelCtrl.$setViewValue(dts.formatDateISO8601(d));
} else {
ngModelCtrl.$setViewValue(null);
}

});
//On blur of the date picker field, we need to update the clean model. This is due to iPads
//not triggering a change event when a date is chosen. The other browsers behave normally and keep
//the clean model up to date.
dateField.blur(function () {
scope.$apply(function () {
scope.clean.text = dateField.val();
});
});

/**
* Watch the clean model. This will be set by the native date picker, and it will be set in
* the ISO8601 format.
*
*/
scope.$watch('clean.text', function (newVal) {
ngModelCtrl.$setViewValue(newVal);
});
}
};
}])
/**
* Validator that checks if the model is being set with an iso8601 date and sets an error
* property if it is not a valid date. *Note: this validator/parser will return a null
* if an error occurs, which will effectively null out the model, preventing it from being set
* with an invalid ISO date
*/
.directive('isoDate', ['DateTimeService', function (dts) {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
var validDate, retVal;
ngModelCtrl.$parsers.unshift(function (viewValue) {
validDate = true;
retVal = viewValue;
try {
dts.parseDateISO8601(viewValue);
} catch (e) {
//Caught exception parsing the date. This means it was not in the ISO8601 format
//and will be considered an invalid date
validDate = false;
retVal = null;
}
ngModelCtrl.$setValidity('validDate', validDate);
return retVal;
});
}
};
}])
/**
* Validator that checks if the date is today or later and sets an error property
* if it is in the past. *Note: this validator will pass back the date even if it is in the past,
* so a model would be updated with the corresponding past date.
*/
.directive('future', ['DateTimeService', function (dts) {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
var viewDate = null, today = null, currentDate, retVal = null;
ngModelCtrl.$parsers.unshift(function (viewValue) {
currentDate = false;
retVal = null;
today = new Date();

try {
viewDate = dts.parseDateISO8601(viewValue);
if (dts.compareDates(today, viewDate) <= 0) {
currentDate = true;
} else {
currentDate = false;
}
retVal = viewValue;
} catch (e) {
//Caught exception parsing the date. This means it was not in the ISO8601 format
}
ngModelCtrl.$setValidity('currentDate', currentDate);
return retVal;
});
}
};
}]);
}());

(function (angular) {
'use strict';

Expand Down Expand Up @@ -1459,11 +1303,3 @@
}]);

}(angular));
angular.module('fac').run(['$templateCache', function($templateCache) {
'use strict';

$templateCache.put('directives/dateshim/dateshim.html',
"<div data-ng-show=\"pickerSupported\"> <input name=\"dateShimNativePicker\" type=\"date\" placeholder=\"mm/dd/yyyy\" data-ng-model=\"clean.text\"> </div> <div data-ng-show=\"!pickerSupported\"> <input name=\"dateShimTextOnly\" type=\"text\" placeholder=\"mm/dd/yyyy\" data-ng-model=\"unclean.text\"> </div>"
);

}]);
Loading

0 comments on commit b9db40e

Please sign in to comment.