wip unpublish list view items

This commit is contained in:
Mads Rasmussen
2018-11-02 09:10:22 +01:00
parent 219c7284b6
commit 3f5fc56656
3 changed files with 169 additions and 2 deletions

View File

@@ -402,7 +402,7 @@ function listViewController($scope, $routeParams, $injector, $timeout, currentUs
const dialog = {
view: "views/propertyeditors/listview/overlays/listviewpublish.html",
submitButtonLabel: "Publish",
submitButtonLabelKey: "actions_publish",
submit: function (model) {
console.log(model);
//console.log(model.languages);
@@ -454,6 +454,49 @@ function listViewController($scope, $routeParams, $injector, $timeout, currentUs
}
$scope.unpublish = function () {
let variesByCulture = false;
const dialog = {
view: "views/propertyeditors/listview/overlays/listviewunpublish.html",
submitButtonLabelKey: "actions_unpublish",
submit: function (model) {
console.log(model);
//console.log(model.languages);
performUnpublish();
overlayService.close();
},
close: function () {
overlayService.close();
}
};
// check if any of the selected nodes has variants
$scope.selection.forEach(selectedItem => {
$scope.listViewResultSet.items.forEach(resultItem => {
if((selectedItem.id === resultItem.id || selectedItem.key === resultItem.key) && resultItem.variesByCulture) {
variesByCulture = true;
}
})
});
// if any of the selected nodes has variants we want to
// show a dialog where the languages can be chosen
if(variesByCulture) {
languageResource.getAll()
.then(languages => {
dialog.languages = languages;
overlayService.open(dialog);
}, error => {
console.log(error);
});
} else {
overlayService.open(dialog);
}
};
function performUnpublish() {
applySelected(
function (selected, index) { return contentResource.unpublish(getIdCallback(selected[index])); },
function (count, total) {
@@ -464,7 +507,7 @@ function listViewController($scope, $routeParams, $injector, $timeout, currentUs
var key = (total === 1 ? "bulk_unpublishedItem" : "bulk_unpublishedItems");
return localizationService.localize(key, [total]);
});
};
}
$scope.move = function () {
var move = {

View File

@@ -0,0 +1,77 @@
(function () {
"use strict";
function ListViewUnpublishController($scope, $routeParams, localizationService) {
var vm = this;
vm.loading = true;
vm.changeSelection = changeSelection;
function changeSelection(language) {
// disable submit button if nothing is selected
var firstSelected = _.find(vm.languages, function (language) {
return language.unpublish;
});
$scope.model.disableSubmitButton = !firstSelected;
//need to set the Save state to true if publish is true
language.save = language.unpublish;
}
function onInit() {
vm.languages = $scope.model.languages;
if (!$scope.model.title) {
localizationService.localize("content_unpublish").then(function (value) {
$scope.model.title = value;
});
}
// node has variants
if (vm.languages && vm.languages.length > 0) {
var culture = $routeParams.cculture ? $routeParams.cculture : $routeParams.mculture;
if(culture) {
// sort languages so the active on is on top
vm.languages = _.sortBy(vm.languages, function (language) {
return language.culture === culture ? 0 : 1;
});
var active = _.find(vm.languages, function (language) {
return language.culture === culture;
});
if (active) {
//ensure that the current one is selected
active.unpublish = true;
}
}
}
vm.loading = false;
}
onInit();
//when this dialog is closed, reset all 'publish' flags
$scope.$on('$destroy', function () {
if(vm.languages && vm.languages.length > 0) {
for (var i = 0; i < vm.languages.length; i++) {
vm.languages[i].unpublish = false;
vm.languages[i].save = false;
}
}
});
}
angular.module("umbraco").controller("Umbraco.Overlays.ListViewUnpublishController", ListViewUnpublishController);
})();

View File

@@ -0,0 +1,47 @@
<div ng-controller="Umbraco.Overlays.ListViewUnpublishController as vm">
<!-- 1 language -->
<div ng-if="!vm.languages">
<p><localize key="prompt_confirmUnpublish"></localize></p>
</div>
<!-- Multiple languages -->
<div ng-if="vm.languages.length > 0">
<div style="margin-bottom: 15px;">
<p><localize key="content_languagesToUnpublish"></localize></p>
</div>
<div class="umb-list umb-list--condensed">
<div class="umb-list-item" ng-repeat="language in vm.languages">
<ng-form name="unpublishVariantSelectorForm">
<div class="flex">
<input id="{{variant.htmlId}}"
name="unpublishVariantSelector"
type="checkbox"
ng-model="language.unpublish"
ng-change="vm.changeSelection(language)"
ng-disabled="language.disabled"
style="margin-right: 8px;" />
<div>
<label style="margin-bottom: 2px;">
<span ng-class="{'bold': language.isDefault}">{{ language.name }}</span>
</label>
<div class="umb-permission__description">
<span ng-if="language.isMandatory"><localize key="languages_mandatoryLanguage"></localize></span>
</div>
</div>
</div>
</ng-form>
</div>
</div>
</div>
</div>