Merge branch 'MDL-72308' of https://github.com/paulholden/moodle
This commit is contained in:
+1
-1
@@ -781,7 +781,7 @@ EditorTextArea.prototype = {
|
||||
// Insert the cleaned content.
|
||||
this.textarea.set('value', newValue);
|
||||
|
||||
// Trigger the onchange callback on the textarea, essentially to notify moodle-core-formchangechecker.
|
||||
// Trigger the onchange callback on the textarea, essentially to notify the formchangechecker module.
|
||||
this.textarea.simulate('change');
|
||||
|
||||
// Trigger handlers for this action.
|
||||
|
||||
+1
-1
@@ -776,7 +776,7 @@ EditorTextArea.prototype = {
|
||||
// Insert the cleaned content.
|
||||
this.textarea.set('value', newValue);
|
||||
|
||||
// Trigger the onchange callback on the textarea, essentially to notify moodle-core-formchangechecker.
|
||||
// Trigger the onchange callback on the textarea, essentially to notify the formchangechecker module.
|
||||
this.textarea.simulate('change');
|
||||
|
||||
// Trigger handlers for this action.
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ EditorTextArea.prototype = {
|
||||
// Insert the cleaned content.
|
||||
this.textarea.set('value', newValue);
|
||||
|
||||
// Trigger the onchange callback on the textarea, essentially to notify moodle-core-formchangechecker.
|
||||
// Trigger the onchange callback on the textarea, essentially to notify the formchangechecker module.
|
||||
this.textarea.simulate('change');
|
||||
|
||||
// Trigger handlers for this action.
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -418,9 +418,6 @@ export const startWatching = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add legacy support to provide b/c for the old YUI version.
|
||||
addLegacyFunctions();
|
||||
|
||||
document.addEventListener('change', e => {
|
||||
if (!isWatchingForm(e.target)) {
|
||||
return;
|
||||
@@ -485,33 +482,6 @@ export const startWatching = () => {
|
||||
window.addEventListener('beforeunload', beforeUnloadHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add legacy functions for backwards compatability.
|
||||
*
|
||||
* @method
|
||||
* @private
|
||||
*/
|
||||
const addLegacyFunctions = () => {
|
||||
// Create a curried function to log use of the old function and provide detail on its replacement.
|
||||
const getLoggedLegacyFallback = (oldFunctionName, newFunctionName, newFunction) => (...args) => {
|
||||
window.console.warn(
|
||||
`The moodle-core-formchangechecker has been deprecated ` +
|
||||
`and replaced with core_form/changechecker. ` +
|
||||
`The ${oldFunctionName} function has been replaced with ${newFunctionName}.`
|
||||
);
|
||||
newFunction(...args);
|
||||
};
|
||||
|
||||
/* eslint-disable */
|
||||
window.M.core_formchangechecker = {
|
||||
init: getLoggedLegacyFallback('init', 'watchFormById', watchFormById),
|
||||
reset_form_dirty_state: getLoggedLegacyFallback('reset_form_dirty_state', 'resetFormDirtyState', resetAllFormDirtyStates),
|
||||
set_form_changed: getLoggedLegacyFallback('set_form_changed', 'markFormAsDirty', markAllFormsAsDirty),
|
||||
set_form_submitted: getLoggedLegacyFallback('set_form_submitted', 'markFormSubmitted', markAllFormsSubmitted),
|
||||
};
|
||||
/* eslint-enable */
|
||||
};
|
||||
|
||||
/**
|
||||
* Watch the form matching the specified ID for changes.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,8 @@ information provided here is intended especially for developers.
|
||||
* The group element has a new method `getAttributesForFormElement` which should be used in conjunction
|
||||
with `createFormElement` to ensure that all elements within the group have unique IDs
|
||||
* New method `setHiddenLabel` added to the group form element type
|
||||
* The deprecated `moodle-core-formchangechecker` YUI module and legacy `M.core_formchangechecker` have been
|
||||
removed and can no longer be used
|
||||
|
||||
=== 4.3 ===
|
||||
|
||||
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
YUI.add('moodle-core-formchangechecker', function (Y, NAME) {
|
||||
|
||||
/**
|
||||
* A utility to check for form changes before navigating away from a page.
|
||||
*
|
||||
* @module moodle-core-formchangechecker
|
||||
*/
|
||||
|
||||
/**
|
||||
* A utility to check for form changes before navigating away from a page.
|
||||
*
|
||||
* Please note that this YUI module has been deprecated in favour of the core_form/changechecker AMD module.
|
||||
*
|
||||
* @class M.core.formchangechecker
|
||||
* @deprecated
|
||||
*/
|
||||
|
||||
window.console.warn(
|
||||
'The moodle-core-formchangechecker has been deprecated ' +
|
||||
'and replaced with core_form/changechecker. ' +
|
||||
'Please update your code to make use of the new module.'
|
||||
);
|
||||
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.startWatching();
|
||||
});
|
||||
|
||||
// The following are provided to prevent race conditions.
|
||||
// Because the AMD module is loaded asynchronously after the YUI module is loaded, there is a possibility that the
|
||||
// calling code may call the YUI function calls before the AMD module has finished loading.
|
||||
// These will be removed in future and are automatically overwritten by the legacy helper provided as part of the new
|
||||
// changechecker AMD module.
|
||||
// eslint-disable-next-line camelcase
|
||||
M.core_formchangechecker = M.core_formchangechecker || {
|
||||
init: function(config) {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.watchFormById(config.formid);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the form changed state to true
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
set_form_changed: function() {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.markAllFormsAsDirty();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the form submitted state to true
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
set_form_submitted: function() {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.markAllFormsSubmitted();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset the form state
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
reset_form_dirty_state: function() {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.resetAllFormDirtyStates();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["base", "event-focus", "moodle-core-event"]});
|
||||
-1
@@ -1 +0,0 @@
|
||||
YUI.add("moodle-core-formchangechecker",function(e,r){window.console.warn("The moodle-core-formchangechecker has been deprecated and replaced with core_form/changechecker. Please update your code to make use of the new module."),require(["core_form/changechecker"],function(e){e.startWatching()}),M.core_formchangechecker=M.core_formchangechecker||{init:function(r){require(["core_form/changechecker"],function(e){e.watchFormById(r.formid)})},set_form_changed:function(){require(["core_form/changechecker"],function(e){e.markAllFormsAsDirty()})},set_form_submitted:function(){require(["core_form/changechecker"],function(e){e.markAllFormsSubmitted()})},reset_form_dirty_state:function(){require(["core_form/changechecker"],function(e){e.resetAllFormDirtyStates()})}}},"@VERSION@",{requires:["base","event-focus","moodle-core-event"]});
|
||||
@@ -1,73 +0,0 @@
|
||||
YUI.add('moodle-core-formchangechecker', function (Y, NAME) {
|
||||
|
||||
/**
|
||||
* A utility to check for form changes before navigating away from a page.
|
||||
*
|
||||
* @module moodle-core-formchangechecker
|
||||
*/
|
||||
|
||||
/**
|
||||
* A utility to check for form changes before navigating away from a page.
|
||||
*
|
||||
* Please note that this YUI module has been deprecated in favour of the core_form/changechecker AMD module.
|
||||
*
|
||||
* @class M.core.formchangechecker
|
||||
* @deprecated
|
||||
*/
|
||||
|
||||
window.console.warn(
|
||||
'The moodle-core-formchangechecker has been deprecated ' +
|
||||
'and replaced with core_form/changechecker. ' +
|
||||
'Please update your code to make use of the new module.'
|
||||
);
|
||||
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.startWatching();
|
||||
});
|
||||
|
||||
// The following are provided to prevent race conditions.
|
||||
// Because the AMD module is loaded asynchronously after the YUI module is loaded, there is a possibility that the
|
||||
// calling code may call the YUI function calls before the AMD module has finished loading.
|
||||
// These will be removed in future and are automatically overwritten by the legacy helper provided as part of the new
|
||||
// changechecker AMD module.
|
||||
// eslint-disable-next-line camelcase
|
||||
M.core_formchangechecker = M.core_formchangechecker || {
|
||||
init: function(config) {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.watchFormById(config.formid);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the form changed state to true
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
set_form_changed: function() {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.markAllFormsAsDirty();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the form submitted state to true
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
set_form_submitted: function() {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.markAllFormsSubmitted();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset the form state
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
reset_form_dirty_state: function() {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.resetAllFormDirtyStates();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["base", "event-focus", "moodle-core-event"]});
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"name": "moodle-core-formchangechecker",
|
||||
"builds": {
|
||||
"moodle-core-formchangechecker": {
|
||||
"jsfiles": [
|
||||
"formchangechecker.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* A utility to check for form changes before navigating away from a page.
|
||||
*
|
||||
* @module moodle-core-formchangechecker
|
||||
*/
|
||||
|
||||
/**
|
||||
* A utility to check for form changes before navigating away from a page.
|
||||
*
|
||||
* Please note that this YUI module has been deprecated in favour of the core_form/changechecker AMD module.
|
||||
*
|
||||
* @class M.core.formchangechecker
|
||||
* @deprecated
|
||||
*/
|
||||
|
||||
window.console.warn(
|
||||
'The moodle-core-formchangechecker has been deprecated ' +
|
||||
'and replaced with core_form/changechecker. ' +
|
||||
'Please update your code to make use of the new module.'
|
||||
);
|
||||
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.startWatching();
|
||||
});
|
||||
|
||||
// The following are provided to prevent race conditions.
|
||||
// Because the AMD module is loaded asynchronously after the YUI module is loaded, there is a possibility that the
|
||||
// calling code may call the YUI function calls before the AMD module has finished loading.
|
||||
// These will be removed in future and are automatically overwritten by the legacy helper provided as part of the new
|
||||
// changechecker AMD module.
|
||||
// eslint-disable-next-line camelcase
|
||||
M.core_formchangechecker = M.core_formchangechecker || {
|
||||
init: function(config) {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.watchFormById(config.formid);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the form changed state to true
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
set_form_changed: function() {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.markAllFormsAsDirty();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the form submitted state to true
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
set_form_submitted: function() {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.markAllFormsSubmitted();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset the form state
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
reset_form_dirty_state: function() {
|
||||
require(['core_form/changechecker'], function(ChangeChecker) {
|
||||
ChangeChecker.resetAllFormDirtyStates();
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"moodle-core-formchangechecker": {
|
||||
"requires": [
|
||||
"base",
|
||||
"event-focus",
|
||||
"moodle-core-event"
|
||||
]
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@
|
||||
* @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("mod_forum/discussion_list",["jquery","core/templates","core/str","core/notification","mod_forum/subscription_toggle","mod_forum/selectors","mod_forum/repository","core/pubsub","mod_forum/forum_events"],(function($,Templates,Str,Notification,SubscriptionToggle,Selectors,Repository,PubSub,ForumEvents){return{init:function(root){SubscriptionToggle.init(root,!1,(function(toggleElement,context){var toggleId=toggleElement.attr("id"),newTargetState=context.userstate.subscribed?0:1;toggleElement.data("targetstate",newTargetState);var stringKey=context.userstate.subscribed?"unsubscribediscussion":"subscribediscussion";return Str.get_string(stringKey,"mod_forum").then((function(string){return toggleElement.closest("td").find('label[for="'+toggleId+'"]').find("span").text(string),string}))})),function(root){PubSub.subscribe(ForumEvents.SUBSCRIPTION_TOGGLED,(function(data){var discussionId=data.discussionId,subscribed=data.subscriptionState,discussionListItem=root.find(Selectors.discussion.item+"[data-discussionid= "+discussionId+"]"),subscribedLabel=discussionListItem.find(Selectors.discussion.subscribedLabel);subscribed?(discussionListItem.addClass("subscribed"),subscribedLabel.removeAttr("hidden")):(discussionListItem.removeClass("subscribed"),subscribedLabel.attr("hidden",!0))})),root.on("click",Selectors.post.inpageCancelButton,(function(){void 0!==M.core_formchangechecker&&M.core_formchangechecker.reset_form_dirty_state()})),root.on("click",Selectors.favourite.toggle,(function(e){e.preventDefault();var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),subscriptionState=toggleElement.data("targetstate");Repository.setFavouriteDiscussionState(forumId,discussionId,subscriptionState).then((function(){return location.reload()})).catch(Notification.exception)})),root.on("click",Selectors.pin.toggle,(function(e){e.preventDefault();var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),state=toggleElement.data("targetstate");Repository.setPinDiscussionState(forumId,discussionId,state).then((function(){return location.reload()})).catch(Notification.exception)})),root.on("click",Selectors.lock.toggle,(function(e){var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),state=toggleElement.data("state");Repository.setDiscussionLockState(forumId,discussionId,state).then((function(context){var icon=toggleElement.parents(Selectors.summary.actions).find(Selectors.lock.icon),lockedLabel=toggleElement.parents(Selectors.discussion.item).find(Selectors.discussion.lockedLabel);return context.locked?(icon.removeClass("hidden"),lockedLabel.removeAttr("hidden")):(icon.addClass("hidden"),lockedLabel.attr("hidden",!0)),context})).then((function(context){return context.forumid=forumId,Templates.render("mod_forum/discussion_lock_toggle",context)})).then((function(html,js){return Templates.replaceNode(toggleElement,html,js)})).then((function(){return Str.get_string("lockupdated","forum").done((function(s){return Notification.addNotification({message:s,type:"info"})}))})).catch(Notification.exception),e.preventDefault()}))}(root)}}}));
|
||||
define("mod_forum/discussion_list",["jquery","core/templates","core/str","core/notification","mod_forum/subscription_toggle","mod_forum/selectors","mod_forum/repository","core/pubsub","mod_forum/forum_events","core_form/changechecker"],(function($,Templates,Str,Notification,SubscriptionToggle,Selectors,Repository,PubSub,ForumEvents,FormChangeChecker){return{init:function(root){SubscriptionToggle.init(root,!1,(function(toggleElement,context){var toggleId=toggleElement.attr("id"),newTargetState=context.userstate.subscribed?0:1;toggleElement.data("targetstate",newTargetState);var stringKey=context.userstate.subscribed?"unsubscribediscussion":"subscribediscussion";return Str.get_string(stringKey,"mod_forum").then((function(string){return toggleElement.closest("td").find('label[for="'+toggleId+'"]').find("span").text(string),string}))})),function(root){PubSub.subscribe(ForumEvents.SUBSCRIPTION_TOGGLED,(function(data){var discussionId=data.discussionId,subscribed=data.subscriptionState,discussionListItem=root.find(Selectors.discussion.item+"[data-discussionid= "+discussionId+"]"),subscribedLabel=discussionListItem.find(Selectors.discussion.subscribedLabel);subscribed?(discussionListItem.addClass("subscribed"),subscribedLabel.removeAttr("hidden")):(discussionListItem.removeClass("subscribed"),subscribedLabel.attr("hidden",!0))})),root.on("click",Selectors.post.inpageCancelButton,(function(e){FormChangeChecker.resetFormDirtyState(e.currentTarget)})),root.on("click",Selectors.favourite.toggle,(function(e){e.preventDefault();var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),subscriptionState=toggleElement.data("targetstate");Repository.setFavouriteDiscussionState(forumId,discussionId,subscriptionState).then((function(){return location.reload()})).catch(Notification.exception)})),root.on("click",Selectors.pin.toggle,(function(e){e.preventDefault();var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),state=toggleElement.data("targetstate");Repository.setPinDiscussionState(forumId,discussionId,state).then((function(){return location.reload()})).catch(Notification.exception)})),root.on("click",Selectors.lock.toggle,(function(e){var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),state=toggleElement.data("state");Repository.setDiscussionLockState(forumId,discussionId,state).then((function(context){var icon=toggleElement.parents(Selectors.summary.actions).find(Selectors.lock.icon),lockedLabel=toggleElement.parents(Selectors.discussion.item).find(Selectors.discussion.lockedLabel);return context.locked?(icon.removeClass("hidden"),lockedLabel.removeAttr("hidden")):(icon.addClass("hidden"),lockedLabel.attr("hidden",!0)),context})).then((function(context){return context.forumid=forumId,Templates.render("mod_forum/discussion_lock_toggle",context)})).then((function(html,js){return Templates.replaceNode(toggleElement,html,js)})).then((function(){return Str.get_string("lockupdated","forum").done((function(s){return Notification.addNotification({message:s,type:"info"})}))})).catch(Notification.exception),e.preventDefault()}))}(root)}}}));
|
||||
|
||||
//# sourceMappingURL=discussion_list.min.js.map
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -5,6 +5,6 @@
|
||||
* @copyright 2019 Peter Dias
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("mod_forum/inpage_reply",["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors","core_form/changechecker"],(function($,Templates,Notification,Repository,Selectors,FormChangeChecker){var DISPLAYCONSTANTS_NESTED_V2=4,DISPLAYCONSTANTS_THREADED=2,DISPLAYCONSTANTS_NESTED=3,DISPLAYCONSTANTS_FLAT_NEWEST_FIRST=-1,EVENTS={POST_CREATED:"mod_forum-post-created"},CONTENT_FORMATS={MOODLE:0},hideSubmitButtonLoadingIcon=function(button){var textContainer=button.find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer);button.css("width",""),textContainer.removeClass("hidden"),loadingIconContainer.addClass("hidden")},registerEventListeners=function(root){root.on("click",Selectors.post.inpageSubmitBtn,(function(e){e.preventDefault();var newid,button,textContainer,loadingIconContainer,width,submitButton=$(e.currentTarget),allButtons=submitButton.parent().find(Selectors.post.inpageReplyButton),form=submitButton.parents(Selectors.post.inpageReplyForm).get(0),message=form.elements.post.value.trim(),messageformat=CONTENT_FORMATS.MOODLE,postid=form.elements.reply.value,subject=form.elements.subject.value,currentRoot=submitButton.closest(Selectors.post.post),isprivatereply=null!=form.elements.privatereply&&form.elements.privatereply.checked,modeSelector=root.find(Selectors.post.modeSelect),mode=modeSelector.length?parseInt(modeSelector.get(0).value):null;message.length&&(textContainer=(button=submitButton).find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer),width=button.outerWidth(),button.css("width",width),textContainer.addClass("hidden"),loadingIconContainer.removeClass("hidden"),allButtons.prop("disabled",!0),Repository.addDiscussionPost(postid,subject,message,messageformat,isprivatereply,!0).then((function(context){var message=context.messages.reduce((function(carry,message){return"success"==message.type&&(carry+="<p>"+message.message+"</p>"),carry}),"");return Notification.addNotification({message:message,type:"success"}),context})).then((function(context){form.reset();var post=context.post;switch(newid=post.id,mode){case DISPLAYCONSTANTS_NESTED_V2:var capabilities=post.capabilities,currentAuthorName=currentRoot.children().not(Selectors.post.repliesContainer).find(Selectors.post.authorName).text();return post.parentauthorname=currentAuthorName,post.showactionmenu=capabilities.view||capabilities.controlreadstatus||capabilities.edit||capabilities.split||capabilities.delete||capabilities.export||post.urls.viewparent,Templates.render("mod_forum/forum_discussion_nested_v2_post_reply",post);case DISPLAYCONSTANTS_THREADED:return Templates.render("mod_forum/forum_discussion_threaded_post",post);case DISPLAYCONSTANTS_NESTED:return Templates.render("mod_forum/forum_discussion_nested_post",post);default:return Templates.render("mod_forum/forum_discussion_post",post)}})).then((function(html,js){var repliesnode=currentRoot.find(Selectors.post.repliesContainer).first();return mode==DISPLAYCONSTANTS_FLAT_NEWEST_FIRST?Templates.prependNodeContents(repliesnode,html,js):Templates.appendNodeContents(repliesnode,html,js)})).then((function(){return submitButton.trigger(EVENTS.POST_CREATED,newid),hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),FormChangeChecker.resetFormDirtyState(submitButton[0]),currentRoot.find(Selectors.post.inpageReplyContent).hide()})).then((function(){location.href="#p"+newid,location.reload()})).catch((function(error){return hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),Notification.exception(error)})))})),root.on("click",Selectors.post.inpageCancelButton,(function(){void 0!==M.core_formchangechecker&&M.core_formchangechecker.reset_form_dirty_state()}))};return{init:function(root){registerEventListeners(root)},CONTENT_FORMATS:CONTENT_FORMATS,EVENTS:EVENTS}}));
|
||||
define("mod_forum/inpage_reply",["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors","core_form/changechecker"],(function($,Templates,Notification,Repository,Selectors,FormChangeChecker){var DISPLAYCONSTANTS_NESTED_V2=4,DISPLAYCONSTANTS_THREADED=2,DISPLAYCONSTANTS_NESTED=3,DISPLAYCONSTANTS_FLAT_NEWEST_FIRST=-1,EVENTS={POST_CREATED:"mod_forum-post-created"},CONTENT_FORMATS={MOODLE:0},hideSubmitButtonLoadingIcon=function(button){var textContainer=button.find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer);button.css("width",""),textContainer.removeClass("hidden"),loadingIconContainer.addClass("hidden")},registerEventListeners=function(root){root.on("click",Selectors.post.inpageSubmitBtn,(function(e){e.preventDefault();var newid,button,textContainer,loadingIconContainer,width,submitButton=$(e.currentTarget),allButtons=submitButton.parent().find(Selectors.post.inpageReplyButton),form=submitButton.parents(Selectors.post.inpageReplyForm).get(0),message=form.elements.post.value.trim(),messageformat=CONTENT_FORMATS.MOODLE,postid=form.elements.reply.value,subject=form.elements.subject.value,currentRoot=submitButton.closest(Selectors.post.post),isprivatereply=null!=form.elements.privatereply&&form.elements.privatereply.checked,modeSelector=root.find(Selectors.post.modeSelect),mode=modeSelector.length?parseInt(modeSelector.get(0).value):null;message.length&&(textContainer=(button=submitButton).find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer),width=button.outerWidth(),button.css("width",width),textContainer.addClass("hidden"),loadingIconContainer.removeClass("hidden"),allButtons.prop("disabled",!0),Repository.addDiscussionPost(postid,subject,message,messageformat,isprivatereply,!0).then((function(context){var message=context.messages.reduce((function(carry,message){return"success"==message.type&&(carry+="<p>"+message.message+"</p>"),carry}),"");return Notification.addNotification({message:message,type:"success"}),context})).then((function(context){form.reset();var post=context.post;switch(newid=post.id,mode){case DISPLAYCONSTANTS_NESTED_V2:var capabilities=post.capabilities,currentAuthorName=currentRoot.children().not(Selectors.post.repliesContainer).find(Selectors.post.authorName).text();return post.parentauthorname=currentAuthorName,post.showactionmenu=capabilities.view||capabilities.controlreadstatus||capabilities.edit||capabilities.split||capabilities.delete||capabilities.export||post.urls.viewparent,Templates.render("mod_forum/forum_discussion_nested_v2_post_reply",post);case DISPLAYCONSTANTS_THREADED:return Templates.render("mod_forum/forum_discussion_threaded_post",post);case DISPLAYCONSTANTS_NESTED:return Templates.render("mod_forum/forum_discussion_nested_post",post);default:return Templates.render("mod_forum/forum_discussion_post",post)}})).then((function(html,js){var repliesnode=currentRoot.find(Selectors.post.repliesContainer).first();return mode==DISPLAYCONSTANTS_FLAT_NEWEST_FIRST?Templates.prependNodeContents(repliesnode,html,js):Templates.appendNodeContents(repliesnode,html,js)})).then((function(){return submitButton.trigger(EVENTS.POST_CREATED,newid),hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),FormChangeChecker.resetFormDirtyState(submitButton[0]),currentRoot.find(Selectors.post.inpageReplyContent).hide()})).then((function(){location.href="#p"+newid,location.reload()})).catch((function(error){return hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),Notification.exception(error)})))})),root.on("click",Selectors.post.inpageCancelButton,(function(e){FormChangeChecker.resetFormDirtyState(e.currentTarget)}))};return{init:function(root){registerEventListeners(root)},CONTENT_FORMATS:CONTENT_FORMATS,EVENTS:EVENTS}}));
|
||||
|
||||
//# sourceMappingURL=inpage_reply.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -30,6 +30,7 @@ define([
|
||||
'mod_forum/repository',
|
||||
'core/pubsub',
|
||||
'mod_forum/forum_events',
|
||||
'core_form/changechecker',
|
||||
], function(
|
||||
$,
|
||||
Templates,
|
||||
@@ -39,7 +40,8 @@ define([
|
||||
Selectors,
|
||||
Repository,
|
||||
PubSub,
|
||||
ForumEvents
|
||||
ForumEvents,
|
||||
FormChangeChecker
|
||||
) {
|
||||
var registerEventListeners = function(root) {
|
||||
PubSub.subscribe(ForumEvents.SUBSCRIPTION_TOGGLED, function(data) {
|
||||
@@ -56,11 +58,9 @@ define([
|
||||
}
|
||||
});
|
||||
|
||||
root.on('click', Selectors.post.inpageCancelButton, function() {
|
||||
root.on('click', Selectors.post.inpageCancelButton, function(e) {
|
||||
// Tell formchangechecker to reset the form state.
|
||||
if (typeof M.core_formchangechecker !== 'undefined') {
|
||||
M.core_formchangechecker.reset_form_dirty_state();
|
||||
}
|
||||
FormChangeChecker.resetFormDirtyState(e.currentTarget);
|
||||
});
|
||||
|
||||
root.on('click', Selectors.favourite.toggle, function(e) {
|
||||
|
||||
@@ -190,11 +190,9 @@ define([
|
||||
}
|
||||
});
|
||||
|
||||
root.on('click', Selectors.post.inpageCancelButton, function() {
|
||||
root.on('click', Selectors.post.inpageCancelButton, function(e) {
|
||||
// Tell formchangechecker to reset the form state.
|
||||
if (typeof M.core_formchangechecker !== 'undefined') {
|
||||
M.core_formchangechecker.reset_form_dirty_state();
|
||||
}
|
||||
FormChangeChecker.resetFormDirtyState(e.currentTarget);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user