Changeset 45 in bookmarks for trunk/BookmarkApp.pm


Ignore:
Timestamp:
06/03/13 17:43:16 (11 years ago)
Author:
peter
Message:
  • created a separate edit runmode to edit existing bookmarks; handled POST /{id}
  • the old edit runmode has been renamed to create, and only handles POST /
  • added an update method to the Bookmark class
  • the URI field on the bookmark editing form is no longer ever readonly; the URI can be changed after the bookmark has been created
  • changes to the URI or the bookmark's tags cause the bookmark's mtime to be updated
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BookmarkApp.pm

    r43 r45  
    2020        view 
    2121        view_field 
     22        create 
    2223        edit 
    2324    }]); 
     
    361362} 
    362363 
    363 #TODO: split this into edit and create methods 
    364 sub edit { 
     364sub create { 
    365365    my $self = shift; 
    366366    my $q = $self->query; 
    367     #TODO: get the bookmark based on the id and edit it directly? 
    368     #TODO: deal with changing URIs 
    369367    my $uri = $q->param('uri'); 
    370368    my $title = $q->param('title'); 
     
    392390} 
    393391 
     392sub edit { 
     393    my $self = shift; 
     394    my $q = $self->query; 
     395    my $id = $self->param('id'); 
     396 
     397    my $bookmark = $self->_bookmarks->get_bookmark({ id => $id }); 
     398    if ($bookmark) { 
     399        # update the URI, title, and tags 
     400        $bookmark->uri($q->param('uri')); 
     401        $bookmark->title($q->param('title')); 
     402        $bookmark->tags([ split(' ', $q->param('tags')) ]); 
     403        $bookmark->update($self->_bookmarks->dbh); 
     404 
     405        # return to the form 
     406        $self->header_type('redirect'); 
     407        $self->header_props( 
     408            -uri => $bookmark->bookmark_uri->canonical, 
     409            -status => 303, 
     410        ); 
     411    } else { 
     412        $self->header_props( 
     413            -type    => 'text/html', 
     414            -charset => 'UTF-8', 
     415            -status  => 404, 
     416        ); 
     417        return "Bookmark $id Not Found"; 
     418    } 
     419} 
     420 
    3944211; 
Note: See TracChangeset for help on using the changeset viewer.