Skip to content

Commit 7625160

Browse files
authored
Merge pull request #1109 from dpalou/MOBILE-2178
Mobile 2178
2 parents 701d42b + d1d53d1 commit 7625160

File tree

27 files changed

+194
-118
lines changed

27 files changed

+194
-118
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,15 @@ angular.module('mm.addons.mod_data')
214214

215215
// Refresh entry on sync.
216216
syncObserver = $mmEvents.on(mmaModDataEventAutomSynced, function(eventData) {
217-
if (eventData.entryid == entryId && data.id == eventData.dataid && $mmSite.getId() == eventData.siteid) {
217+
if ((eventData.entryid == entryId || eventData.offlineentryid == entryId) && data.id == eventData.dataid &&
218+
$mmSite.getId() == eventData.siteid) {
218219
if (eventData.deleted) {
219220
// If deleted, go back.
220221
$ionicHistory.goBack();
221222
} else {
223+
entryId = eventData.entryid;
222224
$scope.databaseLoaded = false;
223-
return fetchEntryData(true);
225+
fetchEntryData(true);
224226
}
225227
}
226228
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ angular.module('mm.addons.mod_data')
191191
}
192192
}).then(function(entries) {
193193
var numEntries = (entries && entries.entries && entries.entries.length) || 0;
194-
$scope.isEmpty = !numEntries && Object.keys($scope.offlineActions).length <= 0;
194+
$scope.isEmpty = !numEntries && !Object.keys($scope.offlineActions).length && !Object.keys($scope.offlineEntries).length;
195195
$scope.hasNextPage = numEntries >= mmaModDataPerPage && (($scope.search.page + 1) * mmaModDataPerPage) < entries.totalcount;
196196
$scope.entriesRendered = "";
197197

@@ -439,7 +439,7 @@ angular.module('mm.addons.mod_data')
439439
// Update just when all database is synced.
440440
if (data.id == eventData.dataid && siteId == eventData.siteid && typeof eventData.entryid == "undefined") {
441441
$scope.databaseLoaded = false;
442-
return fetchDatabaseData(true);
442+
fetchDatabaseData(true);
443443
}
444444
});
445445

www/addons/mod/data/fields/checkbox/directive.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
angular.module('mm.addons.mod_data')
1616

