105 lines
3.1 KiB
PHTML
105 lines
3.1 KiB
PHTML
<div id="title">
|
|
<h1><?php print $type == 'add' ? 'Add Project' : 'Edit Project' ?></h1>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="span4">
|
|
<div class="well" style="">
|
|
<?php if(!is_null($key)): ?>
|
|
<p>To make it easier to get started, we've generated a public / private key pair for you to use for this project. To use it, just add the following public key to the "deploy keys" section of your repository settings on Github / Bitbucket.</p>
|
|
|
|
<textarea style="width: 90%; height: 150px;"><?php print $key ?></textarea>
|
|
<?php elseif($type == 'add'): ?>
|
|
<p>Fill in the form to the right to add your new project.</p>
|
|
<?php else: ?>
|
|
<p>Edit your project details using the form to the right.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="span8">
|
|
<?php print $form; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
<?php
|
|
$gh = \b8\Registry::getInstance()->get('github_app', null);
|
|
|
|
if($gh)
|
|
{
|
|
print 'window.github_app_id = ' . json_encode($gh['id']) . ';' . PHP_EOL;
|
|
}
|
|
|
|
if(!empty($token))
|
|
{
|
|
print 'window.github_token = ' . json_encode($token) . ';' . PHP_EOL;
|
|
}
|
|
?>
|
|
|
|
$(document).ready(function()
|
|
{
|
|
$('#element-reference').change(function()
|
|
{
|
|
var el = $(this);
|
|
var val = el.val();
|
|
|
|
var acceptable = {
|
|
'github_ssh': /git\@github\.com\:([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)\.git/,
|
|
'github_git': /git\:\/\/github.com\/([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)\.git/,
|
|
'github_http': /https\:\/\/github\.com\/([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)(\.git)?/,
|
|
'bb_ssh': /git\@bitbucket\.org\:([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)\.git/,
|
|
'bb_http': /https\:\/\/[a-zA-Z0-9_\-]+\@bitbucket.org\/([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)\.git/,
|
|
'bb_anon': /https\:\/\/bitbucket.org\/([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)(\.git)?/
|
|
};
|
|
|
|
for(var i in acceptable) {
|
|
if(val.match(acceptable[i])) {
|
|
el.val(val.replace(acceptable[i], '$1'));
|
|
}
|
|
}
|
|
});
|
|
|
|
$('#element-type').change(function()
|
|
{
|
|
if(!window.github_app_id || $(this).val() != 'github' || window.github_token) {
|
|
return;
|
|
}
|
|
|
|
// Show sign in with Github button.
|
|
var el = $('#element-reference');
|
|
var rtn = <?php print json_encode((empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>;
|
|
var url = 'https://github.com/login/oauth/authorize?client_id=' + window.github_app_id + '&scope=repo&redirect_uri=' + rtn;
|
|
var btn = $('<a>').addClass('btn btn-inverse').text('Sign in with Github').attr('href', url);
|
|
|
|
el.after(btn);
|
|
el.remove();
|
|
});
|
|
|
|
$('#element-github').change(function()
|
|
{
|
|
var val = $('#element-github').val();
|
|
|
|
if(val != 'choose') {
|
|
$('#element-type').val('github');
|
|
$('#element-reference').val(val);
|
|
|
|
$('label[for=element-reference]').hide();
|
|
$('label[for=element-type]').hide();
|
|
$('#element-reference').hide();
|
|
$('#element-type').hide();
|
|
$('#element-token').val(window.github_token);
|
|
$('#element-title').val(val);
|
|
}
|
|
else {
|
|
$('label[for=element-reference]').show();
|
|
$('label[for=element-type]').show();
|
|
$('#element-reference').show();
|
|
$('#element-type').show();
|
|
$('#element-reference').val('');
|
|
$('#element-token').val('');
|
|
}
|
|
});
|
|
});
|
|
|
|
</script>
|