2013-05-10 13:28:43 +02:00
< div id = "title" >
2013-05-14 19:28:03 +02:00
< h1 > <?php print $type == 'add' ? 'Add Project' : 'Edit Project' ?> </ h1 >
2013-05-10 13:28:43 +02:00
< / 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 >
2013-05-14 19:28:03 +02:00
< textarea style = "width: 90%; height: 150px;" > <?php print $key ?> </ textarea >
2013-05-10 13:28:43 +02:00
<?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" >
2013-05-14 19:28:03 +02:00
<?php print $form ; ?>
2013-05-10 13:28:43 +02:00
< / div >
2013-05-14 10:00:56 +02:00
< / div >
< script >
2013-05-14 17:37:54 +02:00
<?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;
}
?>
2013-05-14 10:00:56 +02:00
$(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'));
}
}
});
2013-05-14 17:37:54 +02:00
$('#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');
2013-05-15 17:31:21 +02:00
var rtn = <?php print json_encode (( empty ( $_SERVER [ 'HTTPS' ]) ? 'http' : 'https' ) . '://' . $_SERVER [ 'HTTP_HOST' ] . $_SERVER [ 'REQUEST_URI' ]); ?> ;
2013-05-14 17:37:54 +02:00
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);
2013-05-14 17:58:14 +02:00
$('#element-title').val(val);
2013-05-14 17:37:54 +02:00
}
else {
$('label[for=element-reference]').show();
$('label[for=element-type]').show();
$('#element-reference').show();
$('#element-type').show();
$('#element-reference').val('');
$('#element-token').val('');
}
});
2013-05-14 10:00:56 +02:00
});
< / script >