Skip to content

Commit 59f8e58

Browse files
authored
Merge pull request #934 from crazyserver/MOBILE-1987
Mobile 1987
2 parents 82cc19f + a30dacd commit 59f8e58

File tree

8 files changed

+93
-31
lines changed

8 files changed

+93
-31
lines changed

www/addons/mod/folder/templates/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<mm-context-menu-item priority="500" ng-if="size" content="size" icon-description="'ion-cube'" icon-action="'ion-trash-a'" action="removeFiles()"></mm-context-menu-item>
1010
</mm-context-menu>
1111
</ion-nav-buttons>
12-
<ion-content padding="true" mm-state-class>
12+
<ion-content mm-state-class>
1313
<ion-refresher pulling-text="{{ 'mm.core.pulltorefresh' | translate }}" ng-if="canReload" on-refresh="refreshFolder()"></ion-refresher>
1414
<mm-loading hide-until="folderLoaded">
1515
<mm-course-mod-description description="description" component="{{component}}" component-id="{{componentId}}" watch="true"></mm-course-mod-description>
@@ -22,7 +22,7 @@
2222
</a>
2323
</li>
2424
</ul>
25-
<div ng-if="!contents || contents.length == 0">
25+
<div class="padding" ng-if="!contents || contents.length == 0">
2626
<p>{{ 'mma.mod_folder.emptyfilelist' | translate}}</p>
2727
</div>
2828
</mm-loading>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ angular.module('mm.addons.mod_glossary')
142142
attachments = $scope.attachments;
143143

