From 5011132bf5aed9b71ed053771e34622c435a56d4 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 24 Feb 2017 15:37:13 +0100 Subject: [PATCH 1/4] MOBILE-1987 text: Format HTML if RTE disabled --- www/addons/messages/controllers/discussion.js | 4 +-- www/addons/messages/filters/format.js | 4 +-- .../mod/assign/feedback/comments/handlers.js | 11 ++++++-- .../assign/submission/onlinetext/handlers.js | 20 +++++++++---- www/addons/mod/chat/controllers/chat.js | 4 +-- .../mod/forum/directives/discussionpost.js | 2 +- www/addons/mod/wiki/controllers/edit.js | 2 ++ www/addons/notifications/filters/format.js | 2 +- .../userprofilefield/textarea/handlers.js | 28 ++++++++++++------- www/core/components/grades/services/helper.js | 4 +-- .../textviewer/controllers/index.js | 4 +-- www/core/lib/text.js | 4 +-- 12 files changed, 57 insertions(+), 32 deletions(-) diff --git a/www/addons/messages/controllers/discussion.js b/www/addons/messages/controllers/discussion.js index 4064ca2a891..6a9d579cb08 100644 --- a/www/addons/messages/controllers/discussion.js +++ b/www/addons/messages/controllers/discussion.js @@ -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'); @@ -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, '
'); + text = $mmText.replaceNewLines(text, '
'); message = { pending: true, sending: true, diff --git a/www/addons/messages/filters/format.js b/www/addons/messages/filters/format.js index d4eb905462a..7daa7613e39 100644 --- a/www/addons/messages/filters/format.js +++ b/www/addons/messages/filters/format.js @@ -24,8 +24,8 @@ angular.module('mm.addons.messages') .filter('mmaMessagesFormat', function($mmText) { return function(text) { text = text.replace(/-{4,}/ig, ''); - text = text.replace(/

/ig, "
"); - text = $mmText.replaceNewLines(text, '
'); + text = text.replace(/

/ig, "
"); + text = $mmText.replaceNewLines(text, '
'); return text; }; }); diff --git a/www/addons/mod/assign/feedback/comments/handlers.js b/www/addons/mod/assign/feedback/comments/handlers.js index f1cea128ce0..d0502ca2495 100644 --- a/www/addons/mod/assign/feedback/comments/handlers.js +++ b/www/addons/mod/assign/feedback/comments/handlers.js @@ -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 = {}; @@ -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; + }); } }; diff --git a/www/addons/mod/assign/submission/onlinetext/handlers.js b/www/addons/mod/assign/submission/onlinetext/handlers.js index 879d0a22f4d..d3b0b4c58bc 100644 --- a/www/addons/mod/assign/submission/onlinetext/handlers.js +++ b/www/addons/mod/assign/submission/onlinetext/handlers.js @@ -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 = {}; @@ -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. + }; + }); }; /** diff --git a/www/addons/mod/chat/controllers/chat.js b/www/addons/mod/chat/controllers/chat.js index 2a04102dc8f..40084e4838e 100644 --- a/www/addons/mod/chat/controllers/chat.js +++ b/www/addons/mod/chat/controllers/chat.js @@ -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'); @@ -173,7 +173,7 @@ angular.module('mm.addons.mod_chat') // Silent error. return; } - text = text.replace(/(?:\r\n|\r|\n)/g, '
'); + text = $mmText.replaceNewLines(text, '
'); $mmaModChat.sendMessage($scope.chatsid, text, beep).then(function() { if (beep === '') { diff --git a/www/addons/mod/forum/directives/discussionpost.js b/www/addons/mod/forum/directives/discussionpost.js index ec34050526d..259e80bd272 100644 --- a/www/addons/mod/forum/directives/discussionpost.js +++ b/www/addons/mod/forum/directives/discussionpost.js @@ -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. diff --git a/www/addons/mod/wiki/controllers/edit.js b/www/addons/mod/wiki/controllers/edit.js index a24ba1aa6d3..cf8e940532f 100644 --- a/www/addons/mod/wiki/controllers/edit.js +++ b/www/addons/mod/wiki/controllers/edit.js @@ -70,6 +70,8 @@ angular.module('mm.addons.mod_wiki') if (rteEnabled) { text = $mmText.restorePluginfileUrls(text, subwikiFiles); + } else { + text = $mmText.formatHtmlLines(text); } if (editing) { diff --git a/www/addons/notifications/filters/format.js b/www/addons/notifications/filters/format.js index 62e341a390d..fc3d5fcf914 100644 --- a/www/addons/notifications/filters/format.js +++ b/www/addons/notifications/filters/format.js @@ -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, '
'); + text = $mmText.replaceNewLines(text, '
'); return text; }; }); diff --git a/www/addons/userprofilefield/textarea/handlers.js b/www/addons/userprofilefield/textarea/handlers.js index e057f7d177e..be9003c9e3e 100644 --- a/www/addons/userprofilefield/textarea/handlers.js +++ b/www/addons/userprofilefield/textarea/handlers.js @@ -21,7 +21,7 @@ angular.module('mm.addons.userprofilefield_textarea') * @ngdoc service * @name $mmaUserProfileFieldTextareaHandler */ -.factory('$mmaUserProfileFieldTextareaHandler', function() { +.factory('$mmaUserProfileFieldTextareaHandler', function($mmUtil, $mmText) { var self = {}; @@ -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 + }) + }; + }); } }; diff --git a/www/core/components/grades/services/helper.js b/www/core/components/grades/services/helper.js index 9506106f536..ad5defa03aa 100644 --- a/www/core/components/grades/services/helper.js +++ b/www/core/components/grades/services/helper.js @@ -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", "
"); + content = $mmText.replaceNewLines(content, '
'); content = img + " " + content; row.text += "<" + celltype + " " + id + " " + headers + " " + "class='"+ tclass +"' " + colspan +">"; @@ -208,7 +208,7 @@ angular.module('mm.core.grades') content = $mmText.cleanTags(content); content = img + " " + content; } else { - content = content.replace("\n", "
"); + content = $mmText.replaceNewLines(content, '
'); } if (content == ' ') { diff --git a/www/core/components/textviewer/controllers/index.js b/www/core/components/textviewer/controllers/index.js index fe1b07ed1fd..7c91647baa6 100644 --- a/www/core/components/textviewer/controllers/index.js +++ b/www/core/components/textviewer/controllers/index.js @@ -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, '
'); + $scope.content = $mmText.replaceNewLines($stateParams.content, '
'); } else { $scope.content = $stateParams.content; } diff --git a/www/core/lib/text.js b/www/core/lib/text.js index 478e9ad7f2f..652504edc0c 100644 --- a/www/core/lib/text.js +++ b/www/core/lib/text.js @@ -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('

