$(function() { $('#copyProjects a').click(function() { setCopyProject($(this).data('id')); $('#copyProjectModal').modal('hide') }); setAclList($("#parent").val()); if(typeof(currentPlanID) == 'undefined') { $('#productsBox select[id^="products"]').each(function() { var branchID = 0; if($(this).closest('.input-group').find('select[id^="branch"]').size() > 0) { var branchID = $(this).closest('.input-group').find('select[id^="branch"]').val(); } loadPlans($(this), branchID); }); } $('[data-toggle="popover"]').popover(); var acl = $("[name^='acl']:checked").val(); setWhite(acl); $('#submit').click(function() { var products = new Array(); var existedBranch = false; /* Determine whether the products of the same branch are linked. */ $("#productsBox select[name^='products']").each(function() { var productID = $(this).val(); if(typeof(products[productID]) == 'undefined') products[productID] = new Array(); if(multiBranchProducts[productID]) { var branchID = $(this).closest('.input-group').find("select[id^=branch]").val(); if(products[productID][branchID]) { existedBranch = true; } else { products[productID][branchID] = branchID; } if(existedBranch) return false; } }); if(existedBranch) { bootbox.alert(errorSameBranches); return false; } }); if(selectedProductID) { $('#products0').val(selectedProductID); $('#products0').trigger("chosen:updated"); loadBranches($('#products0'), selectedBranchID); } }); /** * Set parent program. * * @param $parentProgram * @access public * @return void */ function setParentProgram(parentProgram) { location.href = createLink('project', 'create', 'model=' + model + '&programID=' + parentProgram); } /** * Set copy project. * * @param int $copyProjectID * @access public * @return void */ function setCopyProject(copyProjectID) { location.href = createLink('project', 'create', 'model=' + model + '&programID=' + programID + '©ProjectID=' + copyProjectID); } /** * Add new product. * * @param obj $obj * @access public * @return void */ function addNewProduct(obj) { if($(obj).attr('checked')) { $('#productName').removeAttr('disabled', true); $('#productName').closest('tr').removeClass('hidden'); $('#plansBox .col-sm-4').find('select').attr('disabled', true).trigger("chosen:updated"); $('#plansBox').closest('tr').addClass('hidden'); $('#productsBox .col-sm-4 .input-group').find('select').attr('disabled', true).trigger("chosen:updated"); } else { $('#productName').attr('disabled', true); $('#productName').closest('tr').addClass('hidden'); $('#plansBox .col-sm-4').find('select').removeAttr('disabled', true).trigger("chosen:updated"); $('#plansBox').closest('tr').removeClass('hidden'); $('#productsBox .col-sm-4 .input-group').find('select').removeAttr('disabled').trigger("chosen:updated"); } } /** * Set access control box. * * @param int $programID * @access public * @return void */ function setAclList(programID) { if(programID != 0) { $('.aclBox').html($('#programAcl').html()); } else { $('.aclBox').html($('#projectAcl').html()); } } /** * Load branches. * * @param int $product * @param int $branchID * @access public * @return void */ function loadBranches(product, branchID) { $("#productsBox select[name^='products']").each(function() { var $product = $(product); if($product.val() != 0 && $product.val() == $(this).val() && $product.attr('id') != $(this).attr('id') && !multiBranchProducts[$product.val()]) { bootbox.alert(errorSameProducts); $product.val(0); $product.trigger("chosen:updated"); return false; } }); if($('#productsBox .input-group:last select:first').val() != 0) { var length = $('#productsBox .input-group').size(); var $html = $('#productsBox .col-sm-4:last').html(); $('#productsBox .col-sm-4:last').find('.input-group-addon').remove(); $('#productsBox .row').append('