CMS  Version 3.9
photo_upload_field_renderer.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 Fakoli::using("image");
40 
41 class PhotoUploadFieldRenderer extends FieldRenderer
42 {
43  static function create($form, $field, $xrefClass)
44  {
46  {
48  }
49  }
50 
52  var $imageSize = 300;
53  var $takePhotoLabel = "Take a Photo";
54  var $uploadPhotoLabel = "Choose a Photo";
55  var $uploadRedirect = false;
56 
58  {
59  $this->FieldRenderer($form);
60  $this->gallery_id = $gallery_id;
61 
62  if ($form->data->hasField($field))
63  {
64  $form->override($field, $label, $this);
65  }
66  else
67  {
68  $form->add($this, $field);
69  $form->overrides[$field]['label'] = $label;
70  }
71  }
72 
73  function renderScript($field)
74  {
75 
76  if ($this->parent->readOnlyForm || $this->parent->isReadOnly($this->field) || array_key_exists($field, $this->parent->hidden)) return "";
77 
78  if (!$field) $field = $this->field;
79 
80  global $phonegap;
81 
82  ob_start();
83 
84  $redirect = $this->uploadRedirect ? "'{$this->uploadRedirect}'" : "false";
85 ?>
86  <script type="text/javascript" src="/components/phonegap/js/photo_uploader.js"></script>
87  <script type="text/javascript">
88  window.addEvent('load', function()
89  {
90  new PhotoUploader().setup('<?echo $this->parent->id?>_<?echo $field?>', '<?echo $this->parent->id?>_<?echo $field?>_thumbnail', '<?echo $this->parent->id?>_<?echo $field?>_status', '<?echo $this->gallery_id?>', <?echo $redirect?>);
91  });
92  </script>
93 <?
94  $phonegap .= ob_get_contents();
95  ob_end_clean();
96 
97  }
98 
99  function renderField($field = "")
100  {
101  global $user;
102 
103  if (!$field) $field = $this->field;
104 
105  $this->_startField($field);
106 
107  $id = $this->parent->data->get($field);
108 
109  if ($id)
110  {
111  $img = "<img src='/action/image/thumbnail?image_id={$id}&size={$this->imageSize}' alt=''/>";
112  }
113 ?>
114  <input type="hidden" value="<?echo $id?>" name="<?echo $field?>" id="<?echo $this->parent->id?>_<?echo $field?>"/>
115  <div id="<?echo $this->parent->id?>_<?echo $field?>_thumbnail"><?echo $img?></div>
116  <div id="<?echo $this->parent->id?>_<?echo $field?>_status"></div>
117  <br/>
118 <?
120  {
121 ?>
122  <a href="#" onclick="new PhotoUploader().capturePhoto(); return false" class="button"><i class='icon-camera'></i> <?echo $this->takePhotoLabel?></a>&nbsp;&nbsp;
123  <a href="#" onclick="new PhotoUploader().choosePhoto(); return false" class="button"><i class='icon-picture'></i> <?echo $this->uploadPhotoLabel?></a>
124 <?
125  }
126  $this->_endField($field);
127  }
128 
129  function renderReadOnly($field = "")
130  {
131  if (!$field) $field = $this->field;
132 
133  $id = $this->parent->data->get($field);
134  $this->_startField($field);
135 
136  if ($id)
137  {
138  echo "<img src='/action/image/thumbnail?image_id=".$this->parent->data->get($field)."&size=300' alt=''/>";
139  }
140  else
141  {
142  echo "No image uploaded";
143  }
144 
145  $this->_endField($field);
146  }
147 
148 }
149 ?>
& nbsp
Definition: index.inc:49
$form
$redirect
$image gallery_id
Definition: image_form.inc:58
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
PhotoUploadFieldRenderer($form, $field, $label, $gallery_id)
static create($form, $field, $xrefClass)
global $user
global $phonegap
Provides a central management class for event handlers and common functionality for the phonegap comp...