').html(text).text(); // Get directive's content. // Recover or remove new lines. - text = self.replaceNewLines(text, singleLine ? ' ' : '
'); + text = self.replaceNewLines(text, singleLine ? ' ' : '
'); return text; }; @@ -155,7 +155,7 @@ angular.module('mm.core') // Wrap the text in

tags. text = '

' + text + '

'; } - return text.replace(/\n/g, '
'); + return self.replaceNewLines(text, '
'); }; /** From 6321c0fde07c62d68e617ebf96b3f88c822e40f0 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 27 Feb 2017 08:53:44 +0100 Subject: [PATCH 2/4] MOBILE-1987 forum: Prevent error undefined forum object --- www/addons/mod/forum/controllers/discussions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/addons/mod/forum/controllers/discussions.js b/www/addons/mod/forum/controllers/discussions.js index cb1d3d40e4a..0615ff28257 100644 --- a/www/addons/mod/forum/controllers/discussions.js +++ b/www/addons/mod/forum/controllers/discussions.js @@ -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); @@ -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(); }); }); From 232e331b4efdc13ebcedc7aa3fca3b8e1196283a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 27 Feb 2017 10:16:38 +0100 Subject: [PATCH 3/4] MOBILE-1987 scorm: Fix fieldName variable not found --- www/addons/mod/scorm/services/scorm_offline.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/www/addons/mod/scorm/services/scorm_offline.js b/www/addons/mod/scorm/services/scorm_offline.js index f90bb7d7b2f..e5220dfef6f 100644 --- a/www/addons/mod/scorm/services/scorm_offline.js +++ b/www/addons/mod/scorm/services/scorm_offline.js @@ -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); From b23ff70d6acf306e9a6f1c65231323c856181161 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 27 Feb 2017 12:01:58 +0100 Subject: [PATCH 4/4] MOBILE-1987 assign: Fix Invalid date and bad button text --- www/addons/mod/assign/templates/submission.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/www/addons/mod/assign/templates/submission.html b/www/addons/mod/assign/templates/submission.html index a8f2d1dc8c9..5dfb03b054f 100644 --- a/www/addons/mod/assign/templates/submission.html +++ b/www/addons/mod/assign/templates/submission.html @@ -43,7 +43,7 @@

{{ 'mma.mod_assign.submissionstatus' | translate }}

-

{{ 'mma.mod_assign.erroreditpluginsnotsupported' | translate }}