List view pre-values working with fields and headers, list view now rendering data again, removed the config ui bits from the content type editor

This commit is contained in:
Shannon
2014-09-12 14:07:42 +10:00
parent 74a113646d
commit afbeb50d55
7 changed files with 428 additions and 446 deletions

View File

@@ -0,0 +1,117 @@
function includePropsPreValsController($rootScope, $scope, localizationService, contentTypeResource) {
if (!$scope.model.value) {
$scope.model.value = [];
}
$scope.propertyAliases = [];
$scope.selectedField = null;
$scope.systemFields = [
{ value: "updateDate", name: "Last edited" },
{ value: "updater", name: "Updated by" },
{ value: "createDate", name: "Created" },
{ value: "creator", name: "Created by" }
];
$scope.getLocalizedKey = function(alias) {
switch (alias) {
case "updateDate":
return "content_updateDate";
case "updater":
return "content_updatedBy";
case "createDate":
return "content_createDate";
case "creator":
return "content_createBy";
}
return alias;
}
$scope.removeField = function(e) {
$scope.model.value = _.reject($scope.model.value, function (x) {
return x.alias === e.alias;
});
}
//now we'll localize these strings, for some reason the directive doesn't work inside of the select group with an ng-model declared
_.each($scope.systemFields, function (e, i) {
var key = $scope.getLocalizedKey(e.value);
localizationService.localize(key).then(function (v) {
e.name = v;
});
});
// Return a helper with preserved width of cells
var fixHelper = function (e, ui) {
var h = ui.clone();
h.children().each(function () {
$(this).width($(this).width());
});
h.css("background-color", "lightgray");
return h;
};
$scope.sortableOptions = {
helper: fixHelper,
handle: ".handle",
opacity: 0.5,
axis: 'y',
containment: 'parent',
cursor: 'move',
items: '> tr',
tolerance: 'pointer',
update: function (e, ui) {
// Get the new and old index for the moved element (using the text as the identifier)
var newIndex = ui.item.index();
var movedAlias = $('.alias-value', ui.item).text();
var originalIndex = getAliasIndexByText(movedAlias);
// Move the element in the model
if (originalIndex > -1) {
var movedElement = $scope.model.value[originalIndex];
$scope.model.value.splice(originalIndex, 1);
$scope.model.value.splice(newIndex, 0, movedElement);
}
}
};
contentTypeResource.getAllPropertyTypeAliases().then(function(data) {
$scope.propertyAliases = data;
});
$scope.addField = function () {
var val = $scope.selectedField;
var isSystem = val.startsWith("_system_");
if (isSystem) {
val = val.trimStart("_system_");
}
var exists = _.find($scope.model.value, function (i) {
return i.alias === val;
});
if (!exists) {
$scope.model.value.push({
alias: val,
isSystem: isSystem ? 1 : 0
});
}
}
function getAliasIndexByText(value) {
for (var i = 0; i < $scope.model.value.length; i++) {
if ($scope.model.value[i].alias === value) {
return i;
}
}
return -1;
}
}
angular.module("umbraco").controller("Umbraco.PrevalueEditors.ListViewController", includePropsPreValsController);

View File

@@ -0,0 +1,51 @@
<div class="umb-editor" ng-controller="Umbraco.PrevalueEditors.ListViewController">
<div class="control-group">
<select ng-model="selectedField">
<option ng-repeat="field in systemFields" value="_system_{{field.value}}">{{field.name}}</option>
<option class="select-dash" disabled="disabled">----</option>
<option ng-repeat="alias in propertyAliases" value="{{alias}}">{{alias}}</option>
</select>
<button type="button" class="btn" ng-click="addField()">
<localize key="general_add">Add</localize>
</button>
</div>
<div class="control-group">
<table ng-show="model.value.length > 0" class="table">
<thead>
<tr>
<td style="width:20px;"></td>
<th style="width:220px;">Alias</th>
<th>Header</th>
<td style="width:100px;"></td>
</tr>
</thead>
<tbody ui-sortable="sortableOptions">
<tr ng-repeat="val in model.value">
<td>
<i class="icon icon-navigation handle"></i>
</td>
<td>
<span class="alias-value" ng-if="!val.isSystem">{{val.alias}}</span>
<span class="alias-value" ng-if="val.isSystem == 1">
{{val.alias}}
</span>
<em ng-show="val.isSystem == 1"><small>(system field)</small></em>
</td>
<td>
<input type="text" ng-model="val.header" ng-if="!val.isSystem" />
<span ng-if="val.isSystem">
<localize key="{{getLocalizedKey(val.alias)}}">{{val.alias}}</localize>
</span>
</td>
<td>
<button type="button" class="btn btn-danger" ng-click="removeField(val)">Remove</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>

