Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions www/addons/mod/data/controllers/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions www/addons/mod/data/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down Expand Up @@ -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);
}
});

Expand Down
7 changes: 6 additions & 1 deletion www/addons/mod/data/fields/checkbox/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

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

.filter('mmaModDataFieldCheckboxFormat', function() {
return function(text) {
return text.split("##").join("<br>");
};
})

/**
* Directive to render data checkbox field.
*
Expand All @@ -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("<br>") : "";
return;
}

Expand Down
2 changes: 1 addition & 1 deletion www/addons/mod/data/fields/checkbox/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<ion-checkbox ng-repeat="option in options" name="f_{{field.id}}" ng-value="option" ng-model="values[option]">{{ option }}</ion-checkbox>
<ion-checkbox ng-if="mode == 'search'" name="f_{{field.id}}_allreq" ng-value="1">{{ 'mma.mod_data.selectedrequired' | translate }}</ion-checkbox>
</ion-list>
<mm-format-text ng-if="mode == 'show'" watch="true">{{ text }}</mm-format-text>
<mm-format-text ng-if="mode == 'show' && value && value.content" watch="true">{{ value.content | mmaModDataFieldCheckboxFormat }}</mm-format-text>
7 changes: 6 additions & 1 deletion www/addons/mod/data/fields/date/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion www/addons/mod/data/fields/date/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<span class="assertive mm-data-error" ng-if="error && mode == 'edit'">{{ error }}</span>
<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. -->
<ion-checkbox ng-if="mode == 'search'" name="f_{{field.id}}_z" ng-model="enable" ng-value="1">{{ 'mma.mod_data.usedate' | translate }}</ion-checkbox>
<mm-format-text ng-if="mode == 'show'" watch="true">{{ text | mmFormatDate:"dfdaymonthyear" }}</mm-format-text>
<mm-format-text ng-if="mode == 'show' && value && value.content" watch="true">{{ value.content | mmaModDataFieldDateFormat | mmFormatDate:"dfdaymonthyear" }}</mm-format-text>
33 changes: 26 additions & 7 deletions www/addons/mod/data/fields/file/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
38 changes: 22 additions & 16 deletions www/addons/mod/data/fields/latlong/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<a href="' + link + '">' + latitude + ' ' + longitude + '</a>';
}
};
})

/**
* Directive to render data latlong field.
*
Expand All @@ -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)) || "";
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions www/addons/mod/data/fields/latlong/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
<span class="placeholder-icon">°E</span>
</label>

<a ng-href="{{link}}" ng-if="mode == 'show' && latitude">
{{latitude}} {{longitude}}
</label>
<span ng-if="mode == 'show' && value" ng-bind-html="value | mmaModDataFieldLatLongFormat"></span>
1 change: 0 additions & 1 deletion www/addons/mod/data/fields/menu/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion www/addons/mod/data/fields/menu/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<option ng-repeat="option in options" value="{{option}}">{{ option }}</option>
</select>
</div>
<mm-format-text ng-if="mode == 'show'" watch="true">{{ text }}</mm-format-text>
<mm-format-text ng-if="mode == 'show' && value && value.content" watch="true">{{ value.content }}</mm-format-text>
7 changes: 6 additions & 1 deletion www/addons/mod/data/fields/multimenu/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

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

.filter('mmaModDataFieldMultimenuFormat', function() {
return function(text) {
return text.split("##").join("<br>");
};
})

/**
* Directive to render data multimenu field.
*
Expand All @@ -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("<br>") : "";
return;
}

Expand Down
2 changes: 1 addition & 1 deletion www/addons/mod/data/fields/multimenu/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<span class="assertive mm-data-error" ng-if="error && mode == 'edit'">{{ error }}</span>
<mm-multiple-select ng-if="mode != 'show'" title="{{field.name}}" name="f_{{field.id}}" options="options"></mm-multiple-select>
<ion-checkbox ng-if="mode == 'search'" name="f_{{field.id}}_allreq" ng-value="1">{{ 'mma.mod_data.selectedrequired' | translate }}</ion-checkbox>
<mm-format-text ng-if="mode == 'show'" watch="true">{{ text }}</mm-format-text>
<mm-format-text ng-if="mode == 'show' && value && value.content" watch="true">{{ value.content | mmaModDataFieldMultimenuFormat }}</mm-format-text>
4 changes: 0 additions & 4 deletions www/addons/mod/data/fields/number/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion www/addons/mod/data/fields/number/template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span ng-if="mode == 'edit'" mm-mark-required="{{field.required}}"></span>
<span class="assertive mm-data-error" ng-if="error && mode == 'edit'">{{ error }}</span>
<input ng-if="mode != 'show'" type="number" placeholder="{{field.name}}" name="f_{{field.id}}" ng-model="val">
<mm-format-text ng-if="mode == 'show'" watch="true">{{ text }}</mm-format-text>
<mm-format-text ng-if="mode == 'show' && value && value.content" watch="true">{{ value.content }}</mm-format-text>
85 changes: 52 additions & 33 deletions www/addons/mod/data/fields/picture/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion www/addons/mod/data/fields/radiobutton/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion www/addons/mod/data/fields/radiobutton/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<option ng-repeat="option in options" value="{{option}}">{{ option }}</option>
</select>
</div>
<mm-format-text ng-if="mode == 'show'" watch="true">{{ text }}</mm-format-text>
<mm-format-text ng-if="mode == 'show' && value && value.content" watch="true">{{ value.content }}</mm-format-text>
4 changes: 0 additions & 4 deletions www/addons/mod/data/fields/text/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading