From da04a0a9186765b1c7d2fe1c3578d56a9d11ef57 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 7 May 2019 21:06:38 +0800 Subject: [PATCH] MDL-65520 mod_forum: Add lock icon to indicate locked discussions --- mod/forum/amd/build/discussion_list.min.js | 2 +- mod/forum/amd/build/selectors.min.js | 2 +- mod/forum/amd/src/discussion_list.js | 9 +++++++++ mod/forum/amd/src/selectors.js | 4 ++++ mod/forum/templates/discussion_list.mustache | 11 +++++++---- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/mod/forum/amd/build/discussion_list.min.js b/mod/forum/amd/build/discussion_list.min.js index dc8b9ffd389..9bb733bad88 100644 --- a/mod/forum/amd/build/discussion_list.min.js +++ b/mod/forum/amd/build/discussion_list.min.js @@ -1 +1 @@ -define(["jquery","core/templates","core/str","core/notification","mod_forum/subscription_toggle","mod_forum/selectors","mod_forum/repository"],function(a,b,c,d,e,f,g){var h=function(e){e.on("click",f.favourite.toggle,function(){var b=a(this),c=b.data("forumid"),e=b.data("discussionid"),f=b.data("targetstate");g.setFavouriteDiscussionState(c,e,f).then(function(){return location.reload()})["catch"](d.exception)}),e.on("click",f.pin.toggle,function(b){b.preventDefault();var c=a(this),e=c.data("forumid"),f=c.data("discussionid"),h=c.data("targetstate");g.setPinDiscussionState(e,f,h).then(function(){return location.reload()})["catch"](d.exception)}),e.on("click",f.lock.toggle,function(e){var f=a(this),h=f.data("forumid"),i=f.data("discussionid"),j=f.data("state");g.setDiscussionLockState(h,i,j).then(function(a){return a.forumid=h,b.render("mod_forum/discussion_lock_toggle",a)}).then(function(a,c){return b.replaceNode(f,a,c)}).then(function(){return c.get_string("lockupdated","forum").done(function(a){return d.addNotification({message:a,type:"info"})})})["catch"](d.exception),e.preventDefault()})};return{init:function(a){e.init(a),h(a)}}}); \ No newline at end of file +define(["jquery","core/templates","core/str","core/notification","mod_forum/subscription_toggle","mod_forum/selectors","mod_forum/repository"],function(a,b,c,d,e,f,g){var h=function(e){e.on("click",f.favourite.toggle,function(){var b=a(this),c=b.data("forumid"),e=b.data("discussionid"),f=b.data("targetstate");g.setFavouriteDiscussionState(c,e,f).then(function(){return location.reload()})["catch"](d.exception)}),e.on("click",f.pin.toggle,function(b){b.preventDefault();var c=a(this),e=c.data("forumid"),f=c.data("discussionid"),h=c.data("targetstate");g.setPinDiscussionState(e,f,h).then(function(){return location.reload()})["catch"](d.exception)}),e.on("click",f.lock.toggle,function(e){var h=a(this),i=h.data("forumid"),j=h.data("discussionid"),k=h.data("state");g.setDiscussionLockState(i,j,k).then(function(a){var b=h.parents(f.summary.actions).find(f.lock.icon);return a.locked?b.removeClass("hidden"):b.addClass("hidden"),a}).then(function(a){return a.forumid=i,b.render("mod_forum/discussion_lock_toggle",a)}).then(function(a,c){return b.replaceNode(h,a,c)}).then(function(){return c.get_string("lockupdated","forum").done(function(a){return d.addNotification({message:a,type:"info"})})})["catch"](d.exception),e.preventDefault()})};return{init:function(a){e.init(a),h(a)}}}); \ No newline at end of file diff --git a/mod/forum/amd/build/selectors.min.js b/mod/forum/amd/build/selectors.min.js index d5a48dcc650..bfdbe3a660a 100644 --- a/mod/forum/amd/build/selectors.min.js +++ b/mod/forum/amd/build/selectors.min.js @@ -1 +1 @@ -define([],function(){return{subscription:{toggle:"[data-type='subscription-toggle'][data-action='toggle']"},post:{post:'[data-region="post"]',action:'[data-region="post-action"]',actionsContainer:'[data-region="post-actions-container"]',forumCoreContent:"[data-region-content='forum-post-core']",forumContent:"[data-content='forum-post']",forumSubject:"[data-region-content='forum-post-core-subject']",inpageReplyButton:"button",inpageReplyLink:"[data-action='collapsible-link']",inpageReplyContent:"[data-content='inpage-reply-content']",inpageReplyForm:"form[data-content='inpage-reply-form']",inpageSubmitBtn:"[data-action='forum-inpage-submit']",inpageSubmitBtnText:"[data-region='submit-text']",loadingIconContainer:"[data-region='loading-icon-container']",repliesContainer:"[data-region='replies-container']",modeSelect:"select[name='mode']"},lock:{toggle:"[data-action='toggle'][data-type='lock-toggle']"},favourite:{toggle:"[data-type='favorite-toggle'][data-action='toggle']"},pin:{toggle:"[data-type='pin-toggle'][data-action='toggle']"}}}); \ No newline at end of file +define([],function(){return{subscription:{toggle:"[data-type='subscription-toggle'][data-action='toggle']"},summary:{actions:"[data-container='discussion-summary-actions']"},post:{post:'[data-region="post"]',action:'[data-region="post-action"]',actionsContainer:'[data-region="post-actions-container"]',forumCoreContent:"[data-region-content='forum-post-core']",forumContent:"[data-content='forum-post']",forumSubject:"[data-region-content='forum-post-core-subject']",inpageReplyButton:"button",inpageReplyLink:"[data-action='collapsible-link']",inpageReplyContent:"[data-content='inpage-reply-content']",inpageReplyForm:"form[data-content='inpage-reply-form']",inpageSubmitBtn:"[data-action='forum-inpage-submit']",inpageSubmitBtnText:"[data-region='submit-text']",loadingIconContainer:"[data-region='loading-icon-container']",repliesContainer:"[data-region='replies-container']",modeSelect:"select[name='mode']"},lock:{toggle:"[data-action='toggle'][data-type='lock-toggle']",icon:"[data-region='locked-icon']"},favourite:{toggle:"[data-type='favorite-toggle'][data-action='toggle']"},pin:{toggle:"[data-type='pin-toggle'][data-action='toggle']"}}}); \ No newline at end of file diff --git a/mod/forum/amd/src/discussion_list.js b/mod/forum/amd/src/discussion_list.js index 06ea7dc7d40..b24718a0fa1 100644 --- a/mod/forum/amd/src/discussion_list.js +++ b/mod/forum/amd/src/discussion_list.js @@ -71,6 +71,15 @@ define([ var state = toggleElement.data('state'); Repository.setDiscussionLockState(forumId, discussionId, state) + .then(function(context) { + var icon = toggleElement.parents(Selectors.summary.actions).find(Selectors.lock.icon); + if (context.locked) { + icon.removeClass('hidden'); + } else { + icon.addClass('hidden'); + } + return context; + }) .then(function(context) { context.forumid = forumId; return Templates.render('mod_forum/discussion_lock_toggle', context); diff --git a/mod/forum/amd/src/selectors.js b/mod/forum/amd/src/selectors.js index 7773b002ac4..a4cd6e10a04 100644 --- a/mod/forum/amd/src/selectors.js +++ b/mod/forum/amd/src/selectors.js @@ -26,6 +26,9 @@ define([], function() { subscription: { toggle: "[data-type='subscription-toggle'][data-action='toggle']", }, + summary: { + actions: "[data-container='discussion-summary-actions']" + }, post: { post: '[data-region="post"]', action: '[data-region="post-action"]', @@ -45,6 +48,7 @@ define([], function() { }, lock: { toggle: "[data-action='toggle'][data-type='lock-toggle']", + icon: "[data-region='locked-icon']" }, favourite: { toggle: "[data-type='favorite-toggle'][data-action='toggle']", diff --git a/mod/forum/templates/discussion_list.mustache b/mod/forum/templates/discussion_list.mustache index ebd32e42b8d..3d8801eb19b 100644 --- a/mod/forum/templates/discussion_list.mustache +++ b/mod/forum/templates/discussion_list.mustache @@ -257,13 +257,16 @@ {{/discussion.timed.istimed}} - + {{#discussion}} -
-
+
+
+ {{#pix}}i/lock, core, {{#str}}locked, forum{{/str}}{{/pix}} +
+
{{> mod_forum/discussion_subscription_toggle}}
-
+
{{> mod_forum/forum_action_menu}}