Move busui to seperate repository
[bus.git] / owa.widgets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// OWA Widgets
 
OWA.widget = function() {
 
        this.config = OWA.config;
        
        return; 
}
 
OWA.widget.prototype = {
 
        properties: new Object,
        
        config: '',
        
        dom_id: '',
        
        name: '',
        
        current_view: '',
        
        page_num: 1,
        
        max_page_num: 2,
        
        more_pages: false,
        
        minimized: false,
        
        displayPagination: function() {
        
                var widget_pagination_div = "#"+this.dom_id+"_widget-pagination";
                var pages = this._makePagination();
                jQuery(widget_pagination_div).show("fast");
                jQuery(widget_pagination_div).html(pages);
                jQuery('.owa_widget-paginationcontrol').click(owa_widget_page_results);
                
                return;
        },
        
                
        hidePagination: function() {
        
                var widget_pagination_div = "#"+this.dom_id+"_widget-pagination";
                jQuery(widget_pagination_div).hide();
                
                return;
        },
                        
        changeView: function(view) {
                        
                        var widgetcontentid = "#"+this.dom_id+"_widget-content";
                        
                        this.properties.format = view;
                        
                        jQuery(widgetcontentid).slideUp("fast"); 
                                 
                        jQuery.ajax({ 
                                method: "get",
                                url: this.config.action_url,
                                data: OWA.util.nsAll(this.properties), 
                                //show loading just when link is clicked 
                                beforeSend: function(){ jQuery("#"+this.dom_id).children(".owa_widget-status").show("slow");}, 
                                //stop showing loading when the process is complete 
                                complete: function(){ jQuery("#"+this.dom_id).children(".owa_widget-status").hide("slow");}, 
                                //so, if data is retrieved, store it in html
                                success: function(html){  
                                        jQuery(widgetcontentid).show("slow"); //animation 
                                        jQuery(widgetcontentid).html(html); //show the html inside .content div 
                                        
                                        
                                        
                                        
                                } 
                        }); //close $.ajax( 
                        
                        this.current_view = view;
                        
                        if (view == "table") {
                                this.displayPagination();
                        } else {
                                this.hidePagination();
                        }
                        
                        return true;
                
        },
        
        _makePagination: function() {
                
                var pagination = '';
                var anchor = this._makeLinkAnchor();
                
                // previous nav link
                if (this.page_num > 1) {
                        pagination = 'Pages: ';
                        pagination = pagination + this._makePaginationLink(anchor, "<< Previous") + ' ... ';
                }
                
                for (i = 1; i <= this.max_page_num; i++) {
                        
                        // let's pick a page name for our link
                        var page_name = i;
                
                        // to link or not to link
                        if (i == this.page_num) {
                                pagination = pagination + page_name;
                        } else {
                                pagination = pagination + this._makePaginationLink(anchor, page_name);
                        }
                        
                        // add commas
                        if (i != this.max_page_num) {
                                pagination = pagination + ', ';
                        }
 
                }
                
                // previous nav link
                if (this.page_num < this.max_page_num) {
                        if (this.more_pages == true) {
                                pagination = pagination + this._makePaginationLink(anchor, "Next >>") + ' ... ';
                        }
                }
                
        
        return pagination;
        
        },
        
        _makePaginationLink: function(anchor, page_name) {
                
                var link = '<a href="' + anchor + '" class="owa_widget-paginationcontrol">' + page_name + '</a>';
                return link;
        },
        
        _makeLinkAnchor: function() {
                
                return anchor = "#"+this.dom_id+"_widget-header";
        }
        
        
 
}
 
// Bind event handlers
jQuery(document).ready(function(){  
        //jQuery.getScript(OWA.config.js_url + "includes/jquery/tablesorter/jquery.tablesorter.js");     
        jQuery('.owa_widget-control').click(owa_widget_changeView);
        jQuery('.owa_widget-pagecontrol').click(owa_widget_changeView);
        jQuery('.owa_widget-close').click(owa_widget_close);
        jQuery('.owa_widget-status').hide("slow");
        jQuery('.owa_widget-collapsetoggle').click(owa_widget_toggle);
        jQuery('.owa_widget-paginationcontrol').click(owa_widget_page_results);
        
});
 
 
// Event handler for changeing views
function owa_widget_changeView() {
 
        var view = jQuery(this).attr("name");
        var widgetname = jQuery(this).parents(".owa_widget-container").get(0).id;       
        //alert(widgetname);
        return OWA.items[widgetname].changeView(view);
        
}
 
function owa_widget_close() {
        
        return jQuery(this).parents(".owa_widget-container").hide("slow");      
}
 
function owa_widget_toggle() {
        
        // get the widget name
        var widgetname = jQuery(this).parents(".owa_widget-container").get(0).id;
        
        // toggle the visibility of the child element
        jQuery('#'+widgetname).children(".owa_widget-innercontainer").toggle("slow");
        
        if (OWA.items[widgetname].minimized != true) {
                // set property on widget object
                OWA.items[widgetname].minimized = true;
                //change the text of the link to reflect new state
                jQuery(this).html("Show");
        } else {
                // set property on widget object
                OWA.items[widgetname].minimized = false;
                //change the text of the link to reflect new state
                jQuery(this).html("Minimize");
        }
        
        return;
}
 
function owa_widget_page_results() {
        var page = jQuery(this).text();
        alert(page);
        var widgetname = jQuery(this).parents(".owa_widget-container").get(0).id;
        OWA.items[widgetname].page_num = page;
        OWA.items[widgetname].properties.page = page;
        var view = OWA.items[widgetname].current_view;
        return OWA.items[widgetname].changeView(view);
 
}