| 1 | {* $Id$ *} |
|---|
| 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}admin/template/{$themeconf.template}/theme/{$themeconf.theme}/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 |
|---|
| 15 | function 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 | // min_linked_date: selector of hidden linked date control witch give min value |
|---|
| 24 | // max_linked_date: selector of hidden linked date control witch give max value |
|---|
| 25 | function pwg_initialization_datepicker(day, month, year, linked_date, min_linked_date, max_linked_date) |
|---|
| 26 | { |
|---|
| 27 | // Prevent selection of invalid dates through the select controls |
|---|
| 28 | function pwg_check_date() |
|---|
| 29 | { |
|---|
| 30 | array_date = $(linked_date).val().split('-'); |
|---|
| 31 | y = array_date[0]; |
|---|
| 32 | m = array_date[1]; |
|---|
| 33 | d = array_date[2]; |
|---|
| 34 | |
|---|
| 35 | $(linked_date).val(pwg_get_fmt_datepicker(day, month, year)); |
|---|
| 36 | |
|---|
| 37 | if ((min_linked_date != null) && ($(min_linked_date).datepicker("getDate") != null)) |
|---|
| 38 | { |
|---|
| 39 | cancel = ($(min_linked_date).datepicker("getDate") > $(linked_date).datepicker("getDate")); |
|---|
| 40 | } |
|---|
| 41 | else if ((max_linked_date != null) && ($(max_linked_date).datepicker("getDate") != null)) |
|---|
| 42 | { |
|---|
| 43 | cancel = ($(max_linked_date).datepicker("getDate") < $(linked_date).datepicker("getDate")); |
|---|
| 44 | } |
|---|
| 45 | else |
|---|
| 46 | { |
|---|
| 47 | cancel = false; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | if (cancel) |
|---|
| 51 | { |
|---|
| 52 | $(year).val(y); |
|---|
| 53 | $(month).val(m); |
|---|
| 54 | $(day).val(d); |
|---|
| 55 | // check again |
|---|
| 56 | pwg_check_date(); |
|---|
| 57 | } |
|---|
| 58 | else |
|---|
| 59 | { |
|---|
| 60 | var daysInMonth = 32 - new Date($(year).val(), $(month).val() - 1, 32).getDate(); |
|---|
| 61 | $(day + " option").attr("disabled", ""); |
|---|
| 62 | $(day + " option:gt(" + (daysInMonth) +")").attr("disabled", "disabled"); |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | jQuery().ready(function(){ |
|---|
| 67 | // Init hidden value |
|---|
| 68 | $(linked_date).val(pwg_get_fmt_datepicker(day, month, year)); |
|---|
| 69 | |
|---|
| 70 | // Init Datepicker |
|---|
| 71 | jQuery(linked_date).datepicker({ |
|---|
| 72 | dateFormat:'yy-m-d', |
|---|
| 73 | beforeShow: |
|---|
| 74 | // Prepare to show a date picker linked to three select controls |
|---|
| 75 | function readLinked(input) { |
|---|
| 76 | //$(linked_date).val(pwg_get_fmt_datepicker(day, month, year)); |
|---|
| 77 | if (min_linked_date != null) |
|---|
| 78 | { |
|---|
| 79 | return {minDate: $(min_linked_date).datepicker("getDate")}; |
|---|
| 80 | } |
|---|
| 81 | else if (max_linked_date != null) |
|---|
| 82 | { |
|---|
| 83 | return {maxDate: $(max_linked_date).datepicker("getDate")}; |
|---|
| 84 | } |
|---|
| 85 | else |
|---|
| 86 | { |
|---|
| 87 | return {}; |
|---|
| 88 | } |
|---|
| 89 | }, |
|---|
| 90 | onSelect: |
|---|
| 91 | // Update three select controls to match a date picker selection |
|---|
| 92 | function updateLinked(date) { |
|---|
| 93 | if (date.length == 0) |
|---|
| 94 | { |
|---|
| 95 | $(year).val(""); |
|---|
| 96 | $(month).val("0"); |
|---|
| 97 | $(day).val("0"); |
|---|
| 98 | } |
|---|
| 99 | else |
|---|
| 100 | { |
|---|
| 101 | array_date = date.split('-'); |
|---|
| 102 | $(year).val(array_date[0]); |
|---|
| 103 | $(month).val(array_date[1]); |
|---|
| 104 | $(day).val(array_date[2]); |
|---|
| 105 | } |
|---|
| 106 | pwg_check_date(); |
|---|
| 107 | }, |
|---|
| 108 | showOn: "both", |
|---|
| 109 | {/literal} |
|---|
| 110 | buttonImage: "{$ROOT_URL}admin/template/{$themeconf.template}/icon/datepicker.png", |
|---|
| 111 | {literal} |
|---|
| 112 | buttonImageOnly: true |
|---|
| 113 | }); |
|---|
| 114 | |
|---|
| 115 | // Check showed controls |
|---|
| 116 | jQuery(day + ", " + month + ", " + year).change( |
|---|
| 117 | function () |
|---|
| 118 | { |
|---|
| 119 | pwg_check_date(); |
|---|
| 120 | }); |
|---|
| 121 | |
|---|
| 122 | // In order to desable element of list |
|---|
| 123 | pwg_check_date(); |
|---|
| 124 | }); |
|---|
| 125 | |
|---|
| 126 | } |
|---|
| 127 | </script> |
|---|
| 128 | {/literal} |
|---|