U4-8749: Use watch do dynamically refresh sort column list
This commit is contained in:
@@ -1,77 +1,73 @@
|
||||
function sortByPreValsController($rootScope, $scope, localizationService, editorState) {
|
||||
// Helper to find a particular value from the list of sort by options
|
||||
function findFromSortByFields(value) {
|
||||
return _.find($scope.sortByFields, function (e) {
|
||||
return e.value.toLowerCase() === value.toLowerCase();
|
||||
});
|
||||
}
|
||||
//Watch the prevalues
|
||||
$scope.$watch(function () {
|
||||
return _.findWhere(editorState.current.preValues, { key: "includeProperties" }).value;
|
||||
}, function () {
|
||||
populateFields();
|
||||
}, true); //Use deep watching, otherwise we won't pick up header changes
|
||||
|
||||
// Get list of properties assigned as columns of the list view
|
||||
var propsPreValue = _.findWhere(editorState.current.preValues, { key: "includeProperties" });
|
||||
|
||||
// Populate list of options for the default sort (all the columns plus then node name)
|
||||
$scope.sortByFields = [];
|
||||
$scope.sortByFields.push({ value: "name", name: "Name", isSystem: 1 });
|
||||
if (propsPreValue != undefined) {
|
||||
for (var i = 0; i < propsPreValue.value.length; i++) {
|
||||
var value = propsPreValue.value[i];
|
||||
$scope.sortByFields.push({
|
||||
value: value.alias,
|
||||
name: value.header,
|
||||
isSystem: value.isSystem
|
||||
function populateFields() {
|
||||
// Helper to find a particular value from the list of sort by options
|
||||
function findFromSortByFields(value) {
|
||||
return _.find($scope.sortByFields, function (e) {
|
||||
return e.value.toLowerCase() === value.toLowerCase();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Localize the system fields, for some reason the directive doesn't work inside of the select group with an ng-model declared
|
||||
var systemFields = [
|
||||
{ value: "SortOrder", key: "general_sort" },
|
||||
{ value: "Name", key: "general_name" },
|
||||
{ value: "VersionDate", key: "content_updateDate" },
|
||||
{ value: "Updater", key: "content_updatedBy" },
|
||||
{ value: "CreateDate", key: "content_createDate" },
|
||||
{ value: "Owner", key: "content_createBy" },
|
||||
{ value: "ContentTypeAlias", key: "content_documentType" },
|
||||
{ value: "Published", key: "content_isPublished" },
|
||||
{ value: "Email", key: "general_email" },
|
||||
{ value: "Username", key: "general_username" }
|
||||
];
|
||||
_.each(systemFields, function (e) {
|
||||
localizationService.localize(e.key).then(function (v) {
|
||||
// Get list of properties assigned as columns of the list view
|
||||
var propsPreValue = _.findWhere(editorState.current.preValues, { key: "includeProperties" });
|
||||
|
||||
var sortByListValue = findFromSortByFields(e.value);
|
||||
if (sortByListValue) {
|
||||
sortByListValue.name = v;
|
||||
switch (e.value) {
|
||||
case "Updater":
|
||||
e.name += " (Content only)";
|
||||
break;
|
||||
case "Published":
|
||||
e.name += " (Content only)";
|
||||
break;
|
||||
case "Email":
|
||||
e.name += " (Members only)";
|
||||
break;
|
||||
case "Username":
|
||||
e.name += " (Members only)";
|
||||
break;
|
||||
}
|
||||
// Populate list of options for the default sort (all the columns plus then node name)
|
||||
$scope.sortByFields = [];
|
||||
$scope.sortByFields.push({ value: "name", name: "Name", isSystem: 1 });
|
||||
if (propsPreValue != undefined) {
|
||||
for (var i = 0; i < propsPreValue.value.length; i++) {
|
||||
var value = propsPreValue.value[i];
|
||||
$scope.sortByFields.push({
|
||||
value: value.alias,
|
||||
name: value.header,
|
||||
isSystem: value.isSystem
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Localize the system fields, for some reason the directive doesn't work inside of the select group with an ng-model declared
|
||||
var systemFields = [
|
||||
{ value: "SortOrder", key: "general_sort" },
|
||||
{ value: "Name", key: "general_name" },
|
||||
{ value: "VersionDate", key: "content_updateDate" },
|
||||
{ value: "Updater", key: "content_updatedBy" },
|
||||
{ value: "CreateDate", key: "content_createDate" },
|
||||
{ value: "Owner", key: "content_createBy" },
|
||||
{ value: "ContentTypeAlias", key: "content_documentType" },
|
||||
{ value: "Published", key: "content_isPublished" },
|
||||
{ value: "Email", key: "general_email" },
|
||||
{ value: "Username", key: "general_username" }
|
||||
];
|
||||
_.each(systemFields, function (e) {
|
||||
localizationService.localize(e.key).then(function (v) {
|
||||
|
||||
var sortByListValue = findFromSortByFields(e.value);
|
||||
if (sortByListValue) {
|
||||
sortByListValue.name = v;
|
||||
switch (e.value) {
|
||||
case "Updater":
|
||||
e.name += " (Content only)";
|
||||
break;
|
||||
case "Published":
|
||||
e.name += " (Content only)";
|
||||
break;
|
||||
case "Email":
|
||||
e.name += " (Members only)";
|
||||
break;
|
||||
case "Username":
|
||||
e.name += " (Members only)";
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Check existing model value is available in list and ensure a value is set
|
||||
var existingValue = findFromSortByFields($scope.model.value);
|
||||
if (existingValue) {
|
||||
// Set the existing value
|
||||
// The old implementation pre Umbraco 7.5 used PascalCase aliases, this uses camelCase, so this ensures that any previous value is set
|
||||
$scope.model.value = existingValue.value;
|
||||
}
|
||||
else {
|
||||
// Existing value not found, set to first value
|
||||
$scope.model.value = $scope.sortByFields[0].value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user