diff --git a/module/project/css/create.css b/module/project/css/create.css
index 444ddd1b34..3036ebd760 100755
--- a/module/project/css/create.css
+++ b/module/project/css/create.css
@@ -15,14 +15,14 @@
#budget {border-right: 0px;}
#budgetUnit {border-left: 0px;}
#projectName {display: inline-block; width: 32%;}
-#productsBox a {border-radius: 2px !important;}
-#productsBox .col-sm-4 {padding-right: 5px;}
-#productsBox .required:after {right: -9.5px !important;}
-#productsBox .addProduct {padding-left: 0px !important; padding-right: 10px;}
-#productsBox .addProduct.required:after {right: -1px !important;}
-#productsBox .input-group-addon > div {display: inline-block !important;}
-#productsBox .required + .text-danger.help-text {position: relative; left: 10px;}
-#productsBox > #productNameLabel {padding-top: 8px;}
+.productsBox a {border-radius: 2px !important;}
+.productsBox .col-sm-4 {padding-right: 5px;}
+.productsBox .required:after {right: -9.5px !important;}
+.productsBox .addProduct {padding-left: 0px !important;}
+.productsBox .addProduct.required:after {right: -1px !important;}
+.productsBox .input-group-addon > div {display: inline-block !important;}
+.productsBox .required + .text-danger.help-text {position: relative; left: 10px;}
+.productsBox > #productNameLabel {padding-top: 8px;}
#plansBox .col-sm-4 {float: none; display: inline-block; padding-right: 5px;}
.futureBox {vertical-align: top !important; padding-top: 13px !important;}
#projectType {padding-top: 7px !important;}
diff --git a/module/project/js/create.js b/module/project/js/create.js
index 64daca13ba..7bce25f5f7 100644
--- a/module/project/js/create.js
+++ b/module/project/js/create.js
@@ -11,7 +11,7 @@ $(function()
if(hasProduct == 1)
{
var chosenProducts = 0;
- $("#productsBox select[name^='products']").each(function()
+ $(".productsBox select[name^='products']").each(function()
{
if($(this).val() > 0) chosenProducts ++;
});
@@ -31,14 +31,14 @@ $(function()
if(typeof(currentPlanID) == 'undefined')
{
- $('#productsBox select[id^="products"]').each(function()
+ $('.productsBox select[id^="products"]').each(function()
{
- var branchID = 0;
- if($(this).closest('.input-group').find('select[id^="branch"]').size() > 0)
+ var branch = 0;
+ if($(this).closest('.table-row').find('select[name^="branch"]').size() > 0)
{
- var branchID = $(this).closest('.input-group').find('select[id^="branch"]').val();
+ var branch = $(this).closest('.table-row').find('select[name^="branch"]');
}
- loadPlans($(this), branchID);
+ loadPlans($(this), branch);
});
}
@@ -63,7 +63,7 @@ $(function()
$('#daysLabelInfo').remove();
/* Determine whether the products of the same branch are linked. */
- $("#productsBox select[name^='products']").each(function()
+ $(".productsBox select[name^='products']").each(function()
{
var productID = $(this).val();
if(typeof(products[productID]) == 'undefined') products[productID] = new Array();
@@ -98,7 +98,6 @@ $(function()
}
/* Init for copy execution. */
- $("select[id^=branch]").each(disableSelectedBranch);
disableSelectedProduct();
/* Check the all products and branches control when uncheck the product. */
@@ -106,14 +105,10 @@ $(function()
{
if($(this).val() == 0)
{
- $("select[id^='branch']").each(disableSelectedBranch);
-
disableSelectedProduct();
}
});
- $(document).on('change', "select[id^='branch']", disableSelectedBranch);
-
if(copyProjectID > 0 && copyType != 'previous')
{
$('#name').addClass('has-info')
@@ -167,7 +162,7 @@ function setParentProgram(parentProgram)
var productSelectHtml = data.allProducts;
var planSelectHtml = data.plans;
- $('#productsBox .row .col-sm-4 .input-group').each(function(index)
+ $('.productsBox .row .col-sm-4 .input-group').each(function(index)
{
var selectedProduct = $(this).find('[name^=products]').val();
var selectedBranch = $(this).find('[name^=branch]').val();
@@ -177,7 +172,7 @@ function setParentProgram(parentProgram)
$(this).find('[name^=products]').attr('name', 'products[' + index + ']').attr('id', 'products' + index).attr('data-branch', selectedBranch).attr('data-plan', selectedPlan);
$(this).find('[name^=products]').val(selectedProduct).chosen().change();
});
- $('#productsBox .row .col-sm-4:last').find('.input-group').append($('#productsBox .addProduct .input-group:first .input-group-addon').prop('outerHTML'));
+ $('.productsBox .row .col-sm-4:last').find('.input-group').append($('.productsBox .addProduct .input-group:first .input-group-addon').prop('outerHTML'));
}
if(parentProgram != 0)
@@ -198,13 +193,13 @@ function setParentProgram(parentProgram)
if(parentProgram != '0')
{
- $('#productsBox .addProduct .input-group:first').addClass('required');
- $('#productsBox .row .input-group:first').addClass('required');
+ $('.productsBox .addProduct .input-group:first').addClass('required');
+ $('.productsBox .row .input-group:first').addClass('required');
}
else
{
- $('#productsBox .addProduct .input-group').removeClass('required');
- $('#productsBox .row .input-group').removeClass('required');
+ $('.productsBox .addProduct .input-group').removeClass('required');
+ $('.productsBox .row .input-group').removeClass('required');
}
}
@@ -232,35 +227,35 @@ function addNewProduct(obj)
if($(obj).attr('checked'))
{
/* Hide product and plan dropdown controls. */
- $('#productsBox .row .col-sm-4').addClass('hidden');
- $('#productsBox .row .col-sm-4 .input-group').find('select').attr('disabled', true).trigger("chosen:updated");
- $('#plansBox').closest('tr').addClass('hidden');
- $('#plansBox .col-sm-4').find('select').attr('disabled', true).trigger("chosen:updated");
+ $('.newLine').addClass('hidden');
+ $('.productsBox .row').addClass('hidden');
+ $('.productsBox .row .input-group').find('select').attr('disabled', true).trigger("chosen:updated");
$('.division').addClass('hide');
/* Displays the input box for creating a product. */
+ $(obj).closest('td').attr('colspan', 1);
$("[name^='newProduct']").prop('checked', true);
$('#productName').removeAttr('disabled', true);
- $('#productsBox .addProduct').removeClass('hidden');
+ $('.productsBox .addProduct').removeClass('hidden');
$('#productTitle').html(productName);
}
else
{
/* Show product and product dropdown controls. */
- $('#productsBox .row .col-sm-4').removeClass('hidden');
- $('#productsBox .row .col-sm-4 .input-group').find('select').removeAttr('disabled').trigger("chosen:updated");
- $('#plansBox').closest('tr').removeClass('hidden');
- $('#plansBox .col-sm-4').find('select').removeAttr('disabled', true).trigger("chosen:updated");
+ $('.newLine').removeClass('hidden');
+ $('.productsBox .row').removeClass('hidden');
+ $('.productsBox .row .input-group').find('select').removeAttr('disabled').trigger("chosen:updated");
if($('#plansBox .col-sm-4').find('select').length > 1) $('.division').removeClass('hide');
/* Hide the input box for creating a product. */
+ $(obj).closest('td').attr('colspan', 3);
$("[name^='newProduct']").prop('checked', false);
$('#productName').attr('disabled', true);
- $('#productsBox .addProduct').addClass('hidden');
+ $('.productsBox .addProduct').addClass('hidden');
$('#productTitle').html(manageProducts);
}
- $('#productsBox div + .text-danger.help-text').remove();
+ $('.productsBox div + .text-danger.help-text').remove();
}
/**
@@ -295,7 +290,7 @@ function loadBranches(product)
$("#planDefault").remove();
var chosenProducts = [];
- $("#productsBox select[name^='products']").each(function()
+ $(".productsBox select[name^='products']").each(function()
{
var $product = $(product);
var productID = $(this).val();
@@ -311,111 +306,127 @@ function loadBranches(product)
(chosenProducts.length > 1 && model == 'waterfall') ? $('.division').removeClass('hide') : $('.division').addClass('hide');
- if($('#productsBox .row .input-group:last select:first').val() != 0)
+ /*
+ if($('.productsBox .row .input-group:last select:first').val() != 0)
{
- var length = $('#productsBox .row .input-group').size();
- var $html = $('#productsBox .row .col-sm-4:last').html().replace('required', '');
- $('#productsBox .row .col-sm-4:last').find('.input-group-addon').remove();
- $('#productsBox .row').append('
' + $html + '
');
- if($('#productsBox .row .input-group:last select').size() >= 2) $('#productsBox .row .input-group:last select:last').remove();
- $('#productsBox .row .input-group:last .chosen-container').remove();
- $('#productsBox .row .input-group:last select:first').attr('name', 'products[' + length + ']').attr('id', 'products' + length);
- $('#productsBox .row .input-group:last .chosen').chosen();
+ var length = $('.productsBox .row .input-group').size();
+ var $html = $('.productsBox .row .col-sm-4:last').html().replace('required', '');
+ $('.productsBox .row .col-sm-4:last').find('.input-group-addon').remove();
+ $('.productsBox .row').append('' + $html + '
');
+ if($('.productsBox .row .input-group:last select').size() >= 2) $('.productsBox .row .input-group:last select:last').remove();
+ $('.productsBox .row .input-group:last .chosen-container').remove();
+ $('.productsBox .row .input-group:last select:first').attr('name', 'products[' + length + ']').attr('id', 'products' + length);
+ $('.productsBox .row .input-group:last .chosen').chosen();
$('[data-toggle="popover"]').popover();
adjustProductBoxMargin();
}
+ */
- var $inputgroup = $(product).closest('.input-group');
- if($inputgroup.find('select').size() >= 2) $inputgroup.removeClass('has-branch').find('select:last').remove();
- if($inputgroup.find('.chosen-container').size() >= 2) $inputgroup.find('.chosen-container:last').remove();
-
- var index = $inputgroup.find('select:first').attr('id').replace('products' , '');
+ var $tableRow = $(product).closest('.table-row');
+ var index = $tableRow.find('select:first').attr('id').replace('products' , '');
var oldBranch = $(product).attr('data-branch') !== undefined ? $(product).attr('data-branch') : 0;
+ if($(product).val() != 0)
+ {
+ $(product).closest('tr').find('.newProduct').addClass('hidden')
+ }
+ else
+ {
+ $(product).closest('tr').find('.newProduct').removeClass('hidden')
+ }
+
+ if(!multiBranchProducts[$(product).val()])
+ {
+ $tableRow.find('.table-col:last select').val('').trigger('chosen:updated');
+ $tableRow.find('.table-col:last').addClass('hidden');
+ }
+
$.get(createLink('branch', 'ajaxGetBranches', "productID=" + $(product).val() + "&oldBranch=" + oldBranch + "¶m=active"), function(data)
{
if(data)
{
- $inputgroup.addClass('has-branch').append(data);
- $inputgroup.find('select:last').attr('name', 'branch[' + index + ']').attr('id', 'branch' + index).attr('onchange', "loadPlans('#products" + index + "', this.value)").chosen();
+ $tableRow.find("select[name^='branch']").replaceWith(data);
+ $tableRow.find('.table-col:last .chosen-container').remove();
+ $tableRow.find('.table-col:last').removeClass('hidden');
+ $tableRow.find("select[name^='branch']").attr('multiple', '').attr('name', 'branch[' + index + '][]').attr('id', 'branch' + index).attr('onchange', "loadPlans('#products" + index + "', this)").chosen();
- $inputgroup.find('select:last').each(disableSelectedBranch);
disableSelectedProduct();
}
- var branchID = $('#branch' + index).val();
- loadPlans(product, branchID);
+ var branch = $('#branch' + index);
+ loadPlans(product, branch);
});
-
- if(!multiBranchProducts[$(product).val()]) disableSelectedProduct();
}
/**
* Load plans.
*
* @param obj $product
- * @param int $branchID
+ * @param obj $branchID
* @access public
* @return void
*/
-function loadPlans(product, branchID)
+function loadPlans(product, branch)
{
- if($('#plansBox').size() == 0) return false;
-
var productID = $(product).val();
- var branchID = typeof(branchID) == 'undefined' ? 0 : branchID;
+ var branchID = $(branch).val() == null ? 0 : $(branch).val();
var planID = $(product).attr('data-plan') !== undefined ? $(product).attr('data-plan') : 0;
var index = $(product).attr('id').replace('products', '');
- $.get(createLink('product', 'ajaxGetPlans', "productID=" + productID + '&branch=0,' + branchID + '&planID=' + planID + '&fieldID&needCreate=&expired=unexpired,noclosed¶m=skipParent,multiple'), function(data)
+ $.get(createLink('product', 'ajaxGetPlans', "productID=" + productID + '&branch=' + branchID + '&planID=' + planID + '&fieldID&needCreate=&expired=unexpired,noclosed¶m=skipParent,multiple'), function(data)
{
if(data)
{
- if($("div#plan" + index).size() == 0) $("#plansBox .row").append('');
- $("div#plan" + index).html(data).find('select').attr('name', 'plans[' + productID + '][' + branchID + '][]').attr('id', 'plans' + productID).chosen();
-
- adjustPlanBoxMargin();
+ $("div#plan" + index).find("select[name^='plans']").replaceWith(data);
+ $("div#plan" + index).find('.chosen-container').remove();
+ $("div#plan" + index).find('select').attr('name', 'plans[' + productID + '][' + branchID + '][]').attr('id', 'plans' + productID).chosen();
}
});
}
/**
- * Adjust product box margin.
- *
+ * Add new line for link product.
+ *
+ * @param obj $obj
* @access public
* @return void
*/
-function adjustProductBoxMargin()
+function addNewLine(obj)
{
- var productRows = Math.ceil($('#productsBox > .row > .col-sm-4').length / 3);
- if(productRows > 1)
+ var newLine = $(obj).closest('tr').clone();
+ var index = 0;
+ $(".productsBox select[name^='products']").each(function()
{
- for(i = 1; i <= productRows - 1; i++)
- {
- $('#productsBox .row .col-sm-4:lt(' + (i * 3) + ')').css('margin-bottom', '10px');
- $('#productsBox .row .col-sm-4').eq(i * 3).css('padding-right', '6px');
- }
- }
+ var id = $(this).attr('id').replace('products' , '');
+
+ id = parseInt(id);
+ id ++;
+
+ index = id > index ? id : index;
+ })
+
+ newLine.find('.newProduct').remove();
+ newLine.find('.addProduct').remove();
+ newLine.addClass('newLine');
+ newLine.find('th').html('');
+ newLine.find('.removeLine').css('visibility', 'visible');
+ newLine.find('.chosen-container').remove();
+ newLine.find('.productsBox .table-col:last').addClass('hidden');
+ newLine.find("select[name^='products']").attr('name', 'products[' + index + ']').attr('id', 'products' + index).chosen();
+ newLine.find("select[name^='plans']").attr('name', 'plans[' + index + '][' + 0 + '][]').chosen();
+ newLine.find("div[id^='plan']").attr('id', 'plan' + index);
+
+ $(obj).closest('tr').after(newLine);
+ var product = newLine.find("select[name^='products']");
+ var branch = newLine.find("select[name^='branch']");
+ loadPlans(product, branch);
+ disableSelectedProduct();
}
-/**
- * Adjust plan box margin.
- *
- * @access public
- * @return void
- */
-function adjustPlanBoxMargin()
+function removeLine(obj)
{
- var planRows = Math.ceil($('#plansBox > .row > .col-sm-4').length / 3);
- if(planRows > 1)
- {
- for(j = 1; j <= planRows - 1; j++)
- {
- $('#plansBox .col-sm-4:lt(' + (j * 3) + ')').css('margin-bottom', '10px');
- $('#plansBox .col-sm-4').eq(j * 3).css('padding-right', '6px');
- }
- }
+ $(obj).closest('tr').remove();
}
/**
diff --git a/module/project/model.php b/module/project/model.php
index 5804db56cb..81b3bc3dd9 100644
--- a/module/project/model.php
+++ b/module/project/model.php
@@ -2404,24 +2404,29 @@ class projectModel extends model
$oldPlan = 0;
$branch = isset($branches[$i]) ? $branches[$i] : 0;
- if(isset($existedProducts[$productID][$branch])) continue;
+ if(!is_array($branch)) $branch = array($branch => $branch);
- if(isset($oldProjectProducts[$productID][$branch]))
+ foreach($branch as $branchID)
{
- $oldProjectProduct = $oldProjectProducts[$productID][$branch];
- if($this->app->rawMethod != 'edit') $oldPlan = $oldProjectProduct->plan;
+ if(isset($existedProducts[$productID][$branchID])) continue;
+
+ if(isset($oldProjectProducts[$productID][$branchID]))
+ {
+ $oldProjectProduct = $oldProjectProducts[$productID][$branchID];
+ if($this->app->rawMethod != 'edit') $oldPlan = $oldProjectProduct->plan;
+ }
+
+ $data = new stdclass();
+ $data->project = $projectID;
+ $data->product = $productID;
+ $data->branch = $branchID;
+ $data->plan = isset($plans[$productID][$branchID]) ? implode(',', $plans[$productID][$branchID]) : $oldPlan;
+ $data->plan = trim($data->plan, ',');
+ $data->plan = empty($data->plan) ? 0 : ",$data->plan,";
+
+ $this->dao->insert(TABLE_PROJECTPRODUCT)->data($data)->exec();
+ $existedProducts[$productID][$branchID] = true;
}
-
- $data = new stdclass();
- $data->project = $projectID;
- $data->product = $productID;
- $data->branch = $branch;
- $data->plan = isset($plans[$productID][$branch]) ? implode(',', $plans[$productID][$branch]) : $oldPlan;
- $data->plan = trim($data->plan, ',');
- $data->plan = empty($data->plan) ? 0 : ",$data->plan,";
-
- $this->dao->insert(TABLE_PROJECTPRODUCT)->data($data)->exec();
- $existedProducts[$productID][$branch] = true;
}
/* Delete the execution linked products that is not linked with the execution. */
diff --git a/module/project/view/create.html.php b/module/project/view/create.html.php
index f80f3bea14..5c1b77ab19 100755
--- a/module/project/view/create.html.php
+++ b/module/project/view/create.html.php
@@ -139,6 +139,49 @@
| |
+ | 关联产品和计划 |
+
+
+
+
+
+
+
+ product->branchName['branch'];?>
+
+
+
+
+
+
+
+
+
+ project->addProduct, '', "onchange=addNewProduct(this);");?>
+
+ |
+
+
| project->division;?> |
diff --git a/www/js/my.full.js b/www/js/my.full.js
index 30bf823463..24a60642db 100644
--- a/www/js/my.full.js
+++ b/www/js/my.full.js
@@ -1044,12 +1044,7 @@ function disableSelectedProduct()
$("select[id^='products']").each(function()
{
var selectedProduct = $(this).val();
- if(selectedProduct != 0 && $.inArray(selectedProduct, selectedVal) < 0 && !multiBranchProducts[selectedProduct]) selectedVal.push(selectedProduct);
- if(multiBranchProducts[selectedProduct])
- {
- var isDisabled = checkMultiProducts(this);
- if(isDisabled) selectedVal.push(selectedProduct);
- }
+ if(selectedProduct != 0 && $.inArray(selectedProduct, selectedVal) < 0) selectedVal.push(selectedProduct);
})
$("select[id^='products']").each(function()