Changes between Version 1 and Version 2 of BossaExampleFour

Show
Ignore:
Author:
davea (IP: 128.32.18.181)
Timestamp:
07/31/08 14:19:00 (1 year ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BossaExampleFour

    v1 v2  
    2323Using the administrative interface, create an application named "bossa_example4". 
    2424Create a directory '''~/projects/test/html/user/example4_images'''. 
    25 Put some images (.png or .jpg) there; a good source is 
     25Put some images (.png or .jpg) there; some sample images are in 
    2626http://isaac.ssl.berkeley.edu/test/example4_images/ 
    2727 
    3232}}} 
    3333 
    34 == 
     34== Opaque data == 
     35 
     36The application uses the following opaque data: 
     37 
     38 * Jobs 
     39{{{ 
     40path: the name of image file 
     41}}} 
     42 * Instances 
     43{{{ 
     44features: an array of structures, each containing: 
     45 
     46x: the X coordinate of the center 
     47y: the Y coordinate of the center 
     48type: the feature type (Tooth, Skull, Other) 
     49comment: the user-supplied comment 
     50}}} 
     51 
     52== Callback functions == 
     53 
     54The '''job_show()''' function displays the image and overlays 
     55existing annotations. 
     56Each one is shown as a box with an "info" button 
     57(which pops up the type and comment) 
     58and a "delete" button linked to the edit page. 
     59 
     60The image is an input item in a form linked to the edit page, 
     61so that clicks on the image produce a new annotation. 
     62Javascript is used to require that a feature type be selected 
     63in order for the annotation to be accepted. 
     64 
     65The "Done" button is linked to '''bossa_job_finished.php'''. 
     66 
     67== The edit handler == 
     68 
     69The edit handler is invoked with the following GET arguments: 
     70 
     71 * '''bji''': the ID of the instance 
     72 * '''action''': "add", "delete", or "" (to display the image) 
     73 * '''pic_x''' and '''pic_y''' (if action is "add") 
     74 
     75The code is as follows. 
     76The first two functions add and delete annotations; 
     77each one ends by redirecting to the same page with no "action" argument; 
     78this will redisplay the image with the new set of annotations. 
     79{{{ 
     80     7  function handle_add($job, $inst) { 
     81     8      $f = null; 
     82     9      $f->x = get_int('pic_x'); 
     83    10      $f->y = get_int('pic_y'); 
     84    11      $f->type = get_str('type'); 
     85    12      $c = get_str('comment', true); 
     86    13      if (strstr($c, "(optional)")) $c = ""; 
     87    14      $f->comment = $c; 
     88    15      $output = $inst->get_opaque_data(); 
     89    16      $output->features[] = $f; 
     90    17      $inst->set_opaque_data($output); 
     91    18      header("location: bossa_example4.php?bji=$inst->id"); 
     92    19  } 
     93    20 
     94    21  function handle_delete($job, $inst, $index) { 
     95    22      $output = $inst->get_opaque_data(); 
     96    23      $features = $output->features; 
     97    24      array_splice($features, $index, 1); 
     98    25      $output->features = $features; 
     99    26      $inst->set_opaque_data($output); 
     100    27      header("location: bossa_example4.php?bji=$inst->id"); 
     101    28  } 
     102}}} 
     103 
     104The main part of the script is as follows. 
     105First, we get the instance ID and call a Bossa API function 
     106to get the job, instance, and user: 
     107{{{ 
     108    30  $bji = get_int("bji"); 
     109    31  if (!bossa_lookup_job($bji, $job, $inst, $u)) { 
     110    32      error_page("No such instance"); 
     111    33  } 
     112}}} 
     113Then we verify that this instance belongs to the logged-in user: 
     114{{{ 
     115    34  $user = get_logged_in_user(); 
     116    35  if ($u->id != $user->id) { 
     117    36      error_page("Not your job"); 
     118    37  } 
     119}}} 
     120Then we perform the operation (or show the image with existing annotations): 
     121{{{ 
     122    39  $action = get_str("action", true); 
     123    40  switch ($action) { 
     124    41  case "add": 
     125    42      handle_add($job, $inst); 
     126    43      break; 
     127    44  case "delete": 
     128    45      $index = get_int("index"); 
     129    46      handle_delete($job, $inst, $index); 
     130    47      break; 
     131    48  default: 
     132    49      job_show($job, $inst, $user); 
     133    50      break; 
     134    51  } 
     135    52 
     136    53  ?> 
     137}}} 

If this page is incomplete or incorrect, please edit it or add it to the wiki to-do list. To do this, you must be logged in; click Login or Register above.