Skip to content

Commit 0340386

Browse files
authored
Merge pull request #1105 from dpalou/MOBILE-2178
Mobile 2178
2 parents 65fc720 + b1225c3 commit 0340386

File tree

10 files changed

+68
-52
lines changed

10 files changed

+68
-52
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/lang/en.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"recorddeleted": "Entry deleted",
3434
"recorddisapproved": "Entry unapproved",
3535
"resetsettings": "Reset filters",
36-
"restore": "Restore",
3736
"search": "Search",
3837
"selectedrequired": "All selected required",
3938
"timeadded": "Time added",

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -622,12 +622,7 @@ angular.module('mm.addons.mod_data')
622622
params.groupid = groupId;
623623
}
624624

625-
return site.write('mod_data_add_entry', params).then(function(result) {
626-
if (result.newentryid) {
627-
return result;
628-
}
629-
return $q.reject();
630-
}).catch(function(error) {
625+
return site.write('mod_data_add_entry', params).catch(function(error) {
631626
return $q.reject({
632627
error: error,
633628
wserror: $mmUtil.isWebServiceError(error)
@@ -766,12 +761,7 @@ angular.module('mm.addons.mod_data')
766761
data: data
767762
};
768763

769-
return site.write('mod_data_update_entry', params).then(function(result) {
770-
if (result.updated) {
771-
return result;
772-
}
773-
return $q.reject();
774-
}).catch(function(error) {
764+
return site.write('mod_data_update_entry', params).catch(function(error) {
775765
return $q.reject({
776766
error: error,
777767
wserror: $mmUtil.isWebServiceError(error)
@@ -808,8 +798,8 @@ angular.module('mm.addons.mod_data')
808798
perpage: perPage || mmaModDataPerPage
809799
},
810800
preSets = {
811-
getCache: 0,
812-
saveCache: 1,
801+
getFromCache: 0,
802+
saveToCache: 1,
813803
emergencyCache: 1
814804
};
815805

@@ -839,11 +829,13 @@ angular.module('mm.addons.mod_data')
839829
* @module mm.addons.mod_data
840830
* @ngdoc method
841831
* @name $mmaModData#getFields
842-
* @param {Number} dataId Data ID.
843-
* @param {String} [siteId] Site ID. If not defined, current site.
844-
* @return {Promise} Promise resolved when the database is retrieved.
832+
* @param {Number} dataId Data ID.
833+
* @param {Boolean} [forceCache] True to always get the value from cache, false otherwise. Default false.
834+
* @param {Boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
835+
* @param {String} [siteId] Site ID. If not defined, current site.
836+
* @return {Promise} Promise resolved when the fields are retrieved.
845837
*/
846-
self.getFields = function(dataId, siteId) {
838+
self.getFields = function(dataId, forceCache, ignoreCache, siteId) {
847839
return $mmSitesManager.getSite(siteId).then(function(site) {
848840
var params = {
849841
databaseid: dataId
@@ -852,6 +844,13 @@ angular.module('mm.addons.mod_data')
852844
cacheKey: getFieldsCacheKey(dataId)
853845
};
854846

847+
if (forceCache) {
848+
preSets.omitExpires = true;
849+
} else if (ignoreCache) {
850+
preSets.getFromCache = 0;
851+
preSets.emergencyCache = 0;
852+
}
853+
855854
return site.read('mod_data_get_fields', params, preSets).then(function(response) {
856855
if (response && response.fields) {
857856
return response.fields;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ angular.module('mm.addons.mod_data')
3737
{
3838
name: 'entryid'
3939
},
40-
{
41-
name: 'fields'
42-
},
4340
{
4441
name: 'timemodified'
4542
},

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

Lines changed: 44 additions & 2 deletions
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: {
@@ -101,7 +101,7 @@ angular.module('mm.addons.mod_data')
101101
replacements.timeadded = true;
102102
replacements.timemodified = true;
103103

104-
replacements.edit = accessInfo.canmanageentries || (accessInfo.inreadonlyperiod && record.canmanageentry);
104+
replacements.edit = record.canmanageentry; // This already checks capabilities and readonly period.
105105
replacements.delete = replacements.edit;
106106
replacements.approve = database.approval && accessInfo.canapprove && !record.approved;
107107
replacements.disapprove = database.approval && accessInfo.canapprove && record.approved;
@@ -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
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ angular.module('mm.addons.mod_data')
323323
var database = info.database,
324324
promises = [];
325325

326+
promises.push($mmaModData.getFields(database.id, false, true, siteId));
327+
326328
promises.push($mmFilepool.addFilesToQueueByUrl(siteId, info.files, self.component, module.id));
327329

328330
angular.forEach(info.groups, function(group) {

www/addons/mod/data/templates/action.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<a ng-if="action == 'more'" class="button button-icon icon ion-ios-search-strong" ng-href="{{url}}/mod/data/view.php?d={{entry.dataid}}&rid={{entry.id}}" mm-link capture-link="true" title="{{ 'mma.mod_data.more' | translate }}"></a>
22
<a ng-if="action == 'edit'" class="button button-icon icon ion-gear-b" ng-href="{{url}}/mod/data/edit.php?d={{entry.dataid}}&rid={{entry.id}}" mm-link capture-link="true" title="{{ 'mm.core.edit' | translate }}"></a>
33
<a ng-if="action == 'delete' && !entry.deleted" class="button button-icon icon ion-trash-a" ng-href="{{url}}/mod/data/view.php?d={{entry.dataid}}&delete={{entry.id}}" mm-link capture-link="true" title="{{ 'mm.core.delete' | translate }}"></a>
4-
<a ng-if="action == 'delete' && entry.deleted" class="button button-icon icon ion-reply" ng-click="undoDelete()" mm-link capture-link="true" title="{{ 'mma.mod_data.restore' | translate }}"></a>
4+
<a ng-if="action == 'delete' && entry.deleted" class="button button-icon icon ion-reply" ng-click="undoDelete()" mm-link capture-link="true" title="{{ 'mm.core.restore' | translate }}"></a>
55
<a ng-if="action == 'approve'" class="button button-icon icon ion-thumbsup" ng-href="{{url}}/mod/data/view.php?d={{entry.dataid}}&approve={{entry.id}}" mm-link capture-link="true" title="{{ 'mma.mod_data.approve' | translate }}"></a>
66
<a ng-if="action == 'disapprove'" class="button button-icon icon ion-minus-circled" ng-href="{{url}}/mod/data/view.php?d={{entry.dataid}}&disapprove={{entry.id}}" mm-link capture-link="true" title="{{ 'mma.mod_data.disapprove' | translate }}"></a>
77

www/addons/mod/lesson/lang/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"emptypassword": "Password cannot be empty",
2323
"enterpassword": "Please enter the password:",
2424
"eolstudentoutoftimenoanswers": "You did not answer any questions. You have received a 0 for this lesson.",
25-
"errorprefetchrandombranch": "This lesson contains a jump to a random content page, it cannot be attempted in the app until it has been started in web.",
25+
"errorprefetchrandombranch": "This lesson contains a jump to a random content page. It can't be attempted in the app until it has been started in a web browser.",
2626
"errorreviewretakenotlast": "This attempt can no longer be reviewed because another attempt has been finished.",
2727
"finish": "Finish",
2828
"finishretakeoffline": "This attempt was finished offline.",

www/core/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"refresh": "Refresh",
164164
"required": "Required",
165165
"requireduserdatamissing": "This user lacks some required profile data. Please, fill this data in your Moodle and try again.<br>{{$a}}",
166+
"restore": "Restore",
166167
"retry": "Retry",
167168
"save": "Save",
168169
"search": " Search...",

0 commit comments

Comments
 (0)