@@ -177,6 +177,80 @@ class BestiarySublistManager extends SublistManager {
177
177
}
178
178
}
179
179
180
+ class BestiaryPageBookView extends ListPageBookView {
181
+ constructor ( opts ) {
182
+ super ( {
183
+ namePlural : "creatures" ,
184
+ pageTitle : "Bestiary Printer View" ,
185
+ ...opts ,
186
+ } ) ;
187
+ }
188
+
189
+ _$getWrpControls ( { $wrpContent} ) {
190
+ const out = super . _$getWrpControls ( { $wrpContent} ) ;
191
+ const { $wrpPrint} = out ;
192
+
193
+ // region Markdown
194
+ // TODO refactor this and spell markdown section
195
+ const pGetAsMarkdown = async ( ) => {
196
+ const toRender = this . _bookViewToShow . length ? this . _bookViewToShow : [ this . _fnGetEntLastLoaded ( ) ] ;
197
+ return RendererMarkdown . monster . pGetMarkdownDoc ( toRender ) ;
198
+ } ;
199
+
200
+ const $btnDownloadMarkdown = $ ( `<button class="btn btn-default btn-sm">Download as Markdown</button>` )
201
+ . click ( async ( ) => DataUtil . userDownloadText ( "bestiary.md" , await pGetAsMarkdown ( ) ) ) ;
202
+
203
+ const $btnCopyMarkdown = $ ( `<button class="btn btn-default btn-sm px-2" title="Copy Markdown to Clipboard"><span class="glyphicon glyphicon-copy"/></button>` )
204
+ . click ( async ( ) => {
205
+ await MiscUtil . pCopyTextToClipboard ( await pGetAsMarkdown ( ) ) ;
206
+ JqueryUtil . showCopiedEffect ( $btnCopyMarkdown ) ;
207
+ } ) ;
208
+
209
+ const $btnDownloadMarkdownSettings = $ ( `<button class="btn btn-default btn-sm px-2" title="Markdown Settings"><span class="glyphicon glyphicon-cog"/></button>` )
210
+ . click ( async ( ) => RendererMarkdown . pShowSettingsModal ( ) ) ;
211
+
212
+ $$ `<div class="ve-flex-v-center btn-group ml-2">
213
+ ${ $btnDownloadMarkdown }
214
+ ${ $btnCopyMarkdown }
215
+ ${ $btnDownloadMarkdownSettings }
216
+ </div>` . appendTo ( $wrpPrint ) ;
217
+ // endregion
218
+
219
+ return out ;
220
+ }
221
+
222
+ async _pGetRenderContentMeta ( { $wrpContent} ) {
223
+ this . _bookViewToShow = this . _sublistManager . getPinnedEntities ( )
224
+ . sort ( this . _getSorted . bind ( this ) ) ;
225
+
226
+ let cntSelectedEnts = 0 ;
227
+ let isAnyEntityRendered = false ;
228
+
229
+ const stack = [ ] ;
230
+
231
+ const renderCreature = ( mon ) => {
232
+ isAnyEntityRendered = true ;
233
+ stack . push ( `<div class="bkmv__wrp-item ve-inline-block print__ve-block print__my-2"><table class="w-100 stats stats--book stats--bkmv"><tbody>` ) ;
234
+ stack . push ( Renderer . monster . getCompactRenderedString ( mon ) ) ;
235
+ stack . push ( `</tbody></table></div>` ) ;
236
+ } ;
237
+
238
+ this . _bookViewToShow . forEach ( mon => renderCreature ( mon ) ) ;
239
+ if ( ! this . _bookViewToShow . length && Hist . lastLoadedId != null ) {
240
+ renderCreature ( this . _fnGetEntLastLoaded ( ) ) ;
241
+ }
242
+
243
+ cntSelectedEnts += this . _bookViewToShow . length ;
244
+ $wrpContent . append ( stack . join ( "" ) ) ;
245
+
246
+ return { cntSelectedEnts, isAnyEntityRendered} ;
247
+ }
248
+
249
+ _getSorted ( a , b ) {
250
+ return SortUtil . ascSort ( a . _displayName || a . name , b . _displayName || b . name ) ;
251
+ }
252
+ }
253
+
180
254
class BestiaryPage extends ListPageMultiSource {
181
255
static async _prereleaseBrewDataSource ( { brewUtil} ) {
182
256
const brew = await brewUtil . pGetBrewProcessed ( ) ;
@@ -210,9 +284,7 @@ class BestiaryPage extends ListPageMultiSource {
210
284
hasAudio : true ,
211
285
212
286
bookViewOptions : {
213
- $btnOpen : $ ( `#btn-printbook` ) ,
214
- $eleNoneVisible : $ ( `<span class="initial-message">If you wish to view multiple creatures, please first make a list</span>` ) ,
215
- pageTitle : "Bestiary Printer View" ,
287
+ ClsBookView : BestiaryPageBookView ,
216
288
} ,
217
289
218
290
tableViewOptions : {
@@ -321,60 +393,6 @@ class BestiaryPage extends ListPageMultiSource {
321
393
322
394
get list_ ( ) { return this . _list ; }
323
395
324
- async _bookView_popTblGetNumShown ( { $wrpContent, $dispName, $wrpControls} ) {
325
- this . _bookViewToShow = await this . _sublistManager . getPinnedEntities ( ) ;
326
-
327
- this . _bookViewToShow . sort ( ( a , b ) => SortUtil . ascSort ( a . _displayName || a . name , b . _displayName || b . name ) ) ;
328
-
329
- let numShown = 0 ;
330
-
331
- const stack = [ ] ;
332
-
333
- const renderCreature = ( mon ) => {
334
- stack . push ( `<div class="bkmv__wrp-item"><table class="w-100 stats stats--book stats--bkmv"><tbody>` ) ;
335
- stack . push ( Renderer . monster . getCompactRenderedString ( mon ) ) ;
336
- stack . push ( `</tbody></table></div>` ) ;
337
- } ;
338
-
339
- stack . push ( `<div class="w-100 h-100">` ) ;
340
- this . _bookViewToShow . forEach ( mon => renderCreature ( mon ) ) ;
341
- if ( ! this . _bookViewToShow . length && Hist . lastLoadedId != null ) {
342
- renderCreature ( this . _dataList [ Hist . lastLoadedId ] ) ;
343
- }
344
- stack . push ( `</div>` ) ;
345
-
346
- numShown += this . _bookViewToShow . length ;
347
- $wrpContent . append ( stack . join ( "" ) ) ;
348
-
349
- // region Markdown
350
- // TODO refactor this and spell markdown section
351
- const pGetAsMarkdown = async ( ) => {
352
- const toRender = this . _bookViewToShow . length ? this . _bookViewToShow : [ this . _dataList [ Hist . lastLoadedId ] ] ;
353
- return RendererMarkdown . monster . pGetMarkdownDoc ( toRender ) ;
354
- } ;
355
-
356
- const $btnDownloadMarkdown = $ ( `<button class="btn btn-default btn-sm">Download as Markdown</button>` )
357
- . click ( async ( ) => DataUtil . userDownloadText ( "bestiary.md" , await pGetAsMarkdown ( ) ) ) ;
358
-
359
- const $btnCopyMarkdown = $ ( `<button class="btn btn-default btn-sm px-2" title="Copy Markdown to Clipboard"><span class="glyphicon glyphicon-copy"/></button>` )
360
- . click ( async ( ) => {
361
- await MiscUtil . pCopyTextToClipboard ( await pGetAsMarkdown ( ) ) ;
362
- JqueryUtil . showCopiedEffect ( $btnCopyMarkdown ) ;
363
- } ) ;
364
-
365
- const $btnDownloadMarkdownSettings = $ ( `<button class="btn btn-default btn-sm px-2" title="Markdown Settings"><span class="glyphicon glyphicon-cog"/></button>` )
366
- . click ( async ( ) => RendererMarkdown . pShowSettingsModal ( ) ) ;
367
-
368
- $$ `<div class="ve-flex-v-center btn-group ml-2">
369
- ${ $btnDownloadMarkdown }
370
- ${ $btnCopyMarkdown }
371
- ${ $btnDownloadMarkdownSettings }
372
- </div>` . appendTo ( $wrpControls ) ;
373
- // endregion
374
-
375
- return numShown ;
376
- }
377
-
378
396
getListItem ( mon , mI ) {
379
397
const hash = UrlUtil . autoEncodeHash ( mon ) ;
380
398
if ( this . _seenHashes . has ( hash ) ) return null ;
0 commit comments