list-before: $:/core/ui/EditTemplate/body
tags: $:/tags/EditTemplate
title: $:/community/recipes/ui/EditTemplate/photo
type: text/vnd.tiddlywiki

\whitespace trim
<% if [all[current]tag[Recipe]] [all[current]tag[Ingredient]] %>
<$let photosMode={{{ [[$:/config/community/recipes/photos]get[text]!is[blank]] ~[[own]] }}}
      draftTitle=<<currentTiddler>>
      canonicalTitle={{{ [<currentTiddler>get[draft.of]else<currentTiddler>] }}}
      photoTitle={{{ [<currentTiddler>get[photo]] }}}
      newPhotoTitle={{{ [<canonicalTitle>addsuffix[ (photo)]] }}}
      formBase={{{ [[$:/state/community/recipes/photo-form/]addsuffix<draftTitle>addsuffix[/]] }}}
      openState={{{ [<formBase>addsuffix[open]] }}}
      workingPhotoState={{{ [<formBase>addsuffix[working-photo]] }}}
      urlState={{{ [<formBase>addsuffix[url]] }}}
      photographerState={{{ [<formBase>addsuffix[photographer]] }}}
      photoSourceState={{{ [<formBase>addsuffix[photo-source]] }}}
      sourceNameState={{{ [<formBase>addsuffix[photo-source-name]] }}}
      formOpen={{{ [<openState>get[text]] }}}
      formWorkingPhoto={{{ [<workingPhotoState>get[text]] }}}>
<%if [<photosMode>!match[none]] [<photoTitle>!is[blank]] %>
<div class="tc-recipe-photo-edit-section">
<strong><<t EditPhoto/Heading>></strong>
<%if [<formOpen>!is[blank]] %>
<div class="tc-recipe-photo-form">
{{$:/community/recipes/ui/EditTemplate/photo-size-advisory}}
<%if [<formWorkingPhoto>!is[blank]] %>
<div class="tc-recipe-photo-form-preview"><$transclude $tiddler=<<formWorkingPhoto>> $mode="block"/></div>
<%endif%>
<div class="tc-recipe-photo-form-image-row">
<$button tooltip=<<t EditPhoto/UploadTooltip>>><$action-attach-photo $photo=<<newPhotoTitle>> $state=<<workingPhotoState>>/><<t EditPhoto/UploadButton>></$button>
<span class="tc-recipe-photo-or"><<t EditPhoto/Or>></span>
<$edit-text tiddler=<<urlState>> field="text" placeholder=<<t EditPhoto/UrlPlaceholder>> default="" tag="input"/>
</div>
<%if [<photosMode>match[attributed]] %>
<details class="tc-recipe-photo-form-attribution" open><<photo-attribution-body>></details>
<%else%>
<details class="tc-recipe-photo-form-attribution"><<photo-attribution-body>></details>
<%endif%>
<div class="tc-recipe-photo-form-actions">
<$button>
<$action-deletetiddler $filter="[prefix<formBase>]"/>
<<t EditPhoto/Cancel>>
</$button>
<$button class="tc-recipe-photo-save-btn">
<%if [<formWorkingPhoto>!is[blank]] %>
<$action-setfield $tiddler=<<formWorkingPhoto>> photographer={{{ [<photographerState>get[text]] }}} photo-source={{{ [<photoSourceState>get[text]] }}} photo-source-name={{{ [<sourceNameState>get[text]] }}}/>
<%if [<urlState>get[text]!is[blank]] %>
<$action-setfield $tiddler=<<formWorkingPhoto>> _canonical_uri={{{ [<urlState>get[text]] }}} type="image/jpeg"/>
<%endif%>
<$action-setfield $tiddler=<<draftTitle>> photo=<<formWorkingPhoto>>/>
<%else%>
<%if [<urlState>get[text]!is[blank]] %>
<$action-setfield $tiddler=<<newPhotoTitle>> _canonical_uri={{{ [<urlState>get[text]] }}} type="image/jpeg" tags="Photo" photographer={{{ [<photographerState>get[text]] }}} photo-source={{{ [<photoSourceState>get[text]] }}} photo-source-name={{{ [<sourceNameState>get[text]] }}}/>
<$action-setfield $tiddler=<<draftTitle>> photo=<<newPhotoTitle>>/>
<%endif%>
<%endif%>
<$action-deletetiddler $filter="[prefix<formBase>]"/>
<<t EditPhoto/Save>>
</$button>
</div>
</div>
<%else%>
<%if [<photoTitle>!is[blank]] %>
<div class="tc-recipe-photo-edit-preview">
<div class="tc-recipe-photo-preview-thumb"><$transclude $tiddler=<<photoTitle>> $mode="block"/></div>
<div class="tc-recipe-photo-edit-meta">
<$link to=<<photoTitle>>><<photoTitle>></$link>
<$button>
<$action-setfield $tiddler=<<openState>> text="yes"/>
<$action-setfield $tiddler=<<workingPhotoState>> text=<<photoTitle>>/>
<$action-setfield $tiddler=<<photographerState>> text={{{ [<photoTitle>get[photographer]] }}}/>
<$action-setfield $tiddler=<<photoSourceState>> text={{{ [<photoTitle>get[photo-source]] }}}/>
<$action-setfield $tiddler=<<sourceNameState>> text={{{ [<photoTitle>get[photo-source-name]] }}}/>
<$action-setfield $tiddler=<<urlState>> text={{{ [<photoTitle>get[_canonical_uri]] }}}/>
<<t EditPhoto/ChangePhoto>>
</$button>
<$button>
<$action-deletefield $tiddler=<<draftTitle>> $field="photo"/>
<<t EditPhoto/RemovePhoto>>
</$button>
</div>
</div>
<%else%>
<$button>
<$action-setfield $tiddler=<<openState>> text="yes"/>
<<t EditPhoto/AddPhoto>>
</$button>
<%endif%>
<%endif%>
</div>
<%endif%>
</$let>
<% endif %>
