PageRenderTime 289ms CodeModel.GetById 146ms app.highlight 9ms RepoModel.GetById 132ms app.codeStats 0ms

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