~lss-team/lilsoftstats/trunk

« back to all changes in this revision

Viewing changes to js/jquery/pages.js

  • Committer: Nick
  • Date: 2011-11-14 04:10:28 UTC
  • Revision ID: nick@little-apps.org-20111114041028-cvmpwq6z6hx3pkya
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
$(document).ready(function() {
 
2
        // Visualize script
 
3
        $('table.pie').visualize({type: 'pie', height: '300px', width: '620px'});
 
4
        $('table.bar').visualize({type: 'bar', height: '300px', width: '620px'});
 
5
        $('table.area').visualize({type: 'area', height: '300px', width: '620px'});
 
6
        $('table.line').visualize({type: 'line', height: '300px', width: '620px'});
 
7
        
 
8
        // Styled Select Box
 
9
        $('.styledselect_pages_1').selectbox({ inputClass: "styledselect_form_1" });
 
10
 
 
11
        // Charting script
 
12
        $("table.stats").each(function() {
 
13
        var colors = [];
 
14
        $("table.stats thead th:not(:first)").each(function() {
 
15
            colors.push($(this).css("color"));
 
16
        });
 
17
        $(this).graphTable({
 
18
            series: 'columns',
 
19
            position: 'replace',
 
20
                        width: '99%',
 
21
            height: '200px',
 
22
            colors: colors
 
23
        }, {
 
24
            xaxis: {
 
25
                tickSize: 1
 
26
            }
 
27
        });
 
28
    });
 
29
 
 
30
    $("table.stats-date").each(function() {
 
31
        var colors = [];
 
32
        var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
 
33
 
 
34
        $("table.stats-date thead th:not(:first)").each(function() {
 
35
            colors.push($(this).css("color"));
 
36
        });
 
37
        $(this).graphTable({
 
38
            series: 'columns',
 
39
            position: 'replace',
 
40
            height: '200px',
 
41
                        width: '99%',
 
42
            colors: colors,
 
43
            xaxisTransform: function(month) {
 
44
                var i = 0;
 
45
                while ((i < 12) && (month != months[i])) {
 
46
                    i++;
 
47
                }
 
48
                return i;
 
49
            }
 
50
        }, {
 
51
            xaxis: {
 
52
                tickSize: 1,
 
53
                tickFormatter: function(v, a) {
 
54
                    return months[v];
 
55
                }
 
56
            }
 
57
        });
 
58
    });
 
59
 
 
60
        if ($('div#space').length <= 0) {
 
61
                $('.flot-graph').before('<div class="space"></div>');
 
62
        }
 
63
 
 
64
    function showTooltip(x, y, contents) {
 
65
        $('<div id="tooltip">' + contents + '</div>').css({
 
66
            position: 'absolute',
 
67
            display: 'none',
 
68
            top: y + 5,
 
69
            left: x + 5
 
70
        }).appendTo("body").fadeIn("fast");
 
71
    }
 
72
 
 
73
    var previousPoint = null;
 
74
    $(".flot-graph").bind("plothover", function(event, pos, item) {
 
75
        $("#x").text(pos.x);
 
76
        $("#y").text(pos.y);
 
77
 
 
78
        if (item) {
 
79
            if (previousPoint != item.dataIndex) {
 
80
                previousPoint = item.dataIndex;
 
81
 
 
82
                $("#tooltip").remove();
 
83
                var x = item.datapoint[0],
 
84
                    y = item.datapoint[1];
 
85
 
 
86
                showTooltip(item.pageX, item.pageY, "<b>" + item.series.label + "</b>: " + y);
 
87
            }
 
88
        }
 
89
        else {
 
90
            $("#tooltip").remove();
 
91
            previousPoint = null;
 
92
        }
 
93
    });
 
94
        
 
95
        // UI Checkboxes
 
96
        $('input').checkBox();
 
97
        $('#toggle-all').click(function(){
 
98
                $('#toggle-all').toggleClass('toggle-checked');
 
99
                $('#mainform input[type=checkbox]').checkBox('toggle');
 
100
                return false;
 
101
        });
 
102
        
 
103
        // jQuery Forms
 
104
        var options = { 
 
105
                target:        '#output',   // target element(s) to be updated with server response 
 
106
                beforeSubmit:  showRequest,  // pre-submit callback 
 
107
                success:       showResponse  // post-submit callback 
 
108
 
 
109
                // other available options: 
 
110
                //url:       url         // override for form's 'action' attribute 
 
111
                //type:      type        // 'get' or 'post', override for form's 'method' attribute 
 
112
                //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
 
113
                //clearForm: true        // clear all form fields after successful submit 
 
114
                //resetForm: true        // reset the form after successful submit 
 
115
 
 
116
                // $.ajax options can be used here too, for example: 
 
117
                //timeout:   3000 
 
118
        }; 
 
119
        
 
120
        // bind to the form's submit event 
 
121
        $('form[id$=form]').each( function() {
 
122
                $(this).ajaxForm(options);
 
123
        });
 
124
        
 
125
        // Exception Info Expander
 
126
        $("a#exceptiondetails").click(function() {
 
127
                var exceptionid = $(this).parent().parent().attr("id");
 
128
                $("div[class='exceptiondetails']").hide();
 
129
                $(".exceptiondetailscontainer").show();
 
130
                $("div[class='exceptiondetails'][id='"+exceptionid+"']").show();
 
131
        });
 
132
        
 
133
        // Tab Switching
 
134
        $("#tabs, #graphs").tabs();
 
135
        
 
136
        // Select all checkboxes
 
137
        $("#checkboxall").click(function() {
 
138
                var checked_status = this.checked;
 
139
                $("input[name=checkall]").each(function() { this.checked = checked_status; });
 
140
        });
 
141
        
 
142
        // Rich text editor/WYSIWYG
 
143
        $('#wysiwyg').wysiwyg();
 
144
        
 
145
        // Google Maps API
 
146
        var map;
 
147
        var arrMarkers = [];
 
148
        var arrInfoWindows = [];
 
149
        
 
150
        function mapInit(){
 
151
                var centerCoord = new google.maps.LatLng(18.23, -66.39); // Puerto Rico
 
152
                var mapOptions = {
 
153
                        zoom: 3,
 
154
                        center: centerCoord,
 
155
                        mapTypeId: google.maps.MapTypeId.TERRAIN
 
156
                };
 
157
                map = new google.maps.Map(document.getElementById("map"), mapOptions);
 
158
                
 
159
                $.getJSON("inc/map.json", {}, function(data){
 
160
                        $.each(data.places, function(i, item){
 
161
                                $("#markers").append('<li><a href="#" rel="' + i + '">' + item.title + '</a></li>');
 
162
                                var marker = new google.maps.Marker({
 
163
                                        position: new google.maps.LatLng(item.lat, item.lng),
 
164
                                        map: map,
 
165
                                        title: item.title
 
166
                                });
 
167
                                arrMarkers[i] = marker;
 
168
                                var infowindow = new google.maps.InfoWindow({
 
169
                                        content: "<h3>"+ item.title +"</h3><p>"+ item.description +"</p>"
 
170
                                });
 
171
                                arrInfoWindows[i] = infowindow;
 
172
                                google.maps.event.addListener(marker, 'click', function() {
 
173
                                        infowindow.open(map, marker);
 
174
                                });
 
175
                        });
 
176
                });
 
177
        }
 
178
        $(function(){
 
179
                // initialize map (create markers, infowindows and list)
 
180
                mapInit();
 
181
                
 
182
                // "live" bind click event
 
183
                $("#markers a").live("click", function(){
 
184
                        var i = $(this).attr("rel");
 
185
                        // this next line closes all open infowindows before opening the selected one
 
186
                        //for(x=0; x < arrInfoWindows.length; x++){ arrInfoWindows[x].close(); }
 
187
                        arrInfoWindows[i].open(map, arrMarkers[i]);
 
188
                });
 
189
        });
 
190
        
 
191
        // Action Slider
 
192
        $(".action-slider").click(function () {
 
193
        $("#actions-box-slider").slideToggle("fast");
 
194
        $(this).toggleClass("activated");
 
195
        return false;
 
196
    });
 
197
        
 
198
        // Data Tables
 
199
        $('.datatable').dataTable({"sPaginationType": "full_numbers"});
 
200
        
 
201
        // Validate input
 
202
        $("input#validate-text").keyup(function () {
 
203
                if ($(this).val() == "") {
 
204
                        $(this).removeClass("inp-form"); 
 
205
                        $(this).addClass("inp-form-error");
 
206
                        
 
207
                        $(this).parent().parent().find("td#error").html("<div class='error-left'></div><div class='error-inner'>This field is required.</div>");
 
208
                } else {
 
209
                        $(this).addClass("inp-form"); 
 
210
                        $(this).removeClass("inp-form-error");
 
211
                        
 
212
                        $(this).parent().parent().find("td#error").html("");
 
213
                }
 
214
        });
 
215
        
 
216
        // Integration
 
217
        var appName;
 
218
        var programmingLang;
 
219
        var installer;
 
220
        
 
221
        var refreshIntegration = function () {
 
222
                $("div#integration div").each(function() { $(this).hide(); });
 
223
                $("div#"+programmingLang).show();
 
224
                $("div#"+installer).show();
 
225
        }
 
226
        
 
227
        $("input#appname").keyup(function () {
 
228
                appName = $(this).val(); 
 
229
                if (appName == "") { 
 
230
                        $("input#appname").removeClass("inp-form"); 
 
231
                        $("input#appname").addClass("inp-form-error");
 
232
                        $("tr#appname td#error").html("<div class='error-left'></div><div class='error-inner'>This field is required.</div>");
 
233
                } else {
 
234
                        $("input#appname").addClass("inp-form"); 
 
235
                        $("input#appname").removeClass("inp-form-error");
 
236
                        $("tr#appname td#error").html("");
 
237
                }
 
238
        });
 
239
        $("div#language_container ul").click(function () { programmingLang = $("#language_container ul li.selected2").attr('title'); refreshIntegration(); });
 
240
        $("div#installer_container ul").click(function () { installer = $("#installer_container ul li.selected2").attr('title'); refreshIntegration(); });
 
241
});
 
