/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. * file is responsible to handle all javascript tasks on ShowProjectForm require
  17. * jquery 1.3.2
  18. */
  19. // onload calls the method to load all the projects
  20. google.setOnLoadCallback(function() {
  21. ie.progressStart();
  22. //Call to load all the projects
  23. project.loadProjects(0);
  24. });
  25. project = {
  26. }
  27. // Fetch all the projects and render through an HTML
  28. project.loadProjects = function(offset, heading) {
  29. var url = '';
  30. url = ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'projects/get.json?startIndex=' + offset);
  31. $.get(
  32. url,
  33. {},
  34. function (handle) {
  35. // render all the projects
  36. if(handle != ''){
  37. if(handle.viewStatus.status == ie.config.SUCCESS) {
  38. // TODO: Abhishek, Need to handle with Template :)
  39. $('#listProject').html('');
  40. var counter = 0;
  41. for (i in handle.viewStatus.data.projects) {
  42. counter++;
  43. if(counter > ie.config.RECORD_PER_PAGE)
  44. break;
  45. $('#listProject').append(createHtml(handle.viewStatus.data.projects[i]));
  46. }
  47. // Handles Pagination
  48. if(undefined != handle.viewStatus.data.paging)
  49. $('#pagination').html(ie.Paging.getHTML(handle.viewStatus.data.paging, 'project.loadProjects'));
  50. ie.progressEnd();
  51. }
  52. else {
  53. $('#listProject').html(handle.viewStatus.messages.projects);
  54. }
  55. }
  56. else {
  57. ie.globalError();
  58. }
  59. ie.progressEnd();
  60. },
  61. ie.config.RESPONSE_TYPE
  62. );
  63. }
  64. // HTML to render all the projects data
  65. function createHtml(jsonData) {
  66. var output = '';
  67. output += '<div style="width:100%; height:180px;" class="ie-top-mar-25">';
  68. output += ' <div class="ie-left-mar-20 ie-text ie-projects">';
  69. output += ' <h1 class="blu-heading">';
  70. output += ' <a href="' + ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'projects/show/'+ jsonData['key']) + '">';
  71. output += ie.escapeHTML(jsonData['name']) + '</a></h1><br />';
  72. output += ' <table width="98%" border="0" align="left" cellpadding="10%" cellspacing="10">';
  73. output += ' <tr>';
  74. output += ' <td width="80px">';
  75. if(undefined != jsonData.logo && undefined != jsonData.logo.bytes && '' != jsonData.logo.bytes) {
  76. output += ' <img src= "/showImage/' + jsonData['key'] + '" height="60px" width="60px"/>';
  77. }
  78. else {
  79. output += ' <img src= "' + ie.config.PUBLIC_URL + 'images/img.gif" height="60px" width="60px"/>';
  80. }
  81. output += ' </td>';
  82. output += ' <td>';
  83. output += ie.escapeHTML(jsonData['descriptionAsString']) + '<br />';
  84. output += ' <strong>Last Updated: </strong>' + jsonData['updatedOn'] + '<br />';
  85. output += ' </td>';
  86. output += ' </tr>';
  87. output += ' </div>';
  88. output += '</div>';
  89. return output;
  90. }