diff options
author | Yorhel <git@yorhel.nl> | 2019-07-25 14:30:04 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-07-25 14:36:21 +0200 |
commit | f296495a912ce759df11c43e78b4552788bdbff2 (patch) | |
tree | 0c10802de65fb7c8475722e12234bff5eb980628 /lib/VN3/Docs/Edit.pm | |
parent | 0f3cfeb85caec6424bcbea47142eefbf8011636b (diff) |
Merge the v3 branch into separate namespace + fix Docker stuff (again)
I was getting tired of having to keep two branches up-to-date with the
latest developments, so decided to throw v3 into the same branch - just
different files (...which will get mostly rewritten again soon). The two
versions aren't very different in terms of dependencies, build system
and support code, so they can now properly share files. Added a section
to the README to avoid confusion.
This merge also makes it easier to quickly switch between the different
versions, which is handy for development. It's even possible to run both
at the same time, but my scripts use the same port so that needs a
workaround.
And it's amazing how often I break the Docker scripts.
Diffstat (limited to 'lib/VN3/Docs/Edit.pm')
-rw-r--r-- | lib/VN3/Docs/Edit.pm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/VN3/Docs/Edit.pm b/lib/VN3/Docs/Edit.pm new file mode 100644 index 00000000..b4eae572 --- /dev/null +++ b/lib/VN3/Docs/Edit.pm @@ -0,0 +1,52 @@ +package VN3::Docs::Edit; + +use VN3::Prelude; +use VN3::Docs::Lib; + + +my $FORM = { + title => { maxlength => 200 }, + content => { required => 0, default => '' }, + hidden => { anybool => 1 }, + locked => { anybool => 1 }, + + editsum => { _when => 'in out', editsum => 1 }, + id => { _when => 'out', id => 1 }, +}; + +our $FORM_OUT = form_compile out => $FORM; +our $FORM_IN = form_compile in => $FORM; +our $FORM_CMP = form_compile cmp => $FORM; + + +TUWF::get qr{/$DREV_RE/edit} => sub { + my $d = entry d => tuwf->capture('id'), tuwf->capture('rev') or return tuwf->resNotFound; + return tuwf->resDenied if !can_edit d => $d; + + $d->{editsum} = $d->{chrev} == $d->{maxrev} ? '' : "Reverted to revision d$d->{id}.$d->{chrev}"; + + Framework title => "Edit $d->{title}", index => 0, + sub { + Div class => 'row', sub { + Div class => 'fixed-size-left-sidebar-md doc-list', \&Sidebar; + Div class => 'col-md col-md--4', sub { + Div 'data-elm-module' => 'DocEdit', + 'data-elm-flags' => JSON::XS->new->encode($FORM_OUT->analyze->coerce_for_json($d)), ''; + }; + }; + }; +}; + + +json_api qr{/$DOC_RE/edit}, $FORM_IN, sub { + my $data = shift; + my $doc = entry d => tuwf->capture('id') or return tuwf->resNotFound; + + return tuwf->resJSON({Unauth => 1}) if !can_edit d => $doc; + return tuwf->resJSON({Unchanged => 1}) if !form_changed $FORM_CMP, $data, $doc; + + my($id,undef,$rev) = update_entry d => $doc->{id}, $data; + tuwf->resJSON({Changed => [$id, $rev]}); +}; + +1; |