242
 
 
243
// pre-submit callback 
 
244
function showRequest(formData, jqForm, options) { 
 
245
        $('#output').html('<center><img src="images/forms/ajaxloader.gif" width="220" height="19" /></center><br />');
 
246
 
 
247
        // here we could return false to prevent the form from being submitted; 
 
248
        // returning anything other than false will allow the form submit to continue 
 
249
        return true; 
 
250
 
251
 
 
252
// post-submit callback 
 
253
function showResponse(responseText, statusText, xhr, $form)  { 
 
254
    // for normal html responses, the first argument to the success callback 
 
255
    // is the XMLHttpRequest object's responseText property 
 
256
 
 
257
    // if the ajaxForm method was passed an Options Object with the dataType 
 
258
    // property set to 'xml' then the first argument to the success callback 
 
259
    // is the XMLHttpRequest object's responseXML property 
 
260
 
 
261
    // if the ajaxForm method was passed an Options Object with the dataType 
 
262
    // property set to 'json' then the first argument to the success callback 
 
263
    // is the json data object returned by the server 
 
264
        
 
265
        // Message Box Fading Scripts
 
266
        $(".close-yellow").click(function () {
 
267
                $("#message-yellow").fadeOut("slow");
 
268
        });
 
269
        $(".close-red").click(function () {
 
270
                $("#message-red").fadeOut("slow");
 
271
        });
 
272
        $(".close-blue").click(function () {
 
273
                $("#message-blue").fadeOut("slow");
 
274
        });
 
275
        $(".close-green").click(function () {
 
276
                $("#message-green").fadeOut("slow");
 
277
        });
 
278
}
 
 
b'\\ No newline at end of file'