MojoMojo

 view release on metacpan or  search on metacpan

lib/MojoMojo/Controller/Jsrpc.pm  view on Meta::CPAN


Loads diff on demand. Takes an absolute revision number as arg,
and diffs it against the previous version.

=cut

sub diff : Local {
    my ( $self, $c, $page, $revision, $against, $sparse ) = @_;
    unless ($revision) {
        my $page = $c->model("DBIC::Page")->find($page) or do {
            $c->res->output($c->loc("Can't diff a nonexistent page"));
            return 0;
        };
        $revision = $page->content->id;
    }
    $revision = $c->model("DBIC::Content")->search(
        {
            page    => $page,
            version => $revision
        }
    )->next;
    if (
        my $previous = $against
        ? $c->model("DBIC::Content")->search(
            {
                page    => $page,
                version => $against
            }
        )->next
        : $revision->previous
        )
    {
        $c->res->output( $revision->formatted_diff( $c, $previous, $sparse ) );
    }
    else {
        $c->res->output($c->loc("This is the first revision! Nothing to diff against."));
    }
}

=head2 submittag ( /.jsrpc/submittag )

Add a tag through form submit

=cut

sub submittag : Local {
    my ( $self, $c, $page ) = @_;
    $c->forward( '/jsrpc/tag', [ $c->req->params->{tag} ] );
}

=head2 tag ( /.jsrpc/tag )

Add a tag to a page. Returns a list of yours and popular tags.

=cut

sub tag : Local Args(1) {
    my ( $self, $c, $tagname ) = @_;
    ($tagname) = $tagname =~ m/([\w\s]+)/;
    my $page = $c->stash->{page};
    foreach my $tag ( split m/\s/, $tagname ) {
        if (
            $tag
            && !$c->model("DBIC::Tag")->search(
                {
                    page   => $page->id,
                    person => $c->req->{user_id},
                    tag    => $tagname,
                }
            )->next()
            )
        {
            $page->add_to_tags(
                {
                    tag    => $tag,
                    person => $c->stash->{user}->id
                }
            ) if $page;
        }
    }
    $c->req->args( [$tagname] );
    $c->forward('/page/inline_tags');
}

=head2 untag ( /.jsrpc/untag )

Remove a tag from a page. Returns a list of yours and popular tags.

=cut

sub untag : Local Args(1) {
    my ( $self, $c, $tagname ) = @_;
    my $page = $c->stash->{page};
    die "Page " . $page . " not found" unless ref $page;
    my $tag = $c->model("DBIC::Tag")->search(
      {
        page   => $page->id,
        person => $c->user->obj->id,
        tag    => $tagname
      }
    )->next();
    $tag->delete() if $tag;
    $c->req->args( [$tagname] );
    $c->forward('/page/inline_tags');
}

=head2 imginfo ( .jsrpc/imginfo )

Inline info on hover for gallery photos.

=cut

sub imginfo : Local {
    my ( $self, $c, $photo ) = @_;
    $c->stash->{photo}    = $c->model("DBIC::Photo")->find($photo);
    $c->stash->{template} = 'gallery/imginfo.tt';
}

=head2 usersearch ( .jsrpc/usersearch )

Backend that handles jQuery autocomplete requests for users.



( run in 0.468 second using v1.01-cache-2.11-cpan-71847e10f99 )