source: trunk/calendar_new/js/drag_area.js @ 420

Revision 420, 2.9 KB checked in by niltonneto, 16 years ago (diff)

Commit inicial da agenda com layout usando Ajax.

  • Property svn:executable set to *
Line 
1var agt=navigator.userAgent.toLowerCase();
2var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
3
4function DragArea(){
5        this.pressed = 0;
6        this.resizing = 0;
7        this.initEvent;
8        this.endEvent;
9        this.currentEvent;
10}
11
12DragArea.prototype.loadMouseDown = function(e) {
13        var     _event  = is_ie ? window.event : e;
14        var     _target = is_ie ? window.event.srcElement : e.target;
15        var _button = is_ie ? _event.button : _event.which;
16       
17        if (typeof _event.preventDefault != 'undefined') {
18                _event.preventDefault();
19        }
20
21        this.pressed = 1;       
22
23        if(_button != 2 && _button != 3) {
24                if(_target.id && _target.id.length == 12){
25                        if (parseInt(_target.id) > 0)
26                                this.initEvent = _target.id;
27                }       
28        }       
29};
30
31DragArea.prototype.loadMouseMove = function(e) {
32        if(!this.pressed) {
33                return true;
34        }
35        var id = is_ie ? window.event.srcElement.id : e.target.id;
36        var colorCell = function (id,style){
37                try {
38                        document.getElementById(id).style.background = style;
39                }
40                catch(e)
41                { document.style.background = "#000;"; };
42        };
43
44        var incHour = function (hour,op){
45        if (op == '+')
46                (hour%100 >= 30)?hour+=70:hour+=30;
47        else
48                (hour%100 == 30)?hour-=30:hour-=70;
49        return hour;
50        };
51
52        if((parseInt(id) > 0) && (id.length == 12)){
53                if (this.endEvent < this.initEvent)
54                        if (id <= this.endEvent)
55                                for (var hour = parseInt(this.initEvent); hour >= parseInt(id);hour=incHour(hour,'-'))
56                                        colorCell(hour,"#EEE;");
57                        else
58                                for (var hour = parseInt(id); hour >= parseInt(this.endEvent);hour=incHour(hour,'-'))
59                                        colorCell(hour,"");
60                else
61                        if (id < this.endEvent)
62                                for (var hour = parseInt(id); hour <= parseInt(this.endEvent);hour=incHour(hour,'+'))
63                                        colorCell(hour,"");
64                        else
65                                for (var hour = parseInt(this.initEvent); hour <= parseInt(id);hour=incHour(hour,'+'))
66                                        colorCell(hour,"#EEE;");
67                this.endEvent=id;
68                return true;
69        }
70};
71
72document.onmousemove = function(event) {_dragArea.loadMouseMove(event);};
73document.onmousedown = function(event) {_dragArea.loadMouseDown(event);};
74document.onmouseup = function(event) {_dragArea.loadMouseUp(event);};
75
76DragArea.prototype.loadMouseUp = function(e) {
77        this.pressed = 0;
78        var _event  = is_ie ? window.event : e;
79        var id = is_ie ? window.event.srcElement.id : e.target.id;
80        var _button = is_ie ? _event.button : _event.which;
81       
82        if(_button != 2 && _button != 3) {
83                if (this.resizing == 0){
84                        if((parseInt(id) > 0) && (id.length == 12))
85                                calendar.dialog();
86                }else{
87                        if (confirm(get_lang('Change the end of this event to %1',calendar.parseDate(id2timeStamp(id)))+' ('+id.substr(8,2)+':'+id.substr(10,2)+') ?')){
88                                changeEvent(this.currentEvent,'edatetime',parseInt((id2timeStamp(id)+1800000)/1000));
89                        }
90                        for (var hour = parseInt(_dragArea.initEvent); hour <= parseInt(_dragArea.endEvent);(hour%100 == 30)?hour+=70:hour+=30)
91                                document.getElementById(hour).style.background = "";
92                        this.resizing = 0;
93                }
94        }
95}
96
97var _dragArea = new DragArea();
Note: See TracBrowser for help on using the repository browser.