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

http://thoughtsite.googlecode.com/ · JavaScript · 127 lines · 97 code · 5 blank · 25 comment · 10 complexity · ec20603e4e9786090af570121b1c2995 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 Projects Form on Admin Tab require
  17. * jquery 1.3.2
  18. */
  19. // onload
  20. google.setOnLoadCallback(function() {
  21. ie.progressStart();
  22. // Call to the method that renders all the projects
  23. project.loadProjects(0);
  24. });
  25. project = {
  26. }
  27. //Show all the Porjects.
  28. project.loadProjects = function(offset) {
  29. var url = '';
  30. url = ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'admin/projects.json?startIndex=' + offset);
  31. $.get(
  32. url,
  33. {},
  34. function (handle) {
  35. // render projects
  36. if(handle != ''){
  37. if(handle.viewStatus.status == ie.config.SUCCESS) {
  38. // TODO: Abhishek, Need to handle with Template :)
  39. $('#listData').html('');
  40. var counter = 0;
  41. for (i in handle.viewStatus.data.projects) {
  42. counter++;
  43. if(counter > ie.config.RECORD_PER_PAGE_ADMIN)
  44. break;
  45. $('#listData').append(createHtml(handle.viewStatus.data.projects[i]));
  46. }
  47. // Handles pagination
  48. if(undefined != handle.viewStatus.data.paging)
  49. {
  50. $('#pagination').html(ie.Paging.getHTML(handle.viewStatus.data.paging, 'project.loadProjects'));
  51. }
  52. ie.progressEnd();
  53. }
  54. else {
  55. $('#listData').html(handle.viewStatus.messages.projects);
  56. }
  57. }
  58. else {
  59. ie.globalError();
  60. }
  61. ie.progressEnd();
  62. },
  63. ie.config.RESPONSE_TYPE
  64. );
  65. }
  66. // HTML that renders the page
  67. function createHtml(jsonData) {
  68. var output = '';
  69. output += '<div id="ProjectData" style="width:100%; class="ie-top-mar-25">';
  70. output += '<div id="' + jsonData['key'] + '" class="ie-adm-lt-bar ie-clear">';
  71. output += ' <div class="ie-left ie-left-mar-5 ie-nm-blu">';
  72. output += ie.escapeHTML(jsonData['name']);
  73. output += ' </div>';
  74. output += ' <div class="ie-right ie-left-mar-10 ie-right-mar-0">';
  75. output += ' <a href="' + ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'projects/show/'+ jsonData['key']) + ' " onclick="window.open(this.href,\'window_name\',\'options\'); return false;" class="ie-nm-blu">View</a> |';
  76. output += ' <a href="javascript:void(0);" onclick="adminReasonDelete(\'' + jsonData['key'] + '\')" class="ie-nm-blu">Delete</a>';
  77. output += ' </div>';
  78. output += '</div>';
  79. output += '</div>';
  80. return output;
  81. }
  82. function adminReasonDelete(projectKey)
  83. {
  84. var url = '';
  85. $('#dialog').html('<div class="hiddenInViewSource" style="padding-left: 70px; margin-top: 20px;">'
  86. + '<b>Enter reason for deleting: </b><textarea id="inputVal"></textarea><br/>'
  87. + '</div>');
  88. $('#dialog').dialog('option', 'title', 'Input Reason!');
  89. $('#dialog').dialog('option', 'buttons', { "Submit": function() {
  90. if($.trim($('#inputVal').val()) != null && $.trim($('#inputVal').val()) != '')
  91. {
  92. url = ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'admin/deleteProject/' + projectKey);
  93. $.post(
  94. url,
  95. {adminReason: $.trim($('#inputVal').val())},
  96. function (handle) {
  97. if(ie.config.SUCCESS == handle.viewStatus.status) {
  98. project.loadProjects(0);
  99. }
  100. else {
  101. var div = document.getElementById(projectKey);
  102. var d = document.getElementById('ProjectData');
  103. d.removeChild(div);
  104. $('#errDisplay').html(handle.viewStatus.messages.projects);
  105. ie.progressEnd();
  106. }
  107. },
  108. ie.config.RESPONSE_TYPE
  109. );
  110. $(this).dialog("close");
  111. }
  112. else
  113. {
  114. alert('Please provide reason for action.');
  115. $('#dialog').dialog('option', 'buttons', { "Ok": function() { $(this).dialog("close"); } });
  116. }
  117. $(this).dialog("close");
  118. } });
  119. $('#dialog').dialog('option', 'modal', true);
  120. $('#dialog').dialog('open');
  121. }