active_scaffold_vho 3.0.31 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/Gemfile +9 -1
  2. data/Gemfile.lock +8 -79
  3. data/Rakefile +17 -20
  4. data/active_scaffold_vho.gemspec +374 -15
  5. data/{frontends/default → app/assets}/images/add.gif +0 -0
  6. data/{frontends/default → app/assets}/images/arrow_down.gif +0 -0
  7. data/{frontends/default → app/assets}/images/arrow_up.gif +0 -0
  8. data/{frontends/default → app/assets}/images/close.gif +0 -0
  9. data/{frontends/default → app/assets}/images/close_touch.png +0 -0
  10. data/{frontends/default → app/assets}/images/config.png +0 -0
  11. data/{frontends/default → app/assets}/images/cross.png +0 -0
  12. data/{frontends/default → app/assets}/images/gears.png +0 -0
  13. data/{frontends/default → app/assets}/images/indicator-small.gif +0 -0
  14. data/{frontends/default → app/assets}/images/indicator.gif +0 -0
  15. data/{frontends/default → app/assets}/images/magnifier.png +0 -0
  16. data/app/assets/javascripts/active_scaffold.js.erb +12 -0
  17. data/{frontends/default → app/assets}/javascripts/jquery/active_scaffold.js +73 -245
  18. data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +24 -0
  19. data/app/assets/javascripts/jquery/jquery-ui-timepicker-addon.js +1060 -0
  20. data/{frontends/default → app/assets}/javascripts/jquery/jquery.editinplace.js +1 -1
  21. data/{lib/active_scaffold/bridges/tiny_mce/public → app/assets}/javascripts/jquery/tiny_mce_bridge.js +4 -3
  22. data/{frontends/default → app/assets}/javascripts/prototype/active_scaffold.js +36 -122
  23. data/{frontends/default → app/assets}/javascripts/prototype/dhtml_history.js +0 -0
  24. data/{frontends/default → app/assets}/javascripts/prototype/form_enhancements.js +0 -0
  25. data/{frontends/default → app/assets}/javascripts/prototype/rico_corner.js +0 -0
  26. data/{frontends/default/stylesheets/stylesheet-ie.css → app/assets/stylesheets/active_scaffold-ie.css} +0 -0
  27. data/{frontends/default/stylesheets/stylesheet.css → app/assets/stylesheets/active_scaffold.css.erb} +24 -22
  28. data/app/assets/stylesheets/jquery-ui-timepicker-addon.css +6 -0
  29. data/frontends/default/views/_action_group.html.erb +1 -1
  30. data/frontends/default/views/_base_form.html.erb +1 -1
  31. data/frontends/default/views/_form_association_footer.html.erb +11 -7
  32. data/frontends/default/views/_horizontal_subform_record.html.erb +5 -9
  33. data/frontends/default/views/_list.html.erb +1 -2
  34. data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
  35. data/frontends/default/views/_list_messages.html.erb +2 -2
  36. data/frontends/default/views/_list_pagination.html.erb +6 -3
  37. data/frontends/default/views/_list_pagination_links.html.erb +9 -0
  38. data/frontends/default/views/_list_record.html.erb +2 -1
  39. data/frontends/default/views/_list_record_columns.html.erb +2 -1
  40. data/frontends/default/views/_list_with_header.html.erb +1 -1
  41. data/frontends/default/views/_messages.html.erb +0 -1
  42. data/frontends/default/views/_render_field.js.erb +13 -0
  43. data/frontends/default/views/_vertical_subform_record.html.erb +5 -9
  44. data/frontends/default/views/add_existing.js.erb +20 -0
  45. data/frontends/default/views/destroy.js.erb +24 -0
  46. data/frontends/default/views/{edit_associated.js.rjs → edit_associated.js.erb} +3 -2
  47. data/frontends/default/views/form_messages.js.erb +1 -0
  48. data/frontends/default/views/list.js.erb +1 -0
  49. data/frontends/default/views/on_action_update.js.erb +13 -0
  50. data/frontends/default/views/on_create.js.erb +45 -0
  51. data/frontends/default/views/on_mark_all.js.erb +12 -0
  52. data/frontends/default/views/on_update.js.erb +31 -0
  53. data/frontends/default/views/update_column.js.erb +16 -0
  54. data/frontends/default/views/update_row.js.erb +1 -0
  55. data/init.rb +1 -7
  56. data/lib/active_scaffold/actions/delete.rb +3 -5
  57. data/lib/active_scaffold/actions/field_search.rb +2 -6
  58. data/lib/active_scaffold/actions/list.rb +16 -14
  59. data/lib/active_scaffold/actions/search.rb +3 -3
  60. data/lib/active_scaffold/active_record_permissions.rb +2 -25
  61. data/lib/active_scaffold/attribute_params.rb +21 -44
  62. data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +1 -1
  63. data/lib/active_scaffold/bridges/date_picker/bridge.rb +2 -16
  64. data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +86 -56
  65. data/lib/active_scaffold/bridges/file_column/bridge.rb +1 -1
  66. data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +1 -1
  67. data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +1 -1
  68. data/lib/active_scaffold/bridges/paperclip/bridge.rb +1 -1
  69. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +2 -2
  70. data/lib/active_scaffold/bridges/shared/date_bridge.rb +3 -3
  71. data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +0 -12
  72. data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +1 -1
  73. data/lib/active_scaffold/config/base.rb +1 -1
  74. data/lib/active_scaffold/config/core.rb +1 -8
  75. data/lib/active_scaffold/config/delete.rb +1 -1
  76. data/lib/active_scaffold/config/field_search.rb +1 -22
  77. data/lib/active_scaffold/config/list.rb +10 -18
  78. data/lib/active_scaffold/data_structures/action_link.rb +9 -0
  79. data/lib/active_scaffold/data_structures/action_links.rb +1 -1
  80. data/lib/active_scaffold/data_structures/column.rb +4 -30
  81. data/lib/active_scaffold/data_structures/nested_info.rb +3 -3
  82. data/lib/active_scaffold/data_structures/sorting.rb +1 -1
  83. data/lib/active_scaffold/engine.rb +8 -0
  84. data/lib/active_scaffold/extensions/action_controller_rendering.rb +22 -0
  85. data/lib/active_scaffold/extensions/action_view_rendering.rb +79 -59
  86. data/lib/active_scaffold/extensions/action_view_resolver.rb +4 -2
  87. data/lib/active_scaffold/extensions/active_association_reflection.rb +3 -3
  88. data/lib/active_scaffold/extensions/reverse_associations.rb +3 -3
  89. data/lib/active_scaffold/finder.rb +27 -39
  90. data/lib/active_scaffold/helpers/association_helpers.rb +3 -3
  91. data/lib/active_scaffold/helpers/form_column_helpers.rb +3 -3
  92. data/lib/active_scaffold/helpers/human_condition_helpers.rb +2 -4
  93. data/lib/active_scaffold/helpers/list_column_helpers.rb +16 -22
  94. data/lib/active_scaffold/helpers/search_column_helpers.rb +1 -1
  95. data/lib/active_scaffold/helpers/view_helpers.rb +35 -13
  96. data/lib/active_scaffold/locale/de.rb +120 -0
  97. data/lib/active_scaffold/locale/en.rb +119 -0
  98. data/lib/active_scaffold/version.rb +2 -2
  99. data/lib/active_scaffold.rb +12 -27
  100. data/lib/active_scaffold_env.rb +3 -3
  101. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +1 -1
  102. metadata +84 -86
  103. data/.gitignore +0 -42
  104. data/frontends/default/views/_render_field.js.rjs +0 -10
  105. data/frontends/default/views/add_existing.js.rjs +0 -17
  106. data/frontends/default/views/destroy.js.rjs +0 -23
  107. data/frontends/default/views/form_messages.js.rjs +0 -1
  108. data/frontends/default/views/list.js.rjs +0 -1
  109. data/frontends/default/views/on_action_update.js.rjs +0 -10
  110. data/frontends/default/views/on_create.js.rjs +0 -41
  111. data/frontends/default/views/on_mark_all.js.rjs +0 -12
  112. data/frontends/default/views/on_update.js.rjs +0 -28
  113. data/frontends/default/views/update_column.js.rjs +0 -13
  114. data/frontends/default/views/update_row.js.rjs +0 -1
  115. data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +0 -36
  116. data/lib/active_scaffold/bridges/tiny_mce/public/javascripts/prototype/tiny_mce_bridge.js +0 -21
  117. data/lib/active_scaffold/locale/de.yml +0 -120
  118. data/lib/active_scaffold/locale/en.yml +0 -115
  119. data/lib/active_scaffold_assets.rb +0 -45
