only enable the schedule button if a date is selected

This commit is contained in:
Shannon
2018-11-08 17:14:04 +11:00
parent 4b23090e97
commit 3ac3590f2c
2 changed files with 29 additions and 26 deletions

View File

@@ -55,7 +55,6 @@
if (active) {
//ensure that the current one is selected
active.schedule = true;
active.save = true;
}
@@ -85,7 +84,7 @@
variant.datePickerConfig = datePickerConfig;
// format all dates to local
if(variant.releaseDate || variant.removeDate) {
if(variant.releaseDate || variant.expireDate) {
formatDatesToLocal(variant);
}
});
@@ -108,6 +107,7 @@
} else if (type === 'unpublish') {
variant.removeDatePickerInstance = datePickerInstance;
}
$scope.model.disableSubmitButton = !canSchedule();
};
/**
@@ -122,6 +122,7 @@
} else if (type === 'unpublish') {
setUnpublishDate(variant, dateStr);
}
$scope.model.disableSubmitButton = !canSchedule();
}
/**
@@ -136,6 +137,7 @@
variant.removeDatePickerOpen = true;
}
checkForBackdropClick();
$scope.model.disableSubmitButton = !canSchedule();
}
/**
@@ -151,7 +153,9 @@
variant.removeDatePickerOpen = false;
}
checkForBackdropClick();
$scope.model.disableSubmitButton = !canSchedule();
}, 200);
}
/**
@@ -212,13 +216,13 @@
var serverTime = dateHelper.convertToServerStringTime(moment(date), Umbraco.Sys.ServerVariables.application.serverTimeOffset);
// update publish value
variant.removeDate = serverTime;
variant.expireDate = serverTime;
// make sure dates are formatted to the user's locale
formatDatesToLocal(variant);
// make sure the publish date can't be after the publish date
variant.releaseDatePickerInstance.set("maxDate", moment(variant.removeDate).format("YYYY-MM-DD HH:mm"));
variant.releaseDatePickerInstance.set("maxDate", moment(variant.expireDate).format("YYYY-MM-DD HH:mm"));
}
@@ -241,8 +245,8 @@
* @param {any} variant
*/
function clearUnpublishDate(variant) {
if(variant && variant.removeDate) {
variant.removeDate = null;
if(variant && variant.expireDate) {
variant.expireDate = null;
// we don't have a unpublish date anymore so we can clear the max date for publish
variant.releaseDatePickerInstance.set("maxDate", null);
}
@@ -256,8 +260,8 @@
if(variant && variant.releaseDate) {
variant.releaseDateFormatted = dateHelper.getLocalDate(variant.releaseDate, vm.currentUser.locale, "MMM Do YYYY, HH:mm");
}
if(variant && variant.removeDate) {
variant.removeDateFormatted = dateHelper.getLocalDate(variant.removeDate, vm.currentUser.locale, "MMM Do YYYY, HH:mm");
if(variant && variant.expireDate) {
variant.removeDateFormatted = dateHelper.getLocalDate(variant.expireDate, vm.currentUser.locale, "MMM Do YYYY, HH:mm");
}
}
@@ -268,7 +272,7 @@
function changeSelection(variant) {
$scope.model.disableSubmitButton = !canSchedule();
//need to set the Save state to true if publish is true
variant.save = variant.schedule;
variant.save = variant.save;
}
function dirtyVariantFilter(variant) {
@@ -287,7 +291,7 @@
/** Returns true if publishing is possible based on if there are un-published mandatory languages */
function canSchedule() {
var selected = [];
var selectedWithDates = [];
for (var i = 0; i < vm.variants.length; i++) {
var variant = vm.variants[i];
@@ -295,7 +299,7 @@
var publishable = dirtyVariantFilter(variant);
if ((variant.language.isMandatory && (variant.state === "NotCreated" || variant.state === "Draft"))
&& (!publishable || !variant.schedule)) {
&& (!publishable || !variant.save)) {
//if a mandatory variant isn't published and it's not publishable or not selected to be published
//then we cannot publish anything
@@ -303,11 +307,11 @@
return false;
}
if (variant.schedule) {
selected.push(variant.schedule);
if (variant.save && (variant.releaseDate || variant.expireDate)) {
selectedWithDates.push(variant.save);
}
}
return selected.length > 0;
return selectedWithDates.length > 0;
}
onInit();
@@ -316,7 +320,6 @@
$scope.$on('$destroy', function () {
for (var i = 0; i < vm.variants.length; i++) {
vm.variants[i].save = false;
vm.variants[i].schedule = false;
// remove properties only needed for this dialog
delete vm.variants[i].releaseDateFormatted;
delete vm.variants[i].removeDateFormatted;

View File

@@ -49,7 +49,7 @@
<div class="btn-group flex" style="font-size: 15px;">
<umb-flatpickr
ng-model="vm.variants[0].removeDate"
ng-model="vm.variants[0].expireDate"
options="vm.variants[0].datePickerConfig"
on-setup="vm.datePickerSetup(vm.variants[0], 'unpublish', fpItem)"
on-change="vm.datePickerChange(vm.variants[0], dateStr, 'unpublish')"
@@ -57,18 +57,18 @@
on-close="vm.datePickerClose(vm.variants[0], 'unpublish')">
<div>
<button ng-if="vm.variants[0].removeDate" class="btn umb-button--xs" style="outline: none;">
<button ng-if="vm.variants[0].expireDate" class="btn umb-button--xs" style="outline: none;">
{{vm.variants[0].removeDateFormatted}}
</button>
<a ng-hide="vm.variants[0].removeDate" href="" class="bold" style="color: #00aea2; text-decoration: underline;">
<a ng-hide="vm.variants[0].expireDate" href="" class="bold" style="color: #00aea2; text-decoration: underline;">
<localize key="content_setDate">Set date</localize>
</a>
</div>
</umb-flatpickr>
<a ng-if="vm.variants[0].removeDate" ng-click="vm.clearUnpublishDate(vm.variants[0])" class="btn umb-button--xs dropdown-toggle umb-button-group__toggle" style="margin-left: -2px;">
<a ng-if="vm.variants[0].expireDate" ng-click="vm.clearUnpublishDate(vm.variants[0])" class="btn umb-button--xs dropdown-toggle umb-button-group__toggle" style="margin-left: -2px;">
<span class="icon icon-wrong"></span>
</a>
@@ -93,7 +93,7 @@
id="{{variant.language.culture}}"
name="saveVariantSelector"
type="checkbox"
ng-model="variant.schedule"
ng-model="variant.save"
ng-change="vm.changeSelection(variant)"
style="margin-right: 8px;" />
<div>
@@ -107,7 +107,7 @@
<span ng-if="variant.language.isMandatory"> - <localize key="languages_mandatoryLanguage"></localize></span>
</div>
<div ng-if="variant.schedule" class="flex items-center" style="margin-top: 10px; margin-bottom: 10px;">
<div ng-if="variant.save" class="flex items-center" style="margin-top: 10px; margin-bottom: 10px;">
<div style="font-size: 13px; margin-right: 5px;">Publish: </div>
<div class="btn-group flex" style="font-size: 14px; margin-right: 10px;">
@@ -137,23 +137,23 @@
<div class="btn-group flex" style="font-size: 14px;">
<umb-flatpickr
ng-model="variant.removeDate"
ng-model="variant.expireDate"
options="variant.datePickerConfig"
on-setup="vm.datePickerSetup(variant, 'unpublish', fpItem)"
on-change="vm.datePickerChange(variant, dateStr, 'unpublish')"
on-open="vm.datePickerShow(variant, 'unpublish')"
on-close="vm.datePickerClose(variant, 'unpublish')">
<div>
<button ng-if="variant.removeDate" class="btn umb-button--xxs" style="outline: none;">
<button ng-if="variant.expireDate" class="btn umb-button--xxs" style="outline: none;">
{{variant.removeDateFormatted}}
</button>
<a ng-hide="variant.removeDate" href="" class="bold" style="color: #00aea2; text-decoration: underline;">
<a ng-hide="variant.expireDate" href="" class="bold" style="color: #00aea2; text-decoration: underline;">
<localize key="content_setDate">Set date</localize>
</a>
</div>
</umb-flatpickr>
<a ng-if="variant.removeDate" ng-click="vm.clearUnpublishDate(variant)" class="btn umb-button--xxs dropdown-toggle umb-button-group__toggle" style="margin-left: -2px;">
<a ng-if="variant.expireDate" ng-click="vm.clearUnpublishDate(variant)" class="btn umb-button--xxs dropdown-toggle umb-button-group__toggle" style="margin-left: -2px;">
<span class="icon icon-wrong"></span>
</a>
</div>
@@ -188,4 +188,4 @@
</div>
</div>
</div>