diff --git a/www/addons/mod/data/controllers/entry.js b/www/addons/mod/data/controllers/entry.js
index 82731060624..be4b8fdea49 100644
--- a/www/addons/mod/data/controllers/entry.js
+++ b/www/addons/mod/data/controllers/entry.js
@@ -214,13 +214,15 @@ angular.module('mm.addons.mod_data')
// Refresh entry on sync.
syncObserver = $mmEvents.on(mmaModDataEventAutomSynced, function(eventData) {
- if (eventData.entryid == entryId && data.id == eventData.dataid && $mmSite.getId() == eventData.siteid) {
+ if ((eventData.entryid == entryId || eventData.offlineentryid == entryId) && data.id == eventData.dataid &&
+ $mmSite.getId() == eventData.siteid) {
if (eventData.deleted) {
// If deleted, go back.
$ionicHistory.goBack();
} else {
+ entryId = eventData.entryid;
$scope.databaseLoaded = false;
- return fetchEntryData(true);
+ fetchEntryData(true);
}
}
});
diff --git a/www/addons/mod/data/controllers/index.js b/www/addons/mod/data/controllers/index.js
index d131c30e69e..16d48783748 100644
--- a/www/addons/mod/data/controllers/index.js
+++ b/www/addons/mod/data/controllers/index.js
@@ -191,7 +191,7 @@ angular.module('mm.addons.mod_data')
}
}).then(function(entries) {
var numEntries = (entries && entries.entries && entries.entries.length) || 0;
- $scope.isEmpty = !numEntries && Object.keys($scope.offlineActions).length <= 0;
+ $scope.isEmpty = !numEntries && !Object.keys($scope.offlineActions).length && !Object.keys($scope.offlineEntries).length;
$scope.hasNextPage = numEntries >= mmaModDataPerPage && (($scope.search.page + 1) * mmaModDataPerPage) < entries.totalcount;
$scope.entriesRendered = "";
@@ -439,7 +439,7 @@ angular.module('mm.addons.mod_data')
// Update just when all database is synced.
if (data.id == eventData.dataid && siteId == eventData.siteid && typeof eventData.entryid == "undefined") {
$scope.databaseLoaded = false;
- return fetchDatabaseData(true);
+ fetchDatabaseData(true);
}
});
diff --git a/www/addons/mod/data/fields/checkbox/directive.js b/www/addons/mod/data/fields/checkbox/directive.js
index 9615d28647c..16e95b2ca4e 100644
--- a/www/addons/mod/data/fields/checkbox/directive.js
+++ b/www/addons/mod/data/fields/checkbox/directive.js
@@ -14,6 +14,12 @@
angular.module('mm.addons.mod_data')
+.filter('mmaModDataFieldCheckboxFormat', function() {
+ return function(text) {
+ return text.split("##").join("
");
+ };
+})
+
/**
* Directive to render data checkbox field.
*
@@ -29,7 +35,6 @@ angular.module('mm.addons.mod_data')
link: function(scope) {
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
if (scope.mode == 'show') {
- scope.text = scope.value && scope.value.content ? scope.value.content.split("##").join("
") : "";
return;
}
diff --git a/www/addons/mod/data/fields/checkbox/template.html b/www/addons/mod/data/fields/checkbox/template.html
index 04ab7849e15..82c3ac440c3 100644
--- a/www/addons/mod/data/fields/checkbox/template.html
+++ b/www/addons/mod/data/fields/checkbox/template.html
@@ -4,4 +4,4 @@
{{ option }}
{{ 'mma.mod_data.selectedrequired' | translate }}
-{{ text }}
\ No newline at end of file
+{{ value.content | mmaModDataFieldCheckboxFormat }}
\ No newline at end of file
diff --git a/www/addons/mod/data/fields/date/directive.js b/www/addons/mod/data/fields/date/directive.js
index 859ed4c1064..9626c53b9f0 100644
--- a/www/addons/mod/data/fields/date/directive.js
+++ b/www/addons/mod/data/fields/date/directive.js
@@ -14,6 +14,12 @@
angular.module('mm.addons.mod_data')
+.filter('mmaModDataFieldDateFormat', function() {
+ return function(text) {
+ return text * 1000;
+ };
+})
+
/**
* Directive to render data date field.
*
@@ -29,7 +35,6 @@ angular.module('mm.addons.mod_data')
link: function(scope) {
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
if (scope.mode == 'show') {
- scope.text = scope.value ? scope.value.content * 1000 : "";
return;
}
diff --git a/www/addons/mod/data/fields/date/template.html b/www/addons/mod/data/fields/date/template.html
index e9bac5373f2..783d1fc842b 100644
--- a/www/addons/mod/data/fields/date/template.html
+++ b/www/addons/mod/data/fields/date/template.html
@@ -2,4 +2,4 @@
{{ error }}
{{ 'mma.mod_data.usedate' | translate }}
-{{ text | mmFormatDate:"dfdaymonthyear" }}
\ No newline at end of file
+{{ value.content | mmaModDataFieldDateFormat | mmFormatDate:"dfdaymonthyear" }}
\ No newline at end of file
diff --git a/www/addons/mod/data/fields/file/directive.js b/www/addons/mod/data/fields/file/directive.js
index 149b59fcce7..238d362ce52 100644
--- a/www/addons/mod/data/fields/file/directive.js
+++ b/www/addons/mod/data/fields/file/directive.js
@@ -22,6 +22,24 @@ angular.module('mm.addons.mod_data')
* @name mmaModDataFieldFile
*/
.directive('mmaModDataFieldFile', function($mmFileSession, mmaModDataComponent) {
+
+ /**
+ * Get the files from the input value.
+ *
+ * @param {Object} value Input value.
+ * @return {Object[]} List of files.
+ */
+ function getFiles(value) {
+ var files = (value && value.files) || [];
+
+ // Reduce to first element.
+ if (files.length > 0) {
+ files = [files[0]];
+ }
+
+ return files;
+ }
+
return {
restrict: 'A',
priority: 100,
@@ -32,14 +50,15 @@ angular.module('mm.addons.mod_data')
scope.component = mmaModDataComponent;
scope.componentId = scope.database.coursemodule;
- scope.files = (scope.value && scope.value.files) || [];
-
- // Reduce to first element.
- if (scope.files.length > 0) {
- scope.files = [scope.files[0]];
- }
+ if (scope.mode == 'show') {
+ // Displaying the list of files, watch the value to update the list if it changes.
+ scope.$watch('value', function(newValue) {
+ scope.files = getFiles(newValue);
+ });
+ } else {
+ // Edit mode, the list shouldn't change so there is no need to watch it.
+ scope.files = getFiles(scope.value);
- if (scope.mode == 'edit') {
scope.maxSizeBytes = parseInt(scope.field.param3, 10);
$mmFileSession.setFiles(mmaModDataComponent, scope.database.id + '_' + scope.field.id, scope.files);
}
diff --git a/www/addons/mod/data/fields/latlong/directive.js b/www/addons/mod/data/fields/latlong/directive.js
index 0f214ac81d0..9d3bf66b413 100644
--- a/www/addons/mod/data/fields/latlong/directive.js
+++ b/www/addons/mod/data/fields/latlong/directive.js
@@ -14,6 +14,25 @@
angular.module('mm.addons.mod_data')
+.filter('mmaModDataFieldLatLongFormat', function() {
+ return function(value) {
+ var north = (value && parseFloat(value.content)) || "",
+ east = (value && parseFloat(value.content1)) || "";
+
+ if (north !== '' || east !== '') {
+ north = north ? north.toFixed(4) : '0.0000';
+ east = east ? east.toFixed(4) : '0.0000';
+
+ var latitude = north < 0 ? -north + '°S' : north + '°N',
+ longitude = east < 0 ? -east + '°W' : east + '°E',
+ link = ionic.Platform.isAndroid() ? 'geo:' + north + ',' + east :
+ 'http://maps.apple.com/?ll=' + north + ',' + east + '&near=' + north + ',' + east;
+
+ return '' + latitude + ' ' + longitude + '';
+ }
+ };
+})
+
/**
* Directive to render data latlong field.
*
@@ -29,22 +48,9 @@ angular.module('mm.addons.mod_data')
link: function(scope) {
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
if (scope.value) {
- scope.north = (scope.value && parseFloat(scope.value.content)) || "";
- scope.east = (scope.value && parseFloat(scope.value.content1)) || "";
-
- if (scope.mode == 'show') {
- if (scope.north != "" || scope.east != "") {
- scope.north = scope.north ? parseFloat(scope.north).toFixed(4) : '0.0000';
- scope.east = scope.east ? parseFloat(scope.east).toFixed(4) : '0.0000';
- scope.latitude = scope.north < 0 ? -scope.north + '°S' : scope.north + '°N';
- scope.longitude = scope.east < 0 ? -scope.east + '°W' : scope.east + '°E';
-
- if (ionic.Platform.isIOS()) {
- scope.link = "http://maps.apple.com/?ll=" + scope.north + "," + scope.east + "&near=" + scope.north + "," + scope.east;
- } else {
- scope.link = "geo:"+scope.north+","+scope.east;
- }
- }
+ if (scope.mode == 'edit') {
+ scope.north = (scope.value && parseFloat(scope.value.content)) || "";
+ scope.east = (scope.value && parseFloat(scope.value.content1)) || "";
}
}
}
diff --git a/www/addons/mod/data/fields/latlong/template.html b/www/addons/mod/data/fields/latlong/template.html
index 545ed0137b5..5f0383efcde 100644
--- a/www/addons/mod/data/fields/latlong/template.html
+++ b/www/addons/mod/data/fields/latlong/template.html
@@ -10,6 +10,4 @@
°E
-
- {{latitude}} {{longitude}}
-
+
diff --git a/www/addons/mod/data/fields/menu/directive.js b/www/addons/mod/data/fields/menu/directive.js
index fb046e29fa4..d4d6bcbbd4d 100644
--- a/www/addons/mod/data/fields/menu/directive.js
+++ b/www/addons/mod/data/fields/menu/directive.js
@@ -29,7 +29,6 @@ angular.module('mm.addons.mod_data')
link: function(scope) {
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
if (scope.mode == 'show') {
- scope.text = scope.value ? scope.value.content : "";
return;
}
diff --git a/www/addons/mod/data/fields/menu/template.html b/www/addons/mod/data/fields/menu/template.html
index 38a0de74239..0966a1b3f34 100644
--- a/www/addons/mod/data/fields/menu/template.html
+++ b/www/addons/mod/data/fields/menu/template.html
@@ -6,4 +6,4 @@
-{{ text }}
\ No newline at end of file
+{{ value.content }}
\ No newline at end of file
diff --git a/www/addons/mod/data/fields/multimenu/directive.js b/www/addons/mod/data/fields/multimenu/directive.js
index 2c03ba665bb..612b71d7f7b 100644
--- a/www/addons/mod/data/fields/multimenu/directive.js
+++ b/www/addons/mod/data/fields/multimenu/directive.js
@@ -14,6 +14,12 @@
angular.module('mm.addons.mod_data')
+.filter('mmaModDataFieldMultimenuFormat', function() {
+ return function(text) {
+ return text.split("##").join("
");
+ };
+})
+
/**
* Directive to render data multimenu field.
*
@@ -29,7 +35,6 @@ angular.module('mm.addons.mod_data')
link: function(scope) {
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
if (scope.mode == 'show') {
- scope.text = scope.value && scope.value.content ? scope.value.content.split("##").join("
") : "";
return;
}
diff --git a/www/addons/mod/data/fields/multimenu/template.html b/www/addons/mod/data/fields/multimenu/template.html
index d5ff2a43fb2..bae95d7a2ce 100644
--- a/www/addons/mod/data/fields/multimenu/template.html
+++ b/www/addons/mod/data/fields/multimenu/template.html
@@ -2,4 +2,4 @@
{{ error }}
{{ 'mma.mod_data.selectedrequired' | translate }}
-{{ text }}
\ No newline at end of file
+{{ value.content | mmaModDataFieldMultimenuFormat }}
\ No newline at end of file
diff --git a/www/addons/mod/data/fields/number/directive.js b/www/addons/mod/data/fields/number/directive.js
index 7b0708dc79a..b3dcb81413d 100644
--- a/www/addons/mod/data/fields/number/directive.js
+++ b/www/addons/mod/data/fields/number/directive.js
@@ -28,10 +28,6 @@ angular.module('mm.addons.mod_data')
templateUrl: 'addons/mod/data/fields/number/template.html',
link: function(scope) {
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
- if (scope.mode == 'show') {
- scope.text = scope.value ? scope.value.content : "";
- return;
- }
if (scope.mode == 'edit' && scope.value) {
scope.val = scope.value && parseFloat(scope.value.content);
diff --git a/www/addons/mod/data/fields/number/template.html b/www/addons/mod/data/fields/number/template.html
index ee80050dfb6..4f1dd5780ab 100644
--- a/www/addons/mod/data/fields/number/template.html
+++ b/www/addons/mod/data/fields/number/template.html
@@ -1,4 +1,4 @@
{{ error }}
-{{ text }}
\ No newline at end of file
+{{ value.content }}
\ No newline at end of file
diff --git a/www/addons/mod/data/fields/picture/directive.js b/www/addons/mod/data/fields/picture/directive.js
index 7c81317bfa2..cf5a0419f5b 100644
--- a/www/addons/mod/data/fields/picture/directive.js
+++ b/www/addons/mod/data/fields/picture/directive.js
@@ -33,49 +33,68 @@ angular.module('mm.addons.mod_data')
return false;
}
+ /**
+ * Given an input value, extract the image files and all the required data.
+ *
+ * @param {Object} scope Directive's scope.
+ * @param {Object} value Field value.
+ * @return {Void}
+ */
+ function treatFiles(scope, value) {
+ var files = value && value.files || [];
+
+ // Get image or thumb.
+ if (files.length > 0) {
+ var filenameSeek = scope.mode == 'list' ? 'thumb_' + value.content : value.content;
+ scope.image = findFile(files, filenameSeek);
+
+ if (!scope.image && scope.mode == 'list') {
+ scope.image = findFile(files, value.content);
+ }
+
+ scope.files = [scope.image];
+ } else {
+ scope.image = false;
+ scope.files = [];
+ }
+
+ if (scope.mode == 'edit') {
+ scope.maxSizeBytes = parseInt(scope.field.param3, 10);
+ $mmFileSession.setFiles(mmaModDataComponent, scope.database.id + '_' + scope.field.id, scope.files);
+ scope.alttext = (value && value.content1) || "";
+ } else {
+ scope.entryId = (value && value.recordid) || false;
+ scope.title = (value && value.content1) || "";
+ scope.imageUrl = false;
+ if (scope.image) {
+ if (scope.image.offline) {
+ scope.imageUrl = (scope.image && scope.image.toURL()) || false;
+ } else {
+ scope.imageUrl = (scope.image && scope.image.fileurl) || false;
+ }
+ }
+ scope.width = scope.field.param1 || "";
+ scope.height = scope.field.param2 || "";
+ }
+ }
+
return {
restrict: 'A',
priority: 100,
templateUrl: 'addons/mod/data/fields/picture/template.html',
link: function(scope) {
if (scope.mode != 'search') {
- var files = scope.value && scope.value.files || [];
-
scope.component = mmaModDataComponent;
scope.componentId = scope.database.coursemodule;
- // Get image or thumb.
- if (files.length > 0) {
- var filenameSeek = scope.mode == 'list' ? 'thumb_' + scope.value.content : scope.value.content;
- scope.image = findFile(files, filenameSeek);
-
- if (!scope.image && scope.mode == 'list') {
- scope.image = findFile(files, scope.value.content);
- }
-
- scope.files = [scope.image];
- } else {
- scope.image = false;
- scope.files = [];
- }
-
- if (scope.mode == 'edit') {
- scope.maxSizeBytes = parseInt(scope.field.param3, 10);
- $mmFileSession.setFiles(mmaModDataComponent, scope.database.id + '_' + scope.field.id, scope.files);
- scope.alttext = (scope.value && scope.value.content1) || "";
+ if (scope.mode == 'show') {
+ // Displaying the list of files, watch the value to update the list if it changes.
+ scope.$watch('value', function(newValue) {
+ treatFiles(scope, newValue);
+ });
} else {
- scope.entryId = (scope.value && scope.value.recordid) || false;
- scope.title = (scope.value && scope.value.content1) || "";
- scope.imageUrl = false;
- if (scope.image) {
- if (scope.image.offline) {
- scope.imageUrl = (scope.image && scope.image.toURL()) || false;
- } else {
- scope.imageUrl = (scope.image && scope.image.fileurl) || false;
- }
- }
- scope.width = scope.field.param1 || "";
- scope.height = scope.field.param2 || "";
+ // Edit mode, the list shouldn't change so there is no need to watch it.
+ treatFiles(scope, scope.value);
}
}
}
diff --git a/www/addons/mod/data/fields/radiobutton/directive.js b/www/addons/mod/data/fields/radiobutton/directive.js
index 4d33daace68..86eaf2bd78f 100644
--- a/www/addons/mod/data/fields/radiobutton/directive.js
+++ b/www/addons/mod/data/fields/radiobutton/directive.js
@@ -29,7 +29,6 @@ angular.module('mm.addons.mod_data')
link: function(scope) {
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
if (scope.mode == 'show') {
- scope.text = scope.value ? scope.value.content : "";
return;
}
diff --git a/www/addons/mod/data/fields/radiobutton/template.html b/www/addons/mod/data/fields/radiobutton/template.html
index 38a0de74239..0966a1b3f34 100644
--- a/www/addons/mod/data/fields/radiobutton/template.html
+++ b/www/addons/mod/data/fields/radiobutton/template.html
@@ -6,4 +6,4 @@
-{{ text }}
\ No newline at end of file
+{{ value.content }}
\ No newline at end of file
diff --git a/www/addons/mod/data/fields/text/directive.js b/www/addons/mod/data/fields/text/directive.js
index dc6352f4a16..18bdb2c3362 100644
--- a/www/addons/mod/data/fields/text/directive.js
+++ b/www/addons/mod/data/fields/text/directive.js
@@ -28,10 +28,6 @@ angular.module('mm.addons.mod_data')
templateUrl: 'addons/mod/data/fields/text/template.html',
link: function(scope) {
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
- if (scope.mode == 'show') {
- scope.text = scope.value ? scope.value.content : "";
- return;
- }
if (scope.mode == 'edit' && scope.value) {
scope.val = scope.value.content;
diff --git a/www/addons/mod/data/fields/text/template.html b/www/addons/mod/data/fields/text/template.html
index 926a77c56c0..3fe5aa19cba 100644
--- a/www/addons/mod/data/fields/text/template.html
+++ b/www/addons/mod/data/fields/text/template.html
@@ -1,4 +1,4 @@
{{ error }}
-{{ text }}
\ No newline at end of file
+{{ value.content }}
\ No newline at end of file
diff --git a/www/addons/mod/data/fields/textarea/directive.js b/www/addons/mod/data/fields/textarea/directive.js
index 58edaf071c7..66662e9d2ad 100644
--- a/www/addons/mod/data/fields/textarea/directive.js
+++ b/www/addons/mod/data/fields/textarea/directive.js
@@ -14,6 +14,13 @@
angular.module('mm.addons.mod_data')
+.filter('mmaModDataFieldTextareaFormat', function($mmText) {
+ return function(value) {
+ var files = (value && value.files) || [];
+ return value ? $mmText.replacePluginfileUrls(value.content, files) : '';
+ };
+})
+
/**
* Directive to render data textarea field.
*
@@ -21,7 +28,7 @@ angular.module('mm.addons.mod_data')
* @ngdoc directive
* @name mmaModDataFieldTextarea
*/
-.directive('mmaModDataFieldTextarea', function($mmUtil, $mmText, mmaModDataComponent) {
+.directive('mmaModDataFieldTextarea', function($mmText, mmaModDataComponent) {
return {
restrict: 'A',
priority: 100,
@@ -31,24 +38,18 @@ angular.module('mm.addons.mod_data')
if (scope.mode == 'show') {
scope.component = mmaModDataComponent;
scope.componentId = scope.database.coursemodule;
-
- var files = (scope.value && scope.value.files) || [];
-
- scope.text = scope.value ? $mmText.replacePluginfileUrls(scope.value.content, files) : "";
return;
}
// Check if rich text editor is enabled.
if (scope.mode == 'edit') {
- $mmUtil.isRichTextEditorEnabled().then(function(enabled) {
- var files = (scope.value && scope.value.files) || [],
- text = scope.value ? $mmText.replacePluginfileUrls(scope.value.content, files) : "";
+ var files = (scope.value && scope.value.files) || [],
+ text = scope.value ? $mmText.replacePluginfileUrls(scope.value.content, files) : "";
- // Get the text.
- scope.model = {
- text: text
- };
- });
+ // Get the text.
+ scope.model = {
+ text: text
+ };
scope.firstRender = function() {
if (!scope.value) {
diff --git a/www/addons/mod/data/fields/textarea/template.html b/www/addons/mod/data/fields/textarea/template.html
index f3623b92ab7..4260325d1a6 100644
--- a/www/addons/mod/data/fields/textarea/template.html
+++ b/www/addons/mod/data/fields/textarea/template.html
@@ -4,4 +4,4 @@
-{{ text }}
\ No newline at end of file
+{{ value | mmaModDataFieldTextareaFormat }}
\ No newline at end of file
diff --git a/www/addons/mod/data/fields/url/directive.js b/www/addons/mod/data/fields/url/directive.js
index e621cbe2e3f..5306dbd9904 100644
--- a/www/addons/mod/data/fields/url/directive.js
+++ b/www/addons/mod/data/fields/url/directive.js
@@ -28,10 +28,6 @@ angular.module('mm.addons.mod_data')
templateUrl: 'addons/mod/data/fields/url/template.html',
link: function(scope) {
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
- if (scope.mode == 'show') {
- scope.text = scope.value ? scope.value.content : "";
- return;
- }
if (scope.mode == 'edit' && scope.value) {
scope.val = scope.value.content;
diff --git a/www/addons/mod/data/fields/url/template.html b/www/addons/mod/data/fields/url/template.html
index a49c0438d7b..1a97133288e 100644
--- a/www/addons/mod/data/fields/url/template.html
+++ b/www/addons/mod/data/fields/url/template.html
@@ -1,3 +1,3 @@
-{{field.name}}
\ No newline at end of file
+{{field.name}}
diff --git a/www/addons/mod/data/services/data.js b/www/addons/mod/data/services/data.js
index c2de10b9f0f..5454e64c275 100644
--- a/www/addons/mod/data/services/data.js
+++ b/www/addons/mod/data/services/data.js
@@ -680,7 +680,11 @@ angular.module('mm.addons.mod_data')
}).then(function() {
if (justAdded) {
// The field was added offline, add again and stop.
- return self.addEntry(dataId, entryId, courseId, contents, groupId, fields, siteId, forceOffline);
+ return self.addEntry(dataId, entryId, courseId, contents, groupId, fields, siteId, forceOffline)
+ .then(function(result) {
+ result.updated = true;
+ return result;
+ });
}
if (!$mmApp.isOnline() || forceOffline) {
diff --git a/www/addons/mod/data/services/data_offline.js b/www/addons/mod/data/services/data_offline.js
index 4cab769cdf0..916a46ae8cc 100644
--- a/www/addons/mod/data/services/data_offline.js
+++ b/www/addons/mod/data/services/data_offline.js
@@ -62,6 +62,27 @@ angular.module('mm.addons.mod_data')
var self = {};
+ /**
+ * Delete all the actions of an entry.
+ *
+ * @module mm.addons.mod_data
+ * @ngdoc method
+ * @name $mmaModDataOffline#deleteAllEntryActions
+ * @param {Number} dataId Database ID.
+ * @param {Number} entryId Database entry ID.
+ * @param {String} [siteId] Site ID. If not defined, current site.
+ * @return {Promise} Promise resolved if deleted, rejected if failure.
+ */
+ self.deleteAllEntryActions = function(dataId, entryId, siteId) {
+ return self.getEntryActions(dataId, entryId, siteId).then(function(actions) {
+ var promises = [];
+ angular.forEach(actions, function(action) {
+ promises.push(self.deleteEntry(dataId, entryId, action.action, siteId));
+ });
+ return $q.all(promises);
+ });
+ };
+
/**
* Delete an stored entry.
*
@@ -122,7 +143,7 @@ angular.module('mm.addons.mod_data')
* @param {Number} dataId Database ID.
* @param {String} entryId Database entry Id.
* @param {String} [siteId] Site ID. If not defined, current site.
- * @return {Promise} Promise resolved with entry.
+ * @return {Promise} Promise resolved with entry actions.
*/
self.getEntryActions = function(dataId, entryId, siteId) {
return $mmSitesManager.getSite(siteId).then(function(site) {
diff --git a/www/addons/mod/data/services/data_sync.js b/www/addons/mod/data/services/data_sync.js
index 20300452faa..5618175fa6c 100644
--- a/www/addons/mod/data/services/data_sync.js
+++ b/www/addons/mod/data/services/data_sync.js
@@ -188,7 +188,7 @@ angular.module('mm.addons.mod_data')
});
angular.forEach(offlineEntries, function(entryActions) {
- promises.push(syncEntry(data, entryActions, result.warnings, siteId));
+ promises.push(syncEntry(data, entryActions, result, siteId));
});
return $q.all(promises);
@@ -216,16 +216,17 @@ angular.module('mm.addons.mod_data')
/**
* Synchronize an entry.
*
- * @param {Object} data Database.
- * @param {Object} entryActions Entry actions.
- * @param {Object[]} warnings List of warnings.
- * @param {String} [siteId] Site ID. If not defined, current site.
- * @return {Promise} Promise resolved if success, rejected otherwise.
+ * @param {Object} data Database.
+ * @param {Object} entryActions Entry actions.
+ * @param {Object} result Object with the result of the sync.
+ * @param {String} [siteId] Site ID. If not defined, current site.
+ * @return {Promise} Promise resolved if success, rejected otherwise.
*/
- function syncEntry(data, entryActions, warnings, siteId) {
+ function syncEntry(data, entryActions, result, siteId) {
var discardError,
timePromise,
entryId = 0,
+ offlineId,
deleted = false,
promises = [];
@@ -237,20 +238,22 @@ angular.module('mm.addons.mod_data')
entryId = entryActions[0].entryid;
if (entryId > 0) {
- timePromise = $mmaModData.getEntry(data.id, entryActions[0].entryid, siteId).then(function(entry) {
+ timePromise = $mmaModData.getEntry(data.id, entryId, siteId).then(function(entry) {
return entry.entry.timemodified;
}).catch(function() {
return -1;
});
} else {
+ offlineId = entryId;
timePromise = $q.when(0);
}
return timePromise.then(function(timemodified) {
if (timemodified < 0 || timemodified >= entryActions[0].timemodified) {
// The entry was not found in Moodle or the entry has been modified, discard the action.
+ result.updated = true;
discardError = $translate.instant('mma.mod_data.warningsubmissionmodified');
- return;
+ return $mmaModDataOffline.deleteAllEntryActions(data.id, entryId, siteId);
}
angular.forEach(entryActions, function(action) {
@@ -310,6 +313,7 @@ angular.module('mm.addons.mod_data')
}
}).then(function() {
// Delete the offline data.
+ result.updated = true;
return $mmaModDataOffline.deleteEntry(action.dataid, action.entryid, action.action, siteId);
}));
});
@@ -323,17 +327,18 @@ angular.module('mm.addons.mod_data')
error: discardError
});
- if (warnings.indexOf(message) == -1) {
- warnings.push(message);
+ if (result.warnings.indexOf(message) == -1) {
+ result.warnings.push(message);
}
}
// Sync done. Send event.
$mmEvents.trigger(mmaModDataEventAutomSynced, {
siteid: siteId,
- dataid: action.dataid,
- entryid: action.entryid,
- warnings: warnings,
+ dataid: data.id,
+ entryid: entryId,
+ offlineentryid: offlineId,
+ warnings: result.warnings,
deleted: deleted
});
});