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
4 changes: 2 additions & 2 deletions www/addons/messages/controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ angular.module('mm.addons.messages')
.controller('mmaMessagesDiscussionCtrl', function($scope, $stateParams, $mmApp, $mmaMessages, $mmSite, $timeout, $mmEvents, $window,
$ionicScrollDelegate, mmUserProfileState, $mmUtil, mmaMessagesPollInterval, $interval, $log, $ionicHistory, $ionicPlatform,
mmCoreEventKeyboardShow, mmCoreEventKeyboardHide, mmaMessagesDiscussionLoadedEvent, mmaMessagesDiscussionLeftEvent,
$mmUser, $translate, mmaMessagesNewMessageEvent, mmaMessagesAutomSyncedEvent, $mmaMessagesSync, $q, md5,
$mmUser, $translate, mmaMessagesNewMessageEvent, mmaMessagesAutomSyncedEvent, $mmaMessagesSync, $q, md5, $mmText,
mmaMessagesReadChangedEvent) {

$log = $log.getInstance('mmaMessagesDiscussionCtrl');
Expand Down Expand Up @@ -107,7 +107,7 @@ angular.module('mm.addons.messages')
$scope.data.showDelete = false;
$scope.newMessage = ''; // Clear new message.

text = text.replace(/(?:\r\n|\r|\n)/g, '<br />');
text = $mmText.replaceNewLines(text, '<br>');
message = {
pending: true,
sending: true,
Expand Down
4 changes: 2 additions & 2 deletions www/addons/messages/filters/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ angular.module('mm.addons.messages')
.filter('mmaMessagesFormat', function($mmText) {
return function(text) {
text = text.replace(/-{4,}/ig, '');
text = text.replace(/<br \/><br \/>/ig, "<br />");
text = $mmText.replaceNewLines(text, '<br />');
text = text.replace(/<br \/><br \/>/ig, "<br>");
text = $mmText.replaceNewLines(text, '<br>');
return text;
};
});
11 changes: 9 additions & 2 deletions www/addons/mod/assign/feedback/comments/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('mm.addons.mod_assign')
* @ngdoc service
* @name $mmaModAssignFeedbackCommentsHandler
*/
.factory('$mmaModAssignFeedbackCommentsHandler', function($mmText, $mmSite) {
.factory('$mmaModAssignFeedbackCommentsHandler', function($mmText, $mmSite, $mmUtil) {

var self = {},
drafts = {};
Expand Down Expand Up @@ -66,7 +66,14 @@ angular.module('mm.addons.mod_assign')
self.prepareFeedbackData = function(assignId, userId, pluginData, siteId) {
var draft = self.getDraft(assignId, userId, siteId);
if (draft) {
pluginData.assignfeedbackcomments_editor = draft;
return $mmUtil.isRichTextEditorEnabled().then(function(enabled) {
if (!enabled) {
// Rich text editor not enabled, add some HTML to the text if needed.
draft.text = $mmText.formatHtmlLines(draft.text);
}

pluginData.assignfeedbackcomments_editor = draft;
});
}
};

Expand Down
20 changes: 14 additions & 6 deletions www/addons/mod/assign/submission/onlinetext/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ angular.module('mm.addons.mod_assign')
* @name $mmaModAssignSubmissionOnlinetextHandler
*/
.factory('$mmaModAssignSubmissionOnlinetextHandler', function($mmSite, $mmaModAssign, $q, $mmaModAssignHelper, $mmWS, $mmText,
$mmaModAssignOffline) {
$mmaModAssignOffline, $mmUtil) {

var self = {};

Expand Down Expand Up @@ -166,11 +166,19 @@ angular.module('mm.addons.mod_assign')
* @return {Void}
*/
self.prepareSubmissionData = function(assign, submission, plugin, inputData, pluginData, offline, userId, siteId) {
pluginData.onlinetext_editor = {
text: getTextToSubmit(plugin, inputData),
format: 1,
itemid: 0 // Can't add new files yet, so we use a fake itemid.
};
return $mmUtil.isRichTextEditorEnabled().then(function(enabled) {
var text = getTextToSubmit(plugin, inputData);
if (!enabled) {
// Rich text editor not enabled, add some HTML to the text if needed.
text = $mmText.formatHtmlLines(text);
}

pluginData.onlinetext_editor = {
text: text,
format: 1,
itemid: 0 // Can't add new files yet, so we use a fake itemid.
};
});
};

/**
Expand Down
6 changes: 3 additions & 3 deletions www/addons/mod/assign/templates/submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h2>{{ 'mma.mod_assign.submissionstatus' | translate }}</h2>
<div ng-show="showSubmission">
<mma-mod-assign-submission-plugin ng-repeat="plugin in submissionPlugins" assign="assign" submission="userSubmission" plugin="plugin" scroll-handle="{{scrollHandle}}"></mma-mod-assign-submission-plugin>

<div ng-if="userSubmission && userSubmission.status != statusNew" class="item item-text-wrap">
<div ng-if="userSubmission && userSubmission.status != statusNew && userSubmission.timemodified" class="item item-text-wrap">
<h2>{{ 'mma.mod_assign.timemodified' | translate }}</h2>
<p>{{ userSubmission.timemodified * 1000 | mmFormatDate:"dfmediumdate" }}</p>
</div>
Expand Down Expand Up @@ -90,12 +90,12 @@ <h2>{{ 'mma.mod_assign.attemptnumber' | translate }}</h2>
<!-- If has offline data, show edit. -->
<a ng-if="hasOffline" class="button button-block" ng-click="goToEdit()">{{ 'mma.mod_assign.editsubmission' | translate }}</a>
<!-- If no submission or is new, show add submission. -->
<a ng-if="!hasOffline && (!userSubmission || userSubmission.status == statusNew)" class="button button-block" ng-click="goToEdit()">{{ 'mma.mod_assign.addsubmission' | translate }}</a>
<a ng-if="!hasOffline && (!userSubmission || !userSubmission.status || userSubmission.status == statusNew)" class="button button-block" ng-click="goToEdit()">{{ 'mma.mod_assign.addsubmission' | translate }}</a>
<!-- If reopened, show addfromprevious and addnewattempt. -->
<a ng-if="!hasOffline && userSubmission && userSubmission.status == statusReopened" class="button button-block" ng-click="copyPrevious()">{{ 'mma.mod_assign.addnewattemptfromprevious' | translate }}</a>
<a ng-if="userSubmission && userSubmission.status == statusReopened" class="button button-block" ng-click="goToEdit()">{{ 'mma.mod_assign.addnewattempt' | translate }}</a>
<!-- Else show editsubmission. -->
<a ng-if="!hasOffline && userSubmission && userSubmission.status != statusNew && userSubmission.status != statusReopened" class="button button-block" ng-click="goToEdit()">{{ 'mma.mod_assign.editsubmission' | translate }}</a>
<a ng-if="!hasOffline && userSubmission && userSubmission.status && userSubmission.status != statusNew && userSubmission.status != statusReopened" class="button button-block" ng-click="goToEdit()">{{ 'mma.mod_assign.editsubmission' | translate }}</a>
</div>
<div ng-if="unsupportedEditPlugins && unsupportedEditPlugins.length && !showErrorStatementEdit">
<p class="mma-mod-assign-warning">{{ 'mma.mod_assign.erroreditpluginsnotsupported' | translate }}</p>
Expand Down
4 changes: 2 additions & 2 deletions www/addons/mod/chat/controllers/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ angular.module('mm.addons.mod_chat')
* @name mmaModChatChatCtrl
*/
.controller('mmaModChatChatCtrl', function($scope, $stateParams, $mmApp, $mmaModChat, $log, $ionicModal, $mmUtil, $ionicHistory,
$ionicScrollDelegate, $timeout, $mmSite, $interval, mmaChatPollInterval, $q) {
$ionicScrollDelegate, $timeout, $mmSite, $interval, mmaChatPollInterval, $q, $mmText) {

$log = $log.getInstance('mmaModChatChatCtrl');

Expand Down Expand Up @@ -173,7 +173,7 @@ angular.module('mm.addons.mod_chat')
// Silent error.
return;
}
text = text.replace(/(?:\r\n|\r|\n)/g, '<br />');
text = $mmText.replaceNewLines(text, '<br>');

$mmaModChat.sendMessage($scope.chatsid, text, beep).then(function() {
if (beep === '') {
Expand Down
3 changes: 2 additions & 1 deletion www/addons/mod/forum/controllers/discussions.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ angular.module('mm.addons.mod_forum')

// Refresh data if this forum discussion is synchronized from discussions list.
syncManualObserver = $mmEvents.on(mmaModForumManualSyncedEvent, function(data) {
if (data && data.siteid == $mmSite.getId() && data.forumid == forum.id && data.userid == $mmSite.getUserId()) {
if (forum && data && data.siteid == $mmSite.getId() && data.forumid == forum.id && data.userid == $mmSite.getUserId()) {
// Refresh the data.
$scope.discussionsLoaded = false;
return showSpinnerAndFetch(false);
Expand All @@ -360,6 +360,7 @@ angular.module('mm.addons.mod_forum')
obsNewDisc && obsNewDisc.off && obsNewDisc.off();
obsReply && obsReply.off && obsReply.off();
syncObserver && syncObserver.off && syncObserver.off();
syncManualObserver && syncManualObserver.off && syncManualObserver.off();
onlineObserver && onlineObserver.off && onlineObserver.off();
});
});
2 changes: 1 addition & 1 deletion www/addons/mod/forum/directives/discussionpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ angular.module('mm.addons.mod_forum')
$mmUtil.isRichTextEditorEnabled().then(function(enabled) {
if (!enabled) {
// Rich text editor not enabled, add some HTML to the message if needed.
message = message = $mmText.formatHtmlLines(message);
message = $mmText.formatHtmlLines(message);
}

// Upload attachments first if any.
Expand Down
6 changes: 3 additions & 3 deletions www/addons/mod/scorm/services/scorm_offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,15 @@ angular.module('mm.addons.mod_scorm')
return $mmSitesManager.getSite(siteId).then(function(site) {
userId = userId || site.getUserId();

var fileName, where;
var fieldName, where;

if (excludeSynced && excludeNotSynced) {
return $q.when([]);
} else if (excludeSynced || excludeNotSynced) {
fileName = 'scormUserAttemptSynced';
fieldName = 'scormUserAttemptSynced';
where = [scormId, userId, attempt, excludeNotSynced ? 1 : 0];
} else {
fileName = 'scormUserAttempt';
fieldName = 'scormUserAttempt';
where = [scormId, userId, attempt];
}
return site.getDb().whereEqual(mmaModScormOfflineTracksStore, fieldName, where);
Expand Down
2 changes: 2 additions & 0 deletions www/addons/mod/wiki/controllers/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ angular.module('mm.addons.mod_wiki')

if (rteEnabled) {
text = $mmText.restorePluginfileUrls(text, subwikiFiles);
} else {
text = $mmText.formatHtmlLines(text);
}

if (editing) {
Expand Down
2 changes: 1 addition & 1 deletion www/addons/notifications/filters/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ angular.module('mm.addons.notifications')
.filter('mmaNotificationsFormat', function($mmText) {
return function(text) {
text = text.replace(/-{4,}/ig, '');
text = $mmText.replaceNewLines(text, '<br />');
text = $mmText.replaceNewLines(text, '<br>');
return text;
};
});
28 changes: 18 additions & 10 deletions www/addons/userprofilefield/textarea/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('mm.addons.userprofilefield_textarea')
* @ngdoc service
* @name $mmaUserProfileFieldTextareaHandler
*/
.factory('$mmaUserProfileFieldTextareaHandler', function() {
.factory('$mmaUserProfileFieldTextareaHandler', function($mmUtil, $mmText) {

var self = {};

Expand All @@ -41,20 +41,28 @@ angular.module('mm.addons.userprofilefield_textarea')
* @param {Boolean} signup True if user is in signup page.
* @param {String} [registerAuth] Register auth method. E.g. 'email'.
* @param {Object} model Model with the input data.
* @return {Object} Data to send for the field.
* @return {Promise} Promise resolved with data to send for the field.
*/
self.getData = function(field, signup, registerAuth, model) {
var name = 'profile_field_' + field.shortname;

if (model[name]) {
return {
type: 'textarea',
name: name,
value: JSON.stringify({
text: model[name].text || '',
format: model[name].format || 1
})
};
return $mmUtil.isRichTextEditorEnabled().then(function(enabled) {
var text = model[name].text || '';
if (!enabled) {
// Rich text editor not enabled, add some HTML to the message if needed.
text = $mmText.formatHtmlLines(text);
}

return {
type: 'textarea',
name: name,
value: JSON.stringify({
text: text,
format: model[name].format || 1
})
};
});
}
};

Expand Down
4 changes: 2 additions & 2 deletions www/core/components/grades/services/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ angular.module('mm.core.grades')
img = getImgHTML(content);
content = content.replace(/<\/span>/gi, "\n");
content = $mmText.cleanTags(content);
content = content.replace("\n", "<br />");
content = $mmText.replaceNewLines(content, '<br>');
content = img + " " + content;

row.text += "<" + celltype + " " + id + " " + headers + " " + "class='"+ tclass +"' " + colspan +">";
Expand Down Expand Up @@ -208,7 +208,7 @@ angular.module('mm.core.grades')
content = $mmText.cleanTags(content);
content = img + " " + content;
} else {
content = content.replace("\n", "<br />");
content = $mmText.replaceNewLines(content, '<br>');
}

if (content == '&nbsp;') {
Expand Down
4 changes: 2 additions & 2 deletions www/core/components/textviewer/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ angular.module('mm.core.textviewer')
* @ngdoc controller
* @name mmTextViewerIndexCtrl
*/
.controller('mmTextViewerIndexCtrl', function($stateParams, $scope) {
.controller('mmTextViewerIndexCtrl', function($stateParams, $scope, $mmText) {
$scope.title = $stateParams.title;

if ($stateParams.replacelinebreaks) {
$scope.content = $stateParams.content.replace(/(?:\r\n|\r|\n)/g, '<br />');
$scope.content = $mmText.replaceNewLines($stateParams.content, '<br>');
} else {
$scope.content = $stateParams.content;
}
Expand Down
4 changes: 2 additions & 2 deletions www/core/lib/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ angular.module('mm.core')
// Then, we rely on the browser. We need to wrap the text to be sure is HTML.
text = angular.element('<p>').html(text).text(); // Get directive's content.
// Recover or remove new lines.
text = self.replaceNewLines(text, singleLine ? ' ' : '<br />');
text = self.replaceNewLines(text, singleLine ? ' ' : '<br>');
return text;
};

Expand Down Expand Up @@ -155,7 +155,7 @@ angular.module('mm.core')
// Wrap the text in <p> tags.
text = '<p>' + text + '</p>';
}
return text.replace(/\n/g, '<br>');
return self.replaceNewLines(text, '<br>');
};

/**
Expand Down