calendar MDL-23084 Fixed typo regession
[moodle.git] / calendar / yui / eventmanager / eventmanager.js
CommitLineData
33e48a1a
SH
1YUI.add('moodle-calendar-eventmanager', function(Y) {
2
3 var ENAME = 'Calendar event',
4 EVENTID = 'eventId',
5 EVENTNODE = 'node',
6 EVENTTITLE = 'title',
7 EVENTCONTENT = 'content',
8 EVENTDELAY = 'delay',
9 SHOWTIMEOUT = 'showTimeout',
10 HIDETIMEOUT = 'hideTimeout';
11
12 var EVENT = function(config) {
13 EVENT.superclass.constructor.apply(this, arguments);
14 }
15 Y.extend(EVENT, Y.Base, {
16 initializer : function(config){
17 var id = this.get(EVENTID), node = this.get(EVENTNODE), td = node.ancestor('td'), constraint = td.ancestor('div'), panel;
18 this.publish('showevent');
19 this.publish('hideevent');
20 panel = new Y.Overlay({
21 constrain : constraint,
22 align : {
23 node : td,
24 points:[Y.WidgetPositionAlign.TL, Y.WidgetPositionAlign.BC]
25 },
26 headerContent : Y.Node.create('<h2 class="eventtitle">'+this.get(EVENTTITLE)+'</h2>'),
27 bodyContent : Y.Node.create('<div class="eventcontent">'+this.get(EVENTCONTENT)+'</div>'),
28 visible : false,
29 id : this.get(EVENTID)+'_panel',
30 width : Math.floor(constraint.get('offsetWidth')*0.9)+"px"
31 });
32 panel.get('boundingBox').addClass('calendar-event-panel')
33 panel.render(td);
34 this.on('showevent', panel.show, panel);
35 this.on('hideevent', panel.hide, panel);
36 td.on('mouseenter', this.startShow, this);
37 td.on('mouseleave', this.startHide, this);
38 },
39 startShow : function() {
40 if (this.get(SHOWTIMEOUT) !== null) {
41 this.cancelShow();
42 }
43 var self = this;
44 this.set(SHOWTIMEOUT, setTimeout(function(){self.show();}, this.get(EVENTDELAY)));
45 },
46 cancelShow : function() {
47 clearTimeout(this.get(SHOWTIMEOUT));
48 },
49 show : function() {
50 this.fire('showevent');
51 },
52 startHide : function() {
53 if (this.get(HIDETIMEOUT) !== null) {
54 this.cancelHide();
55 }
56 var self = this;
57 this.set(HIDETIMEOUT, setTimeout(function(){self.hide();}, this.get(EVENTDELAY)));
58 },
59 hide : function() {
60 this.fire('hideevent');
61 },
62 cancelHide : function() {
63 clearTimeout(this.get(HIDETIMEOUT));
64 }
65 }, {
66 NAME : ENAME,
67 ATTRS : {
68 eventId : {
69 setter : function(nodeid) {
70 this.set(EVENTNODE, Y.one('#'+nodeid));
71 return nodeid;
72 },
73 validator : Y.Lang.isString
74 },
75 node : {
76 setter : function(node) {
77 var n = Y.one(node);
78 if (!n) {
6793952d 79 Y.fail(ENAME+': invalid event node set');
33e48a1a
SH
80 }
81 return n;
82 }
83 },
84 title : {
85 validator : Y.Lang.isString
86 },
87 content : {
88 validator : Y.Lang.isString
89 },
90 delay : {
91 value : 300,
92 validator : Y.Lang.isNumber
93 },
94 showTimeout : {
95 value : null
96 },
97 hideTimeout : {
98 value : null
99 }
100 }
101 });
102 Y.augment(EVENT, Y.EventTarget);
103
104 var EVENTMANAGER = {
105 add_event : function(config) {
106 new EVENT(config);
107 },
108 init_basic_export : function(allowthisweek, allownextweek, allownextmonth, username, authtoken) {
109 var params = {
110 preset_what : (Y.one('#pw_course').get('checked'))?'courses':'all',
111 preset_time : 'recentupcoming',
112 username : username,
113 authtoken : authtoken
114
115 }
116 if (allowthisweek && Y.one('#pt_wknow').get('checked')) {
117 params.presettime = 'weeknow';
118 } else if (allownextweek && Y.one('#pt_wknext').get('checked')) {
119 params.presettime = 'weeknext';
120 } else if (allownextmonth && Y.one('#pt_monnext').get('checked')) {
121 params.presettime = 'monthnext';
122 } else if (Y.one('#pt_monnow').get('checked')) {
123 params.presettime = 'monthnow';
124 }
125 Y.one('#url').setContent(M.cfg.wwwroot+'/calendar/export_execute.php?'+build_querystring(params));
126 Y.one('#urlbox').setStyle('display', 'block');
127 }
128 }
129
130 M.core_calendar = M.core_calendar || {}
131 Y.mix(M.core_calendar, EVENTMANAGER);
132
133}, '@VERSION@', {requires:['base', 'node', 'event-mouseenter', 'overlay', 'moodle-calendar-eventmanager-skin']});