multi-dates-picker-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/app/assets/images/ui-bg_diagonal-maze_20_6e4f1c_10x10.png +0 -0
- data/app/assets/images/ui-bg_diagonal-maze_40_000000_10x10.png +0 -0
- data/app/assets/images/ui-bg_fine-grain_10_eceadf_60x60.png +0 -0
- data/app/assets/images/ui-bg_fine-grain_10_f8f7f6_60x60.png +0 -0
- data/app/assets/images/ui-bg_fine-grain_15_d3c05a_60x60.png +0 -0
- data/app/assets/images/ui-bg_fine-grain_15_eceadf_60x60.png +0 -0
- data/app/assets/images/ui-bg_fine-grain_15_ffffff_60x60.png +0 -0
- data/app/assets/images/ui-bg_fine-grain_65_654b24_60x60.png +0 -0
- data/app/assets/images/ui-bg_fine-grain_68_b83400_60x60.png +0 -0
- data/app/assets/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/images/ui-icons_3572ac_256x240.png +0 -0
- data/app/assets/images/ui-icons_8c291d_256x240.png +0 -0
- data/app/assets/images/ui-icons_b83400_256x240.png +0 -0
- data/app/assets/images/ui-icons_fbdb93_256x240.png +0 -0
- data/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
- data/app/assets/javascripts/jquery-ui.multidatespicker.js +457 -0
- data/app/assets/stylesheets/mdp.css +126 -0
- data/app/assets/stylesheets/pepper-ginder-custom.css +572 -0
- data/app/assets/stylesheets/prettify.css +1 -0
- data/lib/multi-dates-picker-rails.rb +6 -0
- data/lib/multi-dates-picker-rails/version.rb +9 -0
- data/multi-dates-picker-rails.gemspec +19 -0
- data/vendor/multiple-dates-picker/README.md +48 -0
- data/vendor/multiple-dates-picker/css/images/ui-bg_diagonal-maze_20_6e4f1c_10x10.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-bg_diagonal-maze_40_000000_10x10.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-bg_fine-grain_10_eceadf_60x60.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-bg_fine-grain_10_f8f7f6_60x60.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-bg_fine-grain_15_d3c05a_60x60.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-bg_fine-grain_15_eceadf_60x60.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-bg_fine-grain_15_ffffff_60x60.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-bg_fine-grain_65_654b24_60x60.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-bg_fine-grain_68_b83400_60x60.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-icons_222222_256x240.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-icons_3572ac_256x240.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-icons_8c291d_256x240.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-icons_b83400_256x240.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-icons_fbdb93_256x240.png +0 -0
- data/vendor/multiple-dates-picker/css/images/ui-icons_ffffff_256x240.png +0 -0
- data/vendor/multiple-dates-picker/css/mdp.css +126 -0
- data/vendor/multiple-dates-picker/css/pepper-ginder-custom.css +572 -0
- data/vendor/multiple-dates-picker/css/prettify.css +1 -0
- data/vendor/multiple-dates-picker/favicon.ico +0 -0
- data/vendor/multiple-dates-picker/img/sflogo.gif +0 -0
- data/vendor/multiple-dates-picker/img/valid-html401-blue.png +0 -0
- data/vendor/multiple-dates-picker/index.html +586 -0
- data/vendor/multiple-dates-picker/jquery-ui.multidatespicker.js +457 -0
- data/vendor/multiple-dates-picker/js/jquery-1.7.2.js +9404 -0
- data/vendor/multiple-dates-picker/js/jquery.ui.core.js +319 -0
- data/vendor/multiple-dates-picker/js/jquery.ui.datepicker-es.js +23 -0
- data/vendor/multiple-dates-picker/js/jquery.ui.datepicker.js +1826 -0
- data/vendor/multiple-dates-picker/js/lang-css.js +2 -0
- data/vendor/multiple-dates-picker/js/prettify.js +28 -0
- data/vendor/multiple-dates-picker/mdp-icon.png +0 -0
- metadata +103 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Michael Witrant
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# MultiDatesPicker::Rails
|
2
|
+
|
3
|
+
Rails gem for MultiDatesPicker (http://multidatespickr.sourceforge.net/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'multiple-dates-picker-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install multiple-dates-picker-rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You must already have jquery-ui installed.
|
22
|
+
|
23
|
+
Then add this to your application.js:
|
24
|
+
|
25
|
+
//= require jquery-ui.multidatespicker
|
26
|
+
|
27
|
+
And this to your application.css:
|
28
|
+
|
29
|
+
*= require mdp.css
|
30
|
+
|
31
|
+
And activate it like this:
|
32
|
+
|
33
|
+
$("#dates_field").multiDatesPicker()
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,457 @@
|
|
1
|
+
/*
|
2
|
+
* MultiDatesPicker v1.6.1
|
3
|
+
* http://multidatespickr.sourceforge.net/
|
4
|
+
*
|
5
|
+
* Copyright 2011, Luca Lauretta
|
6
|
+
* Dual licensed under the MIT or GPL version 2 licenses.
|
7
|
+
*/
|
8
|
+
(function( $ ){
|
9
|
+
$.extend($.ui, { multiDatesPicker: { version: "1.6.1" } });
|
10
|
+
|
11
|
+
$.fn.multiDatesPicker = function(method) {
|
12
|
+
var mdp_arguments = arguments;
|
13
|
+
var ret = this;
|
14
|
+
var today_date = new Date();
|
15
|
+
var day_zero = new Date(0);
|
16
|
+
var mdp_events = {};
|
17
|
+
|
18
|
+
function removeDate(date, type) {
|
19
|
+
if(!type) type = 'picked';
|
20
|
+
date = dateConvert.call(this, date);
|
21
|
+
for(var i in this.multiDatesPicker.dates[type])
|
22
|
+
if(!methods.compareDates(this.multiDatesPicker.dates[type][i], date))
|
23
|
+
return this.multiDatesPicker.dates[type].splice(i, 1).pop();
|
24
|
+
}
|
25
|
+
function removeIndex(index, type) {
|
26
|
+
if(!type) type = 'picked';
|
27
|
+
return this.multiDatesPicker.dates[type].splice(index, 1).pop();
|
28
|
+
}
|
29
|
+
function addDate(date, type, no_sort) {
|
30
|
+
if(!type) type = 'picked';
|
31
|
+
date = dateConvert.call(this, date);
|
32
|
+
|
33
|
+
// @todo: use jQuery UI datepicker method instead
|
34
|
+
date.setHours(0);
|
35
|
+
date.setMinutes(0);
|
36
|
+
date.setSeconds(0);
|
37
|
+
date.setMilliseconds(0);
|
38
|
+
|
39
|
+
if (methods.gotDate.call(this, date, type) === false) {
|
40
|
+
this.multiDatesPicker.dates[type].push(date);
|
41
|
+
if(!no_sort) this.multiDatesPicker.dates[type].sort(methods.compareDates);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
function sortDates(type) {
|
45
|
+
if(!type) type = 'picked';
|
46
|
+
this.multiDatesPicker.dates[type].sort(methods.compareDates);
|
47
|
+
}
|
48
|
+
function dateConvert(date, desired_type, date_format) {
|
49
|
+
if(!desired_type) desired_type = 'object';/*
|
50
|
+
if(!date_format && (typeof date == 'string')) {
|
51
|
+
date_format = $(this).datepicker('option', 'dateFormat');
|
52
|
+
if(!date_format) date_format = $.datepicker._defaults.dateFormat;
|
53
|
+
}
|
54
|
+
*/
|
55
|
+
return methods.dateConvert.call(this, date, desired_type, date_format);
|
56
|
+
}
|
57
|
+
|
58
|
+
var methods = {
|
59
|
+
init : function( options ) {
|
60
|
+
var $this = $(this);
|
61
|
+
this.multiDatesPicker.changed = false;
|
62
|
+
|
63
|
+
var mdp_events = {
|
64
|
+
beforeShow: function(input, inst) {
|
65
|
+
this.multiDatesPicker.changed = false;
|
66
|
+
if(this.multiDatesPicker.originalBeforeShow)
|
67
|
+
this.multiDatesPicker.originalBeforeShow.call(this, input, inst);
|
68
|
+
},
|
69
|
+
onSelect : function(dateText, inst) {
|
70
|
+
var $this = $(this);
|
71
|
+
this.multiDatesPicker.changed = true;
|
72
|
+
|
73
|
+
if (dateText) {
|
74
|
+
$this.multiDatesPicker('toggleDate', dateText);
|
75
|
+
}
|
76
|
+
|
77
|
+
if (this.multiDatesPicker.mode == 'normal' && this.multiDatesPicker.dates.picked.length > 0 && this.multiDatesPicker.pickableRange) {
|
78
|
+
var min_date = this.multiDatesPicker.dates.picked[0],
|
79
|
+
max_date = new Date(min_date.getTime());
|
80
|
+
|
81
|
+
methods.sumDays(max_date, this.multiDatesPicker.pickableRange-1);
|
82
|
+
|
83
|
+
// counts the number of disabled dates in the range
|
84
|
+
if(this.multiDatesPicker.adjustRangeToDisabled) {
|
85
|
+
var c_disabled,
|
86
|
+
disabled = this.multiDatesPicker.dates.disabled.slice(0);
|
87
|
+
do {
|
88
|
+
c_disabled = 0;
|
89
|
+
for(var i = 0; i < disabled.length; i++) {
|
90
|
+
if(disabled[i].getTime() <= max_date.getTime()) {
|
91
|
+
if((min_date.getTime() <= disabled[i].getTime()) && (disabled[i].getTime() <= max_date.getTime()) ) {
|
92
|
+
c_disabled++;
|
93
|
+
}
|
94
|
+
disabled.splice(i, 1);
|
95
|
+
i--;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
max_date.setDate(max_date.getDate() + c_disabled);
|
99
|
+
} while(c_disabled != 0);
|
100
|
+
}
|
101
|
+
|
102
|
+
if(this.multiDatesPicker.maxDate && (max_date > this.multiDatesPicker.maxDate))
|
103
|
+
max_date = this.multiDatesPicker.maxDate;
|
104
|
+
|
105
|
+
$this
|
106
|
+
.datepicker("option", "minDate", min_date)
|
107
|
+
.datepicker("option", "maxDate", max_date);
|
108
|
+
} else {
|
109
|
+
$this
|
110
|
+
.datepicker("option", "minDate", this.multiDatesPicker.minDate)
|
111
|
+
.datepicker("option", "maxDate", this.multiDatesPicker.maxDate);
|
112
|
+
}
|
113
|
+
|
114
|
+
if(this.tagName == 'INPUT') { // for inputs
|
115
|
+
$this.val(
|
116
|
+
$this.multiDatesPicker('getDates', 'string')
|
117
|
+
);
|
118
|
+
}
|
119
|
+
|
120
|
+
if(this.multiDatesPicker.originalOnSelect && dateText)
|
121
|
+
this.multiDatesPicker.originalOnSelect.call(this, dateText, inst);
|
122
|
+
|
123
|
+
// thanks to bibendus83 -> http://sourceforge.net/tracker/?func=detail&atid=1495384&aid=3403159&group_id=358205
|
124
|
+
if ($this.datepicker('option', 'altField') != undefined && $this.datepicker('option', 'altField') != "") {
|
125
|
+
$($this.datepicker('option', 'altField')).val(
|
126
|
+
$this.multiDatesPicker('getDates', 'string')
|
127
|
+
);
|
128
|
+
}
|
129
|
+
},
|
130
|
+
beforeShowDay : function(date) {
|
131
|
+
var $this = $(this),
|
132
|
+
gotThisDate = $this.multiDatesPicker('gotDate', date) !== false,
|
133
|
+
isDisabledCalendar = $this.datepicker('option', 'disabled'),
|
134
|
+
isDisabledDate = $this.multiDatesPicker('gotDate', date, 'disabled') !== false,
|
135
|
+
areAllSelected = this.multiDatesPicker.maxPicks == this.multiDatesPicker.dates.picked.length;
|
136
|
+
|
137
|
+
var custom = [true, ''];
|
138
|
+
if(this.multiDatesPicker.originalBeforeShowDay)
|
139
|
+
custom = this.multiDatesPicker.originalBeforeShowDay.call(this, date);
|
140
|
+
|
141
|
+
var highlight_class = gotThisDate ? 'ui-state-highlight' : custom[1];
|
142
|
+
var selectable_date = !(isDisabledCalendar || isDisabledDate || (areAllSelected && !highlight_class));
|
143
|
+
return [selectable_date && custom[0], highlight_class];
|
144
|
+
},
|
145
|
+
onClose: function(dateText, inst) {
|
146
|
+
if(this.tagName == 'INPUT' && this.multiDatesPicker.changed) {
|
147
|
+
$(inst.dpDiv[0]).stop(false,true);
|
148
|
+
setTimeout('$("#'+inst.id+'").datepicker("show")',50);
|
149
|
+
}
|
150
|
+
if(this.multiDatesPicker.originalOnClose) this.multiDatesPicker.originalOnClose.call(this, dateText, inst);
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
if(options) {
|
155
|
+
this.multiDatesPicker.originalBeforeShow = options.beforeShow;
|
156
|
+
this.multiDatesPicker.originalOnSelect = options.onSelect;
|
157
|
+
this.multiDatesPicker.originalBeforeShowDay = options.beforeShowDay;
|
158
|
+
this.multiDatesPicker.originalOnClose = options.onClose;
|
159
|
+
|
160
|
+
$this.datepicker(options);
|
161
|
+
|
162
|
+
this.multiDatesPicker.minDate = $.datepicker._determineDate(this, options.minDate, null);
|
163
|
+
this.multiDatesPicker.maxDate = $.datepicker._determineDate(this, options.maxDate, null);
|
164
|
+
|
165
|
+
if(options.addDates) methods.addDates.call(this, options.addDates);
|
166
|
+
if(options.addDisabledDates)
|
167
|
+
methods.addDates.call(this, options.addDisabledDates, 'disabled');
|
168
|
+
|
169
|
+
methods.setMode.call(this, options);
|
170
|
+
} else {
|
171
|
+
$this.datepicker();
|
172
|
+
}
|
173
|
+
|
174
|
+
$this.datepicker('option', mdp_events);
|
175
|
+
|
176
|
+
if(this.tagName == 'INPUT') $this.val($this.multiDatesPicker('getDates', 'string'));
|
177
|
+
|
178
|
+
// Fixes the altField filled with defaultDate by default
|
179
|
+
var altFieldOption = $this.datepicker('option', 'altField');
|
180
|
+
if (altFieldOption) $(altFieldOption).val($this.multiDatesPicker('getDates', 'string'));
|
181
|
+
},
|
182
|
+
compareDates : function(date1, date2) {
|
183
|
+
date1 = dateConvert.call(this, date1);
|
184
|
+
date2 = dateConvert.call(this, date2);
|
185
|
+
// return > 0 means date1 is later than date2
|
186
|
+
// return == 0 means date1 is the same day as date2
|
187
|
+
// return < 0 means date1 is earlier than date2
|
188
|
+
var diff = date1.getFullYear() - date2.getFullYear();
|
189
|
+
if(!diff) {
|
190
|
+
diff = date1.getMonth() - date2.getMonth();
|
191
|
+
if(!diff)
|
192
|
+
diff = date1.getDate() - date2.getDate();
|
193
|
+
}
|
194
|
+
return diff;
|
195
|
+
},
|
196
|
+
sumDays : function( date, n_days ) {
|
197
|
+
var origDateType = typeof date;
|
198
|
+
obj_date = dateConvert.call(this, date);
|
199
|
+
obj_date.setDate(obj_date.getDate() + n_days);
|
200
|
+
return dateConvert.call(this, obj_date, origDateType);
|
201
|
+
},
|
202
|
+
dateConvert : function( date, desired_format, dateFormat ) {
|
203
|
+
var from_format = typeof date;
|
204
|
+
|
205
|
+
if(from_format == desired_format) {
|
206
|
+
if(from_format == 'object') {
|
207
|
+
try {
|
208
|
+
date.getTime();
|
209
|
+
} catch (e) {
|
210
|
+
$.error('Received date is in a non supported format!');
|
211
|
+
return false;
|
212
|
+
}
|
213
|
+
}
|
214
|
+
return date;
|
215
|
+
}
|
216
|
+
|
217
|
+
var $this = $(this);
|
218
|
+
if(typeof date == 'undefined') date = new Date(0);
|
219
|
+
|
220
|
+
if(desired_format != 'string' && desired_format != 'object' && desired_format != 'number')
|
221
|
+
$.error('Date format "'+ desired_format +'" not supported!');
|
222
|
+
|
223
|
+
if(!dateFormat) {
|
224
|
+
dateFormat = $.datepicker._defaults.dateFormat;
|
225
|
+
|
226
|
+
// thanks to bibendus83 -> http://sourceforge.net/tracker/index.php?func=detail&aid=3213174&group_id=358205&atid=1495382
|
227
|
+
var dp_dateFormat = $this.datepicker('option', 'dateFormat');
|
228
|
+
if (dp_dateFormat) {
|
229
|
+
dateFormat = dp_dateFormat;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
// converts to object as a neutral format
|
234
|
+
switch(from_format) {
|
235
|
+
case 'object': break;
|
236
|
+
case 'string': date = $.datepicker.parseDate(dateFormat, date); break;
|
237
|
+
case 'number': date = new Date(date); break;
|
238
|
+
default: $.error('Conversion from "'+ desired_format +'" format not allowed on jQuery.multiDatesPicker');
|
239
|
+
}
|
240
|
+
// then converts to the desired format
|
241
|
+
switch(desired_format) {
|
242
|
+
case 'object': return date;
|
243
|
+
case 'string': return $.datepicker.formatDate(dateFormat, date);
|
244
|
+
case 'number': return date.getTime();
|
245
|
+
default: $.error('Conversion to "'+ desired_format +'" format not allowed on jQuery.multiDatesPicker');
|
246
|
+
}
|
247
|
+
return false;
|
248
|
+
},
|
249
|
+
gotDate : function( date, type ) {
|
250
|
+
if(!type) type = 'picked';
|
251
|
+
for(var i = 0; i < this.multiDatesPicker.dates[type].length; i++) {
|
252
|
+
if(methods.compareDates.call(this, this.multiDatesPicker.dates[type][i], date) === 0) {
|
253
|
+
return i;
|
254
|
+
}
|
255
|
+
}
|
256
|
+
return false;
|
257
|
+
},
|
258
|
+
getDates : function( format, type ) {
|
259
|
+
if(!format) format = 'string';
|
260
|
+
if(!type) type = 'picked';
|
261
|
+
switch (format) {
|
262
|
+
case 'object':
|
263
|
+
return this.multiDatesPicker.dates[type];
|
264
|
+
case 'string':
|
265
|
+
case 'number':
|
266
|
+
var o_dates = new Array();
|
267
|
+
for(var i in this.multiDatesPicker.dates[type])
|
268
|
+
o_dates.push(
|
269
|
+
dateConvert.call(
|
270
|
+
this,
|
271
|
+
this.multiDatesPicker.dates[type][i],
|
272
|
+
format
|
273
|
+
)
|
274
|
+
);
|
275
|
+
return o_dates;
|
276
|
+
|
277
|
+
default: $.error('Format "'+format+'" not supported!');
|
278
|
+
}
|
279
|
+
},
|
280
|
+
addDates : function( dates, type ) {
|
281
|
+
if(dates.length > 0) {
|
282
|
+
if(!type) type = 'picked';
|
283
|
+
switch(typeof dates) {
|
284
|
+
case 'object':
|
285
|
+
case 'array':
|
286
|
+
if(dates.length) {
|
287
|
+
for(var i in dates)
|
288
|
+
addDate.call(this, dates[i], type, true);
|
289
|
+
sortDates.call(this, type);
|
290
|
+
break;
|
291
|
+
} // else does the same as 'string'
|
292
|
+
case 'string':
|
293
|
+
case 'number':
|
294
|
+
addDate.call(this, dates, type);
|
295
|
+
break;
|
296
|
+
default:
|
297
|
+
$.error('Date format "'+ typeof dates +'" not allowed on jQuery.multiDatesPicker');
|
298
|
+
}
|
299
|
+
$(this).datepicker('refresh');
|
300
|
+
} else {
|
301
|
+
$.error('Empty array of dates received.');
|
302
|
+
}
|
303
|
+
},
|
304
|
+
removeDates : function( dates, type ) {
|
305
|
+
if(!type) type = 'picked';
|
306
|
+
var removed = [];
|
307
|
+
if (Object.prototype.toString.call(dates) === '[object Array]') {
|
308
|
+
for(var i in dates.sort(function(a,b){return b-a})) {
|
309
|
+
removed.push(removeDate.call(this, dates[i], type));
|
310
|
+
}
|
311
|
+
} else {
|
312
|
+
removed.push(removeDate.call(this, dates, type));
|
313
|
+
}
|
314
|
+
$(this).datepicker('refresh');
|
315
|
+
return removed;
|
316
|
+
},
|
317
|
+
removeIndexes : function( indexes, type ) {
|
318
|
+
if(!type) type = 'picked';
|
319
|
+
var removed = [];
|
320
|
+
if (Object.prototype.toString.call(indexes) === '[object Array]') {
|
321
|
+
for(var i in indexes.sort(function(a,b){return b-a})) {
|
322
|
+
removed.push(removeIndex.call(this, indexes[i], type));
|
323
|
+
}
|
324
|
+
} else {
|
325
|
+
removed.push(removeIndex.call(this, indexes, type));
|
326
|
+
}
|
327
|
+
$(this).datepicker('refresh');
|
328
|
+
return removed;
|
329
|
+
},
|
330
|
+
resetDates : function ( type ) {
|
331
|
+
if(!type) type = 'picked';
|
332
|
+
this.multiDatesPicker.dates[type] = [];
|
333
|
+
$(this).datepicker('refresh');
|
334
|
+
},
|
335
|
+
toggleDate : function( date, type ) {
|
336
|
+
if(!type) type = 'picked';
|
337
|
+
|
338
|
+
switch(this.multiDatesPicker.mode) {
|
339
|
+
case 'daysRange':
|
340
|
+
this.multiDatesPicker.dates[type] = []; // deletes all picked/disabled dates
|
341
|
+
var end = this.multiDatesPicker.autoselectRange[1];
|
342
|
+
var begin = this.multiDatesPicker.autoselectRange[0];
|
343
|
+
if(end < begin) { // switch
|
344
|
+
end = this.multiDatesPicker.autoselectRange[0];
|
345
|
+
begin = this.multiDatesPicker.autoselectRange[1];
|
346
|
+
}
|
347
|
+
for(var i = begin; i < end; i++)
|
348
|
+
methods.addDates.call(this, methods.sumDays(date, i), type);
|
349
|
+
break;
|
350
|
+
default:
|
351
|
+
if(methods.gotDate.call(this, date) === false) // adds dates
|
352
|
+
methods.addDates.call(this, date, type);
|
353
|
+
else // removes dates
|
354
|
+
methods.removeDates.call(this, date, type);
|
355
|
+
break;
|
356
|
+
}
|
357
|
+
},
|
358
|
+
setMode : function( options ) {
|
359
|
+
var $this = $(this);
|
360
|
+
if(options.mode) this.multiDatesPicker.mode = options.mode;
|
361
|
+
|
362
|
+
switch(this.multiDatesPicker.mode) {
|
363
|
+
case 'normal':
|
364
|
+
for(option in options)
|
365
|
+
switch(option) {
|
366
|
+
case 'maxPicks':
|
367
|
+
case 'minPicks':
|
368
|
+
case 'pickableRange':
|
369
|
+
case 'adjustRangeToDisabled':
|
370
|
+
this.multiDatesPicker[option] = options[option];
|
371
|
+
break;
|
372
|
+
//default: $.error('Option ' + option + ' ignored for mode "'.options.mode.'".');
|
373
|
+
}
|
374
|
+
break;
|
375
|
+
case 'daysRange':
|
376
|
+
case 'weeksRange':
|
377
|
+
var mandatory = 1;
|
378
|
+
for(option in options)
|
379
|
+
switch(option) {
|
380
|
+
case 'autoselectRange':
|
381
|
+
mandatory--;
|
382
|
+
case 'pickableRange':
|
383
|
+
case 'adjustRangeToDisabled':
|
384
|
+
this.multiDatesPicker[option] = options[option];
|
385
|
+
break;
|
386
|
+
//default: $.error('Option ' + option + ' does not exist for setMode on jQuery.multiDatesPicker');
|
387
|
+
}
|
388
|
+
if(mandatory > 0) $.error('Some mandatory options not specified!');
|
389
|
+
break;
|
390
|
+
}
|
391
|
+
|
392
|
+
/*
|
393
|
+
if(options.pickableRange) {
|
394
|
+
$this.datepicker("option", "maxDate", options.pickableRange);
|
395
|
+
$this.datepicker("option", "minDate", this.multiDatesPicker.minDate);
|
396
|
+
}
|
397
|
+
*/
|
398
|
+
|
399
|
+
if(mdp_events.onSelect)
|
400
|
+
mdp_events.onSelect();
|
401
|
+
$this.datepicker('refresh');
|
402
|
+
}
|
403
|
+
};
|
404
|
+
|
405
|
+
this.each(function() {
|
406
|
+
if (!this.multiDatesPicker) {
|
407
|
+
this.multiDatesPicker = {
|
408
|
+
dates: {
|
409
|
+
picked: [],
|
410
|
+
disabled: []
|
411
|
+
},
|
412
|
+
mode: 'normal',
|
413
|
+
adjustRangeToDisabled: true
|
414
|
+
};
|
415
|
+
}
|
416
|
+
|
417
|
+
if(methods[method]) {
|
418
|
+
var exec_result = methods[method].apply(this, Array.prototype.slice.call(mdp_arguments, 1));
|
419
|
+
switch(method) {
|
420
|
+
case 'getDates':
|
421
|
+
case 'removeDates':
|
422
|
+
case 'gotDate':
|
423
|
+
case 'sumDays':
|
424
|
+
case 'compareDates':
|
425
|
+
case 'dateConvert':
|
426
|
+
ret = exec_result;
|
427
|
+
}
|
428
|
+
return exec_result;
|
429
|
+
} else if( typeof method === 'object' || ! method ) {
|
430
|
+
return methods.init.apply(this, mdp_arguments);
|
431
|
+
} else {
|
432
|
+
$.error('Method ' + method + ' does not exist on jQuery.multiDatesPicker');
|
433
|
+
}
|
434
|
+
return false;
|
435
|
+
});
|
436
|
+
|
437
|
+
if(method != 'gotDate' && method != 'getDates') {
|
438
|
+
aaaa = 1;
|
439
|
+
}
|
440
|
+
|
441
|
+
return ret;
|
442
|
+
};
|
443
|
+
|
444
|
+
var PROP_NAME = 'multiDatesPicker';
|
445
|
+
var dpuuid = new Date().getTime();
|
446
|
+
var instActive;
|
447
|
+
|
448
|
+
$.multiDatesPicker = {version: false};
|
449
|
+
//$.multiDatesPicker = new MultiDatesPicker(); // singleton instance
|
450
|
+
$.multiDatesPicker.initialized = false;
|
451
|
+
$.multiDatesPicker.uuid = new Date().getTime();
|
452
|
+
$.multiDatesPicker.version = $.ui.multiDatesPicker.version;
|
453
|
+
|
454
|
+
// Workaround for #4055
|
455
|
+
// Add another global to avoid noConflict issues with inline event handlers
|
456
|
+
window['DP_jQuery_' + dpuuid] = $;
|
457
|
+
})( jQuery );
|