Fossil

Diff
Login

Differences From Artifact [8fbe8eab12]:

To Artifact [63c80243d9]:


261
262
263
264
265
266
267
268
269
270
271
272
273

274
275
276
277
278
279
280
281
282















283
284
285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
      // Force UI update
      s.dispatchEvent(new Event('change',{target:s}));
    }
  };

  const WikiList = {
    e: {},
    /** Update OPTION elements to reflect whether the page has
        local changes or is new/unsaved. */
    refreshStashMarks: function(){
      this.e.select.querySelectorAll(
        'option'
      ).forEach(function(o){

        const stashed = $stash.getWinfo({name:o.value});
        if(stashed){
          const isNew = 'sandbox'===stashed.type ? false : !stashed.version;
          D.addClass(o, isNew ? 'stashed-new' :'stashed');
        }else{
          D.removeClass(o, 'stashed', 'stashed-new');
        }
      });
    },















    init: function(parentElem){
      const sel = D.select(), btn = D.button("Reload page list");
      this.e.select = sel;
      D.addClass(parentElem, 'wikiedit-page-list-wrapper');
      D.clearElement(parentElem);
      D.append(
        parentElem, btn,
        D.append(D.span(), "Select a page to edit:"),
        sel,
        D.append(D.span(), "* = local edits exist"),
        D.append(D.span(), "+ = new/unsaved page")

      );
      D.attr(sel, 'size', 10);
      D.option(D.disable(D.clearElement(sel)), "Loading...");
      const self = this;
      btn.addEventListener(
        'click',
        function click(){







|


|
<
|
>
|


|

|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






|


|
|
>







261
262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
      // Force UI update
      s.dispatchEvent(new Event('change',{target:s}));
    }
  };

  const WikiList = {
    e: {},
    /** Updates OPTION elements to reflect whether the page has
        local changes or is new/unsaved. */
    refreshStashMarks: function(){
      const sel = this.e.select;

      Object.keys(sel.options).forEach(function(key){
        const opt = sel.options[key];
        const stashed = $stash.getWinfo({name:opt.value});
        if(stashed){
          const isNew = 'sandbox'===stashed.type ? false : !stashed.version;
          D.addClass(opt, isNew ? 'stashed-new' :'stashed');
        }else{
          D.removeClass(opt, 'stashed', 'stashed-new');
        }
      });
    },
    /** Removes the given wiki page entry from the page selection
        list, if it's in the list. */
    removeEntry: function(name){
      const sel = this.e.select;
      const ndx = sel.selectedIndex;
      sel.value = name;
      if(sel.selectedIndex>-1){
        sel.options.remove(sel.selectedIndex);
      }
      sel.selectedIndex = ndx;
    },
    /**
       Installs a wiki page selection list into the given parent DOM
       element and loads the page list from the server.
    */
    init: function(parentElem){
      const sel = D.select(), btn = D.button("Reload page list");
      this.e.select = sel;
      D.addClass(parentElem, 'wikiedit-page-list-wrapper');
      D.clearElement(parentElem);
      D.append(
        parentElem,
        D.append(D.span(), "Select a page to edit:"),
        sel,
        D.append(D.span(), "[*] = page has local edits"),
        D.append(D.span(), "[+] = page is new/unsaved"),
        btn
      );
      D.attr(sel, 'size', 10);
      D.option(D.disable(D.clearElement(sel)), "Loading...");
      const self = this;
      btn.addEventListener(
        'click',
        function click(){
337
338
339
340
341
342
343

344
345
346
347
348
349
350
        false
      );
      F.page.addEventListener(
        'wiki-stash-updated',
        ()=>this.refreshStashMarks(),
        false
      );

    }
  };

  /**
     Keep track of how many in-flight AJAX requests there are so we
     can disable input elements while any are pending. For
     simplicity's sake we simply disable ALL OF IT while any AJAX is







>







353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
        false
      );
      F.page.addEventListener(
        'wiki-stash-updated',
        ()=>this.refreshStashMarks(),
        false
      );
      delete this.init;
    }
  };

  /**
     Keep track of how many in-flight AJAX requests there are so we
     can disable input elements while any are pending. For
     simplicity's sake we simply disable ALL OF IT while any AJAX is
467
468
469
470
471
472
473

474
475



476
477
478








479
480
481
482
483
484
485
    F.confirmer(P.e.btnReload, {
      confirmText: "Really reload, losing edits?",
      onconfirm: function(e){
        const w = P.winfo;
        if(!w){
          F.error("No page loaded.");
          return;

        }else if(!w.version){
          F.error("Cannot reload a new/unsaved page.");



          return;
        }
        P.unstashContent().loadPage();








      },
      ticks: 3
    });
    P.e.taEditor.addEventListener(
      'change', ()=>P.stashContentChange(), false
    );
    







>
|
|
>
>
>


|
>
>
>
>
>
>
>
>







484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
    F.confirmer(P.e.btnReload, {
      confirmText: "Really reload, losing edits?",
      onconfirm: function(e){
        const w = P.winfo;
        if(!w){
          F.error("No page loaded.");
          return;
        }
        if(!w.version/* new/unsaved page */ && P.wikiContent()){
          F.error("This new/unsaved page has content.",
                  "To really discard this page,",
                  "first clear its content",
                  "then use the Discard button.");
          return;
        }
        P.unstashContent()
        if(w.version){
          P.loadPage();
        }else{
          delete P.winfo;
          WikiList.removeEntry(w.name);
          P.updatePageTitle();
          F.message("Discarded new page ["+w.name+"].");
        }
      },
      ticks: 3
    });
    P.e.taEditor.addEventListener(
      'change', ()=>P.stashContentChange(), false
    );
    
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574

