Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

[FIX] History: force "to" date (RT-3374) #2491

Merged
merged 1 commit into from
May 6, 2015
Merged
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
37 changes: 32 additions & 5 deletions src/js/directives/fields.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,51 @@ module.directive('rpDatepicker', [function() {
require: '?ngModel',
link: function(scope, element, attr, ngModel) {
attr.$observe('rpDatepicker', function() {
var dp = $(element).datepicker({
var options = {
format: 'mm/dd/yyyy'
});
};

if (attr.rpDatepickerMin) {
var dateMinVal = 0;
options.onRender = function(date) {
return date.valueOf() < dateMinVal ? 'disabled' : '';
};

scope.$watch(attr.rpDatepickerMin, function(v) {
if (v instanceof Date) {
dateMinVal = v.valueOf();
var viewDate = ngModel.$viewValue.valueOf();
if (typeof viewDate === 'string') {
viewDate = Date.parse(viewDate).valueOf();
}
if (dateMinVal > viewDate) {
var newDate = new Date(dateMinVal + 24 * 60 * 60 * 1000);
ngModel.$setViewValue(newDate);
$(element).datepicker('setValue', newDate);
}
// fore re-render
$(element).data('datepicker').fill();
}
});
}

var dp = $(element).datepicker(options);
dp.on('changeDate', function(e) {
scope.$apply(function () {
ngModel.$setViewValue(e.date.getMonth() ? e.date : new Date(e.date));
});
});
scope.$watch(attr.ngModel,function() {

scope.$watch(attr.ngModel, function() {
var update = ngModel.$viewValue;

function falsy(v) {return v == '0' || v == 'false'; }

if (!falsy(attr.ignoreInvalidUpdate) &&
(update == null ||
(update instanceof Date && isNaN(update.getYear())) )) {
return;
}
return;
}
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/tabs/history.jade
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ section.col-xs-12.content(ng-controller="HistoryCtrl")
i.fa.fa-calendar.fa-fw
span(l10n) To
.input-wrapper
input.form-control(type="text", rp-datepicker, ng-model="dateMaxView", readonly)
input.form-control(type="text", rp-datepicker, ng-model="dateMaxView", rp-datepicker-min="dateMinView", readonly)
button.btn.btn-block.btn-primary.submit(type='submit', l10n) Filter

.transactions.col-lg-9.col-md-8.col-sm-7.col-xs-12
Expand Down