@@ -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 }
0 commit comments