Framework  3.9
start_date_field_renderer.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8 Copyright (c) 2010 Sonjara, Inc
9 
10 Permission is hereby granted, free of charge, to any person
11 obtaining a copy of this software and associated documentation
12 files (the "Software"), to deal in the Software without
13 restriction, including without limitation the rights to use,
14 copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the
16 Software is furnished to do so, subject to the following
17 conditions:
18 
19 The above copyright notice and this permission notice shall be
20 included in all copies or substantial portions of the Software.
21 
22 Except as contained in this notice, the name(s) of the above
23 copyright holders shall not be used in advertising or otherwise
24 to promote the sale, use or other dealings in this Software
25 without prior written authorization.
26 
27 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
29 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34 OTHER DEALINGS IN THE SOFTWARE.
35 
36 *****************************************************************/
37 
38 require_once realpath(dirname(__FILE__))."/../field_renderers.inc";
39 
48 class StartDateTimeFieldRenderer extends DateTimeFieldRenderer
49 {
50  var $endDateField;
51 
59  function __construct($parent, $field, $label = "", $endDateField = "end_date")
60  {
61  $this->FieldRenderer($parent);
62  if ($parent->data->hasField($field))
63  {
64  $parent->override($field, $label, $this);
65  }
66  else
67  {
68  $parent->add($this, $field);
69  $parent->overrides[$field]['label'] = $label;
70  }
71  $this->endDateField = $endDateField;
72  }
73 
74  function renderScript($field)
75  {
76  if ($this->parent->readOnlyForm || $this->parent->isReadOnly($field)
77  || array_key_exists($field, $this->parent->hidden)) return "";
78 
79  $startField = "{$this->parent->id}_{$field}";
80  $endField = "{$this->parent->id}_{$this->endDateField}";
81 
82  parent::renderScript($field);
83 
84  echo "<script type='text/javascript'>\n";
85  echo "window.addEvent('domready', function()\n";
86  echo "{\n";
87  echo "\t\tdocument.id('{$startField}').addEvent('blur', function(e) { {$field}_onChangeStartDate(); });\n";
88  echo "\t\tdocument.id('{$endField}').addEvent('focus', function(e) { {$field}_onChangeStartDate(); });\n";
89  echo "\n";
90  echo "});\n";
91 
92 ?>
93  start_date_calendar.calendar.addEvent('mouseout', function(e) { <?php echo $field ?>_onChangeStartDate(); });
94  function <?echo $field ?>_onChangeStartDate()
95  {
96  var start_date_elt = document.id('<?php echo $startField ?>');
97  if(!start_date_elt || !start_date_elt.get("value")) return;
98  var end_date_elt = document.id('<?php echo $endField ?>');
99  if(!end_date_elt) return;
100  var startObj = new Date(start_date_elt.get("value"));
101  var endObj = null;
102  if(end_date_elt.get("value"))
103  {
104  endObj = new Date(end_date_elt.get("value"));
105  }
106  if(!endObj || endObj.valueOf() < startObj.valueOf())
107  {
108  end_date_elt.set("value", start_date_elt.get("value"));
109  }
110  }
111  <?php
112  echo "</script>\n";
113 
114  }
115 }
116 
117 ?>
Field renderer for date data fields.
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...
FieldRenderer($parent)
Constructor.