17+
.filter('mmaModDataFieldCheckboxFormat', function() {
18+
return function(text) {
19+
return text.split("##").join("<br>");
20+
};
21+
})
22+
1723
/**
1824
* Directive to render data checkbox field.
1925
*
@@ -29,7 +35,6 @@ angular.module('mm.addons.mod_data')
2935
link: function(scope) {
3036
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
3137
if (scope.mode == 'show') {
32-
scope.text = scope.value && scope.value.content ? scope.value.content.split("##").join("<br>") : "";
3338
return;
3439
}
3540

www/addons/mod/data/fields/checkbox/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
<ion-checkbox ng-repeat="option in options" name="f_{{field.id}}" ng-value="option" ng-model="values[option]">{{ option }}</ion-checkbox>
55
<ion-checkbox ng-if="mode == 'search'" name="f_{{field.id}}_allreq" ng-value="1">{{ 'mma.mod_data.selectedrequired' | translate }}</ion-checkbox>
66
</ion-list>
7-
<mm-format-text ng-if="mode == 'show'" watch="true">{{ text }}</mm-format-text>
7+
<mm-format-text ng-if="mode == 'show' && value && value.content" watch="true">{{ value.content | mmaModDataFieldCheckboxFormat }}</mm-format-text>

www/addons/mod/data/fields/date/directive.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
angular.module('mm.addons.mod_data')
1616

17+
.filter('mmaModDataFieldDateFormat', function() {
18+
return function(text) {
19+
return text * 1000;
20+
};
21+
})
22+
1723
/**
1824
* Directive to render data date field.
1925
*
@@ -29,7 +35,6 @@ angular.module('mm.addons.mod_data')
2935
link: function(scope) {
3036
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
3137
if (scope.mode == 'show') {
32-
scope.text = scope.value ? scope.value.content * 1000 : "";
3338
return;
3439
}
3540

www/addons/mod/data/fields/date/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<span class="assertive mm-data-error" ng-if="error && mode == 'edit'">{{ error }}</span>
33
<input ng-if="mode != 'show'" type="date" placeholder="{{ 'mm.core.date' | translate }}" name="f_{{field.id}}" ng-disabled="!enable && mode == 'search'" ng-model="val"> <!-- Use ng-model because iOS doesn't seem to like ng-value. -->
44
<ion-checkbox ng-if="mode == 'search'" name="f_{{field.id}}_z" ng-model="enable" ng-value="1">{{ 'mma.mod_data.usedate' | translate }}</ion-checkbox>
5-
<mm-format-text ng-if="mode == 'show'" watch="true">{{ text | mmFormatDate:"dfdaymonthyear" }}</mm-format-text>
5+
<mm-format-text ng-if="mode == 'show' && value && value.content" watch="true">{{ value.content | mmaModDataFieldDateFormat | mmFormatDate:"dfdaymonthyear" }}</mm-format-text>

www/addons/mod/data/fields/file/directive.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ angular.module('mm.addons.mod_data')
2222
* @name mmaModDataFieldFile
2323
*/
2424
.directive('mmaModDataFieldFile', function($mmFileSession, mmaModDataComponent) {
25+
26+
/**
27+
* Get the files from the input value.
28+
*
29+
* @param {Object} value Input value.
30+
* @return {Object[]} List of files.
31+
*/
32+
function getFiles(value) {
33+
var files = (value && value.files) || [];
34+
35+
// Reduce to first element.
36+
if (files.length > 0) {
37+
files = [files[0]];
38+
}
39+
40+
return files;
41+
}
42+
2543
return {
2644
restrict: 'A',
2745
priority: 100,
@@ -32,14 +50,15 @@ angular.module('mm.addons.mod_data')
3250
scope.component = mmaModDataComponent;
3351
scope.componentId = scope.database.coursemodule;
3452

35-
scope.files = (scope.value && scope.value.files) || [];
36-
37-
// Reduce to first element.
38-
if (scope.files.length > 0) {
39-
scope.files = [scope.files[0]];
40-
}
53+
if (scope.mode == 'show') {
54+
// Displaying the list of files, watch the value to update the list if it changes.
55+
scope.$watch('value', function(newValue) {
56+
scope.files = getFiles(newValue);
57+
});
58+
} else {
59+
// Edit mode, the list shouldn't change so there is no need to watch it.
60+
scope.files = getFiles(scope.value);
4161

42-
if (scope.mode == 'edit') {
4362
scope.maxSizeBytes = parseInt(scope.field.param3, 10);
4463
$mmFileSession.setFiles(mmaModDataComponent, scope.database.id + '_' + scope.field.id, scope.files);
4564
}

www/addons/mod/data/fields/latlong/directive.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@
1414

1515
angular.module('mm.addons.mod_data')
1616

17+
.filter('mmaModDataFieldLatLongFormat', function() {
18+
return function(value) {
19+
var north = (value && parseFloat(value.content)) || "",
20+
east = (value && parseFloat(value.content1)) || "";
21+
22+
if (north !== '' || east !== '') {
23+
north = north ? north.toFixed(4) : '0.0000';
24+
east = east ? east.toFixed(4) : '0.0000';
25+
26+
var latitude = north < 0 ? -north + '°S' : north + '°N',
27+
longitude = east < 0 ? -east + '°W' : east + '°E',
28+
link = ionic.Platform.isAndroid() ? 'geo:' + north + ',' + east :
29+
'http://maps.apple.com/?ll=' + north + ',' + east + '&near=' + north + ',' + east;
30+
31+
return '<a href="' + link + '">' + latitude + ' ' + longitude + '</a>';
32+
}
33+
};
34+
})
35+
1736
/**
1837
* Directive to render data latlong field.
1938
*
@@ -29,22 +48,9 @@ angular.module('mm.addons.mod_data')
2948
link: function(scope) {
3049
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
3150
if (scope.value) {
32-
scope.north = (scope.value && parseFloat(scope.value.content)) || "";
33-
scope.east = (scope.value && parseFloat(scope.value.content1)) || "";
34-
35-
if (scope.mode == 'show') {
36-
if (scope.north != "" || scope.east != "") {
37-
scope.north = scope.north ? parseFloat(scope.north).toFixed(4) : '0.0000';
38-
scope.east = scope.east ? parseFloat(scope.east).toFixed(4) : '0.0000';
39-
scope.latitude = scope.north < 0 ? -scope.north + '°S' : scope.north + '°N';
40-
scope.longitude = scope.east < 0 ? -scope.east + '°W' : scope.east + '°E';
41-
42-
if (ionic.Platform.isIOS()) {
43-
scope.link = "http://maps.apple.com/?ll=" + scope.north + "," + scope.east + "&near=" + scope.north + "," + scope.east;
44-
} else {
45-
scope.link = "geo:"+scope.north+","+scope.east;
46-
}
47-
}
51+
if (scope.mode == 'edit') {
52+
scope.north = (scope.value && parseFloat(scope.value.content)) || "";
53+
scope.east = (scope.value && parseFloat(scope.value.content1)) || "";
4854
}
4955
}
5056
}

www/addons/mod/data/fields/latlong/template.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@
1010
<span class="placeholder-icon">°E</span>
1111
</label>
1212

13-
<a ng-href="{{link}}" ng-if="mode == 'show' && latitude">
14-
{{latitude}} {{longitude}}
15-
</label>
13+
<span ng-if="mode == 'show' && value" ng-bind-html="value | mmaModDataFieldLatLongFormat"></span>

www/addons/mod/data/fields/menu/directive.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ angular.module('mm.addons.mod_data')
2929
link: function(scope) {
3030
scope.mode = scope.mode == 'list' ? 'show' : scope.mode;
3131
if (scope.mode == 'show') {
32-
scope.text = scope.value ? scope.value.content : "";
3332
return;
3433
}
3534

0 commit comments

Comments
 (0)