View File

@@ -1,4 +1,4 @@
function listViewController($rootScope, $scope, $routeParams, $injector, notificationsService, iconHelper, dialogService, editorState) {
function listViewController($rootScope, $scope, $routeParams, $injector, notificationsService, iconHelper, dialogService, editorState, localizationService) {
//this is a quick check to see if we're in create mode, if so just exit - we cannot show children for content
// that isn't created yet, if we continue this will use the parent id in the route params which isn't what
@@ -28,76 +28,86 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
totalPages: 0,
items: []
};
// Set "default default" options (i.e. those if no container configuration has been saved)
$scope.options = {
pageSize: $scope.model.config.pageSize ? $scope.model.config.pageSize : 10,
pageNumber: 1,
filter: '',
orderBy: $scope.model.config.orderBy ? $scope.model.config.orderBy : 'UpdateDate',
orderDirection: $scope.model.config.orderDirection ? $scope.model.config.orderDirection : "desc"
//orderBy: 'updateDate',
//orderDirection: "desc",
orderBy: $scope.model.config.orderBy ? $scope.model.config.orderBy : 'updateDate',
orderDirection: $scope.model.config.orderDirection ? $scope.model.config.orderDirection : "desc",
includeProperties: $scope.model.config.includeProperties ? $scope.model.config.includeProperties : [
{ alias: 'updateDate', header: 'Last edited', isSystem : 1 },
{ alias: 'updater', header: 'Last edited by', isSystem: 1 }
],
allowBulkPublish: true,
allowBulkUnpublish: true,
allowBulkDelete: true,
additionalColumns: [
{ alias: 'UpdateDate', header: 'Last edited', localizationKey: 'defaultdialogs_lastEdited' },
{ alias: 'Updator', header: 'Last edited', localizationKey: 'content_updatedBy' }
]
allowBulkDelete: true,
};
// Retrieve the container configuration for the content type and set options before presenting initial view
contentTypeResource.getContainerConfig($routeParams.id)
.then(function (config) {
if (typeof config.pageSize !== 'undefined') {
$scope.options.pageSize = config.pageSize;
}
if (typeof config.additionalColumns !== 'undefined') {
$scope.options.additionalColumns = config.additionalColumns;
}
if (typeof config.orderBy !== 'undefined') {
$scope.options.orderBy = config.orderBy;
}
if (typeof config.orderDirection !== 'undefined') {
$scope.options.orderDirection = config.orderDirection;
}
if (typeof config.allowBulkPublish !== 'undefined') {
$scope.options.allowBulkPublish = config.allowBulkPublish;
}
if (typeof config.allowBulkUnpublish !== 'undefined') {
$scope.options.allowBulkUnpublish = config.allowBulkUnpublish;
}
if (typeof config.allowBulkDelete !== 'undefined') {
$scope.options.allowBulkDelete = config.allowBulkDelete;
}
//update all of the system includeProperties to enable sorting
_.each($scope.options.includeProperties, function(e, i) {
if (e.isSystem) {
e.allowSorting = true;
//localize the header
var key = getLocalizedKey(e.alias);
localizationService.localize(key).then(function (v) {
e.header = v;
});
}
});
$scope.initView();
});
//// Retrieve the container configuration for the content type and set options before presenting initial view
//contentTypeResource.getContainerConfig($routeParams.id)
// .then(function(config) {
// if (typeof config.pageSize !== 'undefined') {
// $scope.options.pageSize = config.pageSize;
// }
// if (typeof config.additionalColumns !== 'undefined') {
// $scope.options.additionalColumns = config.additionalColumns;
// }
// if (typeof config.orderBy !== 'undefined') {
// $scope.options.orderBy = config.orderBy;
// }
// if (typeof config.orderDirection !== 'undefined') {
// $scope.options.orderDirection = config.orderDirection;
// }
// if (typeof config.allowBulkPublish !== 'undefined') {
// $scope.options.allowBulkPublish = config.allowBulkPublish;
// }
// if (typeof config.allowBulkUnpublish !== 'undefined') {
// $scope.options.allowBulkUnpublish = config.allowBulkUnpublish;
// }
// if (typeof config.allowBulkDelete !== 'undefined') {
// $scope.options.allowBulkDelete = config.allowBulkDelete;
// }
$scope.next = function () {
// $scope.initView();
// });
$scope.next = function() {
if ($scope.options.pageNumber < $scope.listViewResultSet.totalPages) {
$scope.options.pageNumber++;
$scope.reloadView($scope.contentId);
saveLastPageNumber();
//saveLastPageNumber();
}
};
$scope.goToPage = function (pageNumber) {
$scope.goToPage = function(pageNumber) {
$scope.options.pageNumber = pageNumber + 1;
$scope.reloadView($scope.contentId);
saveLastPageNumber();
//saveLastPageNumber();
};
$scope.sort = function (field, allow) {
$scope.sort = function(field, allow) {
if (allow) {
$scope.options.orderBy = field;
if ($scope.options.orderDirection === "desc") {
$scope.options.orderDirection = "asc";
} else {
}
else {
$scope.options.orderDirection = "desc";
}
@@ -105,48 +115,29 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
}
};
$scope.prev = function () {
$scope.prev = function() {
if ($scope.options.pageNumber > 1) {
$scope.options.pageNumber--;
$scope.reloadView($scope.contentId);
saveLastPageNumber();
}
};
saveLastPageNumber = function () {
// Saves the last page number into rootScope, so we can retrieve it when returning to the list and
// re-present the correct page
$rootScope.lastListViewPageViewed = {
contentId: $scope.contentId,
pageNumber: $scope.options.pageNumber
};
};
$scope.initView = function () {
if ($routeParams.id) {
$scope.pagination = new Array(10);
$scope.listViewAllowedTypes = contentTypeResource.getAllowedTypes($routeParams.id);
$scope.contentId = $routeParams.id;
$scope.isTrashed = $routeParams.id === "-20" || $routeParams.id === "-21";
// If we have a last page number saved, go straight to that one
if ($rootScope.lastListViewPageViewed && $rootScope.lastListViewPageViewed.contentId == $scope.contentId) {
$scope.goToPage($rootScope.lastListViewPageViewed.pageNumber - 1);
} else {
$scope.reloadView($scope.contentId);
}
//saveLastPageNumber();
}
};
/*Loads the search results, based on parameters set in prev,next,sort and so on*/
/*Pagination is done by an array of objects, due angularJS's funky way of monitoring state
with simple values */
$scope.reloadView = function (id) {
contentResource.getChildren(id, $scope.options).then(function (data) {
$scope.reloadView = function(id) {
contentResource.getChildren(id, $scope.options).then(function(data) {
$scope.listViewResultSet = data;
//update all values for display
_.each($scope.listViewResultSet.items, function(e, index) {
setPropertyValues(e);
});
$scope.pagination = [];
for (var i = $scope.listViewResultSet.totalPages - 1; i >= 0; i--) {
@@ -160,51 +151,11 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
});
};
$scope.getColumnName = function (index) {
return $scope.options.additionalColumns[index].header;
};
$scope.getColumnLocalizationKey = function (index) {
return $scope.options.additionalColumns[index].localizationKey;
};
$scope.getPropertyValue = function (alias, result) {
// Camel-case the alias
alias = alias.charAt(0).toLowerCase() + alias.slice(1);
// First try to pull the value directly from the alias (e.g. updatedBy)
var value = result[alias];
// If this returns an object, look for the name property of that (e.g. owner.name)
if (value === Object(value)) {
value = value['name'];
}
// If we've got nothing yet, look at a user defined property
if (typeof value === 'undefined') {
value = $scope.getCustomPropertyValue(alias, result.properties);
}
// If we have a date, format it
if (isDate(value)) {
value = value.substring(0, value.length - 3);
}
// Return what we've got
return value;
};
isDate = function (val) {
return val.match(/^(\d{4})\-(\d{2})\-(\d{2})\ (\d{2})\:(\d{2})\:(\d{2})$/);
};
$scope.getCustomPropertyValue = function (alias, properties) {
function getCustomPropertyValue(alias, properties) {
var value = '';
var index = 0;
var foundAlias = false;
for (var i = 0; i < properties.length; i++) {
for (var i = 0; i < properties.length; i++) {
if (properties[i].alias == alias) {
foundAlias = true;
break;
@@ -220,12 +171,12 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
};
//assign debounce method to the search to limit the queries
$scope.search = _.debounce(function () {
$scope.search = _.debounce(function() {
$scope.options.pageNumber = 1;
$scope.reloadView($scope.contentId);
}, 100);
$scope.selectAll = function ($event) {
$scope.selectAll = function($event) {
var checkbox = $event.target;
if (!angular.isArray($scope.listViewResultSet.items)) {
return;
@@ -236,30 +187,30 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
}
};
$scope.isSelectedAll = function () {
$scope.isSelectedAll = function() {
if (!angular.isArray($scope.listViewResultSet.items)) {
return false;
}
return _.every($scope.listViewResultSet.items, function (item) {
return _.every($scope.listViewResultSet.items, function(item) {
return item.selected;
});
};
$scope.isAnythingSelected = function () {
$scope.isAnythingSelected = function() {
if (!angular.isArray($scope.listViewResultSet.items)) {
return false;
}
return _.some($scope.listViewResultSet.items, function (item) {
return _.some($scope.listViewResultSet.items, function(item) {
return item.selected;
});
};
$scope.getIcon = function (entry) {
$scope.getIcon = function(entry) {
return iconHelper.convertFromLegacyIcon(entry.icon);
};
$scope.delete = function () {
var selected = _.filter($scope.listViewResultSet.items, function (item) {
$scope.delete = function() {
var selected = _.filter($scope.listViewResultSet.items, function(item) {
return item.selected;
});
var total = selected.length;
@@ -274,7 +225,7 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
for (var i = 0; i < selected.length; i++) {
$scope.bulkStatus = "Deleted doc " + current + " out of " + total + " documents";
contentResource.deleteById(selected[i].id).then(function (data) {
contentResource.deleteById(selected[i].id).then(function(data) {
if (current === total) {
notificationsService.success("Bulk action", "Deleted " + total + "documents");
$scope.bulkStatus = "";
@@ -288,8 +239,8 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
};
$scope.publish = function () {
var selected = _.filter($scope.listViewResultSet.items, function (item) {
$scope.publish = function() {
var selected = _.filter($scope.listViewResultSet.items, function(item) {
return item.selected;
});
var total = selected.length;
@@ -305,7 +256,7 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
$scope.bulkStatus = "Publishing " + current + " out of " + total + " documents";
contentResource.publishById(selected[i].id)
.then(function (content) {
.then(function(content) {
if (current == total) {
notificationsService.success("Bulk action", "Published " + total + "documents");
$scope.bulkStatus = "";
@@ -313,7 +264,7 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
$scope.actionInProgress = false;
}
current++;
}, function (err) {
}, function(err) {
$scope.bulkStatus = "";
$scope.reloadView($scope.contentId);
@@ -331,8 +282,8 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
}
};
$scope.unpublish = function () {
var selected = _.filter($scope.listViewResultSet.items, function (item) {
$scope.unpublish = function() {
var selected = _.filter($scope.listViewResultSet.items, function(item) {
return item.selected;
});
var total = selected.length;
@@ -348,7 +299,7 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
$scope.bulkStatus = "Unpublishing " + current + " out of " + total + " documents";
contentResource.unPublish(selected[i].id)
.then(function (content) {
.then(function(content) {
if (current == total) {
notificationsService.success("Bulk action", "Published " + total + "documents");
@@ -362,18 +313,101 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
}
};
$scope.includeProperties = $scope.model.config.includeProperties ? _.map($scope.model.config.includeProperties, function (i) {
if (!i.label)
i.label = i.value.replace(/([A-Z]?[a-z]+)/g, '$1 ').trim(' ');
if (typeof (i.isProperty) == "undefined")
i.isProperty = !i.value.match("contentTypeAlias|createDate|icon|owner|published|sortOrder|updateDat|updator");
if (!i.isProperty && !i.sortBy)
i.sortBy = i.value.substring(0, 1).toUpperCase() + i.value.slice(1);
// TODO: Add sort logic for custom properties.
//else if (!i.sortBy)
// ;
return i;
}) : {};
$scope.includeProperties = $scope.model.config.includeProperties ? _.map($scope.model.config.includeProperties, function(i) {
if (!i.label)
i.label = i.value.replace(/([A-Z]?[a-z]+)/g, '$1 ').trim(' ');
if (typeof (i.isProperty) == "undefined")
i.isProperty = !i.value.match("contentTypeAlias|createDate|icon|owner|published|sortOrder|updateDate|updater");
if (!i.isProperty && !i.sortBy)
i.sortBy = i.value.substring(0, 1).toUpperCase() + i.value.slice(1);
// TODO: Add sort logic for custom properties.
//else if (!i.sortBy)
// ;
return i;
}) : {};
/** This ensures that the correct value is set for each item in a row, we don't want to call a function during interpolation or ng-bind as performance is really bad that way */
function setPropertyValues(result) {
_.each($scope.options.includeProperties, function (e, i) {
var alias = e.alias;
// First try to pull the value directly from the alias (e.g. updatedBy)
var value = result[alias];
// If this returns an object, look for the name property of that (e.g. owner.name)
if (value === Object(value)) {
value = value['name'];
}
// If we've got nothing yet, look at a user defined property
if (typeof value === 'undefined') {
value = getCustomPropertyValue(alias, result.properties);
}
// If we have a date, format it
if (isDate(value)) {
value = value.substring(0, value.length - 3);
}
// set what we've got on the result
result[alias] = value;
});
};
function isDate(val) {
return val.match(/^(\d{4})\-(\d{2})\-(\d{2})\ (\d{2})\:(\d{2})\:(\d{2})$/);
};
//function saveLastPageNumber() {
// //TODO: Fix this up, we don't want to use $rootScope
// // Saves the last page number into rootScope, so we can retrieve it when returning to the list and
// // re-present the correct page
// $rootScope.lastListViewPageViewed = {
// contentId: $scope.contentId,
// pageNumber: $scope.options.pageNumber
// };
//};
function initView() {
if ($routeParams.id) {
$scope.pagination = new Array(10);
$scope.listViewAllowedTypes = contentTypeResource.getAllowedTypes($routeParams.id);
$scope.contentId = $routeParams.id;
$scope.isTrashed = $routeParams.id === "-20" || $routeParams.id === "-21";
//// If we have a last page number saved, go straight to that one
//if ($rootScope.lastListViewPageViewed && $rootScope.lastListViewPageViewed.contentId == $scope.contentId) {
// $scope.goToPage($rootScope.lastListViewPageViewed.pageNumber - 1);
//}
//else {
$scope.reloadView($scope.contentId);
//}
}
};
function getLocalizedKey(alias) {
switch (alias) {
case "updateDate":
return "content_updateDate";
case "updater":
return "content_updatedBy";
case "createDate":
return "content_createDate";
case "creator":
return "content_createBy";
}
return alias;
}
//GO!
initView();
}

View File

@@ -54,10 +54,9 @@
</a>
</td>
<td ng-repeat="column in options.additionalColumns">
<a href="#" ng-click="sort(column.alias, column.allowSorting)" ng-class="{'no-sort':!column.allowSorting}" prevent-default>
<localize ng-if="getColumnLocalizationKey($index) !==''" key="{{getColumnLocalizationKey($index)}}">{{getColumnName($index)}}</localize>
<span ng-if="getColumnLocalizationKey($index) === ''">{{getColumnName($index)}}</span>
<td ng-repeat="column in options.includeProperties">
<a href="#" ng-click="sort(column.alias, column.allowSorting)" ng-class="{'no-sort':!column.allowSorting}" prevent-default>
<span ng-bind="column.header"></span>
<i class="icon-sort"></i>
</a>
</td>
@@ -95,27 +94,22 @@
<input type="checkbox" ng-model="result.selected">
</td>
<td>
<a ng-class="{inactive: (entityType === 'content' && !result.published) || isTrashed}" href="#/{{entityType}}/{{entityType}}/edit/{{result.id}}">{{result.name}}</a>
<a ng-class="{inactive: (entityType === 'content' && !result.published) || isTrashed}"
href="#/{{entityType}}/{{entityType}}/edit/{{result.id}}"
ng-bind="result.name"></a>
</td>
<td ng-repeat="column in options.additionalColumns">
{{getPropertyValue(column.alias, result)}}
<td ng-repeat="column in options.includeProperties">
<span>{{result[column.alias]}}</span>
</td>
</td>
<td ng-repeat="property in includeProperties">
{{result[property.value]}}
<div ng-repeat="props in result.properties | filter: { alias: property.value }">
{{props.value}}
</div>
<td></td>
</tr>
</tbody>
<tfoot ng-show="pagination.length > 1">
<tr>
<th colspan="{{options.additionalColumns.length + 3}}">
<th colspan="{{options.includeProperties.length + 3}}">
<div class="pull-left">
</div>
<div class="pagination pagination-right">
@@ -128,7 +122,7 @@
<li ng-repeat="pgn in pagination track by $index"
ng-class="{active:$index + 1 == options.pageNumber}">
<a href="#" ng-click="goToPage($index)" prevent-default>{{$index + 1}}</a>
<a href="#" ng-click="goToPage($index)" prevent-default ng-bind="$index + 1"></a>
</li>
<li ng-class="{disabled:options.pageNumber >= listViewResultSet.totalPages}">

View File

@@ -76,224 +76,10 @@
<cc2:PropertyPanel ID="pp_Root" runat="server" Text="Allow at root <br/><small>Only Content Types with this checked can be created at the root level of Content and Media trees</small>">
<asp:CheckBox runat="server" ID="allowAtRoot" Text="Yes" /><br />
</cc2:PropertyPanel>
<cc2:PropertyPanel ID="pp_isContainer" runat="server" Text="Container<br/><small>A container type doesn't display children in the tree, but as a grid instead</small>">
<asp:CheckBox runat="server" ID="cb_isContainer" Text="Yes" /><br />
</cc2:PropertyPanel>
<!-- Styling for list view configuration -->
<style type="text/css">
#container-config-panel { margin-left: 20px; }
#container-config-column-list { margin: 8px 0 16px 0; }
#container-config-column-list th, #container-config-column-list td { text-align: left; padding: 2px 0px 4px 10px; }
#<%= txtContainerConfigAdditionalColumns.ClientID %> { display: none; }
</style>
<!-- Scripting for list view configuration -->
<script type="text/javascript">
$(document).ready(function () {
var isContainerCheckBox = $("#<%= cb_isContainer.ClientID %>");
var containerConfigPanel = $("#container-config-panel");
var containerConfigAddColumnSelect = $("#<%= ddlContainerConfigAdditionalColumnsChooser.ClientID %>");
var containerConfigColumnList = $("#container-config-column-list");
var containerConfigHiddenField = $("#<%= txtContainerConfigAdditionalColumns.ClientID %>");
function showHideContainerConfig(closingAnimation) {
if (isContainerCheckBox.is(":checked")) {
containerConfigPanel.slideDown();
}
else
{
if (closingAnimation == 'hide') {
containerConfigPanel.hide();
} else {
containerConfigPanel.slideUp();
}
}
}
function loadColumnListFromHiddenField() {
if (containerConfigHiddenField.val() != '') {
var columns = getSelectedColumnAliases();
for (var i = 0; i < columns.length; i++) {
addColumnToList(columns[i]);
}
bindRemoveLinks();
}
}
function getSelectedColumnAliases() {
return containerConfigHiddenField.val().split(',');
}
function getColumnName(alias) {
return $('option[value="' + alias + '"]', containerConfigAddColumnSelect).text();
}
function addColumn() {
var alias = containerConfigAddColumnSelect.val();
if (!isColumnAlreadyAdded(alias)) {
addColumnToList(alias);
addColumnToField(alias);
bindRemoveLinks();
}
}
function isColumnAlreadyAdded(alias) {
var columns = getSelectedColumnAliases();
for (var i = 0; i < columns.length; i++) {
if (columns[i] == alias) {
return true;
}
}
return false;
}
function getColumnIndex(alias) {
var columns = getSelectedColumnAliases();
var index = 0;
for (var i = 0; i < columns.length; i++) {
if (columns[i] == alias) {
return index;
}
index++;
}
return -1;
}
function addColumnToList(alias) {
var html = '<tr data-alias="' + alias + '">' +
'<td><i class="icon-navigation handle"></i></td>' +
'<td>' + getColumnName(alias) + '</td><td><button type="button" class="remove">Remove</button></td>' +
'</tr>';
$('tbody', containerConfigColumnList).append(html);
}
function addColumnToField(alias) {
if (containerConfigHiddenField.val() == '') {
containerConfigHiddenField.val(alias)
} else {
var columns = getSelectedColumnAliases();
columns.push(alias);
containerConfigHiddenField.val(columns.join());
}
}
function removeColumn(alias) {
var index = getColumnIndex(alias);
removeColumnFromList(index);
removeColumnFromField(index);
}
function removeColumnFromList(index) {
$('tbody tr:eq(' + index + ')', containerConfigColumnList).fadeOut(300, function() {
$(this).remove();
})
}
function removeColumnFromField(index) {
var columns = getSelectedColumnAliases();
columns.splice(index, 1);
containerConfigHiddenField.val(columns.join());
}
function bindRemoveLinks() {
$(".remove", containerConfigColumnList).off('click').on('click', function (e) {
e.preventDefault();
var alias = $(this).closest('tr').attr('data-alias');
removeColumn(alias);
});
}
function saveColumnSortOrder() {
var columns = [];
$('tbody tr', containerConfigColumnList).each(function (index) {
var tr = $(this);
columns.push(tr.attr('data-alias'));
});
containerConfigHiddenField.val(columns.join());
}
isContainerCheckBox.on("change", function () {
showHideContainerConfig();
});
containerConfigAddColumnSelect.on('change', function () {
var ddl = $(this);
if (ddl.val() != '') {
addColumn();
ddl.prop('selectedIndex', 0);
}
});
showHideContainerConfig('hide');
loadColumnListFromHiddenField();
$('tbody', containerConfigColumnList).sortable({
containment: 'parent',
tolerance: 'pointer',
update: function (event, ui) {
saveColumnSortOrder();
}
});
});
</script>
<div id="container-config-panel">
<cc2:PropertyPanel ID="pp_containerConfigPageSize" runat="server">
<asp:TextBox ID="txtContainerConfigPageSize" CssClass="guiInputText guiInputStandardSize" runat="server" type="number" min="1" max="100"></asp:TextBox>
</cc2:PropertyPanel>
<cc2:PropertyPanel ID="pp_containerConfigAdditionalColumns" runat="server">
<asp:DropDownList ID="ddlContainerConfigAdditionalColumnsChooser" CssClass="guiInputText guiInputStandardSize" runat="server"></asp:DropDownList>
<table id="container-config-column-list">
<thead>
<tr>
<th colspan="2">Selected columns</th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<asp:TextBox ID="txtContainerConfigAdditionalColumns" CssClass="guiInputText guiInputStandardSize" runat="server"></asp:TextBox>
</cc2:PropertyPanel>
<cc2:PropertyPanel ID="pp_containerConfigOrderBy" runat="server">
<asp:DropDownList ID="ddlContainerConfigOrderBy" CssClass="guiInputText guiInputStandardSize" runat="server"></asp:DropDownList>
</cc2:PropertyPanel>
<cc2:PropertyPanel ID="pp_containerConfigOrderDirection" runat="server">
<asp:DropDownList ID="ddlContainerConfigOrderDirection" CssClass="guiInputText guiInputStandardSize" runat="server">
<asp:ListItem Value="asc">Ascending</asp:ListItem>
<asp:ListItem Value="desc">Descending</asp:ListItem>
</asp:DropDownList>
</cc2:PropertyPanel>
<cc2:PropertyPanel ID="pp_allowBulkPublish" runat="server">
<asp:DropDownList ID="ddlContainerConfigAllowBulkPublish" CssClass="guiInputText guiInputStandardSize" runat="server">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</asp:DropDownList>
</cc2:PropertyPanel>
<cc2:PropertyPanel ID="pp_allowBulkUnpublish" runat="server">
<asp:DropDownList ID="ddlContainerConfigAllowBulkUnpublish" CssClass="guiInputText guiInputStandardSize" runat="server">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</asp:DropDownList>
</cc2:PropertyPanel>
<cc2:PropertyPanel ID="pp_allowBulkDelete" runat="server">
<asp:DropDownList ID="ddlContainerConfigAllowBulkDelete" CssClass="guiInputText guiInputStandardSize" runat="server">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</asp:DropDownList>
</cc2:PropertyPanel>
</div>
</cc2:Pane>
<cc2:Pane ID="Pane5" runat="server">

View File

@@ -40,78 +40,78 @@ namespace Umbraco.Web.Editors
/// <param name="contentId"></param>
public ContentTypeContainerConfiguration GetContainerConfig(int contentId)
{
var contentItem = Services.ContentService.GetById(contentId);
if (contentItem == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
//var contentItem = Services.ContentService.GetById(contentId);
//if (contentItem == null)
//{
// throw new HttpResponseException(HttpStatusCode.NotFound);
//}
if (!string.IsNullOrEmpty(contentItem.ContentType.ContainerConfig))
{
var containerConfig = JsonConvert.DeserializeObject<ContentTypeContainerConfiguration>(contentItem.ContentType.ContainerConfig);
containerConfig.AdditionalColumns = new List<ContentTypeContainerConfiguration.AdditionalColumnDetail>();
//if (!string.IsNullOrEmpty(contentItem.ContentType.ContainerConfig))
//{
// var containerConfig = JsonConvert.DeserializeObject<ContentTypeContainerConfiguration>(contentItem.ContentType.ContainerConfig);
// containerConfig.AdditionalColumns = new List<ContentTypeContainerConfiguration.AdditionalColumnDetail>();
// Populate the column headings and localization keys
if (!string.IsNullOrEmpty(containerConfig.AdditionalColumnAliases))
{
// Find all the properties for doc types that might be in the list
var allowedContentTypeIds = contentItem.ContentType.AllowedContentTypes
.Select(x => x.Id.Value)
.ToArray();
var allPropertiesOfAllowedContentTypes = Services.ContentTypeService
.GetAllContentTypes(allowedContentTypeIds)
.SelectMany(x => x.PropertyTypes)
.ToList();
// // Populate the column headings and localization keys
// if (!string.IsNullOrEmpty(containerConfig.AdditionalColumnAliases))
// {
// // Find all the properties for doc types that might be in the list
// var allowedContentTypeIds = contentItem.ContentType.AllowedContentTypes
// .Select(x => x.Id.Value)
// .ToArray();
// var allPropertiesOfAllowedContentTypes = Services.ContentTypeService
// .GetAllContentTypes(allowedContentTypeIds)
// .SelectMany(x => x.PropertyTypes)
// .ToList();
foreach (var alias in containerConfig.AdditionalColumnAliases.Split(','))
{
var column = new ContentTypeContainerConfiguration.AdditionalColumnDetail
{
Alias = alias,
LocalizationKey = string.Empty,
AllowSorting = true,
};
// foreach (var alias in containerConfig.AdditionalColumnAliases.Split(','))
// {
// var column = new ContentTypeContainerConfiguration.AdditionalColumnDetail
// {
// Alias = alias,
// LocalizationKey = string.Empty,
// AllowSorting = true,
// };
// Try to find heading from custom property (getting the name from the alias)
// - need to look in children of the current content's content type
var property = allPropertiesOfAllowedContentTypes
.FirstOrDefault(x => x.Alias == alias.ToFirstLower());
if (property != null)
{
column.Header = property.Name;
column.AllowSorting = false; // can't sort on custom property columns
}
else if (alias == "UpdateDate")
{
// Special case to restore hard-coded column titles
column.Header = "Last edited";
column.LocalizationKey = "defaultdialogs_lastEdited";
}
else if (alias == "Updator")
{
// Special case to restore hard-coded column titles (2)
column.Header = "Updated by";
column.LocalizationKey = "content_updatedBy";
}
else if (alias == "Owner")
{
// Special case to restore hard-coded column titles (3)
column.Header = "Created by";
column.LocalizationKey = "content_createBy";
}
else
{
// For others just sentence case the alias and camel case for the key
column.Header = alias.ToFirstUpper().SplitPascalCasing();
column.LocalizationKey = "content_" + alias.ToFirstLower();
}
// // Try to find heading from custom property (getting the name from the alias)
// // - need to look in children of the current content's content type
// var property = allPropertiesOfAllowedContentTypes
// .FirstOrDefault(x => x.Alias == alias.ToFirstLower());
// if (property != null)
// {
// column.Header = property.Name;
// column.AllowSorting = false; // can't sort on custom property columns
// }
// else if (alias == "UpdateDate")
// {
// // Special case to restore hard-coded column titles
// column.Header = "Last edited";
// column.LocalizationKey = "defaultdialogs_lastEdited";
// }
// else if (alias == "Updater")
// {
// // Special case to restore hard-coded column titles (2)
// column.Header = "Updated by";
// column.LocalizationKey = "content_updatedBy";
// }
// else if (alias == "Owner")
// {
// // Special case to restore hard-coded column titles (3)
// column.Header = "Created by";
// column.LocalizationKey = "content_createBy";
// }
// else
// {
// // For others just sentence case the alias and camel case for the key
// column.Header = alias.ToFirstUpper().SplitPascalCasing();
// column.LocalizationKey = "content_" + alias.ToFirstLower();
// }
containerConfig.AdditionalColumns.Add(column);
}
}
// containerConfig.AdditionalColumns.Add(column);
// }
// }
return containerConfig;
}
// return containerConfig;
//}
return null;
}

View File

@@ -29,8 +29,8 @@ namespace Umbraco.Web.PropertyEditors
{
"includeProperties", new[]
{
new {alias = "_UpdateDate", header = "Last edited", isSystem = 1},
new {alias = "_Updater", header = "Last edited by", isSystem = 1}
new {alias = "updateDate", header = "Last edited", isSystem = 1},
new {alias = "updater", header = "Last edited by", isSystem = 1}
}
}
};
@@ -50,7 +50,7 @@ namespace Umbraco.Web.PropertyEditors
public int OrderDirection { get; set; }
[PreValueField("includeProperties", "Include Properties", "views/propertyeditors/listview/includeproperties.prevalues.html")]
public int IncludeProperties { get; set; }
public object IncludeProperties { get; set; }
}