Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade a few things. #50

Open
wants to merge 5 commits 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- 0.10
- 6.9.5

before_script:
- npm install -g bower
Expand Down
266 changes: 154 additions & 112 deletions bootstrap-datepicker.js
Original file line number Diff line number Diff line change
@@ -1,126 +1,168 @@
angular.module("schemaForm").run(["$templateCache", function($templateCache) {$templateCache.put("directives/decorators/bootstrap/datepicker/datepicker.html","<div class=\"form-group {{form.htmlClass}}\" ng-class=\"{\'has-error\': hasError()}\">\n <label class=\"control-label {{form.labelHtmlClass}}\" ng-show=\"showTitle()\">{{form.title}}</label>\n <div ng-class=\"{\'input-group\': (form.fieldAddonLeft || form.fieldAddonRight)}\">\n <span ng-if=\"form.fieldAddonLeft\"\n class=\"input-group-addon\"\n ng-bind-html=\"form.fieldAddonLeft\"></span>\n <input ng-show=\"form.key\"\n type=\"text\"\n class=\"form-control {{form.fieldHtmlClass}}\"\n schema-validate=\"form\"\n ng-model=\"$$value$$\"\n ng-disabled=\"form.readonly\"\n pick-a-date=\"form.pickadate\"\n min-date=\"form.minDate\"\n max-date=\"form.maxDate\"\n select-years=\"form.selectYears\"\n select-months=\"form.selectMonths\"\n name=\"{{form.key.slice(-1)[0]}}\"\n format=\"form.format\" />\n <span ng-if=\"form.fieldAddonRight\"\n class=\"input-group-addon\"\n ng-bind-html=\"form.fieldAddonRight\"></span>\n </div>\n <span class=\"help-block\">{{ (hasError() && errorMessage(schemaError())) || form.description}}</span>\n</div>\n");}]);
angular.module('schemaForm').directive('pickADate', function() {

//String dates for min and max is not supported
//https://github.com/amsul/pickadate.js/issues/439
//So strings we create dates from
var formatDate = function(value) {
//Strings or timestamps we make a date of
if (angular.isString(value) || angular.isNumber(value)) {
return new Date(value);
}
return value; //We hope it's a date object
};

return {
restrict: 'A',
require: 'ngModel',
scope: {
ngModel: '=',
pickADate: '=',
minDate: '=',
maxDate: '=',
format: '=',
selectYears: '=?',
selectMonths: '=?'
},
link: function(scope, element, attrs, ngModel) {
//Bail out gracefully if pickadate is not loaded.
if (!element.pickadate) {
return;
}

//By setting formatSubmit to null we inhibit the
//hidden field that pickadate likes to create.
//We use ngModel formatters instead to format the value.
var opts = {
onClose: function() {
element.blur();
angular.module('schemaForm').run(['$templateCache', function($templateCache) {$templateCache.put('directives/decorators/bootstrap/datepicker/datepicker.html','<div class="form-group {{form.htmlClass}}" ng-class="{\'has-error\': hasError()}">\n <label class="control-label {{form.labelHtmlClass}}"\n ng-class="{\'sr-only\': !showTitle()}"\n for="{{form.key.slice(-1)[0]}}">{{form.title}}</label>\n <div ng-class="{\'input-group\': (form.fieldAddonLeft || form.fieldAddonRight)}">\n <span ng-if="form.fieldAddonLeft" class="input-group-addon" ng-bind-html="form.fieldAddonLeft"></span>\n <input id="{{form.key.slice(-1)[0]}}"\n ng-show="form.key"\n type="text"\n class="form-control {{form.fieldHtmlClass}}"\n schema-validate="form"\n sf-field-model\n ng-disabled="form.readonly"\n pick-a-date="form.pickadate"\n min-date="form.minDate"\n max-date="form.maxDate"\n select-years="form.selectYears"\n select-months="form.selectMonths"\n name="{{form.key.slice(-1)[0]}}"\n format="form.format" />\n <span ng-if="form.fieldAddonRight" class="input-group-addon" ng-bind-html="form.fieldAddonRight"></span>\n </div>\n <span class="help-block">{{ (hasError() && errorMessage(schemaError())) || form.description}}</span>\n</div>\n');}]);
/**
* @ngdoc directive
* @module schemaForm
* @name pickADate
* @description
* Creates a directive to pass through to $.fn.pickadate
*/
(function(angular) {
'use strict';

angular
.module('schemaForm')
.directive('pickADate', pickADateDirective);

function pickADateDirective() {
return {
restrict: 'A',
require: 'ngModel',
scope: {
pickADate: '=',
minDate: '=',
maxDate: '=',
format: '=',
selectYears: '=?',
selectMonths: '=?'
},
formatSubmit: null,
selectYears: (scope.selectYears || false),
selectMonths: (scope.selectMonths || false)
};
if (scope.pickADate) {
angular.extend(opts, scope.pickADate);
}
element.pickadate(opts);

//Defaultformat is for json schema date-time is ISO8601
//i.e. "yyyy-mm-dd"
var defaultFormat = 'yyyy-mm-dd';

//View format on the other hand we get from the pickadate translation file
var viewFormat = $.fn.pickadate.defaults.format;

var picker = element.pickadate('picker');

//The view value
ngModel.$formatters.push(function(value) {
if (angular.isUndefined(value) || value === null) {
return value;
}

//We set 'view' and 'highlight' instead of 'select'
//since the latter also changes the input, which we do not want.
picker.set('view', value, {format: scope.format || defaultFormat});
picker.set('highlight', value, {format: scope.format || defaultFormat});

//piggy back on highlight to and let pickadate do the transformation.
return picker.get('highlight', viewFormat);
});

ngModel.$parsers.push(function() {
return picker.get('select', scope.format || defaultFormat);
});

//bind once.
if (angular.isDefined(attrs.minDate)) {
var onceMin = scope.$watch('minDate', function(value) {
if (value) {
picker.set('min', formatDate(value));
onceMin();
link: function(scope, element, attrs, ngModel) {
//Bail out gracefully if pickadate is not loaded.
if (!element.pickadate) {
return;
}

//By setting formatSubmit to null we inhibit the
//hidden field that pickadate likes to create.
//We use ngModel formatters instead to format the value.
var opts = {
onClose: function() {
element.blur();
},
formatSubmit: null,
selectYears: (scope.selectYears || false),
selectMonths: (scope.selectMonths || false)
};
if (scope.pickADate) {
angular.extend(opts, scope.pickADate);
}
element.pickadate(opts);

//Defaultformat is for json schema date-time is ISO8601
//i.e. "yyyy-mm-dd"
var defaultFormat = 'yyyy-mm-dd';

//View format on the other hand we get from the pickadate translation file
var viewFormat = $.fn.pickadate.defaults.format;

var picker = element.pickadate('picker');

//The view value
ngModel.$formatters.push(function(value) {
if (angular.isUndefined(value) || value === null) {
return value;
}

//We set 'view' and 'highlight' instead of 'select'
//since the latter also changes the input, which we do not want.
picker.set('view', value, {format: scope.format || defaultFormat});
picker.set('highlight', value, {format: scope.format || defaultFormat});

//piggy back on highlight to and let pickadate do the transformation.
return picker.get('highlight', viewFormat);
});

ngModel.$parsers.push(function() {
return picker.get('select', scope.format || defaultFormat);
});

//bind once.
if (angular.isDefined(attrs.minDate)) {
var onceMin = scope.$watch('minDate', function(value) {
if (value) {
picker.set('min', formatDate(value));
onceMin();
}
}, true);
}

if (angular.isDefined(attrs.maxDate)) {
var onceMax = scope.$watch('maxDate', function(value) {
if (value) {
picker.set('max', formatDate(value));
onceMax();
}
}, true);
}
}
}, true);
}
};

if (angular.isDefined(attrs.maxDate)) {
var onceMax = scope.$watch('maxDate', function(value) {
if (value) {
picker.set('max', formatDate(value));
onceMax();
}
}, true);
//String dates for min and max is not supported
//https://github.com/amsul/pickadate.js/issues/439
//So strings we create dates from
function formatDate(value) {
//Strings or timestamps we make a date of
if (angular.isString(value) || angular.isNumber(value)) {

return new Date(value);
}
}
};
});

angular.module('schemaForm').config(
['schemaFormProvider', 'schemaFormDecoratorsProvider', 'sfPathProvider',
function(schemaFormProvider, schemaFormDecoratorsProvider, sfPathProvider) {
return value; //We hope it's a date object
}
}
}(window.angular));

(function(angular) {
'use strict';

angular
.module('schemaForm')
.config([
'schemaFormProvider',
'schemaFormDecoratorsProvider',
'sfPathProvider',
'sfBuilderProvider',
datepickerConfig
]);

/**
* Define the datepicker addon in schemaForm
* @param {schemaFormProvider} schemaFormProvider
* @param {schemaFormDecoratorsProvider} schemaFormDecoratorsProvider
* @param {sfPathProvider} sfPathProvider
* @param {sfBuilderProvider} sfBuilderProvider
*/
function datepickerConfig(
schemaFormProvider,
schemaFormDecoratorsProvider,
sfPathProvider,
sfBuilderProvider
) {
schemaFormProvider.defaults.string.unshift(datepicker);
//Add to the bootstrap directive
schemaFormDecoratorsProvider.defineAddOn(
'bootstrapDecorator',
'datepicker',
'directives/decorators/bootstrap/datepicker/datepicker.html',
sfBuilderProvider.stdBuilders
);

var datepicker = function(name, schema, options) {
/**
* Sets date and date-time formats to use datepicker by default.
* @param {string} name
* @param {object} schema
* @param {object} options
* @returns {object|undefined}
*/
function datepicker(name, schema, options) {
if (schema.type === 'string' && (schema.format === 'date' || schema.format === 'date-time')) {
var f = schemaFormProvider.stdFormObj(name, schema, options);

f.key = options.path;
f.type = 'datepicker';
options.lookup[sfPathProvider.stringify(options.path)] = f;

return f;
}
};

schemaFormProvider.defaults.string.unshift(datepicker);

//Add to the bootstrap directive
schemaFormDecoratorsProvider.addMapping(
'bootstrapDecorator',
'datepicker',
'directives/decorators/bootstrap/datepicker/datepicker.html'
);
schemaFormDecoratorsProvider.createDirective(
'datepicker',
'directives/decorators/bootstrap/datepicker/datepicker.html'
);
}
}
]);
}(window.angular));
2 changes: 1 addition & 1 deletion bootstrap-datepicker.min.js

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

4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "angular-schema-form-datepicker",
"main": [
"bootstrap-datepicker.min.js"
"bootstrap-datepicker.js"
],
"version": "0.4.0",
"version": "0.4.2",
"authors": [
"Textalk",
"David Jensen <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var gulp = require('gulp');

var templateCache = require('gulp-angular-templatecache');
var minifyHtml = require('gulp-minify-html');
var minifyHtml = require('gulp-htmlmin');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var streamqueue = require('streamqueue');
Expand Down
49 changes: 25 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
{
"name": "angular-schema-form-datepicker",
"version": "0.4.1",
"description": "Datepicker add-on for schema form",
"version": "0.4.2",
"description": "Datepicker add-on for angular schema form",
"scripts": {
"test": "rm -fr coverage && ./node_modules/karma/bin/karma start --single-run --browsers PhantomJS karma.conf.js"
},
"author": "Textalk",
"license": "MIT",
"main": "bootstrap-datepicker.js",
"devDependencies": {
"chai": "^1.9.0",
"coveralls": "^2.11.0",
"gulp": "^3.5.6",
"gulp-angular-templatecache": "^1.2.1",
"gulp-concat": "^2.2.0",
"gulp-jscs": "^1.1.0",
"gulp-minify-html": "^0.1.1",
"gulp-plumber": "^0.6.5",
"gulp-uglify": "^0.2.1",
"karma": "^0.12.0",
"karma-chai-sinon": "^0.1.3",
"karma-coverage": "^0.2.1",
"karma-growler-reporter": "0.0.1",
"karma-mocha": "^0.1.3",
"karma-ng-html2js-preprocessor": "^0.1.0",
"karma-phantomjs-launcher": "^1.0.0",
"mocha": "^1.18.0",
"mocha-lcov-reporter": "0.0.1",
"phantomjs-prebuilt": "^2.1.7",
"sinon": "^1.9.0",
"sinon-chai": "^2.5.0",
"streamqueue": "0.0.5"
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"gulp": "^3.9.1",
"gulp-angular-templatecache": "^2.2.0",
"gulp-concat": "^2.6.1",
"gulp-htmlmin": "^4.0.0",
"gulp-jscs": "^4.1.0",
"gulp-plumber": "^1.2.0",
"gulp-uglify": "^3.0.0",
"karma": "^2.0.0",
"karma-chai-sinon": "^0.1.5",
"karma-coverage": "^1.1.1",
"karma-growler-reporter": "0.0.2",
"karma-mocha": "^1.3.0",
"karma-ng-html2js-preprocessor": "^1.0.0",
"karma-phantomjs-launcher": "^1.0.4",
"mocha": "^5.0.0",
"mocha-lcov-reporter": "^1.3.0",
"phantomjs-prebuilt": "^2.1.16",
"sinon": "^4.2.2",
"sinon-chai": "^2.14.0",
"streamqueue": "^1.1.2"
}
}
Loading