From b9d262b318e90deb2972952187d80edc46eb3008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 17 Jul 2020 18:14:06 +0300 Subject: [PATCH] Use WidgetManager for the cms reaction --- .../ReactionSelection/Default.cshtml | 4 +- .../ReactionSelectionViewComponent.cs | 1 + .../Components/ReactionSelection/default.js | 60 +++++++++++++------ 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/Default.cshtml index 1d1c4e7306..3927ac3fdb 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/Default.cshtml @@ -1,6 +1,6 @@ @model Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.ReactionSelection.ReactionSelectionViewModel -
+
Pick a reaction: @foreach (var reaction in Model.Reactions) { @@ -9,7 +9,7 @@ }
-
+
Current reactions: @foreach (var reaction in Model.Reactions.Where(r => r.Count > 0)) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/ReactionSelectionViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/ReactionSelectionViewComponent.cs index 45ae31c3b1..efb4db779e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/ReactionSelectionViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/ReactionSelectionViewComponent.cs @@ -8,6 +8,7 @@ using Volo.CmsKit.Reactions; namespace Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.ReactionSelection { + [ViewComponent(Name = "CmsReactionSelection")] [Widget( ScriptTypes = new[] {typeof(ReactionSelectionScriptBundleContributor)}, StyleTypes = new[] {typeof(ReactionSelectionStyleBundleContributor)} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js index 50daa6f162..298ab57c66 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js @@ -1,25 +1,49 @@ -(function () { +(function ($) { $(document).ready(function () { - function initReactionSelection() { - var $wrapper = $(this); - var $availableReactions = $wrapper.find('.cms-reaction-selection-available-reactions'); - - $wrapper.find('.cms-reaction-icon').each(function () { - var $icon = $(this); - $icon.click(function () { - var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create'; - volo.cmsKit.reactions.reactionPublic[methodName]({ - entityType: $wrapper.attr('data-entity-type'), - entityId: $wrapper.attr('data-entity-id'), - reactionName: $icon.attr('data-name') - }).then(function () { - location.reload(); //TODO: JUST TESTING !!!!!!!! + abp.widgets.CmsReactionSelection= function ($widget) { + + var getFilters = function () { + return { + + }; + } + + var refresh = function (filters) { + + }; + + var init = function (filters) { + var $wrapper = $widget.find('.cms-reaction-selection'); + $widget.find('.cms-reaction-icon').each(function () { + var $icon = $(this); + $icon.click(function () { + var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create'; + volo.cmsKit.reactions.reactionPublic[methodName]({ + entityType: $wrapper.attr('data-entity-type'), + entityId: $wrapper.attr('data-entity-id'), + reactionName: $icon.attr('data-name') + }).then(function () { + location.reload(); //TODO: JUST TESTING !!!!!!!! + }); }); }); + }; + + return { + getFilters: getFilters, + init: init, + refresh: refresh + }; + }; + + $('.abp-widget-wrapper[data-widget-name="CmsReactionSelection"]').each(function(){ + var $widget = $(this); + var widgetManager = new abp.WidgetManager({ + wrapper: $widget.parent(), //TODO: Change to $widget once WidgetManager supports it! }); - } - $('.cms-reaction-selection').each(initReactionSelection); + widgetManager.init(); + }); }); -})(); +})(jQuery);