@@ -27,18 +27,19 @@ angular.module('mm.addons.mod_wiki')
2727 var module = $stateParams . module || { } ,
2828 courseId = $stateParams . courseid ,
2929 subwikiId = $stateParams . subwikiid || null ,
30- wikiId = null ,
30+ wikiId = $stateParams . wikiid || null ,
3131 pageId = $stateParams . pageid || null ,
3232 section = $stateParams . section || null ,
3333 originalContent = null ,
3434 editing = false ,
3535 version = false ,
36- groupId ,
37- userId ,
36+ groupId = $stateParams . groupid || null ,
37+ userId = $stateParams . userid || null ,
3838 rteEnabled ,
3939 subwikiFiles ,
4040 renewLockInterval ,
41- editOffline = false ;
41+ editOffline = false ,
42+ blockId = $mmaModWikiSync . subwikiBlockId ( subwikiId , wikiId , userId , groupId ) ;
4243
4344 // Block leaving the view, we want to show a confirm to the user if there's unsaved data.
4445 $mmUtil . blockLeaveView ( $scope , cancel ) ;
@@ -57,9 +58,9 @@ angular.module('mm.addons.mod_wiki')
5758 $scope . title = $scope . page . title ? $translate . instant ( 'mma.mod_wiki.editingpage' , { '$a' : $scope . page . title } ) :
5859 $translate . instant ( 'mma.mod_wiki.newpagehdr' ) ;
5960
60- if ( subwikiId ) {
61+ if ( blockId ) {
6162 // Block the subwiki ASAP.
62- $mmSyncBlock . blockOperation ( mmaModWikiComponent , subwikiId ) ;
63+ $mmSyncBlock . blockOperation ( mmaModWikiComponent , blockId ) ;
6364 }
6465
6566 $scope . save = function ( ) {
@@ -85,7 +86,7 @@ angular.module('mm.addons.mod_wiki')
8586
8687 if ( ! editOffline ) {
8788 // Check if the user has an offline page with the same title.
88- promise = $mmaModWikiOffline . getNewPage ( subwikiId , $scope . page . title ) . then ( function ( ) {
89+ promise = $mmaModWikiOffline . getNewPage ( $scope . page . title , subwikiId , wikiId , userId , groupId ) . then ( function ( ) {
8990 // There's a page with same name, reject with error message.
9091 return $mmLang . translateAndReject ( 'mma.mod_wiki.pageexists' ) ;
9192 } , function ( ) {
@@ -97,8 +98,8 @@ angular.module('mm.addons.mod_wiki')
9798
9899 promise = promise . then ( function ( ) {
99100 // Try to send the page.
100- var instanceId = module && module . instance ;
101- return $mmaModWiki . newPage ( subwikiId , $scope . page . title , text , instanceId ) . then ( function ( createdId ) {
101+ var wikiId = wikiId || ( module && module . instance ) ;
102+ return $mmaModWiki . newPage ( $scope . page . title , text , subwikiId , wikiId , userId , groupId ) . then ( function ( createdId ) {
102103 if ( createdId ) {
103104 // Page was created, get its data and go to the page.
104105 pageId = createdId ;
@@ -153,12 +154,15 @@ angular.module('mm.addons.mod_wiki')
153154 return retrieveModuleInfo ( wikiId ) . then ( function ( ) {
154155 var openPage = false ;
155156
156- if ( ! editing && editOffline && backViewPageIsDifferentOffline ( ) ) {
157- // The user submitted an offline page that isn't loaded in the back view, open it.
158- openPage = true ;
159- } else if ( ! editOffline && backViewIsDifferentPageOnline ( ) ) {
160- // The user submitted an offline page that isn't loaded in the back view, open it.
161- openPage = true ;
157+ // Not the firstpage.
158+ if ( $stateParams . subwikiid ) {
159+ if ( ! editing && editOffline && backViewPageIsDifferentOffline ( ) ) {
160+ // The user submitted an offline page that isn't loaded in the back view, open it.
161+ openPage = true ;
162+ } else if ( ! editOffline && backViewIsDifferentPageOnline ( ) ) {
163+ // The user submitted an offline page that isn't loaded in the back view, open it.
164+ openPage = true ;
165+ }
162166 }
163167
164168 if ( openPage ) {
@@ -249,7 +253,7 @@ angular.module('mm.addons.mod_wiki')
249253 userId = pageContents . userid ;
250254
251255 // Wait for sync to be over (if any).
252- return $mmaModWikiSync . waitForSync ( subwikiId ) ;
256+ return $mmaModWikiSync . waitForSync ( blockId ) ;
253257 } ) . then ( function ( ) {
254258 // Check if rich text editor is enabled.
255259 return $mmUtil . isRichTextEditorEnabled ( ) ;
@@ -284,12 +288,12 @@ angular.module('mm.addons.mod_wiki')
284288 } ) ;
285289 } else {
286290 // New page. Wait for sync to be over (if any).
287- promise = $mmaModWikiSync . waitForSync ( subwikiId ) ;
291+ promise = $mmaModWikiSync . waitForSync ( blockId ) ;
288292
289293 if ( $scope . page . title ) {
290294 // Check if there's already some offline data for this page.
291295 promise = promise . then ( function ( ) {
292- return $mmaModWikiOffline . getNewPage ( subwikiId , $scope . page . title ) ;
296+ return $mmaModWikiOffline . getNewPage ( $scope . page . title , subwikiId , wikiId , userId , groupId ) ;
293297 } ) . then ( function ( page ) {
294298 // Load offline content.
295299 $scope . page . text = page . cachedcontent ;
@@ -306,7 +310,7 @@ angular.module('mm.addons.mod_wiki')
306310 promise . then ( function ( ) {
307311 $scope . wikiLoaded = true ;
308312 editing = false ;
309- canEdit = ! ! subwikiId ; // If no subwikiId is received , the user cannot edit the page.
313+ canEdit = ! ! blockId ; // If no blockId , the user cannot edit the page.
310314 } ) ;
311315 }
312316 } else {
@@ -315,11 +319,7 @@ angular.module('mm.addons.mod_wiki')
315319 }
316320
317321 return promise . catch ( function ( message ) {
318- if ( message ) {
319- $mmUtil . showErrorModal ( message ) ;
320- } else {
321- $mmUtil . showErrorModal ( 'Error getting wiki data.' ) ;
322- }
322+ $mmUtil . showErrorModalDefault ( message , 'Error getting wiki data.' ) ;
323323
324324 return $ionicHistory . goBack ( ) ;
325325 } ) . finally ( function ( ) {
@@ -369,9 +369,14 @@ angular.module('mm.addons.mod_wiki')
369369 } ) ;
370370
371371 fetchWikiPageData ( ) . then ( function ( ) {
372- if ( subwikiId && ! $scope . $$destroyed ) {
373- // Block the subwiki now that we have subwikiId for sure.
374- $mmSyncBlock . blockOperation ( mmaModWikiComponent , subwikiId ) ;
372+ if ( blockId && ! $scope . $$destroyed ) {
373+ // Block the subwiki now that we have blockId for sure.
374+ var newBlockId = $mmaModWikiSync . subwikiBlockId ( subwikiId , wikiId , userId , groupId ) ;
375+ if ( newBlockId != blockId ) {
376+ $mmSyncBlock . unblockOperation ( mmaModWikiComponent , blockId ) ;
377+ blockId = newBlockId ;
378+ $mmSyncBlock . blockOperation ( mmaModWikiComponent , blockId ) ;
379+ }
375380 }
376381 } ) . finally ( function ( ) {
377382 $scope . wikiLoaded = true ;
@@ -380,8 +385,8 @@ angular.module('mm.addons.mod_wiki')
380385
381386 $scope . $on ( '$destroy' , function ( ) {
382387 $interval . cancel ( renewLockInterval ) ;
383- if ( subwikiId ) {
384- $mmSyncBlock . unblockOperation ( mmaModWikiComponent , subwikiId ) ;
388+ if ( blockId ) {
389+ $mmSyncBlock . unblockOperation ( mmaModWikiComponent , blockId ) ;
385390 }
386391 } ) ;
387392} ) ;
0 commit comments