mirror of
https://github.com/moodle/moodle.git
synced 2025-08-09 02:46:40 +02:00
MDL-66481 forum: Remove the YUI subscribe link
* Remove the subscribe link that's powered by YUI and subscribe_ajax.php. This will be replaced by the subscribe action menu item which utilises the subscription toggle template and calls the proper WS function for toggling discussion subscription. * Nuke YUI module for toggling subscription and subscribe_ajax.php (about time!)
This commit is contained in:
parent
2b8e4f2e4b
commit
5132de054c
9 changed files with 4 additions and 468 deletions
|
@ -219,10 +219,6 @@ class discussion {
|
||||||
|
|
||||||
$capabilities = (array) $exporteddiscussion['capabilities'];
|
$capabilities = (array) $exporteddiscussion['capabilities'];
|
||||||
|
|
||||||
if ($capabilities['subscribe']) {
|
|
||||||
$exporteddiscussion['html']['subscribe'] = $this->get_subscription_button_html();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($capabilities['move']) {
|
if ($capabilities['move']) {
|
||||||
$exporteddiscussion['html']['movediscussion'] = $this->get_move_discussion_html();
|
$exporteddiscussion['html']['movediscussion'] = $this->get_move_discussion_html();
|
||||||
}
|
}
|
||||||
|
@ -295,26 +291,6 @@ class discussion {
|
||||||
return $this->renderer->render($select);
|
return $this->renderer->render($select);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the HTML to render the subscription button.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function get_subscription_button_html() : string {
|
|
||||||
global $PAGE;
|
|
||||||
|
|
||||||
$forumrecord = $this->forumrecord;
|
|
||||||
$discussion = $this->discussion;
|
|
||||||
$html = html_writer::div(
|
|
||||||
forum_get_discussion_subscription_icon($forumrecord, $discussion->get_id(), null, true),
|
|
||||||
'discussionsubscription'
|
|
||||||
);
|
|
||||||
$html .= forum_get_discussion_subscription_icon_preloaders();
|
|
||||||
// Add the subscription toggle JS.
|
|
||||||
$PAGE->requires->yui_module('moodle-mod_forum-subscriptiontoggle', 'Y.M.mod_forum.subscriptiontoggle.init');
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the HTML to render the move discussion selector and button.
|
* Get the HTML to render the move discussion selector and button.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
<?php
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
|
||||||
//
|
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Moodle is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subscribe to or unsubscribe from a forum discussion.
|
|
||||||
*
|
|
||||||
* @package mod_forum
|
|
||||||
* @copyright 2014 Andrew Nicols <andrew@nicols.co.uk>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
define('AJAX_SCRIPT', true);
|
|
||||||
require(__DIR__.'/../../config.php');
|
|
||||||
require_once($CFG->dirroot . '/mod/forum/lib.php');
|
|
||||||
|
|
||||||
$forumid = required_param('forumid', PARAM_INT); // The forum to subscribe or unsubscribe.
|
|
||||||
$discussionid = optional_param('discussionid', null, PARAM_INT); // The discussionid to subscribe.
|
|
||||||
$includetext = optional_param('includetext', false, PARAM_BOOL);
|
|
||||||
|
|
||||||
$forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
|
|
||||||
$course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
|
|
||||||
if (!$discussion = $DB->get_record('forum_discussions', array('id' => $discussionid, 'forum' => $forumid))) {
|
|
||||||
print_error('invaliddiscussionid', 'forum');
|
|
||||||
}
|
|
||||||
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
|
|
||||||
$context = context_module::instance($cm->id);
|
|
||||||
|
|
||||||
require_sesskey();
|
|
||||||
require_login($course, false, $cm);
|
|
||||||
require_capability('mod/forum:viewdiscussion', $context);
|
|
||||||
|
|
||||||
$return = new stdClass();
|
|
||||||
|
|
||||||
if (is_guest($context, $USER)) {
|
|
||||||
// is_guest should be used here as this also checks whether the user is a guest in the current course.
|
|
||||||
// Guests and visitors cannot subscribe - only enrolled users.
|
|
||||||
throw new moodle_exception('noguestsubscribe', 'mod_forum');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!\mod_forum\subscriptions::is_subscribable($forum)) {
|
|
||||||
// Nothing to do. We won't actually output any content here though.
|
|
||||||
echo json_encode($return);
|
|
||||||
die;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\mod_forum\subscriptions::is_subscribed($USER->id, $forum, $discussion->id, $cm)) {
|
|
||||||
// The user is subscribed, unsubscribe them.
|
|
||||||
\mod_forum\subscriptions::unsubscribe_user_from_discussion($USER->id, $discussion, $context);
|
|
||||||
} else {
|
|
||||||
// The user is unsubscribed, subscribe them.
|
|
||||||
\mod_forum\subscriptions::subscribe_user_to_discussion($USER->id, $discussion, $context);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now return the updated subscription icon.
|
|
||||||
$return->icon = forum_get_discussion_subscription_icon($forum, $discussion->id, null, $includetext);
|
|
||||||
echo json_encode($return);
|
|
||||||
die;
|
|
|
@ -34,13 +34,11 @@
|
||||||
{{#html}}
|
{{#html}}
|
||||||
{{#hasanyactions}}
|
{{#hasanyactions}}
|
||||||
<div class="d-flex flex-wrap flex-row-reverse m-b-1 text-right" data-container="discussion-tools">
|
<div class="d-flex flex-wrap flex-row-reverse m-b-1 text-right" data-container="discussion-tools">
|
||||||
|
|
||||||
<div class="pl-1">
|
<div class="pl-1">
|
||||||
<div class="discussion-settings-menu">
|
<div class="discussion-settings-menu">
|
||||||
{{> mod_forum/forum_action_menu}}
|
{{> mod_forum/forum_action_menu}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pl-1">{{{subscribe}}}</div>
|
|
||||||
</div>
|
</div>
|
||||||
{{/hasanyactions}}
|
{{/hasanyactions}}
|
||||||
{{{neighbourlinks}}}
|
{{{neighbourlinks}}}
|
||||||
|
@ -61,8 +59,9 @@
|
||||||
{{#html.neighbourlinks}}{{{.}}}{{/html.neighbourlinks}}
|
{{#html.neighbourlinks}}{{{.}}}{{/html.neighbourlinks}}
|
||||||
</div>
|
</div>
|
||||||
{{#js}}
|
{{#js}}
|
||||||
require(['jquery', 'mod_forum/discussion', 'mod_forum/posts_list', 'mod_forum/lock_toggle', 'mod_forum/favourite_toggle', 'mod_forum/pin_toggle'],
|
require(['jquery', 'mod_forum/discussion', 'mod_forum/posts_list', 'mod_forum/lock_toggle', 'mod_forum/favourite_toggle',
|
||||||
function($, Discussion, PostsList, LockToggle, FavouriteToggle, Pin) {
|
'mod_forum/pin_toggle', 'mod_forum/subscription_toggle'],
|
||||||
|
function($, Discussion, PostsList, LockToggle, FavouriteToggle, Pin, SubscribeToggle) {
|
||||||
var root = $("[data-content='forum-discussion']");
|
var root = $("[data-content='forum-discussion']");
|
||||||
Discussion.init(root);
|
Discussion.init(root);
|
||||||
PostsList.init(root);
|
PostsList.init(root);
|
||||||
|
@ -70,5 +69,6 @@ require(['jquery', 'mod_forum/discussion', 'mod_forum/posts_list', 'mod_forum/lo
|
||||||
LockToggle.init(root);
|
LockToggle.init(root);
|
||||||
FavouriteToggle.init(root);
|
FavouriteToggle.init(root);
|
||||||
Pin.init(root);
|
Pin.init(root);
|
||||||
|
SubscribeToggle.init(root);
|
||||||
});
|
});
|
||||||
{{/js}}
|
{{/js}}
|
|
@ -1,119 +0,0 @@
|
||||||
YUI.add('moodle-mod_forum-subscriptiontoggle', function (Y, NAME) {
|
|
||||||
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
|
||||||
//
|
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Moodle is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A utility to check whether the connection to the Moodle server is still
|
|
||||||
* active.
|
|
||||||
*
|
|
||||||
* @module moodle-core-subscriptiontoggle
|
|
||||||
* @package mod_forum
|
|
||||||
* @copyright 2014 Andrew Nicols <andrew@nicols.co.uk>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
* @main moodle-mod_forum-subscriptiontoggle
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @namespace M.mod_forum
|
|
||||||
* @class subscriptiontoggle
|
|
||||||
*/
|
|
||||||
|
|
||||||
function SubscriptionToggle() {
|
|
||||||
SubscriptionToggle.superclass.constructor.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
var LOGNAME = 'moodle-mod_forum-subscriptiontoggle';
|
|
||||||
|
|
||||||
Y.extend(SubscriptionToggle, Y.Base, {
|
|
||||||
initializer: function() {
|
|
||||||
Y.delegate('click', this._toggleSubscription, Y.config.doc.body, '.discussionsubscription .discussiontoggle', this);
|
|
||||||
},
|
|
||||||
_toggleSubscription: function(e) {
|
|
||||||
var clickedLink = e.currentTarget;
|
|
||||||
|
|
||||||
Y.io(this.get('uri'), {
|
|
||||||
data: {
|
|
||||||
sesskey: M.cfg.sesskey,
|
|
||||||
forumid: clickedLink.getData('forumid'),
|
|
||||||
discussionid: clickedLink.getData('discussionid'),
|
|
||||||
includetext: clickedLink.getData('includetext')
|
|
||||||
},
|
|
||||||
context: this,
|
|
||||||
'arguments': {
|
|
||||||
clickedLink: clickedLink
|
|
||||||
},
|
|
||||||
on: {
|
|
||||||
complete: this._handleCompletion
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Prevent the standard browser behaviour now.
|
|
||||||
e.preventDefault();
|
|
||||||
},
|
|
||||||
|
|
||||||
_handleCompletion: function(tid, response, args) {
|
|
||||||
var responseObject;
|
|
||||||
// Attempt to parse the response into an object.
|
|
||||||
try {
|
|
||||||
responseObject = Y.JSON.parse(response.response);
|
|
||||||
if (responseObject.error) {
|
|
||||||
Y.use('moodle-core-notification-ajaxexception', function() {
|
|
||||||
return new M.core.ajaxException(responseObject);
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Y.use('moodle-core-notification-exception', function() {
|
|
||||||
return new M.core.exception(error);
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!responseObject.icon) {
|
|
||||||
Y.log('No icon received. Skipping the current value replacement', 'warn', LOGNAME);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var container = args.clickedLink.ancestor('.discussionsubscription');
|
|
||||||
if (container) {
|
|
||||||
// We should just receive the new value for the table.
|
|
||||||
// Note: We do not need to escape the HTML here as it should be provided sanitised from the JS response already.
|
|
||||||
container.set('innerHTML', responseObject.icon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
NAME: 'subscriptionToggle',
|
|
||||||
ATTRS: {
|
|
||||||
/**
|
|
||||||
* The AJAX endpoint which controls the subscription toggle.
|
|
||||||
*
|
|
||||||
* @attribute uri
|
|
||||||
* @type String
|
|
||||||
* @default M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
|
|
||||||
*/
|
|
||||||
uri: {
|
|
||||||
value: M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var NS = Y.namespace('M.mod_forum.subscriptiontoggle');
|
|
||||||
NS.init = function(config) {
|
|
||||||
return new SubscriptionToggle(config);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}, '@VERSION@', {"requires": ["base-base", "io-base"]});
|
|
|
@ -1 +0,0 @@
|
||||||
YUI.add("moodle-mod_forum-subscriptiontoggle",function(e,t){function n(){n.superclass.constructor.apply(this,arguments)}var r="moodle-mod_forum-subscriptiontoggle";e.extend(n,e.Base,{initializer:function(){e.delegate("click",this._toggleSubscription,e.config.doc.body,".discussionsubscription .discussiontoggle",this)},_toggleSubscription:function(t){var n=t.currentTarget;e.io(this.get("uri"),{data:{sesskey:M.cfg.sesskey,forumid:n.getData("forumid"),discussionid:n.getData("discussionid"),includetext:n.getData("includetext")},context:this,arguments:{clickedLink:n},on:{complete:this._handleCompletion}}),t.preventDefault()},_handleCompletion:function(t,n,r){var i;try{i=e.JSON.parse(n.response);if(i.error)return e.use("moodle-core-notification-ajaxexception",function(){return new M.core.ajaxException(i)}),this}catch(s){return e.use("moodle-core-notification-exception",function(){return new M.core.exception(s)}),this}if(!i.icon)return;var o=r.clickedLink.ancestor(".discussionsubscription");o&&o.set("innerHTML",i.icon)}},{NAME:"subscriptionToggle",ATTRS:{uri:{value:M.cfg.wwwroot+"/mod/forum/subscribe_ajax.php"}}});var i=e.namespace("M.mod_forum.subscriptiontoggle");i.init=function(e){return new n(e)}},"@VERSION@",{requires:["base-base","io-base"]});
|
|
|
@ -1,118 +0,0 @@
|
||||||
YUI.add('moodle-mod_forum-subscriptiontoggle', function (Y, NAME) {
|
|
||||||
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
|
||||||
//
|
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Moodle is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A utility to check whether the connection to the Moodle server is still
|
|
||||||
* active.
|
|
||||||
*
|
|
||||||
* @module moodle-core-subscriptiontoggle
|
|
||||||
* @package mod_forum
|
|
||||||
* @copyright 2014 Andrew Nicols <andrew@nicols.co.uk>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
* @main moodle-mod_forum-subscriptiontoggle
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @namespace M.mod_forum
|
|
||||||
* @class subscriptiontoggle
|
|
||||||
*/
|
|
||||||
|
|
||||||
function SubscriptionToggle() {
|
|
||||||
SubscriptionToggle.superclass.constructor.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
var LOGNAME = 'moodle-mod_forum-subscriptiontoggle';
|
|
||||||
|
|
||||||
Y.extend(SubscriptionToggle, Y.Base, {
|
|
||||||
initializer: function() {
|
|
||||||
Y.delegate('click', this._toggleSubscription, Y.config.doc.body, '.discussionsubscription .discussiontoggle', this);
|
|
||||||
},
|
|
||||||
_toggleSubscription: function(e) {
|
|
||||||
var clickedLink = e.currentTarget;
|
|
||||||
|
|
||||||
Y.io(this.get('uri'), {
|
|
||||||
data: {
|
|
||||||
sesskey: M.cfg.sesskey,
|
|
||||||
forumid: clickedLink.getData('forumid'),
|
|
||||||
discussionid: clickedLink.getData('discussionid'),
|
|
||||||
includetext: clickedLink.getData('includetext')
|
|
||||||
},
|
|
||||||
context: this,
|
|
||||||
'arguments': {
|
|
||||||
clickedLink: clickedLink
|
|
||||||
},
|
|
||||||
on: {
|
|
||||||
complete: this._handleCompletion
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Prevent the standard browser behaviour now.
|
|
||||||
e.preventDefault();
|
|
||||||
},
|
|
||||||
|
|
||||||
_handleCompletion: function(tid, response, args) {
|
|
||||||
var responseObject;
|
|
||||||
// Attempt to parse the response into an object.
|
|
||||||
try {
|
|
||||||
responseObject = Y.JSON.parse(response.response);
|
|
||||||
if (responseObject.error) {
|
|
||||||
Y.use('moodle-core-notification-ajaxexception', function() {
|
|
||||||
return new M.core.ajaxException(responseObject);
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Y.use('moodle-core-notification-exception', function() {
|
|
||||||
return new M.core.exception(error);
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!responseObject.icon) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var container = args.clickedLink.ancestor('.discussionsubscription');
|
|
||||||
if (container) {
|
|
||||||
// We should just receive the new value for the table.
|
|
||||||
// Note: We do not need to escape the HTML here as it should be provided sanitised from the JS response already.
|
|
||||||
container.set('innerHTML', responseObject.icon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
NAME: 'subscriptionToggle',
|
|
||||||
ATTRS: {
|
|
||||||
/**
|
|
||||||
* The AJAX endpoint which controls the subscription toggle.
|
|
||||||
*
|
|
||||||
* @attribute uri
|
|
||||||
* @type String
|
|
||||||
* @default M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
|
|
||||||
*/
|
|
||||||
uri: {
|
|
||||||
value: M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var NS = Y.namespace('M.mod_forum.subscriptiontoggle');
|
|
||||||
NS.init = function(config) {
|
|
||||||
return new SubscriptionToggle(config);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}, '@VERSION@', {"requires": ["base-base", "io-base"]});
|
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"name": "moodle-mod_forum-subscriptiontoggle",
|
|
||||||
"builds": {
|
|
||||||
"moodle-mod_forum-subscriptiontoggle": {
|
|
||||||
"jsfiles": [
|
|
||||||
"toggle.js"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
114
mod/forum/yui/src/subscriptiontoggle/js/toggle.js
vendored
114
mod/forum/yui/src/subscriptiontoggle/js/toggle.js
vendored
|
@ -1,114 +0,0 @@
|
||||||
// This file is part of Moodle - http://moodle.org/
|
|
||||||
//
|
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Moodle is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A utility to check whether the connection to the Moodle server is still
|
|
||||||
* active.
|
|
||||||
*
|
|
||||||
* @module moodle-core-subscriptiontoggle
|
|
||||||
* @package mod_forum
|
|
||||||
* @copyright 2014 Andrew Nicols <andrew@nicols.co.uk>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
* @main moodle-mod_forum-subscriptiontoggle
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @namespace M.mod_forum
|
|
||||||
* @class subscriptiontoggle
|
|
||||||
*/
|
|
||||||
|
|
||||||
function SubscriptionToggle() {
|
|
||||||
SubscriptionToggle.superclass.constructor.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
var LOGNAME = 'moodle-mod_forum-subscriptiontoggle';
|
|
||||||
|
|
||||||
Y.extend(SubscriptionToggle, Y.Base, {
|
|
||||||
initializer: function() {
|
|
||||||
Y.delegate('click', this._toggleSubscription, Y.config.doc.body, '.discussionsubscription .discussiontoggle', this);
|
|
||||||
},
|
|
||||||
_toggleSubscription: function(e) {
|
|
||||||
var clickedLink = e.currentTarget;
|
|
||||||
|
|
||||||
Y.io(this.get('uri'), {
|
|
||||||
data: {
|
|
||||||
sesskey: M.cfg.sesskey,
|
|
||||||
forumid: clickedLink.getData('forumid'),
|
|
||||||
discussionid: clickedLink.getData('discussionid'),
|
|
||||||
includetext: clickedLink.getData('includetext')
|
|
||||||
},
|
|
||||||
context: this,
|
|
||||||
'arguments': {
|
|
||||||
clickedLink: clickedLink
|
|
||||||
},
|
|
||||||
on: {
|
|
||||||
complete: this._handleCompletion
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Prevent the standard browser behaviour now.
|
|
||||||
e.preventDefault();
|
|
||||||
},
|
|
||||||
|
|
||||||
_handleCompletion: function(tid, response, args) {
|
|
||||||
var responseObject;
|
|
||||||
// Attempt to parse the response into an object.
|
|
||||||
try {
|
|
||||||
responseObject = Y.JSON.parse(response.response);
|
|
||||||
if (responseObject.error) {
|
|
||||||
Y.use('moodle-core-notification-ajaxexception', function() {
|
|
||||||
return new M.core.ajaxException(responseObject);
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Y.use('moodle-core-notification-exception', function() {
|
|
||||||
return new M.core.exception(error);
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!responseObject.icon) {
|
|
||||||
Y.log('No icon received. Skipping the current value replacement', 'warn', LOGNAME);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var container = args.clickedLink.ancestor('.discussionsubscription');
|
|
||||||
if (container) {
|
|
||||||
// We should just receive the new value for the table.
|
|
||||||
// Note: We do not need to escape the HTML here as it should be provided sanitised from the JS response already.
|
|
||||||
container.set('innerHTML', responseObject.icon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
NAME: 'subscriptionToggle',
|
|
||||||
ATTRS: {
|
|
||||||
/**
|
|
||||||
* The AJAX endpoint which controls the subscription toggle.
|
|
||||||
*
|
|
||||||
* @attribute uri
|
|
||||||
* @type String
|
|
||||||
* @default M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
|
|
||||||
*/
|
|
||||||
uri: {
|
|
||||||
value: M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var NS = Y.namespace('M.mod_forum.subscriptiontoggle');
|
|
||||||
NS.init = function(config) {
|
|
||||||
return new SubscriptionToggle(config);
|
|
||||||
};
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"moodle-mod_forum-subscriptiontoggle": {
|
|
||||||
"requires": [
|
|
||||||
"base-base",
|
|
||||||
"io-base"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue