~lutostag/ubuntu/utopic/maas/1.5.2

« back to all changes in this revision

Viewing changes to src/maasserver/static/js/yui/3.4.1/calendarnavigator/calendarnavigator.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-03-15 18:14:08 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120315181408-zgl94hzo0x4n99an
Tags: 0.1+bzr295+dfsg-0ubuntu2
* debian/patches:
  - 01-fix-database-settings.patch: Update to set PSERV_URL.
  - 02-pserv-config.patch: Set port to 8001.
* debian/maas.postinst: Run maas-import-isos on install.
* debian/control: Depends on rabbitmq-server.

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('calendarnavigator', function(Y) {
8
 
 
9
 
/**
10
 
 * Provides a plugin which adds navigation controls to Calendar.
11
 
 *
12
 
 * @module calendarnavigator
13
 
 */
14
 
var CONTENT_BOX = "contentBox",
15
 
    HOST        = "host",
16
 
    RENDERED    = "rendered",
17
 
    getCN       = Y.ClassNameManager.getClassName,
18
 
    substitute  = Y.substitute,
19
 
    node        = Y.Node,
20
 
    create      = node.create,
21
 
    CALENDAR    = 'calendar',
22
 
    CALENDARNAV = 'calendarnav',
23
 
    CAL_HD      = getCN(CALENDAR, 'header'),
24
 
    CAL_PREV_M  = getCN(CALENDARNAV, 'prevmonth'),
25
 
    CAL_NEXT_M  = getCN(CALENDARNAV, 'nextmonth'),
26
 
    ydate       = Y.DataType.Date;
27
 
/**
28
 
 * A plugin class which adds navigation controls to Calendar.
29
 
 *
30
 
 * @class CalendarNavigator
31
 
 * @extends Plugin.Base
32
 
 * @namespace Plugin
33
 
 */
34
 
function CalendarNavigator(config) {
35
 
    CalendarNavigator.superclass.constructor.apply(this, arguments);
36
 
}
37
 
 
38
 
/**
39
 
 * The namespace for the plugin. This will be the property on the widget, which will 
40
 
 * reference the plugin instance, when it's plugged in.
41
 
 *
42
 
 * @property NS
43
 
 * @static
44
 
 * @type String
45
 
 * @default "navigator"
46
 
 */
47
 
CalendarNavigator.NS = "navigator";
48
 
 
49
 
/**
50
 
 * The NAME of the CalendarNavigator class. Used to prefix events generated
51
 
 * by the plugin class.
52
 
 *
53
 
 * @property NAME
54
 
 * @static
55
 
 * @type String
56
 
 * @default "pluginCalendarNavigator"
57
 
 */
58
 
CalendarNavigator.NAME = "pluginCalendarNavigator";
59
 
 
60
 
 
61
 
/**
62
 
 * Static property used to define the default attribute 
63
 
 * configuration for the plugin.
64
 
 *
65
 
 * @property ATTRS
66
 
 * @type Object
67
 
 * @static
68
 
 */
69
 
CalendarNavigator.ATTRS = {
70
 
 
71
 
    /**
72
 
     * The number of months to shift by when the control arrows are clicked.
73
 
     *
74
 
     * @attribute shiftByMonths
75
 
     * @type Number
76
 
     * @default 1 (months)
77
 
     */
78
 
    shiftByMonths : {
79
 
        value: 1
80
 
    }
81
 
};
82
 
 
83
 
   /**
84
 
    * The CSS classnames for the calendar navigator controls.
85
 
    * @property CALENDARNAV_STRINGS
86
 
    * @type Object
87
 
    * @readOnly
88
 
    * @protected
89
 
    * @static
90
 
    */ 
91
 
CalendarNavigator.CALENDARNAV_STRINGS = {
92
 
   prev_month_class: CAL_PREV_M,
93
 
   next_month_class: CAL_NEXT_M
94
 
};
95
 
 
96
 
   /**
97
 
    * The template for the calendar navigator previous month control.
98
 
    * @property PREV_MONTH_CONTROL_TEMPLATE
99
 
    * @type String
100
 
    * @protected
101
 
    * @static
102
 
    */ 
103
 
CalendarNavigator.PREV_MONTH_CONTROL_TEMPLATE = '<div class="yui3-u {prev_month_class}" style="width:15px;">' + 
104
 
                                                   "&#9668;" +
105
 
                                                '</div>';
106
 
   /**
107
 
    * The template for the calendar navigator next month control.
108
 
    * @property NEXT_MONTH_CONTROL_TEMPLATE
109
 
    * @type String
110
 
    * @readOnly
111
 
    * @protected
112
 
    * @static
113
 
    */ 
114
 
CalendarNavigator.NEXT_MONTH_CONTROL_TEMPLATE = '<div class="yui3-u {next_month_class}" style="width:15px;">' + 
115
 
                                                   "&#9658;" +
116
 
                                                '</div>';
117
 
 
118
 
 
119
 
Y.extend(CalendarNavigator, Y.Plugin.Base, {
120
 
 
121
 
    /**
122
 
     * The initializer lifecycle implementation. Modifies the host widget's 
123
 
     * render to add navigation controls.
124
 
     *
125
 
     * @method initializer
126
 
     * @param {Object} config The user configuration for the plugin  
127
 
     */
128
 
    initializer : function(config) {
129
 
 
130
 
        // After the host has rendered its UI, place the navigation cotnrols
131
 
        this.afterHostMethod("renderUI", this._initNavigationControls);
132
 
    },
133
 
 
134
 
    /**
135
 
     * The initializer destructor implementation. Responsible for destroying the initialized
136
 
     * control mechanisms.
137
 
     * 
138
 
     * @method destructor
139
 
     */
140
 
    destructor : function() {
141
 
       
142
 
    },
143
 
 
144
 
    /**
145
 
     * Private utility method that subtracts months from the host calendar date
146
 
     * based on the control click and the shiftByMonths property.
147
 
     * 
148
 
     * @method _subtractMonths
149
 
     * @param {Event} ev Click event from the controls
150
 
     * @protected
151
 
     */
152
 
    _subtractMonths : function (ev) {
153
 
        var host = this.get(HOST);
154
 
        var oldDate = host.get("date");
155
 
        host.set("date", ydate.addMonths(oldDate, -1*this.get("shiftByMonths")));
156
 
        ev.preventDefault();
157
 
    },
158
 
 
159
 
    /**
160
 
     * Private utility method that adds months to the host calendar date
161
 
     * based on the control click and the shiftByMonths property.
162
 
     * 
163
 
     * @method _addMonths
164
 
     * @param {Event} ev Click event from the controls
165
 
     * @protected
166
 
     */
167
 
    _addMonths : function (ev) {
168
 
        var host = this.get(HOST);
169
 
        var oldDate = host.get("date");
170
 
        host.set("date", ydate.addMonths(oldDate, this.get("shiftByMonths")));
171
 
        ev.preventDefault();
172
 
    },
173
 
 
174
 
    /**
175
 
     * Private render assist method that renders the previous month control
176
 
     * 
177
 
     * @method _renderPrevControls
178
 
     * @private
179
 
     */
180
 
    _renderPrevControls : function () {
181
 
      var prevControlNode = create(substitute (CalendarNavigator.PREV_MONTH_CONTROL_TEMPLATE,
182
 
                               CalendarNavigator.CALENDARNAV_STRINGS));
183
 
      prevControlNode.on("click", this._subtractMonths, this);
184
 
      prevControlNode.on("selectstart", function (ev) {ev.preventDefault();});
185
 
      
186
 
      return prevControlNode;        
187
 
    },
188
 
 
189
 
    /**
190
 
     * Private render assist method that renders the next month control
191
 
     * 
192
 
     * @method _renderNextControls
193
 
     * @private
194
 
     */
195
 
    _renderNextControls : function () {
196
 
      var nextControlNode = create(substitute (CalendarNavigator.NEXT_MONTH_CONTROL_TEMPLATE,
197
 
                               CalendarNavigator.CALENDARNAV_STRINGS));
198
 
      nextControlNode.on("click", this._addMonths, this);
199
 
      nextControlNode.on("selectstart", function (ev) {ev.preventDefault();});
200
 
      
201
 
      return nextControlNode;     
202
 
    },
203
 
 
204
 
    /**
205
 
     * Protected render assist method that initialized and renders the navigation controls.
206
 
     * @method _initNavigationControls
207
 
     * @protected
208
 
     */
209
 
    _initNavigationControls : function() {
210
 
            var host = this.get(HOST);
211
 
            var headerCell = host.get(CONTENT_BOX).one("." + CAL_HD);
212
 
            headerCell.prepend(this._renderPrevControls(host));
213
 
            headerCell.append(this._renderNextControls(host));
214
 
    }
215
 
});
216
 
 
217
 
Y.namespace("Plugin").CalendarNavigator = CalendarNavigator;
218
 
 
219
 
 
220
 
}, '3.4.1' ,{requires:['plugin', 'classnamemanager', 'datatype-date', 'node', 'substitute']});