Viewing and then Editing

I have got asked a question: What is the best way of showing a read-only details of the model and then allowing users to edit it. I decided to create this example to show you my favourite way

I will also take advantage of the new View_ModelDetails.

I will be taking advantage of view reloading, but since the view would be substituted by form, i need to reload their parent - the page.

SOURCE

$model = $page->add('Model_Person')->tryLoadAny();
$this->api->stickyGET('editing');

if($_GET['editing']=="yes"){
    $form = $page->add('Form');
    $form->setModel($model);
    $form->addSubmit();
    $form->addButton('Cancel')
        ->js('click', $page->js()->reload(array('editing'=>false)));

    if($form->isSubmitted()){
        $form->update();
        $page->js()->reload(array('editing'=>false))->execute();
    }

}else{
    $page->add('Button')
        ->set('Edit')
        ->js('click', $page->js()->reload(array('editing'=>"yes")));
    $page->add('View_ModelDetails')->setModel($model);
}


  
Demo
Id Name Value
id Id 1
name Name sawwjwns