Skip to content

Commit b1225c3

Browse files
committed
MOBILE-2178 database: Allow viewing offline entries
1 parent 3fab7f5 commit b1225c3

File tree

3 files changed

+45
-27
lines changed

3 files changed

+45
-27
lines changed

www/addons/mod/data/controllers/edit.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,7 @@ angular.module('mm.addons.mod_data')
8787
$scope.fields[field.id] = field;
8888
});
8989

90-
if (entryId > 0) {
91-
return $mmaModData.getEntry(data.id, entryId);
92-
}
93-
94-
for (var x in offlineActions) {
95-
if (offlineActions[x].action == 'add') {
96-
offlineEntry = offlineActions[x];
97-
98-
var siteInfo = $mmSite.getInfo(),
99-
entryData = {
100-
id: offlineEntry.entryid,
101-
canmanageentry: true,
102-
approved: !data.approval || data.manageapproved,
103-
dataid: offlineEntry.dataid,
104-
groupid: offlineEntry.groupid,
105-
timecreated: -offlineEntry.entryid,
106-
timemodified: -offlineEntry.entryid,
107-
userid: siteInfo.userid,
108-
fullname: siteInfo.fullname,
109-
contents: {}
110-
};
111-
112-
return {entry: entryData};
113-
}
114-
}
90+
return $mmaModDataHelper.getEntry(data, entryId, offlineActions);
11591
}).then(function(entryData) {
11692
if (entryData) {
11793
entry = entryData.entry;

www/addons/mod/data/controllers/entry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ angular.module('mm.addons.mod_data')
8787
$scope.fields[field.id] = field;
8888
});
8989

90-
return $mmaModData.getEntry(data.id, entryId);
90+
return $mmaModDataHelper.getEntry(data, entryId, offlineActions);
9191
});
9292
}).then(function(entry) {
9393
entry = entry.entry;

www/addons/mod/data/services/helper.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ angular.module('mm.addons.mod_data')
2222
* @name $mmaModDataHelper
2323
*/
2424
.factory('$mmaModDataHelper', function($mmaModData, $mmaModDataFieldsDelegate, $q, mmaModDataComponent, $mmFileUploader, $mmSite,
25-
$mmaModDataOffline, $mmFS, $mmFileUploaderHelper) {
25+
$mmaModDataOffline, $mmFS, $mmFileUploaderHelper, $mmSitesManager) {
2626

2727
var self = {
2828
searchOther: {
@@ -660,6 +660,48 @@ angular.module('mm.addons.mod_data')
660660
});
661661
};
662662

663+
/**
664+
* Get an online or offline entry.
665+
*
666+
* @module mm.addons.mod_data
667+
* @ngdoc method
668+
* @name $mmaModDataHelper#getEntry
669+
* @param {Object} data Database.
670+
* @param {Number} entryId Entry ID.
671+
* @param {Object} [offlineActions] Offline data with the actions done. Required for offline entries.
672+
* @param {String} [siteId] Site ID. If not defined, current site.
673+
* @return {Promise} Promise resolved with the entry.
674+
*/
675+
self.getEntry = function(data, entryId, offlineActions, siteId) {
676+
if (entryId > 0) {
677+
// It's an online entry, get it from WS.
678+
return $mmaModData.getEntry(data.id, entryId, siteId);
679+
}
680+
681+
// It's an offline entry, search it in the offline actions.
682+
return $mmSitesManager.getSite(siteId).then(function(site) {
683+
for (var x in offlineActions) {
684+
if (offlineActions[x].action == 'add') {
685+
var offlineEntry = offlineActions[x],
686+
siteInfo = site.getInfo(),
687+
entryData = {
688+
id: offlineEntry.entryid,
689+
canmanageentry: true,
690+
approved: !data.approval || data.manageapproved,
691+
dataid: offlineEntry.dataid,
692+
groupid: offlineEntry.groupid,
693+
timecreated: -offlineEntry.entryid,
694+
timemodified: -offlineEntry.entryid,
695+
userid: siteInfo.userid,
696+
fullname: siteInfo.fullname,
697+
contents: {}
698+
};
699+
700+
return {entry: entryData};
701+
}
702+
}
703+
});
704+
};
663705

664706
return self;
665707
});

0 commit comments

Comments
 (0)