Files
EasySoft-ZenTaoPMS/module/mr/js/create.ui.js
T
2023-08-01 09:39:39 +08:00

109 lines
2.8 KiB
JavaScript

/**
* Urlencode param.
*
* @param param $param
* @access public
* @return string
*/
function urlencode(param)
{
if(hostType != 'gitlab') return Base64.encode(encodeURIComponent(param));
return param;
}
/**
* Get branch priv.
*
* @param int|string $project
* @access public
* @return void
*/
function getBranchPriv(project)
{
var branchUrl = $.createLink('mr', 'ajaxGetBranchPivs', "hostID=" + hostID + "&project=" + project);
$.get(branchUrl, function(response)
{
branchPrivs = eval('(' + response + ')');
});
}
function onProjectChange()
{
var branchUrl = $.createLink(hostType, 'ajaxGetProjectBranches', hostType + "ID=" + hostID + "&projectID=" + projectID);
$.ajaxSubmit(
{
url: branchUrl,
method: 'get',
onComplete: function(result)
{
zui.Picker.query("[name='sourceBranch']").render({items: result});
zui.Picker.query("[name='targetBranch']").render({items: result});
$("[name='targetBranch']").picker('setValue', '');
},
});
getBranchPriv(projectID);
}
function onSourceProjectChange()
{
var sourceProject = urlencode($('#sourceProject').val());
if(!sourceProject) return false;
if(sourceProject) getBranchPriv(sourceProject);
}
function onBranchChange()
{
$('#removeSourceBranch').removeAttr('disabled');
var sourceProject = $('#sourceProject').val();
var sourceBranch = $('#sourceBranch').val();
var targetProject = $('#targetProject').val();
var targetBranch = $('#targetBranch').val();
if(branchPrivs[sourceBranch])
{
$('#removeSourceBranch').attr('disabled', 'true');
$('#removeSourceBranch').attr("checked",false);
}
if(!sourceProject || !sourceBranch || !targetProject || !targetBranch) return false;
var $this = $(this);
var repoUrl = $.createLink('mr', 'ajaxCheckSameOpened', "hostID=" + hostID);
$.post(repoUrl, {"sourceProject": sourceProject, "sourceBranch": sourceBranch, "targetProject": targetProject, "targetBranch": targetBranch}, function(response)
{
response = $.parseJSON(response);
if(response.result == 'fail')
{
alert(response.message);
if($this.attr('id') == 'sourceBranch') $('#removeSourceBranch').removeAttr('disabled');
return false;
}
});
}
function onNeedCiChange(event)
{
const $needCi = $(event.target) ;
if($needCi.prop('checked') == false)
{
$("#jobID").prop("disabled", true);
$("#jobID").parent().parent().addClass('hidden');
}
if($needCi.prop('checked') == true)
{
$("#jobID").prop("disabled", false);
$("#jobID").parent().parent().removeClass('hidden');
}
}
$(function()
{
if(repo.gitService)
{
onProjectChange();
}
});