144144
// Upload attachments first if any.
145-
if (attachments.length) {
145+
if (!!attachments.length) {
146146
return $mmaModGlossaryHelper.uploadOrStoreFiles(glossaryId, concept, timecreated, attachments, false)
147147
.catch(function() {
148148
// Cannot upload them in online, save them in offline.
@@ -174,7 +174,7 @@ angular.module('mm.addons.mod_glossary')
174174
var promise;
175175
if (entry && !allowDuplicateEntries) {
176176
// Check if the entry is duplicated in online or offline mode.
177-
promise = $mmaModGlossary.isConceptUsed(glossaryId, concept).then(function() {
177+
promise = $mmaModGlossary.isConceptUsed(glossaryId, concept, entry.timecreated).then(function() {
178178
// There's a entry with same name, reject with error message.
179179
return $mmLang.translateAndReject('mma.mod_glossary.errconceptalreadyexists');
180180
}, function() {
@@ -195,7 +195,7 @@ angular.module('mm.addons.mod_glossary')
195195
// Try to send it to server.
196196
// Don't allow offline if there are attachments since they were uploaded fine.
197197
return $mmaModGlossary.addEntry(glossaryId, concept, definition, courseId, options, attach, undefined,
198-
entry, !attachments.length);
198+
entry, !attachments.length, !allowDuplicateEntries);
199199
}
200200
}).then(function(entryId) {
201201
if (entryId) {

www/addons/mod/glossary/services/glossary.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -758,18 +758,20 @@ angular.module('mm.addons.mod_glossary')
758758
* @module mm.addons.mod_glossary
759759
* @ngdoc method
760760
* @name $mmaModGlossary#addEntry
761-
* @param {Number} glossaryId Glossary ID.
762-
* @param {String} concept Glossary entry concept.
763-
* @param {String} definition Glossary entry concept definition.
764-
* @param {Number} courseId Course ID of the glossary.
765-
* @param {Array} [options] Array of options for the entry.
766-
* @param {Mixed} [attach] Attachments ID if sending online, result of $mmFileUploader#storeFilesToUpload otherwise.
767-
* @param {String} [siteId] Site ID. If not defined, current site.
768-
* @param {Object} [discardEntry] The entry provided will be discarded if found.
769-
* @param {Boolean} allowOffline True if it can be stored in offline, false otherwise.
761+
* @param {Number} glossaryId Glossary ID.
762+
* @param {String} concept Glossary entry concept.
763+
* @param {String} definition Glossary entry concept definition.
764+
* @param {Number} courseId Course ID of the glossary.
765+
* @param {Array} [options] Array of options for the entry.
766+
* @param {Mixed} [attach] Attachments ID if sending online, result of $mmFileUploader#storeFilesToUpload otherwise.
767+
* @param {String} [siteId] Site ID. If not defined, current site.
768+
* @param {Object} [discardEntry] The entry provided will be discarded if found.
769+
* @param {Boolean} allowOffline True if it can be stored in offline, false otherwise.
770+
* @param {Boolean} [checkDuplicates] Check for duplicates before storing offline. Only used if allowOffline is true.
770771
* @return {Promise} Promise resolved with entry ID if entry was created in server, false if stored in device.
771772
*/
772-
self.addEntry = function(glossaryId, concept, definition, courseId, options, attach, siteId, discardEntry, allowOffline) {
773+
self.addEntry = function(glossaryId, concept, definition, courseId, options, attach, siteId, discardEntry, allowOffline,
774+
checkDuplicates) {
773775
siteId = siteId || $mmSite.getId();
774776

775777
if (!$mmApp.isOnline() && allowOffline) {
@@ -798,8 +800,10 @@ angular.module('mm.addons.mod_glossary')
798800

799801
// Convenience function to store a new entry to be synchronized later.
800802
function storeOffline() {
803+
var timecreated = discardEntry && discardEntry.timecreated,
804+
duplicatesPromise = checkDuplicates ? self.isConceptUsed(glossaryId, concept, timecreated, siteId) : $q.when(false);
801805
// Check if the entry is duplicated in online or offline mode.
802-
return self.isConceptUsed(glossaryId, concept, siteId).then(function(used) {
806+
return duplicatesPromise.then(function(used) {
803807
if (used) {
804808
return $mmLang.translateAndReject('mma.mod_glossary.errconceptalreadyexists');
805809
}
@@ -882,14 +886,15 @@ angular.module('mm.addons.mod_glossary')
882886
* @module mm.addons.mod_glossary
883887
* @ngdoc method
884888
* @name $mmaModGlossary#isConceptUsed
885-
* @param {Number} glossaryId Glossary ID.
886-
* @param {String} concept Concept to check.
887-
* @param {String} [siteId] Site ID. If not defined, current site.
888-
* @return {Promise} Promise resolved with true if used, resolved with false if not used or error.
889+
* @param {Number} glossaryId Glossary ID.
890+
* @param {String} concept Concept to check.
891+
* @param {Number} [timecreated] Timecreated to check that is not the timecreated we are editing.
892+
* @param {String} [siteId] Site ID. If not defined, current site.
893+
* @return {Promise} Promise resolved with true if used, resolved with false if not used or error.
889894
*/
890-
self.isConceptUsed = function(glossaryId, concept, siteId) {
895+
self.isConceptUsed = function(glossaryId, concept, timecreated, siteId) {
891896
// Check offline first.
892-
return $mmaModGlossaryOffline.isConceptUsed(glossaryId, concept, siteId).then(function(exists) {
897+
return $mmaModGlossaryOffline.isConceptUsed(glossaryId, concept, timecreated, siteId).then(function(exists) {
893898
if (exists) {
894899
return true;
895900
}

www/addons/mod/glossary/services/glossary_offline.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ angular.module('mm.addons.mod_glossary')
5252
* @ngdoc service
5353
* @name $mmaModGlossaryOffline
5454
*/
55-
.factory('$mmaModGlossaryOffline', function($mmSitesManager, $log, mmaModGlossaryAddEntryStore, $mmFS, $q) {
55+
.factory('$mmaModGlossaryOffline', function($mmSitesManager, $log, mmaModGlossaryAddEntryStore, $mmFS, $q, $mmUtil) {
5656
$log = $log.getInstance('$mmaModGlossaryOffline');
5757

5858
var self = {};
@@ -132,16 +132,24 @@ angular.module('mm.addons.mod_glossary')
132132
* @module mm.addons.mod_glossary
133133
* @ngdoc method
134134
* @name $mmaModGlossaryOffline#isConceptUsed
135-
* @param {Number} glossaryId Glossary ID.
136-
* @param {String} concept Concept to check.
137-
* @param {String} [siteId] Site ID. If not defined, current site.
138-
* @return {Promise} Promise resolved with true if concept is found, false otherwise.
135+
* @param {Number} glossaryId Glossary ID.
136+
* @param {String} concept Concept to check.
137+
* @param {Number} [timecreated] Timecreated to check that is not the timecreated we are editing.
138+
* @param {String} [siteId] Site ID. If not defined, current site.
139+
* @return {Promise} Promise resolved with true if concept is found, false otherwise.
139140
*/
140-
self.isConceptUsed = function(glossaryId, concept, siteId) {
141+
self.isConceptUsed = function(glossaryId, concept, timecreated, siteId) {
141142
return $mmSitesManager.getSite(siteId).then(function(site) {
142143
return site.getDb().whereEqual(mmaModGlossaryAddEntryStore, 'glossaryAndConcept', [glossaryId, concept])
143144
.then(function(entries) {
144-
return !!entries.length;
145+
if (!!entries.length) {
146+
if (entries.length > 1 || !timecreated) {
147+
return true;
148+
}
149+
// If there's only one entry, check that is not the one we are editing.
150+
return $mmUtil.promiseFails(self.getAddEntry(glossaryId, concept, timecreated, siteId));
151+
}
152+
return false;
145153
});
146154
}).catch(function() {
147155
// No offline data found, return false.

www/core/components/login/controllers/site.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ angular.module('mm.core.login')
8888
$scope.issue = issue;
8989
var popup = $ionicPopup.show({
9090
templateUrl: 'core/components/login/templates/login-issue.html',
91-
scope: $scope
91+
scope: $scope,
92+
cssClass: 'mm-nohead mm-bigpopup'
9293
});
9394

9495
$scope.closePopup = function() {

www/core/directives/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ angular.module('mm.core')
233233
});
234234
} else {
235235
// File doesn't need to be opened (it's a prefetch). Show confirm modal if file size is defined and it's big.
236-
promise = fileSize ? $mmUtil.confirmDownloadSize(fileSize) : $q.when();
236+
promise = fileSize ? $mmUtil.confirmDownloadSize({size: fileSize, total: true}) : $q.when();
237237
promise.then(function() {
238238
// User confirmed, add the file to queue.
239239
$mmFilepool.invalidateFileByUrl(siteId, fileUrl).finally(function() {

www/core/lib/util.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,9 @@ angular.module('mm.core')
773773

774774
options.template = addFormatTextIfNeeded(template); // Add format-text to handle links.
775775
options.title = title;
776+
if (!title) {
777+
options.cssClass = 'mm-nohead';
778+
}
776779
return $ionicPopup.confirm(options).then(function(confirmed) {
777780
if (!confirmed) {
778781
return $q.reject();
@@ -1200,6 +1203,40 @@ angular.module('mm.core')
12001203
return deferred.promise;
12011204
};
12021205

1206+
/**
1207+
* Check if a promise works and returns true if resolves or false if rejects.
1208+
*
1209+
* @module mm.core
1210+
* @ngdoc method
1211+
* @name $mmUtil#promiseWorks
1212+
* @param {Promise} promise Promise to check
1213+
* @return {Promise} Promise resolved with true if the promises resolves and false if rejects.
1214+
*/
1215+
self.promiseWorks = function(promise) {
1216+
return promise.then(function() {
1217+
return true;
1218+
}).catch(function() {
1219+
return false;
1220+
});
1221+
};
1222+
1223+
/**
1224+
* Check if a promise works and returns true if rejects or false if resolves.
1225+
*
1226+
* @module mm.core
1227+
* @ngdoc method
1228+
* @name $mmUtil#promiseFails
1229+
* @param {Promise} promise Promise to check
1230+
* @return {Promise} Promise resolved with true if the promises rejects and false if resolves.
1231+
*/
1232+
self.promiseFails = function(promise) {
1233+
return promise.then(function() {
1234+
return false;
1235+
}).catch(function() {
1236+
return true;
1237+
});
1238+
};
1239+
12031240
/**
12041241
* Compare two objects. This function won't compare functions and proto properties, it's a basic compare.
12051242
* Also, this will only check if itemA's properties are in itemB with same value. This function will still

www/core/scss/styles.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,17 @@ mm-timer {
688688

689689
.popover.mm-context-menu {
690690
width: 320px;
691+
max-width: 100%;
692+
}
693+
694+
.popup-container.mm-nohead .popup-head {
695+
display: none;
696+
}
697+
698+
.popup-container.mm-bigpopup .popup {
699+
width: 90%; // Fallback of calc.
700+
width: calc(100% - 20px);
701+
max-width: none;
691702
}
692703

693704
// Inline icons and inputs.

0 commit comments

Comments
 (0)