rosa-build/app/assets/javascripts/extra/build_list.js

99 lines
4.1 KiB
JavaScript
Raw Normal View History

$(document).ready(function() {
// TODO: Refactor this handler!! It's too complicated.
$('#build_list_save_to_platform_id').change(function() {
var platform_id = $(this).val();
var base_platforms = $('.all_platforms input[type=checkbox].build_bpl_ids');
base_platforms.each(function(){
if ($.inArray(platform_id, base_platforms.map(function(){ return $(this).val() }).get()) >= 0) {
if ($(this).val() == platform_id) {
if ($(this).attr('data-released') === '1') {
$('#build_list_auto_publish').removeAttr('checked').attr('disabled', 'disabled');
//disableUpdateTypes();
} else {
$('#build_list_auto_publish').removeAttr('disabled').attr('checked', 'checked');
//enableUpdateTypes();
}
$(this).attr('checked', 'checked').removeAttr('disabled').trigger('change');
$(this).parent().find('.offset25 input[type="checkbox"]').removeAttr('disabled');
2012-04-10 10:05:42 +01:00
var rep_name = $('#build_list_save_to_platform_id option[value="' + $(this).val() + '"]').text().match(/[\w-]+\/([\w-]+)/)[1];
2012-04-10 10:05:42 +01:00
if (rep_name != 'main') {
$(this).parent().find('.offset25 input[type="checkbox"][rep_name="' + rep_name + '"]').attr('checked', 'checked');
}
2012-04-10 10:05:42 +01:00
$(this).parent().find('.offset25 input[type="checkbox"][rep_name="main"]').attr('checked', 'checked');
} else {
$(this).removeAttr('checked').attr('disabled', 'disabled').trigger('change');
$(this).parent().find('.offset25 input[type="checkbox"]').attr('disabled', 'disabled').removeAttr('checked');
}
} else {
$(this).removeAttr('disabled').removeAttr('checked').trigger('change');
$(this).parent().find('.offset25 input[type="checkbox"]').removeAttr('disabled').removeAttr('checked');
2012-04-18 18:31:11 +01:00
$('#build_list_auto_publish').removeAttr('disabled').attr('checked', 'checked');
}
});
2012-04-16 17:06:34 +01:00
2012-05-25 09:28:43 +01:00
if ($.inArray(platform_id, base_platforms.map(function(){ return $(this).val() }).get()) == -1) {
// For personal platforms update types always enebaled:
enableUpdateTypes();
}
2012-04-16 17:06:34 +01:00
setBranchSelected();
});
$('#build_list_save_to_platform_id').trigger('change');
$('.offset25 label').click(function() {
setPlChecked($(this).prev()[0], !$(this).prev().attr('checked'));
});
$('.offset25 input[type="checkbox"]').click(function() {
setPlChecked(this, $(this).attr('checked'));
});
$('.build_bpl_ids').click(function() {
return false;
});
});
function setPlChecked(pointer, checked) {
var pl_cbx = $(pointer).parent().parent().parent().find('input[type="checkbox"].build_bpl_ids');
var pl_id = pl_cbx.val();
if (checked && !$(pointer).attr('disabled')) {
pl_cbx.attr('checked', 'checked').trigger('change');
} else if ($('input[pl_id=' + pl_id + '][checked="checked"]').size() == 0) {
pl_cbx.removeAttr('checked').trigger('change');
}
}
2012-04-16 17:06:34 +01:00
function setBranchSelected() {
var pl_id = $('#build_list_save_to_platform_id').val();
2012-04-16 17:06:34 +01:00
// Checks if selected platform is main or not:
if ( $('.all_platforms').find('input[type="checkbox"][value=' + pl_id + '].build_bpl_ids').size() > 0 ) {
var pl_name = $('#build_list_save_to_platform_id option[value="' + pl_id + '"]').text().match(/([\w-.]+)\/[\w-.]+/)[1];
2012-04-16 17:06:34 +01:00
var branch_pl_opt = $('#build_list_project_version option[value="latest_' + pl_name + '"]');
// If there is branch we need - set it selected:
if ( branch_pl_opt.size() > 0 ) {
$('#build_list_project_version option[selected]').removeAttr('selected');
branch_pl_opt.attr('selected', 'selected');
}
}
}
function disableUpdateTypes() {
$("select#build_list_update_type option").each(function(i,el) {
if ( $.inArray($(el).attr("value"), ["security", "bugfix"]) == -1 ) {
$(el).attr("disabled", "disabled");
// If disabled option is selected - select 'bugfix':
if ( $(el).attr("selected") ) {
$( $('select#build_list_update_type option[value="bugfix"]') ).attr("selected", "selected");
}
}
});
}
function enableUpdateTypes() {
$("select#build_list_update_type option").removeAttr("disabled");
}