MDL-65635 forum: add_discussion_post() format support changes
[moodle.git] / mod / forum / amd / src / repository.js
CommitLineData
2646e9d6
RW
1// This file is part of Moodle - http://moodle.org/
2//
3// Moodle is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// Moodle is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15
16/**
c475fe41 17 * Forum repository class to encapsulate all of the AJAX requests that subscribe or unsubscribe
2646e9d6
RW
18 * can be sent for forum.
19 *
20 * @module mod_forum/repository
21 * @package mod_forum
22 * @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25define(['core/ajax'], function(Ajax) {
26 /**
27 * Set the subscription state for a discussion in a forum.
28 *
29 * @param {number} forumId ID of the forum the discussion belongs to
30 * @param {number} discussionId ID of the discussion with the subscription state
31 * @param {boolean} targetState Set the subscribed state. True == subscribed; false == unsubscribed.
32 * @return {object} jQuery promise
33 */
34 var setDiscussionSubscriptionState = function(forumId, discussionId, targetState) {
35 var request = {
36 methodname: 'mod_forum_set_subscription_state',
37 args: {
38 forumid: forumId,
39 discussionid: discussionId,
40 targetstate: targetState
41 }
42 };
43 return Ajax.call([request])[0];
44 };
45
cee572aa 46 var addDiscussionPost = function(postid, subject, message, isprivatereply) {
9b4f09ba
P
47 var request = {
48 methodname: 'mod_forum_add_discussion_post',
49 args: {
50 postid: postid,
51 message: message,
cee572aa
P
52 subject: subject,
53 options: [{
54 name: "private",
55 value: isprivatereply,
56 }]
9b4f09ba
P
57 }
58 };
99bda8a7
P
59 return Ajax.call([request])[0];
60 };
9b4f09ba 61
99bda8a7
P
62 /**
63 * Set the favourite state for a discussion in a forum.
64 *
65 * @param {number} forumId ID of the forum the discussion belongs to
66 * @param {number} discussionId ID of the discussion with the subscription state
8885cd57 67 * @param {null|date} targetState Set the favourite state. True == favourited; false == unfavourited.
99bda8a7
P
68 * @return {object} jQuery promise
69 */
8885cd57 70 var setFavouriteDiscussionState = function(forumId, discussionId, targetState) {
99bda8a7
P
71 var request = {
72 methodname: 'mod_forum_toggle_favourite_state',
73 args: {
99bda8a7
P
74 discussionid: discussionId,
75 targetstate: targetState
76 }
77 };
9b4f09ba
P
78 return Ajax.call([request])[0];
79 };
80
2893812e
P
81 var setDiscussionLockState = function(forumId, discussionId, targetState) {
82 var request = {
83 methodname: 'mod_forum_set_lock_state',
84 args: {
85 forumid: forumId,
86 discussionid: discussionId,
25a97f99 87 targetstate: targetState}
88 };
89 return Ajax.call([request])[0];
90 };
91
8885cd57
P
92 /**
93 * Set the pinned state for the discussion provided.
94 *
95 * @param {number} forumid
96 * @param {number} discussionid
97 * @param {boolean} targetstate
8885cd57
P
98 * @return {*|Promise}
99 */
100 var setPinDiscussionState = function(forumid, discussionid, targetstate) {
25a97f99 101 var request = {
102 methodname: 'mod_forum_set_pin_state',
103 args: {
25a97f99 104 discussionid: discussionid,
8885cd57 105 targetstate: targetstate
2893812e
P
106 }
107 };
108 return Ajax.call([request])[0];
109 };
110
2646e9d6
RW
111 return {
112 setDiscussionSubscriptionState: setDiscussionSubscriptionState,
2893812e 113 addDiscussionPost: addDiscussionPost,
99bda8a7 114 setDiscussionLockState: setDiscussionLockState,
8885cd57
P
115 setFavouriteDiscussionState: setFavouriteDiscussionState,
116 setPinDiscussionState: setPinDiscussionState
2646e9d6
RW
117 };
118});