~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/calendar/calendar.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('calendar', function(Y) {
8
 
 
9
 
/**
10
 
 * The Calendar component is a UI widget that allows users
11
 
 * to view dates in a two-dimensional month grid, as well as
12
 
 * to select one or more dates, or ranges of dates. Calendar
13
 
 * is generated dynamically and relies on the developer to
14
 
 * provide for a progressive enhancement alternative.
15
 
 *
16
 
 *
17
 
 * @module calendar
18
 
 */
19
 
 
20
 
var getCN            = Y.ClassNameManager.getClassName,
21
 
    CALENDAR         = 'calendar',
22
 
    CAL_HD           = getCN(CALENDAR, 'header'),
23
 
    CAL_DAY_SELECTED = getCN(CALENDAR, 'day-selected'),
24
 
    CAL_DAY           = getCN(CALENDAR, 'day'),
25
 
    CAL_PREVMONTH_DAY = getCN(CALENDAR, 'prevmonth-day'),
26
 
    CAL_NEXTMONTH_DAY = getCN(CALENDAR, 'nextmonth-day'),
27
 
    ydate            = Y.DataType.Date,
28
 
    delegate         = Y.delegate,
29
 
    CAL_PANE          = getCN(CALENDAR, 'pane'),
30
 
    os                = Y.UA.os;
31
 
 
32
 
/** Create a calendar view to represent a single or multiple
33
 
  * month range of dates, rendered as a grid with date and
34
 
  * weekday labels.
35
 
  * 
36
 
  * @class Calendar
37
 
  * @extends CalendarBase
38
 
  * @param config {Object} Configuration object (see Configuration attributes)
39
 
  * @constructor
40
 
  */
41
 
function Calendar(config) {
42
 
  Calendar.superclass.constructor.apply ( this, arguments );
43
 
}
44
 
 
45
 
Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
46
 
 
47
 
  /**
48
 
   * A property tracking the last selected date on the calendar, for the
49
 
   * purposes of multiple selection.
50
 
   *
51
 
   * @property _lastSelectedDate
52
 
   * @type Date
53
 
   * @default null
54
 
   * @private
55
 
   */  
56
 
    _lastSelectedDate: null,
57
 
 
58
 
  /**
59
 
   * Designated initializer. Activates the navigation plugin for the calendar.
60
 
   *
61
 
   * @method initializer
62
 
   */ 
63
 
  initializer : function () {
64
 
    this.plug(Y.Plugin.CalendarNavigator);
65
 
  },
66
 
 
67
 
  /**
68
 
    * syncUI implementation
69
 
    *
70
 
    * Update the scroll position, based on the current value of scrollY
71
 
    * @method syncUI
72
 
    */  
73
 
  syncUI : function () {
74
 
 
75
 
  },
76
 
 
77
 
  /**
78
 
   * Overrides the _bindCalendarEvents placeholder in CalendarBase
79
 
   * and binds calendar events during bindUI stage.
80
 
   * @method _bindCalendarEvents
81
 
   * @protected
82
 
   */   
83
 
  _bindCalendarEvents : function () {
84
 
    var contentBox = this.get('contentBox'),
85
 
        pane       = contentBox.one("." + CAL_PANE);
86
 
    pane.on("selectstart", function (ev) { ev.preventDefault();});
87
 
    pane.delegate("click", this._clickCalendar, "." + CAL_DAY, this);
88
 
  },
89
 
 
90
 
  /**
91
 
   * Handles the calendar clicks based on selection mode.
92
 
   * @method _clickCalendar
93
 
   * @param {Event} ev A click event
94
 
   * @private
95
 
   */   
96
 
    _clickCalendar : function (ev) {
97
 
        var clickedCell = ev.target,
98
 
            clickedCellIsDay = clickedCell.hasClass(CAL_DAY) && 
99
 
                               !clickedCell.hasClass(CAL_PREVMONTH_DAY) && 
100
 
                               !clickedCell.hasClass(CAL_NEXTMONTH_DAY),
101
 
            clickedCellIsSelected = clickedCell.hasClass(CAL_DAY_SELECTED);
102
 
        switch (this.get("selectionMode")) {
103
 
          case("single"):
104
 
               if (clickedCellIsDay) {
105
 
                  if (!clickedCellIsSelected) {
106
 
                    this._clearSelection(true);  
107
 
                    this._addDateToSelection(this._nodeToDate(clickedCell));
108
 
                  }
109
 
             }
110
 
               break;
111
 
            case("multiple-sticky"):
112
 
               if (clickedCellIsDay) {
113
 
                 if (clickedCellIsSelected) {
114
 
                  this._removeDateFromSelection(this._nodeToDate(clickedCell));
115
 
                 }
116
 
                 else {
117
 
                  this._addDateToSelection(this._nodeToDate(clickedCell));
118
 
                 }
119
 
               }
120
 
               break;
121
 
            case("multiple"):
122
 
               if (!ev.metaKey && !ev.ctrlKey && !ev.shiftKey) {
123
 
                    this._clearSelection(true);
124
 
                    this._lastSelectedDate = this._nodeToDate(clickedCell);
125
 
                    this._addDateToSelection(this._lastSelectedDate);
126
 
               }
127
 
               else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && !ev.shiftKey) {
128
 
                  if (clickedCellIsSelected) {
129
 
                    this._removeDateFromSelection(this._nodeToDate(clickedCell));
130
 
                    this._lastSelectedDate = null;
131
 
                  }
132
 
                  else {
133
 
                    this._lastSelectedDate = this._nodeToDate(clickedCell);
134
 
                    this._addDateToSelection(this._lastSelectedDate);
135
 
                  }
136
 
               }
137
 
               else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && ev.shiftKey) {
138
 
                  if (this._lastSelectedDate != null) {
139
 
                    var selectedDate = this._nodeToDate(clickedCell);
140
 
                    this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
141
 
                    this._lastSelectedDate = selectedDate;
142
 
                  }
143
 
                  else {
144
 
                    this._lastSelectedDate = this._nodeToDate(clickedCell);
145
 
                    this._addDateToSelection(this._lastSelectedDate);
146
 
                  }
147
 
 
148
 
               }
149
 
               else if (ev.shiftKey) {
150
 
                    if (this._lastSelectedDate != null) {
151
 
                      var selectedDate = this._nodeToDate(clickedCell);
152
 
                      this._clearSelection(true);
153
 
                      this._addDateRangeToSelection(selectedDate, this._lastSelectedDate);
154
 
                      this._lastSelectedDate = selectedDate;
155
 
                    }
156
 
                    else {
157
 
                      this._clearSelection(true);
158
 
                      this._lastSelectedDate = this._nodeToDate(clickedCell);
159
 
                        this._addDateToSelection(this._lastSelectedDate);
160
 
                    }
161
 
               }
162
 
               break;
163
 
        }
164
 
 
165
 
      if (clickedCellIsDay) {
166
 
   /**
167
 
     * Fired when a specific date cell in the calendar is clicked. The event carries a 
168
 
     * payload which includes a `cell` property corresponding to the node of the actual
169
 
     * date cell, and a `date` property, with the `Date` that was clicked.
170
 
     *
171
 
     * @event dateClick
172
 
     */
173
 
        this.fire("dateClick", {cell: clickedCell, date: this._nodeToDate(clickedCell)});
174
 
      }
175
 
      else if (clickedCell.hasClass(CAL_PREVMONTH_DAY)) {
176
 
   /**
177
 
     * Fired when any of the previous month's days displayed before the calendar grid
178
 
     * are clicked.
179
 
     *
180
 
     * @event prevMonthClick
181
 
     */
182
 
        this.fire("prevMonthClick");
183
 
      }
184
 
      else if (clickedCell.hasClass(CAL_NEXTMONTH_DAY)) {
185
 
   /**
186
 
     * Fired when any of the next month's days displayed after the calendar grid
187
 
     * are clicked.
188
 
     *
189
 
     * @event nextMonthClick
190
 
     */
191
 
        this.fire("nextMonthClick");
192
 
      }
193
 
    },
