CMS  Version 3.9
native_datetime_field_renderer.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::usingFeature("field_renderers");
8 
9 class NativeDateTimeFieldRenderer extends DateTimeFieldRenderer
10 {
11  var $pushToSet = false;
12 
14  {
15  trace("Instantiating NativeDateTimeFieldRenderer for $field", 3);
16  $this->DateTimeFieldRenderer($parent);
17  }
18 
19  function renderScript($field)
20  {
21  if ($this->pushToSet)
22  {
23 ?>
24 <script type='text/javascript'>
25 window.addEvent('domready', function()
26 {
27  document.id('<?echo $this->parent->id?>_<?echo $field?>_button').addEvent('click', function()
28  {
29  var now = new Date();
30  var date = now.toISOString().split("T")[0];
31  var time = now.toTimeString().split(" ")[0];
32  document.id('<?echo $this->parent->id?>_<?echo $field?>_date').value = date;
33  document.id('<?echo $this->parent->id?>_<?echo $field?>_time').value = time;
34  return false;
35  });
36 });
37 </script>
38 <?
39  }
40  }
41 
42  function addValidatorsToForm($field, $required = false)
43  {
44  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
45 
46  if($required)
47  {
48  $this->parent->validator->add(new RequiredValidator($field."_date", $label . " Date"));
49  $this->parent->validator->add(new RequiredTimeValidator($field."_time", $label . " Time"));
50  }
51  }
52 
53  function renderField($field)
54  {
55  $obj = $this->parent->data;
56  $value = $obj->get($field);
57 
58  // JDG 10/1/2010 check for empty saved string
59  $date = "";
60  $time = "";
61 
62  if($value AND $value != '0000-00-00 00:00:00')
63  {
64  $date = DateTimeTypeRenderer::format($obj->reformatFromSQLDate($value), "Y-m-d");
65  $time = DateTimeTypeRenderer::format($obj->reformatFromSQLDate($value), "H:i");
66  }
67 
68  $this->_startField($field);
69  echo "<input id='{$this->parent->id}_{$field}_date' type='date' name='{$field}_date' value='$date'>";
70  echo "&nbsp;<input id='{$this->parent->id}_{$field}_time' type='time' name='{$field}_time' value='$time'>";
71 
72  if ($this->pushToSet)
73  {
74  echo "&nbsp;&nbsp;<a id='{$this->parent->id}_{$field}_button' class='button' href='#'><img src='/components/mobile_settings/images/stopwatch_icon.png' alt='Push to Set'/></a>";
75  }
76 
77  $this->_endField($field);
78  }
79 
81  {
82  }
83 
85  {
86  if ($mode == "range")
87  {
88  $date_from = $this->parent->params->get($field, "from");
89  $date_to = $this->parent->params->get($field, "to");
90 
91  $this->_startField($field);
92 
93  echo "<input type='datetime' name='$field:from' value='$date_from'>";
94  echo " to <input type='datetime' name='$field:to' value='$date_to'>\n";
95 
96  $this->_endField($field);
97  }
98  else
99  {
100  $date = $this->parent->params->get($field, $mode);
101 
102  $this->_startField($field);
103  echo "<input type='datetime' name='$field:$mode' value='$date'>";
104  $this->_endField($field);
105  }
106  }
107 
109  {
110  $this->_startField($field);
111  echo $this->format($field);
112 
113  // AJG - if the field is read-only but the form is not, add a hidden field to
114  // retain the field value upon submission.
115 
116  if (!$this->parent->readOnlyForm)
117  {
118  $obj = $this->parent->data;
119  $value = $obj->get($field);
120  echo "<input type='hidden' name='$field' value='{$value}'/>";
121  }
122 
123  $this->_endField();
124  }
125 
126  function preProcess($field = "")
127  {
128  $this->parent->data->set($field, trim($_REQUEST["{$field}_date"]." ".$_REQUEST["{$field}_time"]));
129  trace("DateTime: ".$this->parent->data->get($field), 1);
130  }
131 }?>
$parent
Definition: templates.inc:42
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
addValidatorsToForm($field, $required=false)
$date
Definition: event_list.inc:51
$mode