{ % block review % }
Review :< span id = "dev" > < / span>
{ % endblock % }
{ % block form % }
< form method= "post" action= "../branch_platform_add/" id = "bpform" >
< table style= "border-collapse:separate; border-spacing:0px 10px;" >
< tbody>
< tr>
< td> < label> Branch< / label> < / td>
< td>
< select class = "form-control selectpicker" data- live- search= "true" name= "branch" required id = "plat_formm" >
< option> < / option>
{ % for b in branch_list % }
< option value= "{{ b.branch_obj }}" > { { b. branch } } < / option>
{ % endfor % }
< / select>
< / td>
< / tr>
< tr>
< td style= "width: 130px" > < label> Platform< / label> < / td>
< td style= "width: 85%" > < select class = "form-control selectpicker" data- live- search= "true" id = "plat_form_test" name= "platform" required>
< option> < / option>
{ % for pl in platform_list % }
< option value= "{{ pl.id }}" > { { pl. name } } < / option>
{ % endfor % }
< / select> < / td>
< / tr>
< tr>
< td> < label> Build List< / label> < / td>
< td>
< table width= "150%" style= "border-collapse:separate;border-spacing:5px 5px;" id = "add_build" >
< tr >
< td > < input type = "text" class = "form-control" name= "build_project" value= "" id = "branch_li"
placeholder= "build project" required> < / td>
< td> < input type = "text" class = "form-control" name= "pac_name" placeholder= "pac name" value= "" id = "pac_li"
required> < / td>
< !- - < td align= "center" > < span class = "glyphicon glyphicon-plus addRow" > < / span> < / td> - - >
< td> < button type = "button" onclick= "add_branch('add_build')" > + < / button> < / td>
< / tr>
< / table>
< / td>
< / tr>
< tr>
< td> < label> Components< / label> < / td>
< td>
< table width= "150%" style= "border-collapse:separate;border-spacing:5px 5px;" id = "add_components" >
< tr>
< td > < input type = "text" class = "form-control" name= "build_project" value= "" id = "build_pro"
required> < / td>
< td> < input type = "text" class = "form-control" name= "component_branch" placeholder= "branch" id = "con_branch"
required> < / td>
< td> < button type = "button" onclick= "add_branch('add_components')" > + < / button> < / td>
< / tr>
< / table>
< / td>
< / tr>
< / tbody>
< / table>
< / form>
< button class = "btn btn-info" onclick= "auto_form()" style= "margin:0px 10px 0px 0px;" > Update< / button>
< button class = "btn btn-success" onclick= "review()" style= "margin:0px 10px 0px 0px;" > Review< / button>
< button class = "btn btn-primary" onclick= "submit_form()" style= "margin:0px 10px 0px 0px;" > Submit< / button>
{ % endblock % }
< / tfoot>
< tbody>
{ % for m in model_list % }
< tr>
< td> { { m. id } } < / td>
< td> { { m. branch } } < / td>
< td> { { m. platform. name } } < / td>
< td>
< a ng- click= "show_bl_modal({{ m.id }})" >
{ { m. get_active_builds| length } } / { { m. buildlist_set. all | length } }
< span style= "margin-left: 16px" class = "glyphicon glyphicon-pencil" > < / span> < / a>
< / td>
< td>
< a ng- click= "show_com_modal({{ m.id }})" > 点击查看< / a>
< / td>
< / tr>
{ % endfor % }
< / tbody>
< / table>
< div class = "modal fade" id = "detail_modal" tabindex= "-1" role= "dialog" aria- hidden= "true" >
< div class = "modal-dialog" >
< div class = "modal-content" >
< div class = "modal-header" >
< button type = "button" class = "close" data- dismiss= "modal" aria- hidden= "true" >
& times;
< / button>
< h4 class = "modal-title" > Detail< / h4>
< / div>
< div class = "modal-body" >
< div class = "col-md-6" >
< input type = "text" class = "form-control" ng- model= "modem_branch_add" >
< / div>
< div class = "col-md-1" style= "padding-left: 0" >
< button ng- click= "add_com(current_branch_platform_id)" class = "btn btn-primary" > ADD
< / button>
< / div>
< / div>
< / div>
< div class = "modal-footer" >
< button type = "button" class = "btn btn-default" data- dismiss= "modal" > 关闭
< / button>
< / div>
< / div>
< / div>
< / div>
< / div>
< / div>
< / div>
{ % endblock % }
{ % block back- style % }
{ { block. super } }
{ % endblock % }
{ % block back- script % }
< script>
var flag = false
$( "#plat_formm" ) . change( function( ) {
if ( $( "#plat_formm option:selected" ) . text( ) != "" ) {
$( "#plat_form_test" ) . change( function( ) {
auto_form( )
} )
}
else {
alert( "Please select branch" )
}
} ) ;
function add_branch( add_row, build, pac) {
if ( build== undefined & & pac== undefined) {
build= ''
pac= ''
}
// 创建tr
var tr = document. createElement( "tr" )
// 创建td
var branch_list = document. createElement( "td" )
var pac_list = document. createElement( "td" )
var del = document. createElement( "td" )
var input_1 = document. createElement( "input" )
var input_2 = document. createElement( "input" )
var input_3 = document. createElement( "button" )
input_1. type = "text"
input_1. placeholder = "build project"
input_1. value= build
input_1. name= "build_project"
input_1. style = "padding: 6px 12px;height: 34px;font-size: 14px; line-height: 1.42857143;width: 100%; border-radius: 4px;border: 1px solid #ccc;float:left"
input_2. type = "text"
input_2. placeholder = "pac name"
input_2. name= "pac_name"
input_2. style = "padding: 6px 12px;height: 34px;font-size: 14px; line-height: 1.42857143;width: 100%; border-radius: 4px;border: 1px solid #ccc;float:right"
input_2. value= pac
input_3. innerHTML = " - "
input_3. type = "button"
input_3. onclick = function ( ) {
del_tr( this) ;
} ;
branch_list. appendChild( input_1)
pac_list. appendChild( input_2)
del . appendChild( input_3)
tr. appendChild( branch_list)
tr. appendChild( pac_list)
tr. appendChild( del )
if ( add_row== 'add_build' ) {
document. getElementById( 'add_build' ) . appendChild( tr)
}
if ( add_row== 'add_components' ) {
document. getElementById( 'add_components' ) . appendChild( tr)
}
}
function del_tr( obj) {
obj. parentNode. parentNode. remove( ) ;
}
function auto_form( ) {
let branch = $( "#plat_formm option:selected" ) . text( )
let platform = $( "#plat_form_test option:selected" ) . text( )
$. ajax( {
type : "POST" ,
url: "/prod/auto/" ,
data: { branch: branch, platform: platform} ,
success: function ( response) {
document. getElementById( "dev" ) . innerHTML= ''
var add_buildTr = document. getElementById( "add_build" ) . getElementsByTagName( "tr" )
var add_Length = add_buildTr. length
for ( var i= 1 ; i< add_Length; i+ + ) {
add_buildTr[ 1 ] . remove( ) ;
}
var componentsTr = document. getElementById( "add_components" ) . getElementsByTagName( "tr" )
var con_Length = componentsTr. length
for ( var i= 1 ; i< con_Length; i+ + ) {
componentsTr[ 1 ] . remove( ) ;
}
document. getElementById( "branch_li" ) . value= '' ;
document. getElementById( "pac_li" ) . value= '' ;
document. getElementById( "build_pro" ) . value= '' ;
document. getElementById( "con_branch" ) . value= '' ;
flag = false;
if ( response. success) {
if ( response. info) {
for ( var i= 0 ; i< response. info. length; i+ + ) {
if ( i== 0 ) {
document. getElementById( "branch_li" ) . value= response. info[ i] [ "key" ] ;
document. getElementById( "pac_li" ) . value= response. info[ i] [ "value" ] ;
} else {
add_branch( 'add_build' , response. info[ i] [ "key" ] , response. info[ i] [ "value" ] )
}
} ;
} ;
if ( response. build_list) {
for ( var i= 0 ; i< response. build_list. length; i+ + ) {
if ( i== 0 ) {
document. getElementById( "build_pro" ) . value= response. build_list[ i] [ "key" ] ;
document. getElementById( "con_branch" ) . value= response. build_list[ i] [ "value" ] ;
} else {
add_branch( 'add_components' , response. build_list[ i] [ "key" ] , response. build_list[ i] [ "value" ] )
}
} ;
} ;
} else {
alert( 'The path is incorrect. Enter the path manually' )
}
}
} )
}
function review( ) {
var username = localStorage. getItem( 'user' )
document. getElementById( "dev" ) . innerHTML= username
flag = true
return flag
}
< / script>
{ % endblock % }
function submit_form( ) {
console. log( flag)
return ;
if ( flag) {
$. ajax( {
url: $( '#bpform' ) . attr( 'action' ) ,
type : 'POST' ,
data: $( '#bpform' ) . serialize( ) ,
success: function ( response) {
if ( response. result == 1 ) {
alert( '添加成功' )
} else {
alert( '添加失败,请检查branch 是否重复' )
}
location. reload ( ) ;
}
} ) ;
} else {
alert( "Please check first and click the Reviewer button after confirming everything" )
}