Skip to content

Commit 7b56bc5

Browse files
committed
Merge pull request #257 from dpalou/MOBILE-1271
MOBILE-1271 forum: Set default reply subject
2 parents 6ff116e + 8825fe7 commit 7b56bc5

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

www/addons/mod_forum/controllers/discussion.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ angular.module('mm.addons.mod_forum')
2121
* @ngdoc controller
2222
* @name mmaModForumDiscussionCtrl
2323
*/
24-
.controller('mmaModForumDiscussionCtrl', function($q, $scope, $stateParams, $mmaModForum, $mmSite, $mmUtil, $ionicScrollDelegate,
25-
mmaModForumComponent) {
24+
.controller('mmaModForumDiscussionCtrl', function($q, $scope, $stateParams, $mmaModForum, $mmSite, $mmUtil, $translate,
25+
$ionicScrollDelegate, mmaModForumComponent) {
2626

2727
var discussionid = $stateParams.discussionid,
2828
courseid = $stateParams.courseid,
29-
scrollView = $ionicScrollDelegate.$getByHandle('mmaModForumPostsScroll');
29+
scrollView;
3030

3131
$scope.component = mmaModForumComponent;
3232
$scope.courseid = courseid;
@@ -41,6 +41,12 @@ angular.module('mm.addons.mod_forum')
4141
return $mmaModForum.getDiscussionPosts(discussionid).then(function(posts) {
4242
$scope.discussion = $mmaModForum.extractStartingPost(posts);
4343
$scope.posts = posts;
44+
45+
// Set default reply subject.
46+
return $translate('mma.mod_forum.re').then(function(strReplyPrefix) {
47+
$scope.defaultSubject = strReplyPrefix + ' ' + $scope.discussion.subject;
48+
$scope.newpost.subject = $scope.defaultSubject;
49+
});
4450
}, function(message) {
4551
$mmUtil.showErrorModal(message);
4652
return $q.reject();
@@ -72,10 +78,13 @@ angular.module('mm.addons.mod_forum')
7278

7379
// New post added.
7480
$scope.newPostAdded = function() {
75-
scrollView.scrollTop();
81+
if (!scrollView) {
82+
scrollView = $ionicScrollDelegate.$getByHandle('mmaModForumPostsScroll');
83+
}
84+
scrollView && scrollView.scrollTop && scrollView.scrollTop();
7685

7786
$scope.newpost.replyingto = undefined;
78-
$scope.newpost.subject = '';
87+
$scope.newpost.subject = $scope.defaultSubject;
7988
$scope.newpost.message = '';
8089

8190
$scope.discussionLoaded = false;

www/addons/mod_forum/directives/discussionpost.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ angular.module('mm.addons.mod_forum')
2020
* @module mm.addons.mod_forum
2121
* @ngdoc directive
2222
* @name mmaForumDiscussionPost
23+
* @description
24+
* This directive will show a forum post if the right data is supplied. Attributes:
25+
*
26+
* @param {Object} post Post.
27+
* @param {Number} courseid Post's course ID.
28+
* @param {String} title Post's title.
29+
* @param {String} subject Post's subject.
30+
* @param {String} component Component this post belong to.
31+
* @param {Object} newpost Object with the new post data. Usually shared between posts.
32+
* @param {Boolean} showdivider True if it should have a list divider before the post.
33+
* @param {Boolean} titleimportant True if title should be "important" (bold).
34+
* @oaram {Function} [postadded] Function to call when a new post is added.
35+
* @param {String} [defaultsubject] Default subject to set to new posts.
2336
*/
2437
.directive('mmaModForumDiscussionPost', function($mmaModForum, $mmUtil, $translate, $q) {
2538
return {
@@ -33,7 +46,8 @@ angular.module('mm.addons.mod_forum')
3346
newpost: '=',
3447
showdivider: '=?',
3548
titleimportant: '=?',
36-
postadded: '&?'
49+
postadded: '&?',
50+
defaultsubject: '=?'
3751
},
3852
templateUrl: 'addons/mod_forum/templates/discussionpost.html',
3953
transclude: true,
@@ -85,7 +99,7 @@ angular.module('mm.addons.mod_forum')
8599

86100
promise.then(function() {
87101
scope.newpost.replyingto = undefined;
88-
scope.newpost.subject = '';
102+
scope.newpost.subject = scope.defaultsubject || '';
89103
scope.newpost.message = '';
90104
});
91105
};

www/addons/mod_forum/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"numdiscussions": "{{numdiscussions}} discussions",
1616
"numreplies": "{{numreplies}} replies",
1717
"posttoforum": "Post to forum",
18+
"re": "Re:",
1819
"reply": "Reply",
1920
"subject": "Subject"
2021
}

www/addons/mod_forum/templates/discussion.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
</ion-refresher>
77
<mm-loading hide-until="discussionLoaded">
88
<article class="card" ng-if="discussion">
9-
<mma-mod-forum-discussion-post post="discussion" courseid="courseid" title="discussion.subject" subject="discussion.userfullname" component="component" newpost="newpost" replyingto="replyingto" showdivider="false" titleimportant="true" postadded="newPostAdded()"></mma-mod-forum-discussion-post>
9+
<mma-mod-forum-discussion-post post="discussion" courseid="courseid" title="discussion.subject" subject="discussion.userfullname" component="component" newpost="newpost" replyingto="replyingto" showdivider="false" titleimportant="true" postadded="newPostAdded()" defaultsubject="defaultSubject"></mma-mod-forum-discussion-post>
1010
</article>
1111
<div class="card" ng-if="posts && posts.length">
1212
<article ng-repeat="post in posts track by $index">
13-
<mma-mod-forum-discussion-post post="post" courseid="courseid" title="post.userfullname" subject="post.subject" component="component" newpost="newpost" replyingto="replyingto" showdivider="$index > 0" titleimportant="false" postadded="newPostAdded()"></mma-mod-forum-discussion-post>
13+
<mma-mod-forum-discussion-post post="post" courseid="courseid" title="post.userfullname" subject="post.subject" component="component" newpost="newpost" replyingto="replyingto" showdivider="$index > 0" titleimportant="false" postadded="newPostAdded()" defaultsubject="defaultSubject"></mma-mod-forum-discussion-post>
1414
</article>
1515
</div>
1616
</mm-loading>

0 commit comments

Comments
 (0)