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

http://thoughtsite.googlecode.com/ · JavaScript · 300 lines · 268 code · 9 blank · 23 comment · 60 complexity · 4b7118db125976ab90e96ce9a27a57ac 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. google.setOnLoadCallback(function() {
  16. ie.progressStart();
  17. loadTagCloud(); // start with 0 offset
  18. var $tabs = $('#tab-menu').tabs();
  19. $tabs.tabs('option', 'selected', 0); // => 0
  20. loadUserProfile();
  21. $('#tab-menu').bind('tabsselect', function(event, ui) {
  22. switch(ui.panel.id){
  23. case 'user-profile':
  24. loadUserProfile();
  25. break;
  26. case 'user-ideas':
  27. loadIdeas(0);
  28. break;
  29. case 'user-projects':
  30. loadProjects(0);
  31. break;
  32. default :
  33. loadUserProfile();
  34. break;
  35. }
  36. });
  37. });
  38. function loadUserProfile(){
  39. $.get(
  40. ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'users/profile.json'),
  41. {},
  42. function (handle) {
  43. // render user profile
  44. if(handle != ''){
  45. if(handle.viewStatus.status == ie.config.SUCCESS) {
  46. $('#user-profile').html('');
  47. $('#pagination').html('');
  48. $('#user-profile').append(createProfileHtml(handle.viewStatus.data.user));
  49. ie.progressEnd();
  50. }
  51. else {
  52. $('#user-profile').html(handle.viewStatus.messages.user);
  53. }
  54. }
  55. else {
  56. ie.globalError();
  57. }
  58. ie.progressEnd();
  59. },
  60. ie.config.RESPONSE_TYPE
  61. );
  62. }
  63. function loadIdeas(offset) {
  64. $.get(
  65. ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'users/ideas.json?startIndex='+ offset + ''),
  66. {},
  67. function (handle) {
  68. // render most recent idea
  69. if(handle != ''){
  70. $('#user-ideas').html('');
  71. if(handle.viewStatus.status == ie.config.SUCCESS) {
  72. // TODO: Abhishek, Need to handle with Template :)
  73. $('#user-ideas').html('');
  74. $('#pagination').html('');
  75. var counter = 0;
  76. for (i in handle.viewStatus.data.ideas) {
  77. counter++;
  78. if(counter > ie.config.RECORD_PER_PAGE)
  79. break;
  80. $('#user-ideas').append(createIdeaHtml(handle.viewStatus.data.ideas[i]));
  81. }
  82. $('#pagination').html('');
  83. if(undefined != handle.viewStatus.data.paging)
  84. $('#pagination').html(ie.Paging.getHTML(handle.viewStatus.data.paging, 'loadIdeas'));
  85. ie.progressEnd();
  86. }
  87. else {
  88. $('#user-ideas').html(handle.viewStatus.messages.ideas);
  89. }
  90. }
  91. else {
  92. ie.globalError();
  93. }
  94. ie.progressEnd();
  95. },
  96. ie.config.RESPONSE_TYPE
  97. );
  98. }
  99. function loadIdeasAfterDeletion(ideaKey) {
  100. $.get(
  101. ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'ideas/delete/' + ideaKey),
  102. {},
  103. function(handle) {
  104. loadIdeas(0);
  105. },
  106. ie.config.RESPONSE_TYPE
  107. );
  108. }
  109. function loadProjects(offset) {
  110. $.get(
  111. ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'users/projects.json?startIndex='+ offset + ''),
  112. {},
  113. function (handle) {
  114. // render most recent idea
  115. if(handle != ''){
  116. if(handle.viewStatus.status == ie.config.SUCCESS) {
  117. // TODO: Abhishek, Need to handle with Template :)
  118. $('#user-projects').html('');
  119. var counter =0;
  120. for (i in handle.viewStatus.data.projects) {
  121. counter++;
  122. if(counter > ie.config.RECORD_PER_PAGE)
  123. break;
  124. $('#user-projects').append(createProjectHtml(handle.viewStatus.data.projects[i]));
  125. }
  126. $('#pagination').html('');
  127. if(undefined != handle.viewStatus.data.paging)
  128. $('#pagination').html(ie.Paging.getHTML(handle.viewStatus.data.paging, 'loadProjects'));
  129. ie.progressEnd();
  130. }
  131. else {
  132. $('#user-projects').html(handle.viewStatus.messages.projects);
  133. }
  134. }
  135. else {
  136. ie.globalError();
  137. }
  138. ie.progressEnd();
  139. },
  140. ie.config.RESPONSE_TYPE
  141. );
  142. }
  143. function createProfileHtml(jsonData) {
  144. var output = '';
  145. output += '<div class="ie-profile-desc ie-text" id="mid-wrapper" >';
  146. // output += '<div class="ie-left" ><br /><br /><br />';
  147. // output += '<img src="' + jsonData['thumbnailUrl'] + '" alt="" width="100" height="100" align="left" class="ie-right-mar-10 ie-bottom-mar-20 " /></div>';
  148. output += '<div class="ie-left ie-right-mar-10 ie-left-mar-10"><br /><br />';
  149. output += 'Name:<br /><br /> Email-id:<br /><br />Status: <br /><br />Reputation Points: <br /><br />Joined on:';
  150. output += '</div>';
  151. output += '<div class="ie-left ie-right-mar-10 ie-left-mar-20" ><br /><br />';
  152. output += '<strong>' + jsonData['displayName'] + '</strong><br /><br />';
  153. if(undefined == jsonData['emailId']) {
  154. output += '<span class="ie-nm-blu"> </span><br /><br />';
  155. }
  156. else {
  157. output += '<span class="ie-nm-blu">' + jsonData['emailId'] + '</span><br /><br />';
  158. }
  159. output += jsonData['status'] + '<br /><br />';
  160. output += jsonData['reputationPoints'] + '<br /><br />';
  161. output += jsonData['createdOn'] + '<br /><br />';
  162. output += '</div>';
  163. output += '</div>';
  164. return output;
  165. }
  166. function createProjectHtml(jsonData) {
  167. var output = '';
  168. output += '<div style="width:100%; height:180px;" class="ie-top-mar-25">';
  169. output += ' <div class="ie-left-mar-20 ie-text ie-projects">';
  170. output += ' <h1 class="blu-heading">';
  171. output += ' <a href="' + ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'projects/show/'+ jsonData['project']['key']) + '">';
  172. output += ie.escapeHTML(jsonData['project']['name']) + '</a></h1><br />';
  173. output += '<table width="98%" border="0" align="left" cellpadding="2" cellspacing="1">';
  174. output += '<tr>';
  175. output += ' <td width="80px">';
  176. if(undefined == jsonData['project']['logo']) {
  177. output += ' <img src= "' + ie.config.PUBLIC_URL +'/images/img.gif" height="60px" width="60px"/>';
  178. }
  179. else {
  180. output += ' <img src= "/showImage/' + jsonData['project']['key'] + '" height="60px" width="60px"/>';
  181. }
  182. output += ' </td>';
  183. output += ' <td valign="top">';
  184. output += ie.escapeHTML(jsonData['project']['description']) + '<br />';
  185. output += ' <strong>Last Updated: </strong>' + jsonData['project']['updatedOn'] + '<br />';
  186. output += ' </td>';
  187. output += '</tr>';
  188. output += ' </div>';
  189. output += '</div>';
  190. return output;
  191. }
  192. function createIdeaHtml(jsonData) {
  193. var output = '';
  194. output += '<div style="width:100%; height:180px;" >';
  195. if(ie.config.STATUS_PUBLISHED == jsonData['idea']['status']) {
  196. output += ' <div class="ie-left ie-votes">';
  197. output += '<div class="ie-top-mar-10 ie-center"><strong> Votes</strong>';
  198. output += ' </div>';
  199. output += ' <div class="ie-top-mar-10 ie-left">';
  200. output += ' <img src="' + ie.config.PUBLIC_URL + 'images/hand-up.gif" alt="" width="25" height="30" hspace="10" border="0" /><strong>+ ';
  201. output += jsonData['idea']['totalPositiveVotes']+'</strong>';
  202. output += ' </div>';
  203. output += ' <div class="ie-clear ie-top-mar-5 ie-left" style="width: 85%">';
  204. output += ' <img src="' + ie.config.PUBLIC_URL + 'images/hand-dwn.gif" alt="" width="25" height="30" hspace="10" border="0" /><strong>- ';
  205. output += jsonData['idea']['totalNegativeVotes']+'</strong>';
  206. output += ' </div>';
  207. output += ' </div>';
  208. }
  209. else if(ie.config.STATUS_OBJECTIONABLE == jsonData['idea']['status']) {
  210. output += ' <div class="ie-left ie-votes">';
  211. output += '<div class="ie-top-mar-10 ie-center"><strong> Objectionable Idea</strong>';
  212. output += ' </div>';
  213. output += ' </div>';
  214. }
  215. else if(ie.config.STATUS_DUPLICATE == jsonData['idea']['status']) {
  216. output += ' <div class="ie-left ie-votes">';
  217. output += '<div class="ie-top-mar-10 ie-center"><strong> Duplicate Idea</strong>';
  218. output += ' </div>';
  219. output += ' </div>';
  220. }
  221. else {
  222. output += ' <div class="ie-left ie-votes">';
  223. output += '<div class="ie-top-mar-10 ie-center"><strong> Saved Idea</strong>';
  224. output += ' </div>';
  225. output += ' </div>';
  226. }
  227. output += ' <div class="ie-right ie-text ie-detail">';
  228. output += ' <h1 class="blu-heading">';
  229. if(ie.config.STATUS_SAVED == jsonData['idea']['status']) {
  230. output += ' <a href="' + ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'ideas/edit/'+ jsonData['idea']['key']) + '">';
  231. }
  232. else if(ie.config.STATUS_OBJECTIONABLE == jsonData['idea']['status']) {
  233. output += ' <a href="' + ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'ideas/edit/'+ jsonData['idea']['key']) + '">';
  234. }
  235. else {
  236. output += ' <a href="' + ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'ideas/show/'+ jsonData['idea']['key']) + '">';
  237. }
  238. output += ie.escapeHTML(jsonData['idea']['title']) + '</a></h1><br />';
  239. output += ie.escapeHTML(jsonData['idea']['description']) + '<br/>';
  240. output += ' <div class="ie-left ie-detail-info1">';
  241. output += ' <strong>Tags:</strong>';
  242. if(undefined != jsonData['tags']) {
  243. for(data in jsonData['tags']) {
  244. output += ' <a href="javascript:void(0)" onclick="idea.browseByTag(\'' + jsonData['tags'][data]['title'] + '\');" class="ie-nm-blu">' + jsonData['tags'][data]['title'] + '</a>';
  245. }
  246. }
  247. output += ' </div>';
  248. output += ' <div class="ie-right ie-left-mar-10 ie-right-mar-0">';
  249. if(ie.config.STATUS_SAVED == jsonData['idea']['status']) {
  250. output += ' <a href="javascript:void(0);" onclick="loadIdeasAfterDeletion(\'' + jsonData['idea']['key'] + '\')" class="ie-nm-blu">Delete</a>';
  251. }
  252. output += ' </div>';
  253. if(undefined != jsonData['user']) {
  254. output += ' <div class="ie-right ie-detail-info2">';
  255. output += ' <strong>Last Updated: </strong>'+jsonData['idea']['lastUpdated']+'<br />';
  256. output += ' <a href="#" class="ie-nm-blu">' + jsonData['user']['name'] + '</a><br />';
  257. output += ' <strong>' + jsonData['user']['userPoints'] + ' Points</strong><br />';
  258. output += ' <strong>' + jsonData['user']['userAwards'] + ' Awards</strong></div>';
  259. output += ' </div>';
  260. }
  261. output += '</div>';
  262. return output;
  263. }
  264. function loadTagCloud() {
  265. $.get(
  266. ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'tags/my' + '.json'),
  267. {},
  268. function (handle) {
  269. // render most recent idea
  270. if(ie.config.SUCCESS == handle.viewStatus.status) {
  271. // TODO: Abhishek, Need to handle with Template :)
  272. var html = ie.TagCloud.render(handle.viewStatus.data.tags,
  273. handle.viewStatus.data.weights,
  274. {title : 'title', weightage : 'weightage', css: 'tag'},
  275. {url:ie.buildUrl(ie.config.REQUEST_IDEA_EXCHANGE, 'ideas/list?type=tag&tag=')}
  276. );
  277. $('#cloud').html(html);
  278. ie.progressEnd();
  279. }
  280. else if(ie.config.ERROR == handle.viewStatus.status) {
  281. $('#cloud').html(handle.viewStatus.messages.tag);
  282. ie.progressEnd();
  283. }
  284. else {
  285. ie.progressEnd();
  286. ie.globalError();
  287. }
  288. },
  289. ie.config.RESPONSE_TYPE
  290. );
  291. }