@@ -24,7 +24,7 @@ angular.module('mm.addons.mod_glossary')
2424. controller ( 'mmaModGlossaryIndexCtrl' , function ( $q , $scope , $stateParams , $ionicPopover , $mmUtil , $mmCourseHelper , $mmaModGlossary ,
2525 $ionicScrollDelegate , $translate , $mmText , mmaModGlossaryComponent , mmaModGlossaryLimitEntriesNum , $state , $mmCourse ,
2626 $mmaModGlossaryOffline , $mmEvents , mmaModGlossaryAddEntryEvent , mmCoreEventOnlineStatusChanged , $mmApp , $mmSite ,
27- mmaModGlossaryAutomSyncedEvent , $mmaModGlossarySync ) {
27+ mmaModGlossaryAutomSyncedEvent , $mmaModGlossarySync , mmaModGlossaryShowAllCategories ) {
2828
2929 var module = $stateParams . module || { } ,
3030 courseId = $stateParams . courseid ,
@@ -35,7 +35,7 @@ angular.module('mm.addons.mod_glossary')
3535 popover ,
3636 popoverScope ,
3737 viewMode , // The archetype of view (letter, date, author, cat).
38- fetchMode = 'letter_all' , // Default.
38+ fetchMode , // Default.
3939 fetchFunction ,
4040 fetchInvalidate ,
4141 fetchArguments ,
@@ -72,25 +72,27 @@ angular.module('mm.addons.mod_glossary')
7272 $scope . description = glossary . intro || module . description ;
7373 $scope . canAdd = ( $mmaModGlossary . isPluginEnabledForEditing ( ) && glossary . canaddentry ) || false ;
7474
75+ // Preparing browse modes.
7576 var browseModes = [
76- {
77- key : 'letter_all' ,
78- langkey : 'mma.mod_glossary.byalphabet'
79- } ,
80- {
81- key : 'search' ,
82- langkey : 'mma.mod_glossary.bysearch'
83- }
77+ { key : 'search' , langkey : 'mma.mod_glossary.bysearch' }
8478 ] ;
85-
86- // Preparing browse modes.
87- if ( glossary . browsemodes . indexOf ( 'date' ) >= 0 ) {
88- browseModes . push ( { key : 'newest_first' , langkey : 'mma.mod_glossary.bynewestfirst' } ) ;
89- browseModes . push ( { key : 'recently_updated' , langkey : 'mma.mod_glossary.byrecentlyupdated' } ) ;
90- }
91- if ( glossary . browsemodes . indexOf ( 'author' ) >= 0 ) {
92- browseModes . push ( { key : 'author_all' , langkey : 'mma.mod_glossary.byauthor' } ) ;
93- }
79+ angular . forEach ( glossary . browsemodes , function ( mode ) {
80+ switch ( mode ) {
81+ case 'letter' :
82+ browseModes . push ( { key : 'letter_all' , langkey : 'mma.mod_glossary.byalphabet' } ) ;
83+ break ;
84+ case 'cat' :
85+ browseModes . push ( { key : 'cat_all' , langkey : 'mma.mod_glossary.bycategory' } ) ;
86+ break ;
87+ case 'date' :
88+ browseModes . push ( { key : 'newest_first' , langkey : 'mma.mod_glossary.bynewestfirst' } ) ;
89+ browseModes . push ( { key : 'recently_updated' , langkey : 'mma.mod_glossary.byrecentlyupdated' } ) ;
90+ break ;
91+ case 'author' :
92+ browseModes . push ( { key : 'author_all' , langkey : 'mma.mod_glossary.byauthor' } ) ;
93+ break ;
94+ }
95+ } ) ;
9496
9597 // Preparing the popover.
9698 if ( ! popoverScope ) {
@@ -105,8 +107,6 @@ angular.module('mm.addons.mod_glossary')
105107 } ) ;
106108 }
107109 } ) . then ( function ( ) {
108- // Preparing the initial mode.
109- switchMode ( ) ;
110110
111111 return fetchEntries ( ) . then ( function ( ) {
112112 // All data obtained, now fill the context menu.
@@ -205,7 +205,6 @@ angular.module('mm.addons.mod_glossary')
205205 }
206206
207207 $scope . pickMode = function ( e ) {
208- popoverScope . data . selectedMode = fetchMode ;
209208 popover . show ( e ) ;
210209 } ;
211210
@@ -306,8 +305,11 @@ angular.module('mm.addons.mod_glossary')
306305
307306 // Preparing the popover.
308307 function initSortMenu ( ) {
308+ // Preparing the initial mode.
309+ switchMode ( 'letter_all' ) ;
310+
309311 popoverScope = $scope . $new ( true ) ;
310- popoverScope . data = { selectedMode : '' } ;
312+ popoverScope . data = { selectedMode : fetchMode } ;
311313
312314 popoverScope . modePicked = function ( mode ) {
313315 $scope . loadingMessage = loadingMessage ;
@@ -324,13 +326,15 @@ angular.module('mm.addons.mod_glossary')
324326 $scope . canLoadMore = false ;
325327 $scope . showNoEntries = false ;
326328 }
329+ popoverScope . data . selectedMode = fetchMode ;
327330 popover . hide ( ) ;
328331 } ;
329332
330333 return $ionicPopover . fromTemplateUrl ( 'addons/mod/glossary/templates/mode_picker.html' , {
331334 scope : popoverScope
332335 } ) . then ( function ( po ) {
333336 popover = po ;
337+ $scope . sortMenuInit = true ;
334338 } ) ;
335339 }
336340
@@ -376,68 +380,87 @@ angular.module('mm.addons.mod_glossary')
376380 fetchMode = mode ;
377381 $scope . isSearch = false ;
378382
379- // Browse by author.
380- if ( mode == 'author_all' ) {
381- viewMode = 'author' ;
382- fetchFunction = $mmaModGlossary . getEntriesByAuthor ;
383- fetchInvalidate = $mmaModGlossary . invalidateEntriesByAuthor ;
384- fetchArguments = [ glossary . id , 'ALL' , 'LASTNAME' , 'ASC' ] ;
385- $scope . getDivider = function ( entry ) {
386- return entry . userfullname ;
387- } ;
388- $scope . showDivider = function ( entry , previous ) {
389- if ( typeof previous === 'undefined' ) {
390- return true ;
391- }
392- return entry . userid != previous . userid ;
393- } ;
394-
395- // Newest first.
396- } else if ( mode == 'newest_first' ) {
397- viewMode = 'date' ;
398- fetchFunction = $mmaModGlossary . getEntriesByDate ;
399- fetchInvalidate = $mmaModGlossary . invalidateEntriesByDate ;
400- fetchArguments = [ glossary . id , 'CREATION' , 'DESC' ] ;
401- $scope . getDivider = noop ;
402- $scope . showDivider = function ( ) { return false ; } ;
403-
404- // Recently updated.
405- } else if ( mode == 'recently_updated' ) {
406- viewMode = 'date' ;
407- fetchFunction = $mmaModGlossary . getEntriesByDate ;
408- fetchInvalidate = $mmaModGlossary . invalidateEntriesByDate ;
409- fetchArguments = [ glossary . id , 'UPDATE' , 'DESC' ] ;
410- $scope . getDivider = noop ;
411- $scope . showDivider = function ( ) { return false ; } ;
412-
413- // Search for entries.
414- } else if ( mode == 'search' ) {
415- viewMode = 'search' ;
416- fetchFunction = $mmaModGlossary . getEntriesBySearch ;
417- fetchInvalidate = $mmaModGlossary . invalidateEntriesBySearch ;
418- fetchArguments = false ; // Dynamically set later.
419- $scope . isSearch = true ;
420- $scope . getDivider = noop ;
421- $scope . showDivider = function ( ) { return false ; } ;
422- instantFetch = false ;
423-
424- // Consider it is 'letter_all'.
425- } else {
426- viewMode = 'letter' ;
427- fetchMode = 'letter_all' ;
428- fetchFunction = $mmaModGlossary . getEntriesByLetter ;
429- fetchInvalidate = $mmaModGlossary . invalidateEntriesByLetter ;
430- fetchArguments = [ glossary . id , 'ALL' ] ;
431- $scope . getDivider = function ( entry ) {
432- return entry . concept . substr ( 0 , 1 ) . toUpperCase ( ) ;
433- } ;
434- $scope . showDivider = function ( entry , previous ) {
435- if ( typeof previous === 'undefined' ) {
436- return true ;
437- }
438- return $scope . getDivider ( entry ) != $scope . getDivider ( previous ) ;
439- } ;
440- }
383+ switch ( mode ) {
384+ case 'author_all' :
385+ // Browse by author.
386+ viewMode = 'author' ;
387+ fetchFunction = $mmaModGlossary . getEntriesByAuthor ;
388+ fetchInvalidate = $mmaModGlossary . invalidateEntriesByAuthor ;
389+ fetchArguments = [ glossary . id , 'ALL' , 'LASTNAME' , 'ASC' ] ;
390+ $scope . getDivider = function ( entry ) {
391+ return entry . userfullname ;
392+ } ;
393+ $scope . showDivider = function ( entry , previous ) {
394+ if ( typeof previous === 'undefined' ) {
395+ return true ;
396+ }
397+ return entry . userid != previous . userid ;
398+ } ;
399+ break ;
400+ case 'cat_all' :
401+ // Browse by category.
402+ viewMode = 'cat' ;
403+ fetchFunction = $mmaModGlossary . getEntriesByCategory ;
404+ fetchInvalidate = $mmaModGlossary . invalidateEntriesByCategory ;
405+ fetchArguments = [ glossary . id , mmaModGlossaryShowAllCategories ] ;
406+ $scope . getDivider = function ( entry ) {
407+ return entry . categoryname ;
408+ } ;
409+ $scope . showDivider = function ( entry , previous ) {
410+ if ( typeof previous === 'undefined' ) {
411+ return true ;
412+ }
413+ return $scope . getDivider ( entry ) != $scope . getDivider ( previous ) ;
414+ } ;
415+ break ;
416+ case 'newest_first' :
417+ // Newest first.
418+ viewMode = 'date' ;
419+ fetchFunction = $mmaModGlossary . getEntriesByDate ;
420+ fetchInvalidate = $mmaModGlossary . invalidateEntriesByDate ;
421+ fetchArguments = [ glossary . id , 'CREATION' , 'DESC' ] ;
422+ $scope . getDivider = noop ;
423+ $scope . showDivider = function ( ) { return false ; } ;
424+ break ;
425+ case 'recently_updated' :
426+ // Recently updated.
427+ viewMode = 'date' ;
428+ fetchFunction = $mmaModGlossary . getEntriesByDate ;
429+ fetchInvalidate = $mmaModGlossary . invalidateEntriesByDate ;
430+ fetchArguments = [ glossary . id , 'UPDATE' , 'DESC' ] ;
431+ $scope . getDivider = noop ;
432+ $scope . showDivider = function ( ) { return false ; } ;
433+ break ;
434+ case 'search' :
435+ // Search for entries.
436+ viewMode = 'search' ;
437+ fetchFunction = $mmaModGlossary . getEntriesBySearch ;
438+ fetchInvalidate = $mmaModGlossary . invalidateEntriesBySearch ;
439+ fetchArguments = false ; // Dynamically set later.
440+ $scope . isSearch = true ;
441+ $scope . getDivider = noop ;
442+ $scope . showDivider = function ( ) { return false ; } ;
443+ instantFetch = false ;
444+ break ;
445+ case 'letter_all' :
446+ default :
447+ // Consider it is 'letter_all'.
448+ viewMode = 'letter' ;
449+ fetchMode = 'letter_all' ;
450+ fetchFunction = $mmaModGlossary . getEntriesByLetter ;
451+ fetchInvalidate = $mmaModGlossary . invalidateEntriesByLetter ;
452+ fetchArguments = [ glossary . id , 'ALL' ] ;
453+ $scope . getDivider = function ( entry ) {
454+ return entry . concept . substr ( 0 , 1 ) . toUpperCase ( ) ;
455+ } ;
456+ $scope . showDivider = function ( entry , previous ) {
457+ if ( typeof previous === 'undefined' ) {
458+ return true ;
459+ }
460+ return $scope . getDivider ( entry ) != $scope . getDivider ( previous ) ;
461+ } ;
462+ break ;
463+ }
441464
442465 return instantFetch ;
443466 }
0 commit comments