1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
|
** All errors which "could" have happened up to this point are of a
** degree which keep us from rendering the rest of the page, and
** thus have already caused us to skipped to the end of the page to
** render the errors. Any up-coming errors, barring malloc failure
** or similar, are not "that" fatal. We can/should continue
** rendering the page, then output the error message at the end.
********************************************************************/
CX("<h1>Editing:</h1>");
CX("<p class='fileedit-hint'>");
CX("File: "
"[<a id='finfo-link' href='#'>info</a>] "
/* %R/finfo?name=%T&m=%!S */
"<code id='finfo-file-name'>(loading)</code><br>");
CX("Checkin Version: "
"[<a id='r-link' href='#'>info</a>] "
/* %R/info/%!S */
"<code id='r-label'>(loading...)</code><br>"
);
CX("Permalink: <code>"
"<a id='permalink' href='#'>(loading...)</a></code><br>"
"(Clicking the permalink will reload the page and discard "
"all edits!)",
zFilename, cimi.zParentUuid,
zFilename, cimi.zParentUuid);
CX("</p>");
CX("<p>This page is <em>NEW AND EXPERIMENTAL</em>. "
"USE AT YOUR OWN RISK, preferably on a test "
"repo.</p>\n");
CX("<form action='#' method='POST' "
"class='fileedit' id='fileedit-form' "
"onsubmit='function(e){"
"e.preventDefault(); e.stopPropagation(); return false;"
"}'>\n");
/******* Hidden fields *******/
CX("<input type='hidden' name='r' value='%s'>",
cimi.zParentUuid);
CX("<input type='hidden' name='file' value='%T'>",
zFilename);
/******* Content *******/
CX("<h3>File Content</h3>\n");
CX("<textarea name='content' id='fileedit-content' "
"rows='20' cols='80'>");
CX("Loading...");
CX("</textarea>\n");
CX("<div id='fossil-status-bar'>Async. status messages will go "
"here.</div>\n");
/******* Flags/options *******/
CX("<fieldset class='fileedit-options' id='options'>"
"<legend>Options</legend><div>"
/* Chrome does not sanely lay out multiple
** fieldset children after the <legend>, so
** a containing div is necessary. */);
style_labeled_checkbox("cb-dry-run",
"dry_run", "Dry-run?", "1",
"In dry-run mode, the Save button performs "
"all work needed for saving but then rolls "
"back the transaction, and thus does not "
"really save.",
1);
style_labeled_checkbox("cb-allow-fork",
"allow_fork", "Allow fork?", "1",
"Allow saving to create a fork?",
cimi.flags & CIMINI_ALLOW_FORK);
style_labeled_checkbox("cb-allow-older",
"allow_older", "Allow older?", "1",
"Allow saving against a parent version "
"which has a newer timestamp?",
cimi.flags & CIMINI_ALLOW_OLDER);
style_labeled_checkbox("cb-exec-bit",
"exec_bit", "Executable?", "1",
"Set the executable bit?",
PERM_EXE==cimi.filePerm);
style_labeled_checkbox("cb-allow-merge-conflict",
"allow_merge_conflict",
"Allow merge conflict markers?", "1",
"Allow saving even if the content contains "
"what appear to be fossil merge conflict "
"markers?",
cimi.flags & CIMINI_ALLOW_MERGE_MARKER);
style_labeled_checkbox("cb-prefer-delta",
"prefer_delta",
"Prefer delta manifest?", "1",
"Will create a delta manifest, instead of "
"baseline, if conditions are favorable to do "
"so. This option is only a suggestion.",
cimi.flags & CIMINI_PREFER_DELTA);
style_select_list_int("select-eol-style",
"eol", "EOL Style",
"EOL conversion policy, noting that "
"form-processing may implicitly change the "
"line endings of the input.",
(cimi.flags & CIMINI_CONVERT_EOL_UNIX)
? 1 : (cimi.flags & CIMINI_CONVERT_EOL_WINDOWS
? 2 : 0),
"Inherit", 0,
"Unix", 1,
"Windows", 2,
NULL);
style_select_list_int("select-font-size",
"editor_font_size", "Editor Font Size",
NULL/*tooltip*/,
100,
"100%", 100, "125%", 125,
"150%", 150, "175%", 175,
"200%", 200, NULL);
CX("</div></fieldset>") /* end of checkboxes */;
/******* Comment *******/
CX("<a id='comment'></a>");
CX("<fieldset><legend>Commit message</legend><div>");
CX("<textarea name='comment' rows='3' cols='80' "
"id='fileedit-comment'>");
/* ^^^ adding the 'required' attribute means we cannot even submit
** for PREVIEW mode if it's empty :/. */
if(blob_size(&cimi.comment)){
CX("%h", blob_str(&cimi.comment));
}
CX("</textarea>\n");
CX("<div class='fileedit-hint'>Comments use the Fossil wiki markup "
"syntax.</div>\n"/*TODO: select for fossil/md/plain text*/);
CX("</div></fieldset>\n");
/******* Buttons *******/
CX("<a id='buttons'></a>");
CX("<fieldset class='fileedit-options'>"
"<legend>Ask the server to...</legend><div>");
CX("<button id='fileedit-btn-commit'>Commit</button>");
CX("<button id='fileedit-btn-diffsbs'>Diff (SBS)</button>");
CX("<button id='fileedit-btn-diffu'>Diff (Unified)</button>");
CX("<button id='fileedit-btn-preview'>Preview</button>");
/* Default preview rendering mode selection... */
previewRenderMode = fileedit_render_mode_for_mimetype(zFileMime);
style_select_list_int("select-preview-mode",
"preview_render_mode",
"Preview Mode",
"Preview mode format.",
previewRenderMode,
"Guess", FE_RENDER_GUESS,
"Wiki/Markdown", FE_RENDER_WIKI,
"HTML (iframe)", FE_RENDER_HTML,
"Plain Text", FE_RENDER_PLAIN_TEXT,
NULL);
/*
** Set up a JS-side mapping of the FE_RENDER_xyz values. This is
** used for dynamically toggling certain UI components on and off.
*/
blob_appendf(&endScript, "fossil.page.previewModes={"
"guess: %d, %d: 'guess', wiki: %d, %d: 'wiki',"
"html: %d, %d: 'html', text: %d, %d: 'text'"
"};\n",
FE_RENDER_GUESS, FE_RENDER_GUESS,
FE_RENDER_WIKI, FE_RENDER_WIKI,
FE_RENDER_HTML, FE_RENDER_HTML,
FE_RENDER_PLAIN_TEXT, FE_RENDER_PLAIN_TEXT);
/* Allow selection of HTML preview iframe height */
previewHtmlHeight = atoi(PD("preview_html_ems","0"));
if(!previewHtmlHeight){
previewHtmlHeight = 40;
}
style_select_list_int("select-preview-html-ems",
"preview_html_ems",
"HTML Preview IFrame Height (EMs)",
"Height (in EMs) of the iframe used for "
"HTML preview",
previewHtmlHeight,
"", 20, "", 40,
"", 60, "", 80,
"", 100, NULL);
/* Selection of line numbers for text preview */
style_labeled_checkbox("cb-line-numbers",
"preview_ln",
"Add line numbers to plain-text previews?",
"1",
"If on, plain-text files (only) will get "
"line numbers added to the preview.",
P("preview_ln")!=0);
CX("</div></fieldset>");
/******* End of form *******/
CX("</form>\n");
CX("<div id='ajax-target'>%s</div>"
/* this is where preview/diff go */);
/* Dynamically populate the editor... */
blob_appendf(&endScript,
"fossil.page.loadFile('%j','%j');",
zFilename, cimi.zParentUuid);
end_footer:
fossil_free(zFileUuid);
if(stmt.pStmt){
db_finalize(&stmt);
}
if(blob_size(&err)){
CX("<div class='fileedit-error-report'>%s</div>",
blob_str(&err));
}
blob_reset(&err);
CheckinMiniInfo_cleanup(&cimi);
style_emit_script_fetch();
fileedit_emit_page_script();
if(blob_size(&endScript)>0){
style_emit_script_tag(0);
CX("(function(){\n");
CX("try{\n%b\n}catch(e){console.error('Exception:',e)}\n",
&endScript);
CX("})();");
style_emit_script_tag(1);
}
db_end_transaction(0);
style_footer();
}
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
>
>
>
>
>
>
>
>
>
>
|
|
<
<
<
<
<
<
<
<
<
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
|
>
>
>
>
>
|
<
<
>
|
<
<
<
<
|
>
>
|
<
<
|
>
>
>
>
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
|
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
|
** All errors which "could" have happened up to this point are of a
** degree which keep us from rendering the rest of the page, and
** thus have already caused us to skipped to the end of the page to
** render the errors. Any up-coming errors, barring malloc failure
** or similar, are not "that" fatal. We can/should continue
** rendering the page, then output the error message at the end.
********************************************************************/
CX("<p>This page is <em>NEW AND EXPERIMENTAL</em>. "
"USE AT YOUR OWN RISK, preferably on a test "
"repo.</p>\n");
/*
** We don't strictly need a FORM because we manually cherry-pick and
** submit the form data, but it being in a form allows us to easily
** use the FormData type for serialization.
**
** TODO?: we can almost certainly replace this element with a plain
** DIV, which would eliminate the event-handling hassles of trying
** to suppress the submit... but it would also eliminate the option
** of using HTML form field validation.
*/
CX("<form action='#' method='POST' class='fileedit' "
"id='fileedit-form'>");
/******* Hidden fields *******/
CX("<input type='hidden' name='r' value='%s'>",
cimi.zParentUuid);
CX("<input type='hidden' name='file' value='%T'>",
zFilename);
/* Status bar */
CX("<div id='fossil-status-bar'>Async. status messages will go "
"here.</div>\n"/* will be moved into the tab container via JS */);
/* Main tab container... */
CX("<div id='fileedit-tabs' class='tab-container'></div>");
/***** File/version info tab *****/
{
CX("<div id='fileedit-tab-version' "
"data-tab-parent='fileedit-tabs' "
"data-tab-label='Version Info'"
">");
CX("File: "
"[<a id='finfo-link' href='#'>/finfo</a>] "
/* %R/finfo?name=%T&m=%!S */
"<code id='finfo-file-name'>(loading)</code><br>");
CX("Checkin Version: "
"[<a id='r-link' href='#'>/info</a>] "
/* %R/info/%!S */
"<code id='r-label'>(loading...)</code><br>"
);
CX("Permalink: <code>"
"<a id='permalink' href='#'>(loading...)</a></code><br>"
"(Clicking the permalink will reload the page and discard "
"all edits!)",
zFilename, cimi.zParentUuid,
zFilename, cimi.zParentUuid);
CX("</div>"/*#fileedit-tab-version*/);
}
/******* Content tab *******/
{
CX("<div id='fileedit-tab-content' "
"data-tab-parent='fileedit-tabs' "
"data-tab-label='File Content'"
">");
CX("<textarea name='content' id='fileedit-content-editor' "
"rows='20' cols='80'>");
CX("Loading...");
CX("</textarea>\n");
CX("</div>"/*#tab-file-content*/);
}
/****** Preview tab ******/
{
CX("<div id='fileedit-tab-preview' "
"data-tab-parent='fileedit-tabs' "
"data-tab-label='Preview'"
">");
CX("<fieldset class='fileedit-options'>"
"<legend>Preview...</legend><div>");
CX("<div class='preview-controls'>");
CX("<button>Refresh</button>");
/* Default preview rendering mode selection... */
previewRenderMode = fileedit_render_mode_for_mimetype(zFileMime);
style_select_list_int("select-preview-mode",
"preview_render_mode",
"Preview Mode",
"Preview mode format.",
previewRenderMode,
"Guess", FE_RENDER_GUESS,
"Wiki/Markdown", FE_RENDER_WIKI,
"HTML (iframe)", FE_RENDER_HTML,
"Plain Text", FE_RENDER_PLAIN_TEXT,
NULL);
/*
** Set up a JS-side mapping of the FE_RENDER_xyz values. This is
** used for dynamically toggling certain UI components on and off.
*/
blob_appendf(&endScript, "fossil.page.previewModes={"
"guess: %d, %d: 'guess', wiki: %d, %d: 'wiki',"
"html: %d, %d: 'html', text: %d, %d: 'text'"
"};\n",
FE_RENDER_GUESS, FE_RENDER_GUESS,
FE_RENDER_WIKI, FE_RENDER_WIKI,
FE_RENDER_HTML, FE_RENDER_HTML,
FE_RENDER_PLAIN_TEXT, FE_RENDER_PLAIN_TEXT);
/* Allow selection of HTML preview iframe height */
previewHtmlHeight = atoi(PD("preview_html_ems","0"));
if(!previewHtmlHeight){
previewHtmlHeight = 40;
}
style_select_list_int("select-preview-html-ems",
"preview_html_ems",
"HTML Preview IFrame Height (EMs)",
"Height (in EMs) of the iframe used for "
"HTML preview",
previewHtmlHeight,
"", 20, "", 40,
"", 60, "", 80,
"", 100, NULL);
/* Selection of line numbers for text preview */
style_labeled_checkbox("cb-line-numbers",
"preview_ln",
"Add line numbers to plain-text previews?",
"1",
"If on, plain-text files (only) will get "
"line numbers added to the preview.",
P("preview_ln")!=0);
CX("</div></fieldset>"/*.fileedit-options*/);
CX("<div id='fileedit-tab-preview-wrapper'></div>");
CX("</div>"/*#fileedit-tab-preview*/);
}
/****** Diff tab ******/
{
CX("<div id='fileedit-tab-diff' "
"data-tab-parent='fileedit-tabs' "
"data-tab-label='Diff'"
">");
CX("<div id='fileedit-tab-diff-buttons'>"
"<button class='sbs'>Side-by-side</button>"
"<button class='unified'>Unified</button>"
"</div>");
CX("<div id='fileedit-tab-diff-wrapper'>"
"Diffs will be shown here."
"</div>");
CX("</div>");
}
/****** Commit ******/
CX("<div id='fileedit-tab-commit' "
"data-tab-parent='fileedit-tabs' "
"data-tab-label='Commit'"
">");
{
/******* Flags/options *******/
CX("<fieldset class='fileedit-options'>"
"<legend>Options</legend><div>"
/* Chrome does not sanely lay out multiple
** fieldset children after the <legend>, so
** a containing div is necessary. */);
style_labeled_checkbox("cb-dry-run",
"dry_run", "Dry-run?", "1",
"In dry-run mode, the Save button performs "
"all work needed for saving but then rolls "
"back the transaction, and thus does not "
"really save.",
1);
style_labeled_checkbox("cb-allow-fork",
"allow_fork", "Allow fork?", "1",
"Allow saving to create a fork?",
cimi.flags & CIMINI_ALLOW_FORK);
style_labeled_checkbox("cb-allow-older",
"allow_older", "Allow older?", "1",
"Allow saving against a parent version "
"which has a newer timestamp?",
cimi.flags & CIMINI_ALLOW_OLDER);
style_labeled_checkbox("cb-exec-bit",
"exec_bit", "Executable?", "1",
"Set the executable bit?",
PERM_EXE==cimi.filePerm);
style_labeled_checkbox("cb-allow-merge-conflict",
"allow_merge_conflict",
"Allow merge conflict markers?", "1",
"Allow saving even if the content contains "
"what appear to be fossil merge conflict "
"markers?",
cimi.flags & CIMINI_ALLOW_MERGE_MARKER);
style_labeled_checkbox("cb-prefer-delta",
"prefer_delta",
"Prefer delta manifest?", "1",
"Will create a delta manifest, instead of "
"baseline, if conditions are favorable to "
"do so. This option is only a suggestion.",
cimi.flags & CIMINI_PREFER_DELTA);
style_select_list_int("select-eol-style",
"eol", "EOL Style",
"EOL conversion policy, noting that "
"form-processing may implicitly change the "
"line endings of the input.",
(cimi.flags & CIMINI_CONVERT_EOL_UNIX)
? 1 : (cimi.flags & CIMINI_CONVERT_EOL_WINDOWS
? 2 : 0),
"Inherit", 0,
"Unix", 1,
"Windows", 2,
NULL);
#if 0
style_select_list_int("select-font-size",
"editor_font_size", "Editor Font Size",
NULL/*tooltip*/,
100,
"100%", 100, "125%", 125,
"150%", 150, "175%", 175,
"200%", 200, NULL);
#endif
CX("</div></fieldset>"/*checkboxes*/);
}
{ /******* Comment *******/
CX("<fieldset class='fileedit-options'>"
"<legend>Message (required)</legend><div>");
CX("<input type='text' name='comment' "
"id='fileedit-comment'>");
/* ^^^ adding the 'required' attribute means we cannot even
submit for PREVIEW mode if it's empty :/. */
if(blob_size(&cimi.comment)){
blob_appendf(&endScript,
"document.querySelector('#fileedit-comment').value="
"\"%h\";\n", blob_str(&cimi.comment));
}
CX("</input>\n");
CX("<div class='fileedit-hint'>Comments use the Fossil wiki markup "
"syntax.</div>\n"/*TODO: select for fossil/md/plain text*/);
CX("</div></fieldset>\n"/*commit comment*/);
CX("<div>"
"<button id='fileedit-btn-commit'>Commit</button>"
"</div>\n");
CX("<div id='fileedit-manifest'></div>\n");
}
CX("</div>"/*#fileedit-tab-commit*/);
/******* End of form *******/
CX("</form>\n");
/* Dynamically populate the editor... */
blob_appendf(&endScript,
"fossil.page.loadFile('%j','%j');",
zFilename, cimi.zParentUuid);
end_footer:
fossil_free(zFileUuid);
if(stmt.pStmt){
db_finalize(&stmt);
}
if(blob_size(&err)){
CX("<div class='fileedit-error-report'>%s</div>",
blob_str(&err));
}
blob_reset(&err);
CheckinMiniInfo_cleanup(&cimi);
fileedit_emit_page_script();
if(blob_size(&endScript)>0){
style_emit_script_tag(0);
CX("(function(){\n");
CX("try{\n%b\n}catch(e){console.error('Exception:',e)}\n",
&endScript);
CX("})();");
style_emit_script_tag(1);
}
db_end_transaction(0);
style_footer();
}
|