194
 
 
195
 
  /**
196
 
   * Subtracts one month from the current calendar view.
197
 
   * @method subtractMonth
198
 
   */   
199
 
  subtractMonth : function (e) {
200
 
    this.set("date", ydate.addMonths(this.get("date"), -1));
201
 
    e.halt();
202
 
  },
203
 
 
204
 
  /**
205
 
   * Subtracts one year from the current calendar view.
206
 
   * @method subtractYear
207
 
   */ 
208
 
  subtractYear : function (e) {
209
 
    this.set("date", ydate.addYears(this.get("date"), -1));
210
 
    e.halt();
211
 
  },
212
 
 
213
 
  /**
214
 
   * Adds one month to the current calendar view.
215
 
   * @method addMonth
216
 
   */   
217
 
  addMonth : function (e) {    
218
 
    this.set("date", ydate.addMonths(this.get("date"), 1));
219
 
    e.halt();
220
 
  },
221
 
 
222
 
  /**
223
 
   * Adds one year to the current calendar view.
224
 
   * @method addYear
225
 
   */   
226
 
  addYear : function (e) {
227
 
    this.set("date", ydate.addYears(this.get("date"), 1));
228
 
    e.halt();
229
 
  }
230
 
},
231
 
 
232
 
{
233
 
   /**
234
 
    * The identity of the widget.
235
 
    *
236
 
    * @property NAME
237
 
    * @type String
238
 
    * @default 'Calendar'
239
 
    * @readOnly
240
 
    * @protected
241
 
    * @static
242
 
    */  
243
 
  NAME: "Calendar",
244
 
 
245
 
   /**
246
 
    * Static property used to define the default attribute configuration of
247
 
    * the Widget.
248
 
    *
249
 
    * @property ATTRS
250
 
    * @type {Object}
251
 
    * @protected
252
 
    * @static
253
 
    */  
254
 
  ATTRS: {
255
 
 
256
 
    /**
257
 
     * A setting specifying the type of selection the calendar allows.
258
 
     * Possible values include:
259
 
     * <ul>
260
 
     *   <li>`single`</li> - One date at a time
261
 
     *   <li>`multiple-sticky</li> - Multiple dates, selected one at a time (the dates "stick")
262
 
     *   <li>`multiple`</li> - Multiple dates, selected with Ctrl/Meta keys for additional single
263
 
     *   dates, and Shift key for date ranges.
264
 
     *
265
 
     * @attribute selectionMode
266
 
     * @type String
267
 
     * @default single
268
 
     */
269
 
    selectionMode: {
270
 
      value: "single"
271
 
    },
272
 
 
273
 
    /**
274
 
     * The date corresponding to the current calendar view. Always
275
 
     * normalized to the first of the month that contains the date
276
 
     * at assignment time. Used as the first date visible in the
277
 
     * calendar.
278
 
     *
279
 
     * @attribute date
280
 
     * @type Date
281
 
     * @default Today's date as set on the user's computer.
282
 
     */
283
 
    date: {
284
 
      value: new Date(),
285
 
      setter: function (val) {
286
 
 
287
 
        var newDate = this._normalizeDate(val),
288
 
            newTopDate = ydate.addMonths(newDate, this._paneNumber - 1),
289
 
            minDate = this.get("minimumDate"),
290
 
            maxDate = this.get("maximumDate");
291
 
 
292
 
            if ((minDate == null || ydate.isGreaterOrEqual(newDate, minDate)) && 
293
 
                (maxDate == null || ydate.isGreaterOrEqual(maxDate, newTopDate))) {
294
 
                return newDate;
295
 
            }
296
 
 
297
 
            else if (minDate != null && ydate.isGreater(minDate, newDate)) {
298
 
                   return minDate;
299
 
            }
300
 
 
301
 
            else if (maxDate != null && ydate.isGreater(newTopDate, maxDate)) {
302
 
                var actualMaxDate = ydate.addMonths(maxDate, -1*(this._paneNumber - 1));
303
 
                  return actualMaxDate;
304
 
            }
305
 
     }
306
 
    },
307
 
 
308
 
    /**
309
 
     * The minimum date that can be displayed by the calendar. The calendar will not
310
 
     * allow dates earlier than this one to be set, and will reset any earlier date to
311
 
     * this date. Should be `null` if no minimum date is needed.
312
 
     *
313
 
     * @attribute minimumDate
314
 
     * @type Date
315
 
     * @default null
316
 
     */
317
 
    minimumDate: {
318
 
      value: null,
319
 
      setter: function (val) {
320
 
        if (val != null) {
321
 
          var curDate = this.get('date'),
322
 
              newMinDate = this._normalizeDate(val);
323
 
          if (curDate!= null && !ydate.isGreaterOrEqual(curDate, newMinDate)) {
324
 
              this.set('date', newMinDate);
325
 
          }
326
 
          return newMinDate;
327
 
        }
328
 
        else {
329
 
          return val;
330
 
        }
331
 
      }
332
 
    },
333
 
 
334
 
    /**
335
 
     * The maximum date that can be displayed by the calendar. The calendar will not
336
 
     * allow dates later than this one to be set, and will reset any later date to
337
 
     * this date. Should be `null` if no maximum date is needed.
338
 
     *
339
 
     * @attribute maximumDate
340
 
     * @type Date
341
 
     * @default null
342
 
     */
343
 
    maximumDate: {
344
 
      value: null,
345
 
      setter: function (val) {
346
 
        if (val != null) {
347
 
          var curDate = this.get('date'),
348
 
              newMaxDate = this._normalizeDate(val);
349
 
          if (curDate!= null && !ydate.isGreaterOrEqual(val, ydate.addMonths(curDate, this._paneNumber - 1))) {
350
 
              this.set('date', ydate.addMonths(newMaxDate, -1*(this._paneNumber -1)));
351
 
          }
352
 
          return newMaxDate;
353
 
        }
354
 
        else {
355
 
          return val;
356
 
        }
357
 
      }
358
 
    }
359
 
  }
360
 
});
361
 
 
362
 
 
363
 
}, '3.4.1' ,{requires:['calendar-base', 'calendarnavigator'], lang:['en', 'ja', 'ru']});