@@ -0,0 +1,1060 @@
1
+ /*
2
+ * jQuery timepicker addon
3
+ * By: Trent Richardson [http://trentrichardson.com]
4
+ * Version 0.9.6
5
+ * Last Modified: 07/20/2011
6
+ *
7
+ * Copyright 2011 Trent Richardson
8
+ * Dual licensed under the MIT and GPL licenses.
9
+ * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
10
+ * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
11
+ *
12
+ * HERES THE CSS:
13
+ * .ui-timepicker-div .ui-widget-header{ margin-bottom: 8px; }
14
+ * .ui-timepicker-div dl{ text-align: left; }
15
+ * .ui-timepicker-div dl dt{ height: 25px; }
16
+ * .ui-timepicker-div dl dd{ margin: -25px 10px 10px 65px; }
17
+ * .ui-timepicker-div td { font-size: 90%; }
18
+ */
19
+
20
+ (function($) {
21
+
22
+ $.extend($.ui, { timepicker: { version: "0.9.6" } });
23
+
24
+ /* Time picker manager.
25
+ Use the singleton instance of this class, $.timepicker, to interact with the time picker.
26
+ Settings for (groups of) time pickers are maintained in an instance object,
27
+ allowing multiple different settings on the same page. */
28
+
29
+ function Timepicker() {
30
+ this.regional = []; // Available regional settings, indexed by language code
31
+ this.regional[''] = { // Default regional settings
32
+ currentText: 'Now',
33
+ closeText: 'Done',
34
+ ampm: false,
35
+ timeFormat: 'hh:mm tt',
36
+ timeSuffix: '',
37
+ timeOnlyTitle: 'Choose Time',
38
+ timeText: 'Time',
39
+ hourText: 'Hour',
40
+ minuteText: 'Minute',
41
+ secondText: 'Second',
42
+ timezoneText: 'Time Zone'
43
+ };
44
+ this._defaults = { // Global defaults for all the datetime picker instances
45
+ showButtonPanel: true,
46
+ timeOnly: false,
47
+ showHour: true,
48
+ showMinute: true,
49
+ showSecond: false,
50
+ showTimezone: false,
51
+ showTime: true,
52
+ stepHour: 0.05,
53
+ stepMinute: 0.05,
54
+ stepSecond: 0.05,
55
+ hour: 0,
56
+ minute: 0,
57
+ second: 0,
58
+ timezone: '+0000',
59
+ hourMin: 0,
60
+ minuteMin: 0,
61
+ secondMin: 0,
62
+ hourMax: 23,
63
+ minuteMax: 59,
64
+ secondMax: 59,
65
+ minDateTime: null,
66
+ maxDateTime: null,
67
+ hourGrid: 0,
68
+ minuteGrid: 0,
69
+ secondGrid: 0,
70
+ alwaysSetTime: true,
71
+ separator: ' ',
72
+ altFieldTimeOnly: true,
73
+ showTimepicker: true,
74
+ timezoneList: ["-1100", "-1000", "-0900", "-0800", "-0700", "-0600",
75
+ "-0500", "-0400", "-0300", "-0200", "-0100", "+0000",
76
+ "+0100", "+0200", "+0300", "+0400", "+0500", "+0600",
77
+ "+0700", "+0800", "+0900", "+1000", "+1100", "+1200"]
78
+ };
79
+ $.extend(this._defaults, this.regional['']);
80
+ }
81
+
82
+ $.extend(Timepicker.prototype, {
83
+ $input: null,
84
+ $altInput: null,
85
+ $timeObj: null,
86
+ inst: null,
87
+ hour_slider: null,
88
+ minute_slider: null,
89
+ second_slider: null,
90
+ timezone_select: null,
91
+ hour: 0,
92
+ minute: 0,
93
+ second: 0,
94
+ timezone: '+0000',
95
+ hourMinOriginal: null,
96
+ minuteMinOriginal: null,
97
+ secondMinOriginal: null,
98
+ hourMaxOriginal: null,
99
+ minuteMaxOriginal: null,
100
+ secondMaxOriginal: null,
101
+ ampm: '',
102
+ formattedDate: '',
103
+ formattedTime: '',
104
+ formattedDateTime: '',
105
+ timezoneList: ["-1100", "-1000", "-0900", "-0800", "-0700", "-0600",
106
+ "-0500", "-0400", "-0300", "-0200", "-0100", "+0000",
107
+ "+0100", "+0200", "+0300", "+0400", "+0500", "+0600",
108
+ "+0700", "+0800", "+0900", "+1000", "+1100", "+1200"],
109
+
110
+ /* Override the default settings for all instances of the time picker.
111
+ @param settings object - the new settings to use as defaults (anonymous object)
112
+ @return the manager object */
113
+ setDefaults: function(settings) {
114
+ extendRemove(this._defaults, settings || {});
115
+ return this;
116
+ },
117
+
118
+ //########################################################################
119
+ // Create a new Timepicker instance
120
+ //########################################################################
121
+ _newInst: function($input, o) {
122
+ var tp_inst = new Timepicker(),
123
+ inlineSettings = {};
124
+
125
+ for (var attrName in this._defaults) {
126
+ var attrValue = $input.attr('time:' + attrName);
127
+ if (attrValue) {
128
+ try {
129
+ inlineSettings[attrName] = eval(attrValue);
130
+ } catch (err) {
131
+ inlineSettings[attrName] = attrValue;
132
+ }
133
+ }
134
+ }
135
+ tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, {
136
+ beforeShow: function(input, dp_inst) {
137
+ if ($.isFunction(o.beforeShow))
138
+ o.beforeShow(input, dp_inst, tp_inst);
139
+ },
140
+ onChangeMonthYear: function(year, month, dp_inst) {
141
+ // Update the time as well : this prevents the time from disappearing from the $input field.
142
+ tp_inst._updateDateTime(dp_inst);
143
+ if ($.isFunction(o.onChangeMonthYear))
144
+ o.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst);
145
+ },
146
+ onClose: function(dateText, dp_inst) {
147
+ if (tp_inst.timeDefined === true && $input.val() != '')
148
+ tp_inst._updateDateTime(dp_inst);
149
+ if ($.isFunction(o.onClose))
150
+ o.onClose.call($input[0], dateText, dp_inst, tp_inst);
151
+ },
152
+ timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
153
+ });
154
+
155
+ tp_inst.hour = tp_inst._defaults.hour;
156
+ tp_inst.minute = tp_inst._defaults.minute;
157
+ tp_inst.second = tp_inst._defaults.second;
158
+ tp_inst.ampm = '';
159
+ tp_inst.$input = $input;
160
+
161
+ if (o.altField)
162
+ tp_inst.$altInput = $(o.altField)
163
+ .css({ cursor: 'pointer' })
164
+ .focus(function(){ $input.trigger("focus"); });
165
+
166
+ // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
167
+ if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date)
168
+ tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
169
+ if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date)
170
+ tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
171
+ if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date)
172
+ tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
173
+ if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date)
174
+ tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
175
+
176
+ return tp_inst;
177
+ },
178
+
179
+ //########################################################################
180
+ // add our sliders to the calendar
181
+ //########################################################################
182
+ _addTimePicker: function(dp_inst) {
183
+ var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ?
184
+ this.$input.val() + ' ' + this.$altInput.val() :
185
+ this.$input.val();
186
+
187
+ this.timeDefined = this._parseTime(currDT);
188
+ this._limitMinMaxDateTime(dp_inst, false);
189
+ this._injectTimePicker();
190
+ },
191
+
192
+ //########################################################################
193
+ // parse the time string from input value or _setTime
194
+ //########################################################################
195
+ _parseTime: function(timeString, withDate) {
196
+ var regstr = this._defaults.timeFormat.toString()
197
+ .replace(/h{1,2}/ig, '(\\d?\\d)')
198
+ .replace(/m{1,2}/ig, '(\\d?\\d)')
199
+ .replace(/s{1,2}/ig, '(\\d?\\d)')
200
+ .replace(/t{1,2}/ig, '(am|pm|a|p)?')
201
+ .replace(/z{1}/ig, '((\\+|-)\\d\\d\\d\\d)?')
202
+ .replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$',
203
+ order = this._getFormatPositions(),
204
+ treg;
205
+
206
+ if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
207
+
208
+ if (withDate || !this._defaults.timeOnly) {
209
+ // the time should come after x number of characters and a space.
210
+ // x = at least the length of text specified by the date format
211
+ var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
212
+ // escape special regex characters in the seperator
213
+ var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g");
214
+ regstr = '.{' + dp_dateFormat.length + ',}' + this._defaults.separator.replace(specials, "\\$&") + regstr;
215
+ }
216
+
217
+ treg = timeString.match(new RegExp(regstr, 'i'));
218
+
219
+ if (treg) {
220
+ if (order.t !== -1)
221
+ this.ampm = ((treg[order.t] === undefined || treg[order.t].length === 0) ?
222
+ '' :
223
+ (treg[order.t].charAt(0).toUpperCase() == 'A') ? 'AM' : 'PM').toUpperCase();
224
+
225
+ if (order.h !== -1) {
226
+ if (this.ampm == 'AM' && treg[order.h] == '12')
227
+ this.hour = 0; // 12am = 0 hour
228
+ else if (this.ampm == 'PM' && treg[order.h] != '12')
229
+ this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12
230
+ else this.hour = Number(treg[order.h]);
231
+ }
232
+
233
+ if (order.m !== -1) this.minute = Number(treg[order.m]);
234
+ if (order.s !== -1) this.second = Number(treg[order.s]);
235
+ if (order.z !== -1) this.timezone = treg[order.z];
236
+
237
+ return true;
238
+
239
+ }
240
+ return false;
241
+ },
242
+
243
+ //########################################################################
244
+ // figure out position of time elements.. cause js cant do named captures
245
+ //########################################################################
246
+ _getFormatPositions: function() {
247
+ var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|t{1,2}|z)/g),
248
+ orders = { h: -1, m: -1, s: -1, t: -1, z: -1 };
249
+
250
+ if (finds)
251
+ for (var i = 0; i < finds.length; i++)
252
+ if (orders[finds[i].toString().charAt(0)] == -1)
253
+ orders[finds[i].toString().charAt(0)] = i + 1;
254
+
255
+ return orders;
256
+ },
257
+
258
+ //########################################################################
259
+ // generate and inject html for timepicker into ui datepicker
260
+ //########################################################################
261
+ _injectTimePicker: function() {
262
+ var $dp = this.inst.dpDiv,
263
+ o = this._defaults,
264
+ tp_inst = this,
265
+ // Added by Peter Medeiros:
266
+ // - Figure out what the hour/minute/second max should be based on the step values.
267
+ // - Example: if stepMinute is 15, then minMax is 45.
268
+ hourMax = (o.hourMax - (o.hourMax % o.stepHour)).toFixed(0),
269
+ minMax = (o.minuteMax - (o.minuteMax % o.stepMinute)).toFixed(0),
270
+ secMax = (o.secondMax - (o.secondMax % o.stepSecond)).toFixed(0),
271
+ dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, '');
272
+
273
+ // Prevent displaying twice
274
+ //if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) {
275
+ if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) {
276
+ var noDisplay = ' style="display:none;"',
277
+ html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' +
278
+ '<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' +
279
+ ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +
280
+ '<dd class="ui_tpicker_time" id="ui_tpicker_time_' + dp_id + '"' +
281
+ ((o.showTime) ? '' : noDisplay) + '></dd>' +
282
+ '<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_' + dp_id + '"' +
283
+ ((o.showHour) ? '' : noDisplay) + '>' + o.hourText + '</dt>',
284
+ hourGridSize = 0,
285
+ minuteGridSize = 0,
286
+ secondGridSize = 0,
287
+ size;
288
+
289
+ if (o.showHour && o.hourGrid > 0) {
290
+ html += '<dd class="ui_tpicker_hour">' +
291
+ '<div id="ui_tpicker_hour_' + dp_id + '"' + ((o.showHour) ? '' : noDisplay) + '></div>' +
292
+ '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
293
+
294
+ for (var h = o.hourMin; h <= hourMax; h += o.hourGrid) {
295
+ hourGridSize++;
296
+ var tmph = (o.ampm && h > 12) ? h-12 : h;
297
+ if (tmph < 10) tmph = '0' + tmph;
298
+ if (o.ampm) {
299
+ if (h == 0) tmph = 12 +'a';
300
+ else if (h < 12) tmph += 'a';
301
+ else tmph += 'p';
302
+ }
303
+ html += '<td>' + tmph + '</td>';
304
+ }
305
+
306
+ html += '</tr></table></div>' +
307
+ '</dd>';
308
+ } else html += '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_' + dp_id + '"' +
309
+ ((o.showHour) ? '' : noDisplay) + '></dd>';
310
+
311
+ html += '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_' + dp_id + '"' +
312
+ ((o.showMinute) ? '' : noDisplay) + '>' + o.minuteText + '</dt>';
313
+
314
+ if (o.showMinute && o.minuteGrid > 0) {
315
+ html += '<dd class="ui_tpicker_minute ui_tpicker_minute_' + o.minuteGrid + '">' +
316
+ '<div id="ui_tpicker_minute_' + dp_id + '"' +
317
+ ((o.showMinute) ? '' : noDisplay) + '></div>' +
318
+ '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
319
+
320
+ for (var m = o.minuteMin; m <= minMax; m += o.minuteGrid) {
321
+ minuteGridSize++;
322
+ html += '<td>' + ((m < 10) ? '0' : '') + m + '</td>';
323
+ }
324
+
325
+ html += '</tr></table></div>' +
326
+ '</dd>';
327
+ } else html += '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_' + dp_id + '"' +
328
+ ((o.showMinute) ? '' : noDisplay) + '></dd>';
329
+
330
+ html += '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_' + dp_id + '"' +
331
+ ((o.showSecond) ? '' : noDisplay) + '>' + o.secondText + '</dt>';
332
+
333
+ if (o.showSecond && o.secondGrid > 0) {
334
+ html += '<dd class="ui_tpicker_second ui_tpicker_second_' + o.secondGrid + '">' +
335
+ '<div id="ui_tpicker_second_' + dp_id + '"' +
336
+ ((o.showSecond) ? '' : noDisplay) + '></div>' +
337
+ '<div style="padding-left: 1px"><table><tr>';
338
+
339
+ for (var s = o.secondMin; s <= secMax; s += o.secondGrid) {
340
+ secondGridSize++;
341
+ html += '<td>' + ((s < 10) ? '0' : '') + s + '</td>';
342
+ }
343
+
344
+ html += '</tr></table></div>' +
345
+ '</dd>';
346
+ } else html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_id + '"' +
347
+ ((o.showSecond) ? '' : noDisplay) + '></dd>';
348
+
349
+ html += '<dt class="ui_tpicker_timezone_label" id="ui_tpicker_timezone_label_' + dp_id + '"' +
350
+ ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>';
351
+ html += '<dd class="ui_tpicker_timezone" id="ui_tpicker_timezone_' + dp_id + '"' +
352
+ ((o.showTimezone) ? '' : noDisplay) + '></dd>';
353
+
354
+ html += '</dl></div>';
355
+ $tp = $(html);
356
+
357
+ // if we only want time picker...
358
+ if (o.timeOnly === true) {
359
+ $tp.prepend(
360
+ '<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' +
361
+ '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' +
362
+ '</div>');
363
+ $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
364
+ }
365
+
366
+ this.hour_slider = $tp.find('#ui_tpicker_hour_'+ dp_id).slider({
367
+ orientation: "horizontal",
368
+ value: this.hour,
369
+ min: o.hourMin,
370
+ max: hourMax,
371
+ step: o.stepHour,
372
+ slide: function(event, ui) {
373
+ tp_inst.hour_slider.slider( "option", "value", ui.value);
374
+ tp_inst._onTimeChange();
375
+ }
376
+ });
377
+
378
+ // Updated by Peter Medeiros:
379
+ // - Pass in Event and UI instance into slide function
380
+ this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({
381
+ orientation: "horizontal",
382
+ value: this.minute,
383
+ min: o.minuteMin,
384
+ max: minMax,
385
+ step: o.stepMinute,
386
+ slide: function(event, ui) {
387
+ // update the global minute slider instance value with the current slider value
388
+ tp_inst.minute_slider.slider( "option", "value", ui.value);
389
+ tp_inst._onTimeChange();
390
+ }
391
+ });
392
+
393
+ this.second_slider = $tp.find('#ui_tpicker_second_'+ dp_id).slider({
394
+ orientation: "horizontal",
395
+ value: this.second,
396
+ min: o.secondMin,
397
+ max: secMax,
398
+ step: o.stepSecond,
399
+ slide: function(event, ui) {
400
+ tp_inst.second_slider.slider( "option", "value", ui.value);
401
+ tp_inst._onTimeChange();
402
+ }
403
+ });
404
+
405
+
406
+ this.timezone_select = $tp.find('#ui_tpicker_timezone_'+ dp_id).append('<select></select>').find("select");
407
+ $.fn.append.apply(this.timezone_select,
408
+ $.map(o.timezoneList, function(val, idx) {
409
+ return $("<option />")
410
+ .val(typeof val == "object" ? val.value : val)
411
+ .text(typeof val == "object" ? val.label : val);
412
+ })
413
+ );
414
+ this.timezone_select.val((typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") ? this.timezone : o.timezone);
415
+ this.timezone_select.change(function() {
416
+ tp_inst._onTimeChange();
417
+ });
418
+
419
+ // Add grid functionality
420
+ if (o.showHour && o.hourGrid > 0) {
421
+ size = 100 * hourGridSize * o.hourGrid / (hourMax - o.hourMin);
422
+
423
+ $tp.find(".ui_tpicker_hour table").css({
424
+ width: size + "%",
425
+ marginLeft: (size / (-2 * hourGridSize)) + "%",
426
+ borderCollapse: 'collapse'
427
+ }).find("td").each( function(index) {
428
+ $(this).click(function() {
429
+ var h = $(this).html();
430
+ if(o.ampm) {
431
+ var ap = h.substring(2).toLowerCase(),
432
+ aph = parseInt(h.substring(0,2), 10);
433
+ if (ap == 'a') {
434
+ if (aph == 12) h = 0;
435
+ else h = aph;
436
+ } else if (aph == 12) h = 12;
437
+ else h = aph + 12;
438
+ }
439
+ tp_inst.hour_slider.slider("option", "value", h);
440
+ tp_inst._onTimeChange();
441
+ tp_inst._onSelectHandler();
442
+ }).css({
443
+ cursor: 'pointer',
444
+ width: (100 / hourGridSize) + '%',
445
+ textAlign: 'center',
446
+ overflow: 'hidden'
447
+ });
448
+ });
449
+ }
450
+
451
+ if (o.showMinute && o.minuteGrid > 0) {
452
+ size = 100 * minuteGridSize * o.minuteGrid / (minMax - o.minuteMin);
453
+ $tp.find(".ui_tpicker_minute table").css({
454
+ width: size + "%",
455
+ marginLeft: (size / (-2 * minuteGridSize)) + "%",
456
+ borderCollapse: 'collapse'
457
+ }).find("td").each(function(index) {
458
+ $(this).click(function() {
459
+ tp_inst.minute_slider.slider("option", "value", $(this).html());
460
+ tp_inst._onTimeChange();
461
+ tp_inst._onSelectHandler();
462
+ }).css({
463
+ cursor: 'pointer',
464
+ width: (100 / minuteGridSize) + '%',
465
+ textAlign: 'center',
466
+ overflow: 'hidden'
467
+ });
468
+ });
469
+ }
470
+
471
+ if (o.showSecond && o.secondGrid > 0) {
472
+ $tp.find(".ui_tpicker_second table").css({
473
+ width: size + "%",
474
+ marginLeft: (size / (-2 * secondGridSize)) + "%",
475
+ borderCollapse: 'collapse'
476
+ }).find("td").each(function(index) {
477
+ $(this).click(function() {
478
+ tp_inst.second_slider.slider("option", "value", $(this).html());
479
+ tp_inst._onTimeChange();
480
+ tp_inst._onSelectHandler();
481
+ }).css({
482
+ cursor: 'pointer',
483
+ width: (100 / secondGridSize) + '%',
484
+ textAlign: 'center',
485
+ overflow: 'hidden'
486
+ });
487
+ });
488
+ }
489
+
490
+ var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
491
+ if ($buttonPanel.length) $buttonPanel.before($tp);
492
+ else $dp.append($tp);
493
+
494
+ this.$timeObj = $tp.find('#ui_tpicker_time_'+ dp_id);
495
+
496
+ if (this.inst !== null) {
497
+ var timeDefined = this.timeDefined;
498
+ this._onTimeChange();
499
+ this.timeDefined = timeDefined;
500
+ }
501
+
502
+ //Emulate datepicker onSelect behavior. Call on slidestop.
503
+ var onSelectDelegate = function() {
504
+ tp_inst._onSelectHandler();
505
+ };
506
+ this.hour_slider.bind('slidestop',onSelectDelegate);
507
+ this.minute_slider.bind('slidestop',onSelectDelegate);
508
+ this.second_slider.bind('slidestop',onSelectDelegate);
509
+ }
510
+ },
511
+
512
+ //########################################################################
513
+ // This function tries to limit the ability to go outside the
514
+ // min/max date range
515
+ //########################################################################
516
+ _limitMinMaxDateTime: function(dp_inst, adjustSliders){
517
+ var o = this._defaults,
518
+ dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
519
+
520
+ if(!this._defaults.showTimepicker) return; // No time so nothing to check here
521
+
522
+ if($.datepicker._get(dp_inst, 'minDateTime') !== null && dp_date){
523
+ var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
524
+ minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
525
+
526
+ if(this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null){
527
+ this.hourMinOriginal = o.hourMin;
528
+ this.minuteMinOriginal = o.minuteMin;
529
+ this.secondMinOriginal = o.secondMin;
530
+ }
531
+
532
+ if(dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) {
533
+ this._defaults.hourMin = minDateTime.getHours();
534
+ if (this.hour <= this._defaults.hourMin) {
535
+ this.hour = this._defaults.hourMin;
536
+ this._defaults.minuteMin = minDateTime.getMinutes();
537
+ if (this.minute <= this._defaults.minuteMin) {
538
+ this.minute = this._defaults.minuteMin;
539
+ this._defaults.secondMin = minDateTime.getSeconds();
540
+ } else {
541
+ if(this.second < this._defaults.secondMin) this.second = this._defaults.secondMin;
542
+ this._defaults.secondMin = this.secondMinOriginal;
543
+ }
544
+ } else {
545
+ this._defaults.minuteMin = this.minuteMinOriginal;
546
+ this._defaults.secondMin = this.secondMinOriginal;
547
+ }
548
+ }else{
549
+ this._defaults.hourMin = this.hourMinOriginal;
550
+ this._defaults.minuteMin = this.minuteMinOriginal;
551
+ this._defaults.secondMin = this.secondMinOriginal;
552
+ }
553
+ }
554
+
555
+ if($.datepicker._get(dp_inst, 'maxDateTime') !== null && dp_date){
556
+ var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
557
+ maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
558
+
559
+ if(this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null){
560
+ this.hourMaxOriginal = o.hourMax;
561
+ this.minuteMaxOriginal = o.minuteMax;
562
+ this.secondMaxOriginal = o.secondMax;
563
+ }
564
+
565
+ if(dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()){
566
+ this._defaults.hourMax = maxDateTime.getHours();
567
+ if (this.hour >= this._defaults.hourMax) {
568
+ this.hour = this._defaults.hourMax;
569
+ this._defaults.minuteMax = maxDateTime.getMinutes();
570
+ if (this.minute >= this._defaults.minuteMax) {
571
+ this.minute = this._defaults.minuteMax;
572
+ this._defaults.secondMax = maxDateTime.getSeconds();
573
+ } else {
574
+ if(this.second > this._defaults.secondMax) this.second = this._defaults.secondMax;
575
+ this._defaults.secondMax = this.secondMaxOriginal;
576
+ }
577
+ } else {
578
+ this._defaults.minuteMax = this.minuteMaxOriginal;
579
+ this._defaults.secondMax = this.secondMaxOriginal;
580
+ }
581
+ }else{
582
+ this._defaults.hourMax = this.hourMaxOriginal;
583
+ this._defaults.minuteMax = this.minuteMaxOriginal;
584
+ this._defaults.secondMax = this.secondMaxOriginal;
585
+ }
586
+ }
587
+
588
+ if(adjustSliders !== undefined && adjustSliders === true){
589
+ var hourMax = (this._defaults.hourMax - (this._defaults.hourMax % this._defaults.stepHour)).toFixed(0),
590
+ minMax = (this._defaults.minuteMax - (this._defaults.minuteMax % this._defaults.stepMinute)).toFixed(0),
591
+ secMax = (this._defaults.secondMax - (this._defaults.secondMax % this._defaults.stepSecond)).toFixed(0);
592
+
593
+ if(this.hour_slider)
594
+ this.hour_slider.slider("option", { min: this._defaults.hourMin, max: hourMax }).slider('value', this.hour);
595
+ if(this.minute_slider)
596
+ this.minute_slider.slider("option", { min: this._defaults.minuteMin, max: minMax }).slider('value', this.minute);
597
+ if(this.second_slider)
598
+ this.second_slider.slider("option", { min: this._defaults.secondMin, max: secMax }).slider('value', this.second);
599
+ }
600
+
601
+ },
602
+
603
+
604
+ //########################################################################
605
+ // when a slider moves, set the internal time...
606
+ // on time change is also called when the time is updated in the text field
607
+ //########################################################################
608
+ _onTimeChange: function() {
609
+ var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false,
610
+ minute = (this.minute_slider) ? this.minute_slider.slider('value') : false,
611
+ second = (this.second_slider) ? this.second_slider.slider('value') : false,
612
+ timezone = (this.timezone_select) ? this.timezone_select.val() : false;
613
+
614
+ if (typeof(hour) == 'object') hour = false;
615
+ if (typeof(minute) == 'object') minute = false;
616
+ if (typeof(second) == 'object') second = false;
617
+ if (typeof(timezone) == 'object') timezone = false;
618
+
619
+ if (hour !== false) hour = parseInt(hour,10);
620
+ if (minute !== false) minute = parseInt(minute,10);
621
+ if (second !== false) second = parseInt(second,10);
622
+
623
+ var ampm = (hour < 12) ? 'AM' : 'PM';
624
+
625
+ // If the update was done in the input field, the input field should not be updated.
626
+ // If the update was done using the sliders, update the input field.
627
+ var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || (this.ampm.length > 0 && this.ampm != ampm) || timezone != this.timezone);
628
+
629
+ if (hasChanged) {
630
+
631
+ if (hour !== false)this.hour = hour;
632
+ if (minute !== false) this.minute = minute;
633
+ if (second !== false) this.second = second;
634
+ if (timezone !== false) this.timezone = timezone;
635
+
636
+ if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
637
+
638
+ this._limitMinMaxDateTime(this.inst, true);
639
+ }
640
+ if (this._defaults.ampm) this.ampm = ampm;
641
+
642
+ this._formatTime();
643
+ if (this.$timeObj) this.$timeObj.text(this.formattedTime + this._defaults.timeSuffix);
644
+ this.timeDefined = true;
645
+ if (hasChanged) this._updateDateTime();
646
+ },
647
+
648
+ //########################################################################
649
+ // call custom onSelect.
650
+ // bind to sliders slidestop, and grid click.
651
+ //########################################################################
652
+ _onSelectHandler: function() {
653
+ var onSelect = this._defaults['onSelect'];
654
+ var inputEl = this.$input ? this.$input[0] : null;
655
+ if (onSelect && inputEl) {
656
+ onSelect.apply(inputEl, [this.formattedDateTime, this]);
657
+ }
658
+ },
659
+
660
+ //########################################################################
661
+ // format the time all pretty...
662
+ //########################################################################
663
+ _formatTime: function(time, format, ampm) {
664
+ if (ampm == undefined) ampm = this._defaults.ampm;
665
+ time = time || { hour: this.hour, minute: this.minute, second: this.second, ampm: this.ampm, timezone: this.timezone };
666
+ var tmptime = format || this._defaults.timeFormat.toString();
667
+
668
+ if (ampm) {
669
+ var hour12 = ((time.ampm == 'AM') ? (time.hour) : (time.hour % 12));
670
+ hour12 = (Number(hour12) === 0) ? 12 : hour12;
671
+ tmptime = tmptime.toString()
672
+ .replace(/hh/g, ((hour12 < 10) ? '0' : '') + hour12)
673
+ .replace(/h/g, hour12)
674
+ .replace(/mm/g, ((time.minute < 10) ? '0' : '') + time.minute)
675
+ .replace(/m/g, time.minute)
676
+ .replace(/ss/g, ((time.second < 10) ? '0' : '') + time.second)
677
+ .replace(/s/g, time.second)
678
+ .replace(/TT/g, time.ampm.toUpperCase())
679
+ .replace(/Tt/g, time.ampm.toUpperCase())
680
+ .replace(/tT/g, time.ampm.toLowerCase())
681
+ .replace(/tt/g, time.ampm.toLowerCase())
682
+ .replace(/T/g, time.ampm.charAt(0).toUpperCase())
683
+ .replace(/t/g, time.ampm.charAt(0).toLowerCase())
684
+ .replace(/z/g, time.timezone);
685
+ } else {
686
+ tmptime = tmptime.toString()
687
+ .replace(/hh/g, ((time.hour < 10) ? '0' : '') + time.hour)
688
+ .replace(/h/g, time.hour)
689
+ .replace(/mm/g, ((time.minute < 10) ? '0' : '') + time.minute)
690
+ .replace(/m/g, time.minute)
691
+ .replace(/ss/g, ((time.second < 10) ? '0' : '') + time.second)
692
+ .replace(/s/g, time.second)
693
+ .replace(/z/g, time.timezone);
694
+ tmptime = $.trim(tmptime.replace(/t/gi, ''));
695
+ }
696
+
697
+ if (arguments.length) return tmptime;
698
+ else this.formattedTime = tmptime;
699
+ },
700
+
701
+ //########################################################################
702
+ // update our input with the new date time..
703
+ //########################################################################
704
+ _updateDateTime: function(dp_inst) {
705
+ dp_inst = this.inst || dp_inst,
706
+ dt = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay),
707
+ dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
708
+ formatCfg = $.datepicker._getFormatConfig(dp_inst),
709
+ timeAvailable = dt !== null && this.timeDefined;
710
+ this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
711
+ var formattedDateTime = this.formattedDate;
712
+ if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0))
713
+ return;
714
+
715
+ if (this._defaults.timeOnly === true) {
716
+ formattedDateTime = this.formattedTime;
717
+ } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) {
718
+ formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
719
+ }
720
+
721
+ this.formattedDateTime = formattedDateTime;
722
+
723
+ if(!this._defaults.showTimepicker) {
724
+ this.$input.val(this.formattedDate);
725
+ } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
726
+ this.$altInput.val(this.formattedTime);
727
+ this.$input.val(this.formattedDate);
728
+ } else if(this.$altInput) {
729
+ this.$altInput.val(formattedDateTime);
730
+ this.$input.val(formattedDateTime);
731
+ } else {
732
+ this.$input.val(formattedDateTime);
733
+ }
734
+
735
+ this.$input.trigger("change");
736
+ }
737
+
738
+ });
739
+
740
+ $.fn.extend({
741
+ //########################################################################
742
+ // shorthand just to use timepicker..
743
+ //########################################################################
744
+ timepicker: function(o) {
745
+ o = o || {};
746
+ var tmp_args = arguments;
747
+
748
+ if (typeof o == 'object') tmp_args[0] = $.extend(o, { timeOnly: true });
749
+
750
+ return $(this).each(function() {
751
+ $.fn.datetimepicker.apply($(this), tmp_args);
752
+ });
753
+ },
754
+
755
+ //########################################################################
756
+ // extend timepicker to datepicker
757
+ //########################################################################
758
+ datetimepicker: function(o) {
759
+ o = o || {};
760
+ var $input = this,
761
+ tmp_args = arguments;
762
+
763
+ if (typeof(o) == 'string'){
764
+ if(o == 'getDate')
765
+ return $.fn.datepicker.apply($(this[0]), tmp_args);
766
+ else
767
+ return this.each(function() {
768
+ var $t = $(this);
769
+ $t.datepicker.apply($t, tmp_args);
770
+ });
771
+ }
772
+ else
773
+ return this.each(function() {
774
+ var $t = $(this);
775
+ $t.datepicker($.timepicker._newInst($t, o)._defaults);
776
+ });
777
+ }
778
+ });
779
+
780
+ //########################################################################
781
+ // the bad hack :/ override datepicker so it doesnt close on select
782
+ // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
783
+ //########################################################################
784
+ $.datepicker._base_selectDate = $.datepicker._selectDate;
785
+ $.datepicker._selectDate = function (id, dateStr) {
786
+ var inst = this._getInst($(id)[0]),
787
+ tp_inst = this._get(inst, 'timepicker');
788
+
789
+ if (tp_inst) {
790
+ tp_inst._limitMinMaxDateTime(inst, true);
791
+ inst.inline = inst.stay_open = true;
792
+ //This way the onSelect handler called from calendarpicker get the full dateTime
793
+ this._base_selectDate(id, dateStr + tp_inst._defaults.separator + tp_inst.formattedTime + tp_inst._defaults.timeSuffix);
794
+ inst.inline = inst.stay_open = false;
795
+ this._notifyChange(inst);
796
+ this._updateDatepicker(inst);
797
+ }
798
+ else this._base_selectDate(id, dateStr);
799
+ };
800
+
801
+ //#############################################################################################
802
+ // second bad hack :/ override datepicker so it triggers an event when changing the input field
803
+ // and does not redraw the datepicker on every selectDate event
804
+ //#############################################################################################
805
+ $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
806
+ $.datepicker._updateDatepicker = function(inst) {
807
+
808
+ // don't popup the datepicker if there is another instance already opened
809
+ var input = inst.input[0];
810
+ if($.datepicker._curInst &&
811
+ $.datepicker._curInst != inst &&
812
+ $.datepicker._datepickerShowing &&
813
+ $.datepicker._lastInput != input) {
814
+ return;
815
+ }
816
+
817
+ if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
818
+
819
+ this._base_updateDatepicker(inst);
820
+
821
+ // Reload the time control when changing something in the input text field.
822
+ var tp_inst = this._get(inst, 'timepicker');
823
+ if(tp_inst) tp_inst._addTimePicker(inst);
824
+ }
825
+ };
826
+
827
+ //#######################################################################################
828
+ // third bad hack :/ override datepicker so it allows spaces and colon in the input field
829
+ //#######################################################################################
830
+ $.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
831
+ $.datepicker._doKeyPress = function(event) {
832
+ var inst = $.datepicker._getInst(event.target),
833
+ tp_inst = $.datepicker._get(inst, 'timepicker');
834
+
835
+ if (tp_inst) {
836
+ if ($.datepicker._get(inst, 'constrainInput')) {
837
+ var ampm = tp_inst._defaults.ampm,
838
+ dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
839
+ datetimeChars = tp_inst._defaults.timeFormat.toString()
840
+ .replace(/[hms]/g, '')
841
+ .replace(/TT/g, ampm ? 'APM' : '')
842
+ .replace(/Tt/g, ampm ? 'AaPpMm' : '')
843
+ .replace(/tT/g, ampm ? 'AaPpMm' : '')
844
+ .replace(/T/g, ampm ? 'AP' : '')
845
+ .replace(/tt/g, ampm ? 'apm' : '')
846
+ .replace(/t/g, ampm ? 'ap' : '') +
847
+ " " +
848
+ tp_inst._defaults.separator +
849
+ tp_inst._defaults.timeSuffix +
850
+ (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') +
851
+ dateChars,
852
+ chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
853
+ return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
854
+ }
855
+ }
856
+
857
+ return $.datepicker._base_doKeyPress(event);
858
+ };
859
+
860
+ //#######################################################################################
861
+ // Override key up event to sync manual input changes.
862
+ //#######################################################################################
863
+ $.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
864
+ $.datepicker._doKeyUp = function (event) {
865
+ var inst = $.datepicker._getInst(event.target),
866
+ tp_inst = $.datepicker._get(inst, 'timepicker');
867
+
868
+ if (tp_inst) {
869
+ if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
870
+ try {
871
+ $.datepicker._updateDatepicker(inst);
872
+ }
873
+ catch (err) {
874
+ $.datepicker.log(err);
875
+ }
876
+ }
877
+ }
878
+
879
+ return $.datepicker._base_doKeyUp(event);
880
+ };
881
+
882
+ //#######################################################################################
883
+ // override "Today" button to also grab the time.
884
+ //#######################################################################################
885
+ $.datepicker._base_gotoToday = $.datepicker._gotoToday;
886
+ $.datepicker._gotoToday = function(id) {
887
+ this._base_gotoToday(id);
888
+ this._setTime(this._getInst($(id)[0]), new Date());
889
+ };
890
+
891
+ //#######################################################################################
892
+ // Disable & enable the Time in the datetimepicker
893
+ //#######################################################################################
894
+ $.datepicker._disableTimepickerDatepicker = function(target, date, withDate) {
895
+ var inst = this._getInst(target),
896
+ tp_inst = this._get(inst, 'timepicker');
897
+ $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
898
+ if (tp_inst) {
899
+ tp_inst._defaults.showTimepicker = false;
900
+ tp_inst._updateDateTime(inst);
901
+ }
902
+ };
903
+
904
+ $.datepicker._enableTimepickerDatepicker = function(target, date, withDate) {
905
+ var inst = this._getInst(target),
906
+ tp_inst = this._get(inst, 'timepicker');
907
+ $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
908
+ if (tp_inst) {
909
+ tp_inst._defaults.showTimepicker = true;
910
+ tp_inst._addTimePicker(inst); // Could be disabled on page load
911
+ tp_inst._updateDateTime(inst);
912
+ }
913
+ };
914
+
915
+ //#######################################################################################
916
+ // Create our own set time function
917
+ //#######################################################################################
918
+ $.datepicker._setTime = function(inst, date) {
919
+ var tp_inst = this._get(inst, 'timepicker');
920
+ if (tp_inst) {
921
+ var defaults = tp_inst._defaults,
922
+ // calling _setTime with no date sets time to defaults
923
+ hour = date ? date.getHours() : defaults.hour,
924
+ minute = date ? date.getMinutes() : defaults.minute,
925
+ second = date ? date.getSeconds() : defaults.second;
926
+
927
+ //check if within min/max times..
928
+ if ((hour < defaults.hourMin || hour > defaults.hourMax) || (minute < defaults.minuteMin || minute > defaults.minuteMax) || (second < defaults.secondMin || second > defaults.secondMax)) {
929
+ hour = defaults.hourMin;
930
+ minute = defaults.minuteMin;
931
+ second = defaults.secondMin;
932
+ }
933
+
934
+ tp_inst.hour = hour;
935
+ tp_inst.minute = minute;
936
+ tp_inst.second = second;
937
+
938
+ if (tp_inst.hour_slider) tp_inst.hour_slider.slider('value', hour);
939
+ if (tp_inst.minute_slider) tp_inst.minute_slider.slider('value', minute);
940
+ if (tp_inst.second_slider) tp_inst.second_slider.slider('value', second);
941
+
942
+ tp_inst._onTimeChange();
943
+ tp_inst._updateDateTime(inst);
944
+ }
945
+ };
946
+
947
+ //#######################################################################################
948
+ // Create new public method to set only time, callable as $().datepicker('setTime', date)
949
+ //#######################################################################################
950
+ $.datepicker._setTimeDatepicker = function(target, date, withDate) {
951
+ var inst = this._getInst(target),
952
+ tp_inst = this._get(inst, 'timepicker');
953
+
954
+ if (tp_inst) {
955
+ this._setDateFromField(inst);
956
+ var tp_date;
957
+ if (date) {
958
+ if (typeof date == "string") {
959
+ tp_inst._parseTime(date, withDate);
960
+ tp_date = new Date();
961
+ tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second);
962
+ }
963
+ else tp_date = new Date(date.getTime());
964
+ if (tp_date.toString() == 'Invalid Date') tp_date = undefined;
965
+ this._setTime(inst, tp_date);
966
+ }
967
+ }
968
+
969
+ };
970
+
971
+ //#######################################################################################
972
+ // override setDate() to allow setting time too within Date object
973
+ //#######################################################################################
974
+ $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
975
+ $.datepicker._setDateDatepicker = function(target, date) {
976
+ var inst = this._getInst(target),
977
+ tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;
978
+
979
+ this._updateDatepicker(inst);
980
+ this._base_setDateDatepicker.apply(this, arguments);
981
+ this._setTimeDatepicker(target, tp_date, true);
982
+ };
983
+
984
+ //#######################################################################################
985
+ // override getDate() to allow getting time too within Date object
986
+ //#######################################################################################
987
+ $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
988
+ $.datepicker._getDateDatepicker = function(target, noDefault) {
989
+ var inst = this._getInst(target),
990
+ tp_inst = this._get(inst, 'timepicker');
991
+
992
+ if (tp_inst) {
993
+ this._setDateFromField(inst, noDefault);
994
+ var date = this._getDate(inst);
995
+ if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second);
996
+ return date;
997
+ }
998
+ return this._base_getDateDatepicker(target, noDefault);
999
+ };
1000
+
1001
+ //#######################################################################################
1002
+ // override parseDate() because UI 1.8.14 throws an error about "Extra characters"
1003
+ // An option in datapicker to ignore extra format characters would be nicer.
1004
+ //#######################################################################################
1005
+ $.datepicker._base_parseDate = $.datepicker.parseDate;
1006
+ $.datepicker.parseDate = function(format, value, settings) {
1007
+ var date;
1008
+ try {
1009
+ date = this._base_parseDate(format, value, settings);
1010
+ } catch (err) {
1011
+ // Hack! The error message ends with a colon, a space, and
1012
+ // the "extra" characters. We rely on that instead of
1013
+ // attempting to perfectly reproduce the parsing algorithm.
1014
+ date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings);
1015
+ }
1016
+ return date;
1017
+ };
1018
+
1019
+ //#######################################################################################
1020
+ // override options setter to add time to maxDate(Time) and minDate(Time)
1021
+ //#######################################################################################
1022
+ $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
1023
+ $.datepicker._optionDatepicker = function(target, name, value) {
1024
+ this._base_optionDatepicker(target, name, value);
1025
+ var inst = this._getInst(target),
1026
+ tp_inst = this._get(inst, 'timepicker');
1027
+ if (tp_inst) {
1028
+ //Set minimum and maximum date values if we have timepicker
1029
+ if(name==='minDate') {
1030
+ if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date)
1031
+ tp_inst._defaults.minDateTime = new Date(value);
1032
+ if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date)
1033
+ tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
1034
+ tp_inst._limitMinMaxDateTime(inst,true);
1035
+ }
1036
+ if(name==='maxDate') {
1037
+ if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date)
1038
+ tp_inst._defaults.maxDateTime = new Date(value);
1039
+ if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date)
1040
+ tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
1041
+ tp_inst._limitMinMaxDateTime(inst,true);
1042
+ }
1043
+ }
1044
+ };
1045
+
1046
+ //#######################################################################################
1047
+ // jQuery extend now ignores nulls!
1048
+ //#######################################################################################
1049
+ function extendRemove(target, props) {
1050
+ $.extend(target, props);
1051
+ for (var name in props)
1052
+ if (props[name] === null || props[name] === undefined)
1053
+ target[name] = props[name];
1054
+ return target;
1055
+ }
1056
+
1057
+ $.timepicker = new Timepicker(); // singleton instance
1058
+ $.timepicker.version = "0.9.6";
1059
+
1060
+ })(jQuery);