Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions www/addons/mod_forum/controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ angular.module('mm.addons.mod_forum')
* @ngdoc controller
* @name mmaModForumDiscussionCtrl
*/
.controller('mmaModForumDiscussionCtrl', function($q, $scope, $stateParams, $mmaModForum, $mmSite, $mmUtil, $ionicScrollDelegate,
mmaModForumComponent) {
.controller('mmaModForumDiscussionCtrl', function($q, $scope, $stateParams, $mmaModForum, $mmSite, $mmUtil, $translate,
$ionicScrollDelegate, mmaModForumComponent) {

var discussionid = $stateParams.discussionid,
courseid = $stateParams.courseid,
scrollView = $ionicScrollDelegate.$getByHandle('mmaModForumPostsScroll');
scrollView;

$scope.component = mmaModForumComponent;
$scope.courseid = courseid;
Expand All @@ -41,6 +41,12 @@ angular.module('mm.addons.mod_forum')
return $mmaModForum.getDiscussionPosts(discussionid).then(function(posts) {
$scope.discussion = $mmaModForum.extractStartingPost(posts);
$scope.posts = posts;

// Set default reply subject.
return $translate('mma.mod_forum.re').then(function(strReplyPrefix) {
$scope.defaultSubject = strReplyPrefix + ' ' + $scope.discussion.subject;
$scope.newpost.subject = $scope.defaultSubject;
});
}, function(message) {
$mmUtil.showErrorModal(message);
return $q.reject();
Expand Down Expand Up @@ -72,10 +78,13 @@ angular.module('mm.addons.mod_forum')

// New post added.
$scope.newPostAdded = function() {
scrollView.scrollTop();
if (!scrollView) {
scrollView = $ionicScrollDelegate.$getByHandle('mmaModForumPostsScroll');
}
scrollView && scrollView.scrollTop && scrollView.scrollTop();

$scope.newpost.replyingto = undefined;
$scope.newpost.subject = '';
$scope.newpost.subject = $scope.defaultSubject;
$scope.newpost.message = '';

$scope.discussionLoaded = false;
Expand Down
18 changes: 16 additions & 2 deletions www/addons/mod_forum/directives/discussionpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ angular.module('mm.addons.mod_forum')
* @module mm.addons.mod_forum
* @ngdoc directive
* @name mmaForumDiscussionPost
* @description
* This directive will show a forum post if the right data is supplied. Attributes:
*
* @param {Object} post Post.
* @param {Number} courseid Post's course ID.
* @param {String} title Post's title.
* @param {String} subject Post's subject.
* @param {String} component Component this post belong to.
* @param {Object} newpost Object with the new post data. Usually shared between posts.
* @param {Boolean} showdivider True if it should have a list divider before the post.
* @param {Boolean} titleimportant True if title should be "important" (bold).
* @oaram {Function} [postadded] Function to call when a new post is added.
* @param {String} [defaultsubject] Default subject to set to new posts.
*/
.directive('mmaModForumDiscussionPost', function($mmaModForum, $mmUtil, $translate, $q) {
return {
Expand All @@ -33,7 +46,8 @@ angular.module('mm.addons.mod_forum')
newpost: '=',
showdivider: '=?',
titleimportant: '=?',
postadded: '&?'
postadded: '&?',
defaultsubject: '=?'
},
templateUrl: 'addons/mod_forum/templates/discussionpost.html',
transclude: true,
Expand Down Expand Up @@ -85,7 +99,7 @@ angular.module('mm.addons.mod_forum')

promise.then(function() {
scope.newpost.replyingto = undefined;
scope.newpost.subject = '';
scope.newpost.subject = scope.defaultsubject || '';
scope.newpost.message = '';
});
};
Expand Down
1 change: 1 addition & 0 deletions www/addons/mod_forum/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"numdiscussions": "{{numdiscussions}} discussions",
"numreplies": "{{numreplies}} replies",
"posttoforum": "Post to forum",
"re": "Re:",
"reply": "Reply",
"subject": "Subject"
}
4 changes: 2 additions & 2 deletions www/addons/mod_forum/templates/discussion.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
</ion-refresher>
<mm-loading hide-until="discussionLoaded">
<article class="card" ng-if="discussion">
<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>
<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>
</article>
<div class="card" ng-if="posts && posts.length">
<article ng-repeat="post in posts track by $index">
<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>
<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>
</article>
</div>
</mm-loading>
Expand Down