// Check if the current logged in user is logged in. // If they are not logged in then it shouldn't show // any editing buttons for projects and releases. checkAdminStatus : function() { callApi('userApi', 'isAdmin', 'POST',{}, function(resultObj){ if (!resultObj.success) { $('.project-content-header-options-content').hide(); $('.release-content-header-options-content').hide(); } }, '', '', true); }, // Bind the go project release button to // redirect to the workspace if a project // and release is selected by the user. bindGoProjectReleaseButton: function() { //Listeners for the go button $(".go-project-rev-btn").click(function() { // Get Project Id var y = $(".project-content").children(".project-content-body"); var msg1 = jQuery.parseJSON($($(y).children(".project-name.active")[0]).find('.meta').html()) // Get Release Id var x = $(".release-content").children(".release-content-body"); var msg2 = jQuery.parseJSON($($(x).children(".release-name.active")[0]).find('.meta').html()); // Check if user selected a project and a release if(msg1 == null || msg2 == null) { alert('You must select a project and a release!'); return; } var project_id = msg1.projectId; var release_id = msg2.releaseId; // Redirect user to the workspace var querystring = ''; if( project_id != '' && release_id != '') querystring = '?__pid=' + project_id + '&__rid=' + release_id; window.location ='/workspace.html'+querystring; }); } } renameRelease: function(el){ // Unbind previous click(s) to accept. $(".ui-dialog .accept").unbind("click"); // Unbind previous click(s) to close. $(".ui-dialog .ui-dialog-titlebar-close").unbind("click"); // Bind click to accept. $(".ui-dialog .accept").click(function(){ // Get the edited project name from user. var newReleaseName = $(".ui-dialog .rename-release-overlay-name input").val(); var name = '
' + newReleaseName + '
'; // Replace release with project containing input name var x = $(el).parent().parent().parent().parent().children(".release-content-body"); var msg = jQuery.parseJSON($(x).children(".release-name.active").find('.meta').html()); $(x).children(".release-name.active").removeClass("release-name-text"); $(x).children(".release-name.active").html(name); var param = { "releaseId": msg.releaseId, "name": newReleaseName }; // This function fires after the ajax call returns var callback = function(resultObj){ if (resultObj.success) { alert('Change Release Sucess!'); } else { alert('Change Release Fail!'); } } callApi('projectApi', 'renameRelease', 'POST', param, callback, '', '', false); // Close dialog box $(".rename-release-overlay").dialog("close"); // Unbind previous click to accept. $(".ui-dialog .accept").unbind("click"); }); } // Load current projects and releases loadCurrentProjects: function(){ var param = {}; // Show project's name var get_Project_Id = function(result){ $.each(result.projects, function(key, value){ var parameter = { projectId: key }; var para_encoded = JSON.stringify(parameter); var html_project_name = '
' + value + '
' + para_encoded + '
'; $(".project-content-body").append(html_project_name); }) } // Get project's id and names from database callApi('projectApi', 'listProjects', 'GET', param, get_Project_Id, '', '', false); // Grab project id and release id from project url var input_project_id = getParameterByName( '__pid' ); var input_release_id = getParameterByName( '__rid' ); var t = this; if( input_project_id != '' && input_release_id != '') { // Highlight project $(".project-content-body").children(".project-name").each(function() { var msg = jQuery.parseJSON($(this).find('.meta').html()); if(input_project_id == msg.projectId) { t.highLightElem(this); } }); // Show all releases associated with project and highlight release t.loadCurrentReleases(); $(".release-content-body").children(".release-name").each(function() { var msg = jQuery.parseJSON($(this).find('.meta').html()); if(msg.releaseId == input_release_id) { t.highLightElem(this); } }); // Bind highlight to release names $(".release-name").each(function(){ $(this).click(function(){ t.highLightElem(this); }); }); } },