PageRenderTime 264ms CodeModel.GetById 141ms app.highlight 7ms RepoModel.GetById 114ms app.codeStats 0ms

/src/main/webapp/public/js/projects/list.js

http://thoughtsite.googlecode.com/
JavaScript | 95 lines | 65 code | 5 blank | 25 comment | 17 complexity | aa6feb0857ababc48b63ea27cc7024a7 MD5 | raw file
 1/* Copyright 2010 Google Inc.
 2 * 
 3 * Licensed under the Apache License, Version 2.0 (the "License");
 4 * you may not use this file except in compliance with the License.
 5 * You may obtain a copy of the License at
 6 * 
 7 *      http://www.apache.org/licenses/LICENSE-2.0
 8 * 
 9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS.
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License
14 */
15
16/**
17 * file is responsible to handle all javascript tasks on ShowProjectForm require
18 * jquery 1.3.2
19 */
20// onload calls the method to load all the projects
21google.setOnLoadCallback(function() {
22    ie.progressStart();
23    //Call to load all the projects
24    project.loadProjects(0);
25});
26
27
28project = {
29    
30}
31
32// Fetch all the projects and render through an HTML
33project.loadProjects = function(offset, heading) {
34    var url = '';
35        url = ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'projects/get.json?startIndex=' + offset);
36    $.get(
37            url, 
38            {}, 
39            function (handle) {
40                // render all the projects
41                if(handle != ''){
42                    if(handle.viewStatus.status == ie.config.SUCCESS) {
43                        // TODO: Abhishek, Need to handle with Template :)
44                        $('#listProject').html('');
45                        var counter = 0;
46                        for (i in handle.viewStatus.data.projects) {
47                            counter++;
48                            if(counter > ie.config.RECORD_PER_PAGE)
49                                break;
50                            $('#listProject').append(createHtml(handle.viewStatus.data.projects[i]));
51                        }
52                        // Handles Pagination
53                        if(undefined != handle.viewStatus.data.paging)
54                            $('#pagination').html(ie.Paging.getHTML(handle.viewStatus.data.paging, 'project.loadProjects'));
55                        ie.progressEnd();
56                    }
57                    else {
58                        $('#listProject').html(handle.viewStatus.messages.projects);
59                    }
60                }
61                else {
62                    ie.globalError();
63                }
64                ie.progressEnd();
65            }, 
66            ie.config.RESPONSE_TYPE
67    );
68}
69// HTML to render all the projects data
70function createHtml(jsonData) {
71    var output = '';
72    output += '<div style="width:100%; height:180px;" class="ie-top-mar-25">';
73    output += '		<div class="ie-left-mar-20 ie-text ie-projects">';
74    output += '			<h1 class="blu-heading">';
75    output += '    		<a href="' + ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'projects/show/'+ jsonData['key']) + '">';
76    output += 			ie.escapeHTML(jsonData['name']) + '</a></h1><br />';
77    output += '			<table width="98%" border="0" align="left" cellpadding="10%" cellspacing="10">';
78    output += '				<tr>';
79    output += '  				<td width="80px">';
80    if(undefined != jsonData.logo && undefined != jsonData.logo.bytes && '' != jsonData.logo.bytes) {
81        output += '					<img src= "/showImage/' + jsonData['key'] + '" height="60px" width="60px"/>';
82    }
83    else {
84        output += '         		<img src= "' + ie.config.PUBLIC_URL + 'images/img.gif" height="60px" width="60px"/>';
85    }
86    output += '  				</td>';
87    output += '  				<td>';
88    output +=  						ie.escapeHTML(jsonData['descriptionAsString']) + '<br />';
89    output += '						<strong>Last Updated: </strong>' + jsonData['updatedOn'] + '<br />';  
90    output += '  				</td>';
91    output += '				</tr>';
92    output += '     </div>';
93    output += '</div>';
94    return output;
95}