Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(js) Improve dates constraints of vacation reply
Fixes #3841
- Loading branch information
Showing
3 changed files
with
139 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
UI/WebServerResources/js/Common/sgResetOnDisabled.directive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
|
||
(function() { | ||
'use strict'; | ||
|
||
/** | ||
* sgResetOnDisabled - A directive to reset any error of a datepicker when marked | ||
* as disabled. | ||
* @memberof SOGo.Common | ||
* @ngInject | ||
* @example: | ||
<md-datepicker | ||
ng-model="myDate" | ||
ng-disabled="!myDateEnabled" | ||
sg-reset-on-disabled> | ||
*/ | ||
function sgResetOnDisabled() { | ||
return { | ||
link: postLink, | ||
require: 'mdDatepicker', | ||
restrict: 'A' | ||
}; | ||
|
||
function postLink(scope, element, attrs, datepickerCtrl) { | ||
function getInput() { | ||
return element.find('input').eq(0); | ||
} | ||
|
||
// We need to wait for the datepicker directive to be compiled | ||
var listener = scope.$watch(getInput, function (input) { | ||
var ngModel; | ||
|
||
if (input.length) { | ||
listener(); // self release | ||
datepickerCtrl.$scope.$watch('ctrl.isDisabled', function(isDisabled) { | ||
if (isDisabled) | ||
if (datepickerCtrl.ngModelCtrl.$invalid) | ||
// Trigger the event that will reset the errors and the model value | ||
datepickerCtrl.$scope.$emit('md-calendar-change', datepickerCtrl.date); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
angular | ||
.module('SOGo.Common') | ||
.directive('sgResetOnDisabled', sgResetOnDisabled); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters