Add custom client-side logic to the JavaScript file of the News designer
If you want to add additional client-side logic to the default designer view, you need to override the default designer JavaScript file. To do this, perform the following:
- In your SitefinityWebApp, in folder
Mvc, create a folder and name itScripts - In folder
Mvc/Scripts/, create a folder and name itNews - In folder
Mvc/Scripts/News/, create a filedesignerview-simple.js - In the file, paste the following code:
JavaScript
(function ($) { angular.module('designer').requires.push('expander', 'sfSelectors'); angular.module('designer').controller('SimpleCtrl', ['$scope', 'propertyService', function ($scope, propertyService) { var sortOptions = ['PublicationDate DESC', 'LastModified DESC', 'Title ASC', 'Title DESC', 'AsSetManually']; var emptyGuid = '00000000-0000-0000-0000-000000000000'; $scope.feedback.showLoadingIndicator = true; $scope.additionalFilters = {}; $scope.newsSelector = { selectedItemsIds: [] }; $scope.$watch( 'additionalFilters.value', function (newAdditionalFilters, oldAdditionalFilters) { if (newAdditionalFilters !== oldAdditionalFilters) { $scope.properties.SerializedAdditionalFilters.PropertyValue = JSON.stringify(newAdditionalFilters); } }, true ); $scope.$watch( 'properties.ProviderName.PropertyValue', function (newProviderName, oldProviderName) { if (newProviderName !== oldProviderName) { $scope.properties.SelectionMode.PropertyValue = 'AllItems'; $scope.properties.SerializedSelectedItemsIds.PropertyValue = null; } }, true ); $scope.$watch( 'newsSelector.selectedItemsIds', function (newSelectedItemsIds, oldSelectedItemsIds) { if (newSelectedItemsIds !== oldSelectedItemsIds) { if (newSelectedItemsIds) { $scope.properties.SerializedSelectedItemsIds.PropertyValue = JSON.stringify(newSelectedItemsIds); } } }, true ); $scope.updateSortOption = function (newSortOption) { if (newSortOption !== "Custom") { $scope.properties.SortExpression.PropertyValue = newSortOption; } }; propertyService.get() .then(function (data) { if (data) { $scope.properties = propertyService.toAssociativeArray(data.Items); var additionalFilters = $.parseJSON($scope.properties.SerializedAdditionalFilters.PropertyValue || null); $scope.additionalFilters.value = additionalFilters; var selectedItemsIds = $.parseJSON($scope.properties.SerializedSelectedItemsIds.PropertyValue || null); if (selectedItemsIds) { $scope.newsSelector.selectedItemsIds = selectedItemsIds; } if (sortOptions.indexOf($scope.properties.SortExpression.PropertyValue) >= 0) { $scope.selectedSortOption = $scope.properties.SortExpression.PropertyValue; } else { $scope.selectedSortOption = "Custom"; } } }, function (data) { $scope.feedback.showError = true; if (data) $scope.feedback.errorMessage = data.Detail; }) .then(function () { $scope.feedback.savingHandlers.push(function () { if ($scope.properties.OpenInSamePage.PropertyValue && $scope.properties.OpenInSamePage.PropertyValue.toLowerCase() === 'true') { $scope.properties.DetailsPageId.PropertyValue = emptyGuid; } else { if (!$scope.properties.DetailsPageId.PropertyValue || $scope.properties.DetailsPageId.PropertyValue === emptyGuid) { $scope.properties.OpenInSamePage.PropertyValue = true; } } if ($scope.properties.SelectionMode.PropertyValue === "FilteredItems" && $scope.additionalFilters.value && $scope.additionalFilters.value.QueryItems && $scope.additionalFilters.value.QueryItems.length === 0) { $scope.properties.SelectionMode.PropertyValue = 'AllItems'; } if ($scope.properties.SelectionMode.PropertyValue !== "FilteredItems") { $scope.properties.SerializedAdditionalFilters.PropertyValue = null; } if ($scope.properties.SelectionMode.PropertyValue !== 'SelectedItems') { $scope.properties.SerializedSelectedItemsIds.PropertyValue = null; // If the sorting expression is AsSetManually but the selection mode is AllItems or FilteredItems, this is not a valid combination. // So set the sort expression to the default value: PublicationDate DESC if ($scope.properties.SortExpression.PropertyValue === "AsSetManually") { $scope.properties.SortExpression.PropertyValue = "PublicationDate DESC"; } } }); }) .finally(function () { $scope.feedback.showLoadingIndicator = false; }); }]); })(jQuery); - Add your custom client-side logic.
- Save and close the file.
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.