PageRenderTime 37ms CodeModel.GetById 12ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

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