PlotDirector/PlotLine/Views/Writer/_AuthoringSection.cshtml

32 lines
4.2 KiB
Plaintext

@model PlotLine.Models.AuthoringSection
@{ var add=Model.Kind.StartsWith("Add",StringComparison.Ordinal); var id="authoring-"+Model.Key;var compact=ViewData["CompactEditorial"] is true; }
<section class="writer3-authoring-card" data-authoring-card data-key="@Model.Key" data-kind="@Model.Kind">
<div class="writer3-authoring-heading"><h3>@Model.Title</h3><button type="button" class="btn btn-sm btn-outline-secondary" data-authoring-edit aria-controls="@id" aria-expanded="false">@(add?"Add":"Edit")<span class="visually-hidden"> @Model.Title</span></button></div>
<div data-authoring-display>
@if(Model.Kind=="Checklist"){<label><input type="checkbox" data-checklist-toggle checked="@(Model.Value("IsCompleted")=="true")" /> @Model.Value("ItemText")</label>}
@if(add&&!compact){<p class="muted">Optional — keep a useful detail here when you need it.</p>}
else if(!add&&Model.Kind!="Checklist"){
var readable=Model.Fields.Where(x=>(!compact||x.Name!="SortOrder")&&!string.IsNullOrWhiteSpace(Model.Value(x.Name)) && Model.Value(x.Name)!="false").ToArray();
@if(readable.Length==0&&!compact){<p class="muted">Nothing recorded yet. Add this when it helps your writing.</p>}
@foreach(var f in (Model.Kind=="Goals"?readable.Take(1):readable)){var value=Model.Value(f.Name);<div class="writer3-recorded-field">@if(f.Label!=Model.Title){<strong>@f.Label</strong>}@if(f.Type=="textarea"&&value.Length>280){<p>@value[..280]…</p><details><summary>Read complete text</summary><p>@value</p></details>}else{<p>@(f.Type=="checkbox"?"Yes":f.Type=="purpose"?Model.Purposes.FirstOrDefault(x=>x.Value==value).Label??"Recorded purpose":f.Type=="noteType"?Model.NoteTypes.FirstOrDefault(x=>x.Value==value).Label??"Recorded note":value)</p>}</div>}
@if(Model.Kind=="Goals"&&readable.Length>1){<details><summary>More chapter intentions</summary>@foreach(var f in readable.Skip(1)){<div class="writer3-recorded-field"><strong>@f.Label</strong><p>@Model.Value(f.Name)</p></div>}</details>}
}
</div>
<form id="@id" asp-controller="WriterAuthoring" asp-action="Save" method="post" data-authoring-form hidden>
<input type="hidden" name="bookId" value="@Model.BookID" /><input type="hidden" name="chapterId" value="@Model.ChapterID" /><input type="hidden" name="sceneId" value="@Model.SceneID" />
<input type="hidden" name="kind" value="@Model.Kind" /><input type="hidden" name="entityId" value="@Model.EntityID" /><input type="hidden" name="version" value="@Model.Version" />
@foreach(var f in Model.Fields){var fid=id+"-"+f.Name;var value=Model.Value(f.Name);
<div class="writer3-inline-field"><label for="@fid">@f.Label</label>
@if(f.Type=="textarea"){<textarea id="@fid" name="@f.Name" class="form-control" rows="3" maxlength="@(f.Max==int.MaxValue?null:f.Max.ToString())" required="@f.Required">@value</textarea>}
else if(f.Type is "purpose" or "noteType"){var options=f.Type=="purpose"?Model.Purposes:Model.NoteTypes;<select id="@fid" name="@f.Name" class="form-select" required="@f.Required">@if(f.Type=="purpose"){<option value="">No purpose selected</option>}@if(!string.IsNullOrEmpty(value)&&options.All(x=>x.Value!=value)){<option value="@value" selected>Recorded choice (currently unavailable)</option>}@foreach(var option in options){<option value="@option.Value" selected="@(option.Value==value)">@option.Label</option>}</select>}
else if(f.Type=="checkbox"){<input id="@fid" type="checkbox" name="@f.Name" value="true" checked="@(value=="true")" />}
else{<input id="@fid" type="@(f.Type=="number"?"number":f.Type=="date"?"date":"text")" class="form-control" name="@f.Name" value="@(f.Type=="date" && value.Length>=10?value[..10]:value)" maxlength="@(f.Max==int.MaxValue?null:f.Max.ToString())" required="@f.Required" />}
</div>
}
<p role="alert" data-authoring-error hidden></p>
<div class="button-row"><button class="btn btn-primary" type="submit" data-authoring-save>Save<span class="visually-hidden"> @Model.Title</span></button><button class="btn btn-outline-secondary" type="button" data-authoring-cancel>Cancel</button><button class="btn btn-outline-secondary" type="button" data-authoring-reload hidden>Reload recorded version</button></div>
</form>
<p role="status" class="writer3-caption" data-authoring-status></p>
</section>