multidatespicker-rails 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/lib/multidatespicker/rails.rb +8 -0
- data/lib/multidatespicker/rails/version.rb +5 -0
- data/multidatespicker-rails.gemspec +26 -0
- data/vendor/assets/images/ui-bg_diagonal-maze_20_6e4f1c_10x10.png +0 -0
- data/vendor/assets/images/ui-bg_diagonal-maze_40_000000_10x10.png +0 -0
- data/vendor/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/vendor/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/vendor/assets/images/ui-bg_fine-grain_10_eceadf_60x60.png +0 -0
- data/vendor/assets/images/ui-bg_fine-grain_10_f8f7f6_60x60.png +0 -0
- data/vendor/assets/images/ui-bg_fine-grain_15_d3c05a_60x60.png +0 -0
- data/vendor/assets/images/ui-bg_fine-grain_15_eceadf_60x60.png +0 -0
- data/vendor/assets/images/ui-bg_fine-grain_15_ffffff_60x60.png +0 -0
- data/vendor/assets/images/ui-bg_fine-grain_65_654b24_60x60.png +0 -0
- data/vendor/assets/images/ui-bg_fine-grain_68_b83400_60x60.png +0 -0
- data/vendor/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/vendor/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/vendor/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/vendor/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/vendor/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/vendor/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/vendor/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/vendor/assets/images/ui-icons_222222_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_228ef1_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_3572ac_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_8c291d_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_b83400_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_ef8c08_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_fbdb93_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_ffd27a_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_ffffff_256x240.png +0 -0
- data/vendor/assets/javascripts/jquery-ui.multidatespicker.js +500 -0
- data/vendor/assets/javascripts/lang-css.js +2 -0
- data/vendor/assets/javascripts/prettify.js +28 -0
- data/vendor/assets/stylesheets/jquery-ui.css +1225 -0
- data/vendor/assets/stylesheets/jquery-ui.structure.css +833 -0
- data/vendor/assets/stylesheets/jquery-ui.theme.css +410 -0
- data/vendor/assets/stylesheets/mdp.css +0 -0
- data/vendor/assets/stylesheets/pepper-ginder-custom.css +0 -0
- data/vendor/assets/stylesheets/prettify.css +1 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5fa4fe71061b47af25c8f96d1b1235bd1cbf6ac4
|
4
|
+
data.tar.gz: 83f52fb23c6b98e38aef46bef487b7d2d8a9af6c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc9f4ae6f1a716b28361a9b64ba337e6685aaa4cca8bdcebfbd5bbf077e20493a7402b89c2215b0aefad8b1a69f30bd93cdfdc2408cfeef4989df880e2786113
|
7
|
+
data.tar.gz: 025f2410105f38c7dce925c2838923d927170a09ebebcf2119d9df46ca4cae2ed58d13c22773a2a9996d7aaab4581557f3a65f849ca685d2301aff0c1482285d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 teddy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Multidatespicker::Rails
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/multidatespicker/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'multidatespicker-rails'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install multidatespicker-rails
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/multidatespicker-rails.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'multidatespicker/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "multidatespicker-rails"
|
8
|
+
spec.version = Multidatespicker::Rails::VERSION
|
9
|
+
spec.authors = ["teddy"]
|
10
|
+
spec.email = ["mlc880926@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
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
|
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,500 @@
|
|
1
|
+
/*
|
2
|
+
* MultiDatesPicker v1.6.3
|
3
|
+
* http://multidatespickr.sourceforge.net/
|
4
|
+
*
|
5
|
+
* Copyright 2014, Luca Lauretta
|
6
|
+
* Dual licensed under the MIT or GPL version 2 licenses.
|
7
|
+
*/
|
8
|
+
(function( $ ){
|
9
|
+
$.extend($.ui, { multiDatesPicker: { version: "1.6.3" } });
|
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 = 0; i < this.multiDatesPicker.dates[type].length; i++)
|
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
|
+
this.multiDatesPicker.changed = true;
|
76
|
+
// @todo: this will be optimized when I'll move methods to the singleton.
|
77
|
+
}
|
78
|
+
|
79
|
+
if (this.multiDatesPicker.mode == 'normal' && this.multiDatesPicker.pickableRange) {
|
80
|
+
if(this.multiDatesPicker.dates.picked.length > 0) {
|
81
|
+
var min_date = this.multiDatesPicker.dates.picked[0],
|
82
|
+
max_date = new Date(min_date.getTime());
|
83
|
+
|
84
|
+
methods.sumDays(max_date, this.multiDatesPicker.pickableRange-1);
|
85
|
+
|
86
|
+
// counts the number of disabled dates in the range
|
87
|
+
if(this.multiDatesPicker.adjustRangeToDisabled) {
|
88
|
+
var c_disabled,
|
89
|
+
disabled = this.multiDatesPicker.dates.disabled.slice(0);
|
90
|
+
do {
|
91
|
+
c_disabled = 0;
|
92
|
+
for(var i = 0; i < disabled.length; i++) {
|
93
|
+
if(disabled[i].getTime() <= max_date.getTime()) {
|
94
|
+
if((min_date.getTime() <= disabled[i].getTime()) && (disabled[i].getTime() <= max_date.getTime()) ) {
|
95
|
+
c_disabled++;
|
96
|
+
}
|
97
|
+
disabled.splice(i, 1);
|
98
|
+
i--;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
max_date.setDate(max_date.getDate() + c_disabled);
|
102
|
+
} while(c_disabled != 0);
|
103
|
+
}
|
104
|
+
|
105
|
+
if(this.multiDatesPicker.maxDate && (max_date > this.multiDatesPicker.maxDate))
|
106
|
+
max_date = this.multiDatesPicker.maxDate;
|
107
|
+
|
108
|
+
$this
|
109
|
+
.datepicker("option", "minDate", min_date)
|
110
|
+
.datepicker("option", "maxDate", max_date);
|
111
|
+
} else {
|
112
|
+
$this
|
113
|
+
.datepicker("option", "minDate", this.multiDatesPicker.minDate)
|
114
|
+
.datepicker("option", "maxDate", this.multiDatesPicker.maxDate);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
if(this.multiDatesPicker.originalOnSelect && dateText)
|
119
|
+
this.multiDatesPicker.originalOnSelect.call(this, dateText, inst);
|
120
|
+
|
121
|
+
},
|
122
|
+
beforeShowDay : function(date) {
|
123
|
+
var $this = $(this),
|
124
|
+
gotThisDate = $this.multiDatesPicker('gotDate', date) !== false,
|
125
|
+
isDisabledCalendar = $this.datepicker('option', 'disabled'),
|
126
|
+
isDisabledDate = $this.multiDatesPicker('gotDate', date, 'disabled') !== false,
|
127
|
+
areAllSelected = this.multiDatesPicker.maxPicks <= this.multiDatesPicker.dates.picked.length;
|
128
|
+
|
129
|
+
var bsdReturn = [true, '', null];
|
130
|
+
if(this.multiDatesPicker.originalBeforeShowDay)
|
131
|
+
bsdReturn = this.multiDatesPicker.originalBeforeShowDay.call(this, date);
|
132
|
+
|
133
|
+
bsdReturn[1] = gotThisDate ? 'ui-state-highlight' : bsdReturn[1];
|
134
|
+
bsdReturn[0] = bsdReturn[0] && !(isDisabledCalendar || isDisabledDate || (areAllSelected && !bsdReturn[1]));
|
135
|
+
return bsdReturn;
|
136
|
+
}
|
137
|
+
};
|
138
|
+
|
139
|
+
// value have to be extracted before datepicker is initiated
|
140
|
+
if($this.val()) var inputDates = $this.val()
|
141
|
+
this.multiDatesPicker.separator = ', ';
|
142
|
+
|
143
|
+
if(options) {
|
144
|
+
// value have to be extracted before datepicker is initiated
|
145
|
+
//if(options.altField) var inputDates = $(options.altField).val();
|
146
|
+
if(options.separator) this.multiDatesPicker.separator = options.separator;
|
147
|
+
|
148
|
+
this.multiDatesPicker.originalBeforeShow = options.beforeShow;
|
149
|
+
this.multiDatesPicker.originalOnSelect = options.onSelect;
|
150
|
+
this.multiDatesPicker.originalBeforeShowDay = options.beforeShowDay;
|
151
|
+
this.multiDatesPicker.originalOnClose = options.onClose;
|
152
|
+
|
153
|
+
// datepicker init
|
154
|
+
$this.datepicker(options);
|
155
|
+
|
156
|
+
this.multiDatesPicker.minDate = $.datepicker._determineDate(this, options.minDate, null);
|
157
|
+
this.multiDatesPicker.maxDate = $.datepicker._determineDate(this, options.maxDate, null);
|
158
|
+
if(options.addDates) methods.addDates.call(this, options.addDates);
|
159
|
+
|
160
|
+
if(options.addDisabledDates)
|
161
|
+
methods.addDates.call(this, options.addDisabledDates, 'disabled');
|
162
|
+
|
163
|
+
methods.setMode.call(this, options);
|
164
|
+
} else {
|
165
|
+
$this.datepicker();
|
166
|
+
}
|
167
|
+
$this.datepicker('option', mdp_events);
|
168
|
+
|
169
|
+
// adds any dates found in the input or alt field
|
170
|
+
if(inputDates) $this.multiDatesPicker('value', inputDates);
|
171
|
+
|
172
|
+
// generates the new string of added dates
|
173
|
+
var inputs_values = $this.multiDatesPicker('value');
|
174
|
+
|
175
|
+
// fills the input field back with all the dates in the calendar
|
176
|
+
if(this.tagName == 'INPUT') $this.val(inputs_values);
|
177
|
+
|
178
|
+
// Fixes the altField filled with defaultDate by default
|
179
|
+
var altFieldOption = $this.datepicker('option', 'altField');
|
180
|
+
if (altFieldOption) $(altFieldOption).val(inputs_values);
|
181
|
+
|
182
|
+
// Updates the calendar view
|
183
|
+
$this.datepicker('refresh');
|
184
|
+
},
|
185
|
+
compareDates : function(date1, date2) {
|
186
|
+
date1 = dateConvert.call(this, date1);
|
187
|
+
date2 = dateConvert.call(this, date2);
|
188
|
+
// return > 0 means date1 is later than date2
|
189
|
+
// return == 0 means date1 is the same day as date2
|
190
|
+
// return < 0 means date1 is earlier than date2
|
191
|
+
var diff = date1.getFullYear() - date2.getFullYear();
|
192
|
+
if(!diff) {
|
193
|
+
diff = date1.getMonth() - date2.getMonth();
|
194
|
+
if(!diff)
|
195
|
+
diff = date1.getDate() - date2.getDate();
|
196
|
+
}
|
197
|
+
return diff;
|
198
|
+
},
|
199
|
+
sumDays : function( date, n_days ) {
|
200
|
+
var origDateType = typeof date;
|
201
|
+
obj_date = dateConvert.call(this, date);
|
202
|
+
obj_date.setDate(obj_date.getDate() + n_days);
|
203
|
+
return dateConvert.call(this, obj_date, origDateType);
|
204
|
+
},
|
205
|
+
dateConvert : function( date, desired_format, dateFormat ) {
|
206
|
+
var from_format = typeof date;
|
207
|
+
|
208
|
+
if(from_format == desired_format) {
|
209
|
+
if(from_format == 'object') {
|
210
|
+
try {
|
211
|
+
date.getTime();
|
212
|
+
} catch (e) {
|
213
|
+
$.error('Received date is in a non supported format!');
|
214
|
+
return false;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
return date;
|
218
|
+
}
|
219
|
+
|
220
|
+
var $this = $(this);
|
221
|
+
if(typeof date == 'undefined') date = new Date(0);
|
222
|
+
|
223
|
+
if(desired_format != 'string' && desired_format != 'object' && desired_format != 'number')
|
224
|
+
$.error('Date format "'+ desired_format +'" not supported!');
|
225
|
+
|
226
|
+
if(!dateFormat) {
|
227
|
+
dateFormat = $.datepicker._defaults.dateFormat;
|
228
|
+
|
229
|
+
// thanks to bibendus83 -> http://sourceforge.net/tracker/index.php?func=detail&aid=3213174&group_id=358205&atid=1495382
|
230
|
+
var dp_dateFormat = $this.datepicker('option', 'dateFormat');
|
231
|
+
if (dp_dateFormat) {
|
232
|
+
dateFormat = dp_dateFormat;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
// converts to object as a neutral format
|
237
|
+
switch(from_format) {
|
238
|
+
case 'object': break;
|
239
|
+
case 'string': date = $.datepicker.parseDate(dateFormat, date); break;
|
240
|
+
case 'number': date = new Date(date); break;
|
241
|
+
default: $.error('Conversion from "'+ desired_format +'" format not allowed on jQuery.multiDatesPicker');
|
242
|
+
}
|
243
|
+
// then converts to the desired format
|
244
|
+
switch(desired_format) {
|
245
|
+
case 'object': return date;
|
246
|
+
case 'string': return $.datepicker.formatDate(dateFormat, date);
|
247
|
+
case 'number': return date.getTime();
|
248
|
+
default: $.error('Conversion to "'+ desired_format +'" format not allowed on jQuery.multiDatesPicker');
|
249
|
+
}
|
250
|
+
return false;
|
251
|
+
},
|
252
|
+
gotDate : function( date, type ) {
|
253
|
+
if(!type) type = 'picked';
|
254
|
+
for(var i = 0; i < this.multiDatesPicker.dates[type].length; i++) {
|
255
|
+
if(methods.compareDates.call(this, this.multiDatesPicker.dates[type][i], date) === 0) {
|
256
|
+
return i;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
return false;
|
260
|
+
},
|
261
|
+
value : function( value ) {
|
262
|
+
if(value && typeof value == 'string') {
|
263
|
+
methods.addDates.call(this, value.split(this.multiDatesPicker.separator));
|
264
|
+
} else {
|
265
|
+
var dates = methods.getDates.call(this, 'string');
|
266
|
+
return dates.length
|
267
|
+
? dates.join(this.multiDatesPicker.separator)
|
268
|
+
: "";
|
269
|
+
}
|
270
|
+
},
|
271
|
+
getDates : function( format, type ) {
|
272
|
+
if(!format) format = 'string';
|
273
|
+
if(!type) type = 'picked';
|
274
|
+
switch (format) {
|
275
|
+
case 'object':
|
276
|
+
return this.multiDatesPicker.dates[type];
|
277
|
+
case 'string':
|
278
|
+
case 'number':
|
279
|
+
var o_dates = new Array();
|
280
|
+
for(var i in this.multiDatesPicker.dates[type])
|
281
|
+
o_dates.push(
|
282
|
+
dateConvert.call(
|
283
|
+
this,
|
284
|
+
this.multiDatesPicker.dates[type][i],
|
285
|
+
format
|
286
|
+
)
|
287
|
+
);
|
288
|
+
return o_dates;
|
289
|
+
|
290
|
+
default: $.error('Format "'+format+'" not supported!');
|
291
|
+
}
|
292
|
+
},
|
293
|
+
addDates : function( dates, type ) {
|
294
|
+
if(dates.length > 0) {
|
295
|
+
if(!type) type = 'picked';
|
296
|
+
switch(typeof dates) {
|
297
|
+
case 'object':
|
298
|
+
case 'array':
|
299
|
+
if(dates.length) {
|
300
|
+
for(var i = 0; i < dates.length; i++)
|
301
|
+
addDate.call(this, dates[i], type, true);
|
302
|
+
sortDates.call(this, type);
|
303
|
+
break;
|
304
|
+
} // else does the same as 'string'
|
305
|
+
case 'string':
|
306
|
+
case 'number':
|
307
|
+
addDate.call(this, dates, type);
|
308
|
+
break;
|
309
|
+
default:
|
310
|
+
$.error('Date format "'+ typeof dates +'" not allowed on jQuery.multiDatesPicker');
|
311
|
+
}
|
312
|
+
//$(this).datepicker('refresh');
|
313
|
+
} else {
|
314
|
+
$.error('Empty array of dates received.');
|
315
|
+
}
|
316
|
+
},
|
317
|
+
removeDates : function( dates, type ) {
|
318
|
+
if(!type) type = 'picked';
|
319
|
+
var removed = [];
|
320
|
+
if (Object.prototype.toString.call(dates) === '[object Array]') {
|
321
|
+
for(var i in dates.sort(function(a,b){return b-a})) {
|
322
|
+
removed.push(removeDate.call(this, dates[i], type));
|
323
|
+
}
|
324
|
+
} else {
|
325
|
+
removed.push(removeDate.call(this, dates, type));
|
326
|
+
}
|
327
|
+
return removed;
|
328
|
+
},
|
329
|
+
removeIndexes : function( indexes, type ) {
|
330
|
+
if(!type) type = 'picked';
|
331
|
+
var removed = [];
|
332
|
+
if (Object.prototype.toString.call(indexes) === '[object Array]') {
|
333
|
+
for(var i in indexes.sort(function(a,b){return b-a})) {
|
334
|
+
removed.push(removeIndex.call(this, indexes[i], type));
|
335
|
+
}
|
336
|
+
} else {
|
337
|
+
removed.push(removeIndex.call(this, indexes, type));
|
338
|
+
}
|
339
|
+
return removed;
|
340
|
+
},
|
341
|
+
resetDates : function ( type ) {
|
342
|
+
if(!type) type = 'picked';
|
343
|
+
this.multiDatesPicker.dates[type] = [];
|
344
|
+
},
|
345
|
+
toggleDate : function( date, type ) {
|
346
|
+
if(!type) type = 'picked';
|
347
|
+
|
348
|
+
switch(this.multiDatesPicker.mode) {
|
349
|
+
case 'daysRange':
|
350
|
+
this.multiDatesPicker.dates[type] = []; // deletes all picked/disabled dates
|
351
|
+
var end = this.multiDatesPicker.autoselectRange[1];
|
352
|
+
var begin = this.multiDatesPicker.autoselectRange[0];
|
353
|
+
if(end < begin) { // switch
|
354
|
+
end = this.multiDatesPicker.autoselectRange[0];
|
355
|
+
begin = this.multiDatesPicker.autoselectRange[1];
|
356
|
+
}
|
357
|
+
for(var i = begin; i < end; i++)
|
358
|
+
methods.addDates.call(this, methods.sumDays(date, i), type);
|
359
|
+
break;
|
360
|
+
default:
|
361
|
+
if(methods.gotDate.call(this, date) === false) // adds dates
|
362
|
+
methods.addDates.call(this, date, type);
|
363
|
+
else // removes dates
|
364
|
+
methods.removeDates.call(this, date, type);
|
365
|
+
break;
|
366
|
+
}
|
367
|
+
},
|
368
|
+
setMode : function( options ) {
|
369
|
+
var $this = $(this);
|
370
|
+
if(options.mode) this.multiDatesPicker.mode = options.mode;
|
371
|
+
|
372
|
+
switch(this.multiDatesPicker.mode) {
|
373
|
+
case 'normal':
|
374
|
+
for(option in options)
|
375
|
+
switch(option) {
|
376
|
+
case 'maxPicks':
|
377
|
+
case 'minPicks':
|
378
|
+
case 'pickableRange':
|
379
|
+
case 'adjustRangeToDisabled':
|
380
|
+
this.multiDatesPicker[option] = options[option];
|
381
|
+
break;
|
382
|
+
//default: $.error('Option ' + option + ' ignored for mode "'.options.mode.'".');
|
383
|
+
}
|
384
|
+
break;
|
385
|
+
case 'daysRange':
|
386
|
+
case 'weeksRange':
|
387
|
+
var mandatory = 1;
|
388
|
+
for(option in options)
|
389
|
+
switch(option) {
|
390
|
+
case 'autoselectRange':
|
391
|
+
mandatory--;
|
392
|
+
case 'pickableRange':
|
393
|
+
case 'adjustRangeToDisabled':
|
394
|
+
this.multiDatesPicker[option] = options[option];
|
395
|
+
break;
|
396
|
+
//default: $.error('Option ' + option + ' does not exist for setMode on jQuery.multiDatesPicker');
|
397
|
+
}
|
398
|
+
if(mandatory > 0) $.error('Some mandatory options not specified!');
|
399
|
+
break;
|
400
|
+
}
|
401
|
+
|
402
|
+
/*
|
403
|
+
if(options.pickableRange) {
|
404
|
+
$this.datepicker("option", "maxDate", options.pickableRange);
|
405
|
+
$this.datepicker("option", "minDate", this.multiDatesPicker.minDate);
|
406
|
+
}
|
407
|
+
*/
|
408
|
+
|
409
|
+
if(mdp_events.onSelect)
|
410
|
+
mdp_events.onSelect();
|
411
|
+
},
|
412
|
+
destroy: function(){
|
413
|
+
this.multiDatesPicker = null;
|
414
|
+
$(this).datepicker('destroy');
|
415
|
+
}
|
416
|
+
};
|
417
|
+
|
418
|
+
this.each(function() {
|
419
|
+
var $this = $(this);
|
420
|
+
if (!this.multiDatesPicker) {
|
421
|
+
this.multiDatesPicker = {
|
422
|
+
dates: {
|
423
|
+
picked: [],
|
424
|
+
disabled: []
|
425
|
+
},
|
426
|
+
mode: 'normal',
|
427
|
+
adjustRangeToDisabled: true
|
428
|
+
};
|
429
|
+
}
|
430
|
+
|
431
|
+
if(methods[method]) {
|
432
|
+
var exec_result = methods[method].apply(this, Array.prototype.slice.call(mdp_arguments, 1));
|
433
|
+
switch(method) {
|
434
|
+
case 'removeDates':
|
435
|
+
case 'removeIndexes':
|
436
|
+
case 'resetDates':
|
437
|
+
case 'toggleDate':
|
438
|
+
case 'addDates':
|
439
|
+
var altField = $this.datepicker('option', 'altField');
|
440
|
+
// @todo: should use altFormat for altField
|
441
|
+
var dates_string = methods.value.call(this);
|
442
|
+
if (altField !== undefined && altField != "") {
|
443
|
+
$(altField).val(dates_string);
|
444
|
+
}
|
445
|
+
if(this.tagName == 'INPUT') { // for inputs
|
446
|
+
$this.val(dates_string);
|
447
|
+
}
|
448
|
+
|
449
|
+
$.datepicker._refreshDatepicker(this);
|
450
|
+
}
|
451
|
+
switch(method) {
|
452
|
+
case 'removeDates':
|
453
|
+
case 'getDates':
|
454
|
+
case 'gotDate':
|
455
|
+
case 'sumDays':
|
456
|
+
case 'compareDates':
|
457
|
+
case 'dateConvert':
|
458
|
+
case 'value':
|
459
|
+
ret = exec_result;
|
460
|
+
}
|
461
|
+
return exec_result;
|
462
|
+
} else if( typeof method === 'object' || ! method ) {
|
463
|
+
return methods.init.apply(this, mdp_arguments);
|
464
|
+
} else {
|
465
|
+
$.error('Method ' + method + ' does not exist on jQuery.multiDatesPicker');
|
466
|
+
}
|
467
|
+
return false;
|
468
|
+
});
|
469
|
+
|
470
|
+
return ret;
|
471
|
+
};
|
472
|
+
|
473
|
+
var PROP_NAME = 'multiDatesPicker';
|
474
|
+
var dpuuid = new Date().getTime();
|
475
|
+
var instActive;
|
476
|
+
|
477
|
+
$.multiDatesPicker = {version: false};
|
478
|
+
//$.multiDatesPicker = new MultiDatesPicker(); // singleton instance
|
479
|
+
$.multiDatesPicker.initialized = false;
|
480
|
+
$.multiDatesPicker.uuid = new Date().getTime();
|
481
|
+
$.multiDatesPicker.version = $.ui.multiDatesPicker.version;
|
482
|
+
|
483
|
+
// allows MDP not to hide everytime a date is picked
|
484
|
+
$.multiDatesPicker._hideDatepicker = $.datepicker._hideDatepicker;
|
485
|
+
$.datepicker._hideDatepicker = function(){
|
486
|
+
var target = this._curInst.input[0];
|
487
|
+
var mdp = target.multiDatesPicker;
|
488
|
+
if(!mdp || (this._curInst.inline === false && !mdp.changed)) {
|
489
|
+
return $.multiDatesPicker._hideDatepicker.apply(this, arguments);
|
490
|
+
} else {
|
491
|
+
mdp.changed = false;
|
492
|
+
$.datepicker._refreshDatepicker(target);
|
493
|
+
return;
|
494
|
+
}
|
495
|
+
};
|
496
|
+
|
497
|
+
// Workaround for #4055
|
498
|
+
// Add another global to avoid noConflict issues with inline event handlers
|
499
|
+
window['DP_jQuery_' + dpuuid] = $;
|
500
|
+
})( jQuery );
|