575
576
577



578
579
580

581
582
583
584
585
586
587
  */
  const affirmPageLoaded = function(quiet){
    if(!P.winfo && !quiet) F.error("No wiki page is loaded.");
    return !!P.winfo;
  };

  /**
     Update the page title and header based on the state
     of this.winfo. A no-op if this.winfo is not set.
  */
  P.updatePageTitle = function f(){
    if(!affirmPageLoaded(true)) return;
    if(!f.titleElement){
      f.titleElement = document.head.querySelector('title');
      f.pageTitleHeader = document.querySelector('div.header .title');
    }
    var title = ['Wiki Editor:'];

    if(!P.winfo.version) title.push('[+]');
    else if($stash.getWinfo(P.winfo)) title.push('[*]')
    title.push(P.winfo.name);



    title = title.join(' ');
    f.titleElement.innerText = title;
    f.pageTitleHeader.innerText = title;

  };
  
  /**
     Getter (if called with no args) or setter (if passed an arg) for
     the current file content.

     The setter form sets the content, dispatches a







|
|


<





>
|
|
|
>
>
>



>







587
588
589
590
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
  */
  const affirmPageLoaded = function(quiet){
    if(!P.winfo && !quiet) F.error("No wiki page is loaded.");
    return !!P.winfo;
  };

  /**
     Update the page title and header based on the state of
     this.winfo. A no-op if this.winfo is not set. Returns this.
  */
  P.updatePageTitle = function f(){

    if(!f.titleElement){
      f.titleElement = document.head.querySelector('title');
      f.pageTitleHeader = document.querySelector('div.header .title');
    }
    var title = ['Wiki Editor:'];
    if(P.winfo){
      if(!P.winfo.version) title.push('[+]');
      else if($stash.getWinfo(P.winfo)) title.push('[*]')
      title.push(P.winfo.name);
    }else{
      title.push('(no page loaded)');
    }
    title = title.join(' ');
    f.titleElement.innerText = title;
    f.pageTitleHeader.innerText = title;
    return this;
  };
  
  /**
     Getter (if called with no args) or setter (if passed an arg) for
     the current file content.

     The setter form sets the content, dispatches a
672
673
674
675
676
677
678


679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700

701
702
703
704
705
706
707
      /* Assume winfo-like object */
      const arg = arguments[0];
      name = arg.name;
    }
    const onload = (r)=>this.dispatchEvent('wiki-page-loaded', r);
    const stashWinfo = this.getStashedWinfo({name: name});
    if(stashWinfo){ // fake a response from the stash...


      onload({
        name: stashWinfo.name,
        mimetype: stashWinfo.mimetype,
        type: stashWinfo.type,
        version: stashWinfo.version,
        parent: stashWinfo.parent,
        content: $stash.stashedContent(stashWinfo)
      });
      F.message("Fetched from the local-edit storage:",
                stashWinfo.name);
      return this;
    }
    F.message(
      "Loading content..."
    ).fetch('wikiajax/fetch',{
      urlParams: {
        page: name
      },
      responseType: 'json',
      onload:(r)=>{
        onload(r);
        F.message('Loaded page ['+r.name+'].');

      }
    });
    return this;
  };
  
  /**
     Fetches the page preview based on the contents and settings of







>
>








<
<










<

>







705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721


722
723
724
725
726
727
728
729
730
731

732
733
734
735
736
737
738
739
740
      /* Assume winfo-like object */
      const arg = arguments[0];
      name = arg.name;
    }
    const onload = (r)=>this.dispatchEvent('wiki-page-loaded', r);
    const stashWinfo = this.getStashedWinfo({name: name});
    if(stashWinfo){ // fake a response from the stash...
      F.message("Fetched from the local-edit storage:",
                stashWinfo.name);
      onload({
        name: stashWinfo.name,
        mimetype: stashWinfo.mimetype,
        type: stashWinfo.type,
        version: stashWinfo.version,
        parent: stashWinfo.parent,
        content: $stash.stashedContent(stashWinfo)
      });


      return this;
    }
    F.message(
      "Loading content..."
    ).fetch('wikiajax/fetch',{
      urlParams: {
        page: name
      },
      responseType: 'json',
      onload:(r)=>{

        F.message('Loaded page ['+r.name+'].');
        onload(r);
      }
    });
    return this;
  };
  
  /**
     Fetches the page preview based on the contents and settings of