source: trunk/admin/template/goto/include/datepicker.inc.tpl @ 2680

Last change on this file since 2680 was 2680, checked in by rub, 16 years ago

jQuery Datepicker:

o use id for selector
o check radio button on change date

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1{* $Id: datepicker.inc.tpl 2680 2008-10-07 19:18:55Z rub $ *}
2{known_script id="jquery" src=$ROOT_URL|@cat:"template-common/lib/jquery.packed.js"}
3{known_script id="jquery.ui" src=$ROOT_URL|@cat:"template-common/lib/ui/ui.core.packed.js"}
4{known_script id="jquery.ui.datepicker" src=$ROOT_URL|@cat:"template-common/lib/ui/ui.datepicker.packed.js"}
5{known_script id="jquery.ui.datepicker-$lang_info.code" src=$ROOT_URL|@cat:"template-common/lib/ui/i18n/ui.datepicker-"|@cat:$lang_info.code|@cat:".js"}
6
7{html_head}
8<link rel="stylesheet" type="text/css" href="{$ROOT_URL}template-common/lib/ui/ui.datepicker.css">
9{/html_head}
10
11{literal}
12<script type="text/javascript">
13// return formated date with control values
14// day, month, year: selectors of visible date controls
15function pwg_get_fmt_datepicker(day, month, year)
16{
17  return $(year).val() + "-" + $(month).val() + "-" + $(day).val();
18}
19
20// initialize controls
21// day, month, year: selectors of visible date controls
22// linked_date: selector of hidden linked dates control
23// checked_on_change: selector of control to change "checked" attribut
24// min_linked_date: selector of hidden linked date control witch give min value
25// max_linked_date: selector of hidden linked date control witch give max value
26function pwg_initialization_datepicker(day, month, year, linked_date, checked_on_change, min_linked_date, max_linked_date)
27{
28  // Action on change date value
29  function pwg_on_date_change()
30  {
31    pwg_check_date();
32    if (checked_on_change != null)
33    {
34      $(checked_on_change).attr("checked", "true");
35    }
36  }
37
38  // Prevent selection of invalid dates through the select controls
39  function pwg_check_date()
40  {
41    array_date = $(linked_date).val().split('-');
42    y = array_date[0];
43    m = array_date[1];
44    d = array_date[2];
45
46    $(linked_date).val(pwg_get_fmt_datepicker(day, month, year));
47
48    if ((min_linked_date != null) && ($(min_linked_date).datepicker("getDate") != null))
49    {
50      cancel = ($(min_linked_date).datepicker("getDate") > $(linked_date).datepicker("getDate"));
51    }
52    else if ((max_linked_date != null) && ($(max_linked_date).datepicker("getDate") != null))
53    {
54      cancel = ($(max_linked_date).datepicker("getDate") < $(linked_date).datepicker("getDate"));
55    }
56    else
57    {
58      cancel = false;
59    }
60
61    if (cancel)
62    {
63      $(year).val(y);
64      $(month).val(m);
65      $(day).val(d);
66      // check again
67      pwg_check_date();
68    }
69    else
70    {
71      var daysInMonth = 32 - new Date($(year).val(), $(month).val() - 1, 32).getDate();
72      $(day + " option").attr("disabled", "");
73      $(day + " option:gt(" + (daysInMonth) +")").attr("disabled", "disabled");
74    }
75  }
76
77  jQuery().ready(function(){
78    // Init hidden value
79    $(linked_date).val(pwg_get_fmt_datepicker(day, month, year));
80
81    // Init Datepicker
82    jQuery(linked_date).datepicker({
83      dateFormat:'yy-m-d',
84      beforeShow:
85        // Prepare to show a date picker linked to three select controls
86        function readLinked(input) {
87            //$(linked_date).val(pwg_get_fmt_datepicker(day, month, year));
88            if (min_linked_date != null)
89            {
90              return {minDate: $(min_linked_date).datepicker("getDate")};
91            }
92            else if (max_linked_date != null)
93            {
94              return {maxDate: $(max_linked_date).datepicker("getDate")};
95            }
96            else
97            {
98              return {};
99            }
100        },
101      onSelect:
102        // Update three select controls to match a date picker selection
103        function updateLinked(date) {
104            if (date.length == 0)
105            {
106              $(year).val("");
107              $(month).val("0");
108              $(day).val("0");
109            }
110            else
111            {
112              array_date = date.split('-');
113              $(year).val(array_date[0]);
114              $(month).val(array_date[1]);
115              $(day).val(array_date[2]);
116            }
117            pwg_on_date_change();
118        },
119      showOn: "both",
120{/literal}
121      buttonImage: "{$ROOT_URL}admin/template/{$themeconf.template}/icon/datepicker.png",
122{literal}
123      buttonImageOnly: true,
124      buttonText: ""
125      });
126
127    // Check showed controls
128    jQuery(day + ", " + month + ", " + year).change(
129      function ()
130      {
131        pwg_on_date_change();
132      });
133
134    // In order to desable element of list
135    // In order to init linked input
136    pwg_check_date();
137   });
138
139}
140</script>
141{/literal}
Note: See TracBrowser for help on using the repository browser.