CMS  Version 3.9
document_select_field_renderer.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::using("document");
8 Fakoli::usingFeature("field_renderers", "document_handler");
9 
10 class DocumentSelectFieldRenderer extends FieldRenderer
11 {
12  var $library;
13  var $emptyMessage = "No Document Selected";
14 
16  {
17  $this->FieldRenderer($form);
18  if ($form->data->hasField($field))
19  {
20  $form->override($field, $label, $this);
21  }
22  else
23  {
24  $form->add($this, $field);
25  $form->overrides[$field]['label'] = $label;
26  }
27 
29  }
30 
32  {
33  $documents = $this->library->Documents("ORDER BY title");
34 
35  foreach($documents as $document)
36  {
37  echo "<a href='#' onclick='{$this->parent->id}_{$field}_selectItem(this, {$document->document_id}); return false;'>";
38  echo $this->formatDocument($document);
39  echo "</a>";
40  }
41  }
42 
44  {
45  $img = DocumentHandler::getDocIcon($document->file);
46  return "<img src='$img' alt='' style='display: inline-block; vertical-align: middle'>&nbsp;{$document->title}";
47  }
48 
50  {
51  $library = $document->DocumentLibrary();
52  $size = $library->getFileSize($document);
53  $img = DocumentHandler::getDocIcon($document->file);
54 
55  return "<img src='$img' alt='' style='display: inline-block; vertical-align: middle'>&nbsp;".
56  "<a href='/action/document/download?document_id={$document->document_id}'>{$document->title}</a>&nbsp;$size";
57  }
58 
59  function renderScript($field)
60  {
61  if ($this->parent->isReadOnly($field)) return;
62 
63  $script .= <<<ENDSCRIPT
64 <script type="text/javascript">
65 function {$this->parent->id}_{$field}_showList(e)
66 {
67  new DOMEvent(e).stop();
68  var popup = document.id('{$this->parent->id}_{$field}_list_popup');
69  var txt = document.id('{$this->parent->id}_{$field}');
70  var coords = txt.getCoordinates();
71  popup.setStyles({'display': 'block'});
72  var doc = document.id(document.body ? document.body : document.documentElement);
73  doc.addEvent('click', {$this->parent->id}_{$field}_hideList);
74 }
75 
76 function {$this->parent->id}_{$field}_hideList()
77 {
78  var popup = document.id('{$this->parent->id}_{$field}_list_popup');
79  popup.setStyles({'display': 'none'});
80  var doc = document.id(document.body ? document.body : document.documentElement);
81  doc.removeEvent('click', {$this->parent->id}_{$field}_hideList);
82 }
83 
84 function {$this->parent->id}_{$field}_selectItem(elt, id)
85 {
86  var hidden = document.id('{$this->parent->id}_{$field}');
87 
88  var txt = document.id('{$this->parent->id}_{$field}_text');
89  hidden.set('value', id);
90 
91  if (id)
92  {
93  txt.set('html', elt.get('html'));
94  }
95 
96  {$this->parent->id}_{$field}_hideList();
97 }
98 
99 window.addEvent('domready', function()
100 {
101  var popup = document.id('{$this->parent->id}_{$field}_list_popup');
102  popup.addEvent('click', function(e) { new DOMEvent(e).stop(); });
103 });
104 </script>
105 ENDSCRIPT;
106 
107  echo $script;
108  }
109 
111  {
112  $this->renderField($field);
113  }
114 
115  function renderField($field = "")
116  {
117  if (!$field) $field = $this->field;
118 
119  $this->_startField($field);
120 
121  $autocomplete = (!$this->autocomplete) ? "autocomplete='off' " : "";
122 
123  $value = $this->parent->data->get($field);
124  $text = "";
125  if ($value)
126  {
127  $document = new Document($value);
128  $text = $this->formatDocument($document);
129  }
130  else
131  {
133  }
134 
135  echo "<input id='{$this->parent->id}_{$field}' type='hidden' name='$field' value='".htmlspecialchars($value, ENT_QUOTES, 'UTF-8')."'/>";
136  echo "<span id='{$this->parent->id}_{$field}_text' class='document_select_text' onclick='{$this->parent->id}_{$field}_showList(event); return false;'>".$text."</span>";
137  echo "&nbsp;<a class='button' href='#' onclick='{$this->parent->id}_{$field}_showList(event); return false;'>Browse</a><br/>";
138  echo "<div id='{$this->parent->id}_{$field}_list_popup' class='progressive_search' style='display: none;position:absolute; max-height: 150px; overflow-y: auto'>";
139  $this->writeDocumentList($field);
140  echo "</div>";
141 
142  $this->_endField($field);
143  }
144 
146  {
147  $this->_startField($field);
148 
149  $value = $this->parent->data->get($field);
150  $text = "";
151  if ($value)
152  {
153  $document = new Document($value);
155  }
156  else
157  {
159  }
160 
161  if ($this->parent->readOnlyForm)
162  {
163  echo $text;
164  }
165  else
166  {
167  echo "<input id='{$this->parent->id}_{$field}' type='hidden' name='$field' value='".htmlspecialchars($value, ENT_QUOTES, 'UTF-8')."'/>";
168  echo "<span id='{$this->parent->id}_{$field}_text' class='document_select_text'>".$text."</span>";
169  }
170 
171  $this->_endField($field);
172  }
173 }
174  ?>
$form
$size
Definition: download.inc:47
This class maps the publication table.
Definition: document.inc:43
static findByIdentifier($identifier)
DocumentSelectFieldRenderer(&$form, $field, $label, $libraryIdentifier)
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
if(! $document_id) $document
Definition: delete.inc:43
$mode
$documents