bookkeeper 0.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +22 -0
  3. data/Rakefile +44 -0
  4. data/app/assets/javascripts/bookkeeper.js +10 -0
  5. data/app/assets/javascripts/bookkeeper/bootstrap-datepicker.js +470 -0
  6. data/app/assets/stylesheets/bookkeeper.css +13 -0
  7. data/app/assets/stylesheets/bookkeeper/datepicker.css +182 -0
  8. data/app/assets/stylesheets/bookkeeper/scaffold.css +56 -0
  9. data/app/controllers/bookkeeper/application_controller.rb +5 -0
  10. data/app/controllers/bookkeeper/purchases_controller.rb +74 -0
  11. data/app/helpers/bookkeeper/application_helper.rb +4 -0
  12. data/app/inputs/datepicker_input.rb +9 -0
  13. data/app/models/bookkeeper/purchase.rb +11 -0
  14. data/app/uploaders/receipt_uploader.rb +57 -0
  15. data/app/views/bookkeeper/purchases/_form.html.erb +17 -0
  16. data/app/views/bookkeeper/purchases/edit.html.erb +6 -0
  17. data/app/views/bookkeeper/purchases/index.html.erb +34 -0
  18. data/app/views/bookkeeper/purchases/new.html.erb +5 -0
  19. data/app/views/bookkeeper/purchases/show.html.erb +34 -0
  20. data/app/views/layouts/bookkeeper/application.html.erb +14 -0
  21. data/config/initializers/carrierwave.rb +6 -0
  22. data/config/initializers/simple_form.rb +142 -0
  23. data/config/initializers/simple_form_bootstrap.rb +45 -0
  24. data/config/initializers/validates_timeliness.rb +40 -0
  25. data/config/locales/simple_form.en.yml +26 -0
  26. data/config/locales/validates_timeliness.en.yml +16 -0
  27. data/config/routes.rb +3 -0
  28. data/db/migrate/20130215165240_create_bookkeeper_purchases.rb +13 -0
  29. data/lib/bookkeeper.rb +4 -0
  30. data/lib/bookkeeper/engine.rb +17 -0
  31. data/lib/bookkeeper/version.rb +3 -0
  32. data/lib/tasks/bookkeeper_tasks.rake +4 -0
  33. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  34. data/spec/assets/images/receipt.jpg +0 -0
  35. data/spec/controllers/bookkeeper/purchases_controller_spec.rb +156 -0
  36. data/spec/dummy/README.rdoc +261 -0
  37. data/spec/dummy/Rakefile +7 -0
  38. data/spec/dummy/app/assets/images/glyphicons-halflings-white.png +0 -0
  39. data/spec/dummy/app/assets/images/glyphicons-halflings.png +0 -0
  40. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  41. data/spec/dummy/app/assets/javascripts/bootstrap.js +2268 -0
  42. data/spec/dummy/app/assets/stylesheets/application.css +14 -0
  43. data/spec/dummy/app/assets/stylesheets/bootstrap-responsive.css +1109 -0
  44. data/spec/dummy/app/assets/stylesheets/bootstrap.css +6158 -0
  45. data/spec/dummy/app/assets/stylesheets/font-awesome-ie7.min.css +22 -0
  46. data/spec/dummy/app/assets/stylesheets/font-awesome.min.css +33 -0
  47. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  48. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  49. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/spec/dummy/config.ru +4 -0
  51. data/spec/dummy/config/application.rb +65 -0
  52. data/spec/dummy/config/boot.rb +10 -0
  53. data/spec/dummy/config/database.yml +25 -0
  54. data/spec/dummy/config/environment.rb +5 -0
  55. data/spec/dummy/config/environments/development.rb +37 -0
  56. data/spec/dummy/config/environments/production.rb +67 -0
  57. data/spec/dummy/config/environments/test.rb +37 -0
  58. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  59. data/spec/dummy/config/initializers/inflections.rb +15 -0
  60. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  61. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  62. data/spec/dummy/config/initializers/session_store.rb +8 -0
  63. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/spec/dummy/config/locales/en.yml +5 -0
  65. data/spec/dummy/config/routes.rb +4 -0
  66. data/spec/dummy/db/development.sqlite3 +0 -0
  67. data/spec/dummy/db/schema.rb +26 -0
  68. data/spec/dummy/db/test.sqlite3 +0 -0
  69. data/spec/dummy/public/404.html +26 -0
  70. data/spec/dummy/public/422.html +26 -0
  71. data/spec/dummy/public/500.html +25 -0
  72. data/spec/dummy/public/favicon.ico +0 -0
  73. data/spec/dummy/public/font/FontAwesome.otf +0 -0
  74. data/spec/dummy/public/font/fontawesome-webfont.eot +0 -0
  75. data/spec/dummy/public/font/fontawesome-webfont.svg +284 -0
  76. data/spec/dummy/public/font/fontawesome-webfont.ttf +0 -0
  77. data/spec/dummy/public/font/fontawesome-webfont.woff +0 -0
  78. data/spec/dummy/script/rails +6 -0
  79. data/spec/factories/bookkeeper_purchases.rb +15 -0
  80. data/spec/models/bookkeeper/purchase_spec.rb +51 -0
  81. data/spec/routing/bookkeeper/purchases_routing_spec.rb +37 -0
  82. data/spec/spec_helper.rb +19 -0
  83. data/spec/uploaders/receipt_uploader_spec.rb +26 -0
  84. data/spec/views/bookkeeper/purchases/edit.html.erb_spec.rb +22 -0
  85. data/spec/views/bookkeeper/purchases/index.html.erb_spec.rb +26 -0
  86. data/spec/views/bookkeeper/purchases/new.html.erb_spec.rb +22 -0
  87. data/spec/views/bookkeeper/purchases/show.html.erb_spec.rb +19 -0
  88. metadata +396 -0
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # Bookkeeper
2
+
3
+ Bookkeeper is a Rails engine with the aim of allowing a Rails application (at least 3.1) to handle the purchases you made and their receipt.
4
+
5
+ ## Configure
6
+
7
+ Add to your Gemfile
8
+
9
+ gem 'bookkeeper'
10
+
11
+ then launch `bundle install`.
12
+
13
+ Mount the engine wherever you prefer. To do so, add to `config/routes.rb`:
14
+
15
+ mount Bookkeeper::Engine => "/bookkeeper"
16
+
17
+ or, if you prefer:
18
+
19
+ mount Bookkeeper::Engine => "/"
20
+ root to: 'bookkeeper::purchases#index'
21
+
22
+ Bookkeeper uses Twitter Bootstrap markup, if your app doesn't use Bootstrap or you want to overwrite Bookkeeper views, just create the view into `app/views/bookkeeper/`. Use gem's views as template.
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
9
+
10
+ load 'rails/tasks/engine.rake'
11
+
12
+ Bundler::GemHelper.install_tasks
13
+
14
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
15
+
16
+ require 'rspec/core'
17
+ require 'rspec/core/rake_task'
18
+
19
+ desc "Run all specs in spec directory (excluding plugin specs)"
20
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
21
+
22
+ task :default => :spec
23
+
24
+ # begin
25
+ # require 'rdoc/task'
26
+ # rescue LoadError
27
+ # require 'rdoc/rdoc'
28
+ # require 'rake/rdoctask'
29
+ # RDoc::Task = Rake::RDocTask
30
+ # end
31
+ #
32
+ # RDoc::Task.new(:rdoc) do |rdoc|
33
+ # rdoc.rdoc_dir = 'rdoc'
34
+ # rdoc.title = 'Bookkeeper'
35
+ # rdoc.options << '--line-numbers'
36
+ # rdoc.rdoc_files.include('README.rdoc')
37
+ # rdoc.rdoc_files.include('lib/**/*.rb')
38
+ # end
39
+ #
40
+ #
41
+ #
42
+ #
43
+ # Bundler::GemHelper.install_tasks
44
+ #
@@ -0,0 +1,10 @@
1
+ //= require_tree './bookkeeper'
2
+
3
+ $(document).ready(function(){
4
+ $('input.datepicker').datepicker({ yearRange: "1920:2020", changeMonth: true, changeYear: true });
5
+
6
+ $('form .add-on.calendar').click(function(){
7
+ var el = this.parentNode;
8
+ $(el).find('input').focus();
9
+ });
10
+ })
@@ -0,0 +1,470 @@
1
+ /* =========================================================
2
+ * bootstrap-datepicker.js
3
+ * http://www.eyecon.ro/bootstrap-datepicker
4
+ * =========================================================
5
+ * Copyright 2012 Stefan Petre
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ * ========================================================= */
19
+
20
+ !function( $ ) {
21
+
22
+ // Picker object
23
+
24
+ var Datepicker = function(element, options){
25
+ this.element = $(element);
26
+ this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');
27
+ this.picker = $(DPGlobal.template)
28
+ .appendTo('body')
29
+ .on({
30
+ click: $.proxy(this.click, this)//,
31
+ //mousedown: $.proxy(this.mousedown, this)
32
+ });
33
+ this.isInput = this.element.is('input');
34
+ this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
35
+
36
+ if (this.isInput) {
37
+ this.element.on({
38
+ focus: $.proxy(this.show, this),
39
+ //blur: $.proxy(this.hide, this),
40
+ keyup: $.proxy(this.update, this)
41
+ });
42
+ } else {
43
+ if (this.component){
44
+ this.component.on('click', $.proxy(this.show, this));
45
+ } else {
46
+ this.element.on('click', $.proxy(this.show, this));
47
+ }
48
+ }
49
+
50
+ this.minViewMode = options.minViewMode||this.element.data('date-minviewmode')||0;
51
+ if (typeof this.minViewMode === 'string') {
52
+ switch (this.minViewMode) {
53
+ case 'months':
54
+ this.minViewMode = 1;
55
+ break;
56
+ case 'years':
57
+ this.minViewMode = 2;
58
+ break;
59
+ default:
60
+ this.minViewMode = 0;
61
+ break;
62
+ }
63
+ }
64
+ this.viewMode = options.viewMode||this.element.data('date-viewmode')||0;
65
+ if (typeof this.viewMode === 'string') {
66
+ switch (this.viewMode) {
67
+ case 'months':
68
+ this.viewMode = 1;
69
+ break;
70
+ case 'years':
71
+ this.viewMode = 2;
72
+ break;
73
+ default:
74
+ this.viewMode = 0;
75
+ break;
76
+ }
77
+ }
78
+ this.startViewMode = this.viewMode;
79
+ this.weekStart = options.weekStart||this.element.data('date-weekstart')||0;
80
+ this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
81
+ this.onRender = options.onRender;
82
+ this.fillDow();
83
+ this.fillMonths();
84
+ this.update();
85
+ this.showMode();
86
+ };
87
+
88
+ Datepicker.prototype = {
89
+ constructor: Datepicker,
90
+
91
+ show: function(e) {
92
+ this.picker.show();
93
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
94
+ this.place();
95
+ $(window).on('resize', $.proxy(this.place, this));
96
+ if (e ) {
97
+ e.stopPropagation();
98
+ e.preventDefault();
99
+ }
100
+ if (!this.isInput) {
101
+ }
102
+ var that = this;
103
+ $(document).on('mousedown', function(ev){
104
+ if ($(ev.target).closest('.datepicker').length == 0) {
105
+ that.hide();
106
+ }
107
+ });
108
+ this.element.trigger({
109
+ type: 'show',
110
+ date: this.date
111
+ });
112
+ },
113
+
114
+ hide: function(){
115
+ this.picker.hide();
116
+ $(window).off('resize', this.place);
117
+ this.viewMode = this.startViewMode;
118
+ this.showMode();
119
+ if (!this.isInput) {
120
+ $(document).off('mousedown', this.hide);
121
+ }
122
+ this.set();
123
+ this.element.trigger({
124
+ type: 'hide',
125
+ date: this.date
126
+ });
127
+ },
128
+
129
+ set: function() {
130
+ var formated = DPGlobal.formatDate(this.date, this.format);
131
+ if (!this.isInput) {
132
+ if (this.component){
133
+ this.element.find('input').prop('value', formated);
134
+ }
135
+ this.element.data('date', formated);
136
+ } else {
137
+ this.element.prop('value', formated);
138
+ }
139
+ },
140
+
141
+ setValue: function(newDate) {
142
+ if (typeof newDate === 'string') {
143
+ this.date = DPGlobal.parseDate(newDate, this.format);
144
+ } else {
145
+ this.date = new Date(newDate);
146
+ }
147
+ this.set();
148
+ this.viewDate = new Date(this.date.getFullYear(), this.date.getMonth(), 1, 0, 0, 0, 0);
149
+ this.fill();
150
+ },
151
+
152
+ place: function(){
153
+ var offset = this.component ? this.component.offset() : this.element.offset();
154
+ this.picker.css({
155
+ top: offset.top + this.height,
156
+ left: offset.left
157
+ });
158
+ },
159
+
160
+ update: function(newDate){
161
+ this.date = DPGlobal.parseDate(
162
+ typeof newDate === 'string' ? newDate : (this.isInput ? this.element.prop('value') : this.element.data('date')),
163
+ this.format
164
+ );
165
+ this.viewDate = new Date(this.date.getFullYear(), this.date.getMonth(), 1, 0, 0, 0, 0);
166
+ this.fill();
167
+ },
168
+
169
+ fillDow: function(){
170
+ var dowCnt = this.weekStart;
171
+ var html = '<tr>';
172
+ while (dowCnt < this.weekStart + 7) {
173
+ html += '<th class="dow">'+DPGlobal.dates.daysMin[(dowCnt++)%7]+'</th>';
174
+ }
175
+ html += '</tr>';
176
+ this.picker.find('.datepicker-days thead').append(html);
177
+ },
178
+
179
+ fillMonths: function(){
180
+ var html = '';
181
+ var i = 0
182
+ while (i < 12) {
183
+ html += '<span class="month">'+DPGlobal.dates.monthsShort[i++]+'</span>';
184
+ }
185
+ this.picker.find('.datepicker-months td').append(html);
186
+ },
187
+
188
+ fill: function() {
189
+ var d = new Date(this.viewDate),
190
+ year = d.getFullYear(),
191
+ month = d.getMonth(),
192
+ currentDate = this.date.valueOf();
193
+ this.picker.find('.datepicker-days th:eq(1)')
194
+ .text(DPGlobal.dates.months[month]+' '+year);
195
+ var prevMonth = new Date(year, month-1, 28,0,0,0,0),
196
+ day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
197
+ prevMonth.setDate(day);
198
+ prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
199
+ var nextMonth = new Date(prevMonth);
200
+ nextMonth.setDate(nextMonth.getDate() + 42);
201
+ nextMonth = nextMonth.valueOf();
202
+ html = [];
203
+ var clsName;
204
+ while(prevMonth.valueOf() < nextMonth) {
205
+ if (prevMonth.getDay() === this.weekStart) {
206
+ html.push('<tr>');
207
+ }
208
+ clsName = this.onRender(prevMonth);
209
+ if (prevMonth.getMonth() < month) {
210
+ clsName += ' old';
211
+ } else if (prevMonth.getMonth() > month) {
212
+ clsName += ' new';
213
+ }
214
+ if (prevMonth.valueOf() === currentDate) {
215
+ clsName += ' active';
216
+ }
217
+ html.push('<td class="day '+clsName+'">'+prevMonth.getDate() + '</td>');
218
+ if (prevMonth.getDay() === this.weekEnd) {
219
+ html.push('</tr>');
220
+ }
221
+ prevMonth.setDate(prevMonth.getDate()+1);
222
+ }
223
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
224
+ var currentYear = this.date.getFullYear();
225
+
226
+ var months = this.picker.find('.datepicker-months')
227
+ .find('th:eq(1)')
228
+ .text(year)
229
+ .end()
230
+ .find('span').removeClass('active');
231
+ if (currentYear === year) {
232
+ months.eq(this.date.getMonth()).addClass('active');
233
+ }
234
+
235
+ html = '';
236
+ year = parseInt(year/10, 10) * 10;
237
+ var yearCont = this.picker.find('.datepicker-years')
238
+ .find('th:eq(1)')
239
+ .text(year + '-' + (year + 9))
240
+ .end()
241
+ .find('td');
242
+ year -= 1;
243
+ for (var i = -1; i < 11; i++) {
244
+ html += '<span class="year'+(i === -1 || i === 10 ? ' old' : '')+(currentYear === year ? ' active' : '')+'">'+year+'</span>';
245
+ year += 1;
246
+ }
247
+ yearCont.html(html);
248
+ },
249
+
250
+ click: function(e) {
251
+ e.stopPropagation();
252
+ e.preventDefault();
253
+ var target = $(e.target).closest('span, td, th');
254
+ if (target.length === 1) {
255
+ switch(target[0].nodeName.toLowerCase()) {
256
+ case 'th':
257
+ switch(target[0].className) {
258
+ case 'switch':
259
+ this.showMode(1);
260
+ break;
261
+ case 'prev':
262
+ case 'next':
263
+ this.viewDate['set'+DPGlobal.modes[this.viewMode].navFnc].call(
264
+ this.viewDate,
265
+ this.viewDate['get'+DPGlobal.modes[this.viewMode].navFnc].call(this.viewDate) +
266
+ DPGlobal.modes[this.viewMode].navStep * (target[0].className === 'prev' ? -1 : 1)
267
+ );
268
+ this.fill();
269
+ this.set();
270
+ break;
271
+ }
272
+ break;
273
+ case 'span':
274
+ if (target.is('.month')) {
275
+ var month = target.parent().find('span').index(target);
276
+ this.viewDate.setMonth(month);
277
+ } else {
278
+ var year = parseInt(target.text(), 10)||0;
279
+ this.viewDate.setFullYear(year);
280
+ }
281
+ if (this.viewMode !== 0) {
282
+ this.date = new Date(this.viewDate);
283
+ this.element.trigger({
284
+ type: 'changeDate',
285
+ date: this.date,
286
+ viewMode: DPGlobal.modes[this.viewMode].clsName
287
+ });
288
+ }
289
+ this.showMode(-1);
290
+ this.fill();
291
+ this.set();
292
+ break;
293
+ case 'td':
294
+ if (target.is('.day') && !target.is('.disabled')){
295
+ var day = parseInt(target.text(), 10)||1;
296
+ var month = this.viewDate.getMonth();
297
+ if (target.is('.old')) {
298
+ month -= 1;
299
+ } else if (target.is('.new')) {
300
+ month += 1;
301
+ }
302
+ var year = this.viewDate.getFullYear();
303
+ this.date = new Date(year, month, day,0,0,0,0);
304
+ this.viewDate = new Date(year, month, Math.min(28, day),0,0,0,0);
305
+ this.fill();
306
+ this.set();
307
+ this.element.trigger({
308
+ type: 'changeDate',
309
+ date: this.date,
310
+ viewMode: DPGlobal.modes[this.viewMode].clsName
311
+ });
312
+ }
313
+ break;
314
+ }
315
+ }
316
+ },
317
+
318
+ mousedown: function(e){
319
+ e.stopPropagation();
320
+ e.preventDefault();
321
+ },
322
+
323
+ showMode: function(dir) {
324
+ if (dir) {
325
+ this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
326
+ }
327
+ this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
328
+ }
329
+ };
330
+
331
+ $.fn.datepicker = function ( option, val ) {
332
+ return this.each(function () {
333
+ var $this = $(this),
334
+ data = $this.data('datepicker'),
335
+ options = typeof option === 'object' && option;
336
+ if (!data) {
337
+ $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
338
+ }
339
+ if (typeof option === 'string') data[option](val);
340
+ });
341
+ };
342
+
343
+ $.fn.datepicker.defaults = {
344
+ onRender: function(date) {
345
+ return '';
346
+ }
347
+ };
348
+ $.fn.datepicker.Constructor = Datepicker;
349
+
350
+ var DPGlobal = {
351
+ modes: [
352
+ {
353
+ clsName: 'days',
354
+ navFnc: 'Month',
355
+ navStep: 1
356
+ },
357
+ {
358
+ clsName: 'months',
359
+ navFnc: 'FullYear',
360
+ navStep: 1
361
+ },
362
+ {
363
+ clsName: 'years',
364
+ navFnc: 'FullYear',
365
+ navStep: 10
366
+ }],
367
+ dates:{
368
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
369
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
370
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
371
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
372
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
373
+ },
374
+ isLeapYear: function (year) {
375
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
376
+ },
377
+ getDaysInMonth: function (year, month) {
378
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
379
+ },
380
+ parseFormat: function(format){
381
+ var separator = format.match(/[.\/\-\s].*?/),
382
+ parts = format.split(/\W+/);
383
+ if (!separator || !parts || parts.length === 0){
384
+ throw new Error("Invalid date format.");
385
+ }
386
+ return {separator: separator, parts: parts};
387
+ },
388
+ parseDate: function(date, format) {
389
+ var parts = date.split(format.separator),
390
+ date = new Date(),
391
+ val;
392
+ date.setHours(0);
393
+ date.setMinutes(0);
394
+ date.setSeconds(0);
395
+ date.setMilliseconds(0);
396
+ if (parts.length === format.parts.length) {
397
+ var year = date.getFullYear(), day = date.getDate(), month = date.getMonth();
398
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
399
+ val = parseInt(parts[i], 10)||1;
400
+ switch(format.parts[i]) {
401
+ case 'dd':
402
+ case 'd':
403
+ day = val;
404
+ date.setDate(val);
405
+ break;
406
+ case 'mm':
407
+ case 'm':
408
+ month = val - 1;
409
+ date.setMonth(val - 1);
410
+ break;
411
+ case 'yy':
412
+ year = 2000 + val;
413
+ date.setFullYear(2000 + val);
414
+ break;
415
+ case 'yyyy':
416
+ year = val;
417
+ date.setFullYear(val);
418
+ break;
419
+ }
420
+ }
421
+ date = new Date(year, month, day, 0 ,0 ,0);
422
+ }
423
+ return date;
424
+ },
425
+ formatDate: function(date, format){
426
+ var val = {
427
+ d: date.getDate(),
428
+ m: date.getMonth() + 1,
429
+ yy: date.getFullYear().toString().substring(2),
430
+ yyyy: date.getFullYear()
431
+ };
432
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
433
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
434
+ var date = [];
435
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
436
+ date.push(val[format.parts[i]]);
437
+ }
438
+ return date.join(format.separator);
439
+ },
440
+ headTemplate: '<thead>'+
441
+ '<tr>'+
442
+ '<th class="prev">&lsaquo;</th>'+
443
+ '<th colspan="5" class="switch"></th>'+
444
+ '<th class="next">&rsaquo;</th>'+
445
+ '</tr>'+
446
+ '</thead>',
447
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
448
+ };
449
+ DPGlobal.template = '<div class="datepicker dropdown-menu">'+
450
+ '<div class="datepicker-days">'+
451
+ '<table class=" table-condensed">'+
452
+ DPGlobal.headTemplate+
453
+ '<tbody></tbody>'+
454
+ '</table>'+
455
+ '</div>'+
456
+ '<div class="datepicker-months">'+
457
+ '<table class="table-condensed">'+
458
+ DPGlobal.headTemplate+
459
+ DPGlobal.contTemplate+
460
+ '</table>'+
461
+ '</div>'+
462
+ '<div class="datepicker-years">'+
463
+ '<table class="table-condensed">'+
464
+ DPGlobal.headTemplate+
465
+ DPGlobal.contTemplate+
466
+ '</table>'+
467
+ '</div>'+
468
+ '</div>';
469
+
470
+ }( window.jQuery );