编辑表格:解决选择单元属性值时误更新为待选表格数目的BUG;单列的复合属性编辑时,直接打开属性页面

This commit is contained in:
datagear 2019-02-03 11:34:19 +08:00
parent 806567eb61
commit 3e07532761
5 changed files with 165 additions and 34 deletions

View File

@ -631,11 +631,11 @@ public class SelectPersistenceOperation extends AbstractModelPersistenceOperatio
Property property, PropertyModelMapper<?> propertyModelMapper, int startRow, int count)
{
int propertyIndex = MU.getPropertyIndex(model, property);
Model pmodel = propertyModelMapper.getModel();
Model propertyModel = propertyModelMapper.getModel();
boolean canFetchPropertyColumnsOnly = false;
if (MU.isPrimitiveModel(pmodel))
if (MU.isPrimitiveModel(propertyModel))
canFetchPropertyColumnsOnly = true;
else
{
@ -680,8 +680,13 @@ public class SelectPersistenceOperation extends AbstractModelPersistenceOperatio
{
Object pv = property.get(obj);
// XXX 即使pv为null也不应该忽略因为是INNER JOIN查询
if (pv == null)
;
{
pv = propertyModel.newInstance();
PMU.setPropertyValueMappedByIf(model, obj, propertyModelMapper, pv);
propValueList.add(pv);
}
else if (pv instanceof Object[])
{
addArrayToList(propValueList, (Object[]) pv);

View File

@ -41,11 +41,23 @@ WebUtils.setPageId(request, editGridFormPageId);
po.currentCellIndexes = undefined;
po.currentPropertyIndexesMap = undefined;
po.superPropertySubmitHandler = po.propertySubmitHandler;
po.propertySubmitHandler = function(property, propertyModel, propValue)
{
po.superPropertySubmitHandler(property, propertyModel, propValue);
if(po.isSubmitWhenPropertySubmit)
po.form().modelform("submit");
};
po.superPropertyDataTableAjaxSuccess = po.propertyDataTableAjaxSuccess;
po.propertyDataTableAjaxSuccess = function(property, propertyConcreteModel, propertyValue, propertyValuePagingData)
{
po.superPropertyDataTableAjaxSuccess(property, propertyConcreteModel, propertyValue, propertyValuePagingData);
if(!$.model.isMultipleProperty(property))
return;
var singleRow = $.getDataTableRowIfSingle(po.currentCellIndexes);
//更新服务端数据行的多元属性值数目
@ -703,12 +715,29 @@ WebUtils.setPageId(request, gridPageId);
$cellNodes.removeClass("cell-edit-form");
$editFormCell.addClass("cell-edit-form");
var propertyCount = $.getPropertyCount(propertyIndexesMap);
var singlePropertyIndex = $.getPropertyNameIfSingle(propertyIndexesMap);
var isHideFormPage = false;
if(singlePropertyIndex != null)
{
var property = $.model.getProperty(po.editGridModel, parseInt(singlePropertyIndex));
isHideFormPage = $.model.isMultipleProperty(property);
if(!isHideFormPage)
{
var propertyValue = $.model.propertyValue(data, property.name);
var propertyModel = $.model.getPropertyModelByValue(property, propertyValue);
isHideFormPage = $.model.isCompositeModel(propertyModel);
}
}
po.editGridFormPage.data = data;
po.editGridFormPage.currentDataTable = editDataTable;
po.editGridFormPage.currentCellIndexes = indexes;
po.editGridFormPage.currentPropertyIndexesMap = propertyIndexesMap;
po.editGridFormPage.isSubmitWhenPropertySubmit = isHideFormPage;
var $formPage = po.editGridFormPage.element();
var $formPanel = po.editGridFormPage.element(".form-panel");
@ -721,12 +750,17 @@ WebUtils.setPageId(request, gridPageId);
if($cellValueWrappper.length == 0)
$editFormCell.wrapInner("<span class='value-wrapper'></span>");
$formPage.appendTo($editFormCell).show();
$formPage.appendTo($editFormCell);
if(isHideFormPage)
$formPage.hide();
else
$formPage.show();
var form = po.editGridFormPage.form();
//只有一个属性,隐藏标签,否则,显示标签
if(propertyCount == 1)
if(singlePropertyIndex != null)
{
$formPanel.css("min-width", $tableContainer.width()/3);
form.addClass("hide-form-label");
@ -744,6 +778,7 @@ WebUtils.setPageId(request, gridPageId);
renderProperty : function(property, propertyIndex)
{
var propertyIndexesMap = po.editGridFormPage.currentPropertyIndexesMap;
return (propertyIndexesMap[propertyIndex] != undefined);
},
submit : function()
@ -760,6 +795,7 @@ WebUtils.setPageId(request, gridPageId);
return false;
},
invalidHandler : (isHideFormPage ? undefined : function(){ $formPage.show(); }),
addSinglePropertyValue : function(property, propertyModel)
{
po.editGridFormPage.addSinglePropertyValue(property, propertyModel);
@ -802,10 +838,10 @@ WebUtils.setPageId(request, gridPageId);
filePropertyLabelValue : "<c:out value='${filePropertyLabelValue}' />"
});
if(propertyCount == 1 || focus)
if(singlePropertyIndex != null || focus)
{
//仅选中一个属性,激活焦点
$(":input:not([readonly]):visible:eq(0)", form).focus();
//激活第一个属性
form.modelform("activeProperty");
}
$formPanel.position({ my : "left top", at : "left bottom", of : $editFormCell, within : $table});
@ -1244,6 +1280,8 @@ WebUtils.setPageId(request, gridPageId);
//将表格中的编辑单元格、添加行置为已保存,删除标记为删除的行
po.clearEditGrid = function(editDataTable, modifiedCells, addRows, deleteRows, notDrawTable)
{
po.closeEditCellPanel(editDataTable);
var needDraw = false;
if(modifiedCells != null)

View File

@ -61,6 +61,9 @@ po.isClientPageData = undefined;
po.propertyDataTableAjaxSuccess = function(property, propertyModel, propertyValue, propertyValuePagingData)
{
if(!$.model.isMultipleProperty(property))
return;
var formPropertyValue = po.form().modelform("propValue", property.name);
if(formPropertyValue == null || $.model.isSizeOnlyCollection(formPropertyValue))
po.form().modelform("propValue", property.name, $.model.toSizeOnlyCollection(propertyValuePagingData.total));

View File

@ -95,6 +95,9 @@
//添加操作时对于NotNull特性如果又有AutoGenerated或者ValueGenerator特性则不需要required
validationRequiredAsAdd : false,
//可选,表单提交时验证失败回调函数
invalidHandler : function(event, validator){},
//可选,日期格式
dateFormat : "",
@ -354,6 +357,41 @@
$(".form-foot input[type='reset']", this.element).button("enable");
},
/**
* 激活属性
* 如果是输入框则设为焦点如果是新对话框则打开对话框
*/
activeProperty : function(propertyName)
{
if(this.options.readonly)
return false;
var properties = this.options.model.properties;
for(var i=0; i<properties.length; i++)
{
var property = properties[i];
var propertyWidget = this._propertyWidgets[property.name];
if(propertyWidget)
{
propertyWidget.active();
return true;
}
}
return false;
},
/**
* 提交表单
*/
submit : function()
{
this.element.submit();
},
/**
* 绘制
*/
@ -427,7 +465,8 @@
setValue : function(value)
{
this.value = value;
}
},
active : function(){}
});
//多元属性
@ -513,6 +552,11 @@
if(doSubmit)
form.submit();
};
validateOptions.invalidHandler = function(event, validator)
{
if(_this.options.invalidHandler)
_this.options.invalidHandler.call(_this.element, event, validator);
};
_this.element.validate(validateOptions);
@ -564,6 +608,13 @@
}
button.appendTo(valuediv).button();
propertyWidget.buttonElement = button[0];
propertyWidget.active = function()
{
$(this.buttonElement).focus().click();
};
},
/**
@ -579,23 +630,27 @@
var select=$.model.featureSelect(property);
var selectOptions=select.options;
var selectele=$("<select class='ui-widget ui-widget-content' />").attr("name", propName).appendTo(valuediv);
var selectElement=$("<select class='ui-widget ui-widget-content' />").attr("name", propName).appendTo(valuediv);
for(var i=0; i<selectOptions.length; i++)
{
$("<option />").attr("value", i).text($.model.text(selectOptions[i].label)).appendTo(selectele);
$("<option />").attr("value", i).text($.model.text(selectOptions[i].label)).appendTo(selectElement);
}
propertyWidget.selectele = selectele[0];
propertyWidget.selectElement = selectElement[0];
propertyWidget.getValue = function()
{
var optionIndex = parseInt($(this.selectele).val());
var optionIndex = parseInt($(this.selectElement).val());
return $.model.featureSelect(this.property).options[optionIndex].value;
};
propertyWidget.setValue = function(value)
{
$(this.selectele).val($.model.optionIndex($.model.featureSelect(this.property), value));
$(this.selectElement).val($.model.optionIndex($.model.featureSelect(this.property), value));
};
propertyWidget.active = function()
{
$(this.selectElement).focus();
};
this._addValidatorRequired(property, propName);
@ -750,6 +805,7 @@
propertyWidget.fileInputHidden = fileInputHidden[0];
propertyWidget.fileInputShow = fileInputShow[0];
propertyWidget.fileInputElement = fileInput[0];
propertyWidget.getValue = function()
{
@ -781,6 +837,10 @@
$(this.fileInfoDiv).empty();
}
};
propertyWidget.active = function()
{
$(this.fileInputElement).focus();
};
propertyWidget.setValue(propValue);
@ -797,7 +857,7 @@
var propertyModelType = $.model.getModelType(property.model);
var textinput;
var textElement;
var maxLengthFeature = $.model.featureMaxLength(property);
var maxLength = (maxLengthFeature ? maxLengthFeature.value : undefined);
@ -806,19 +866,19 @@
{
valuediv.addClass("textarea-value");
textinput = $("<textarea class='ui-widget ui-widget-content' />").attr("name", propName)
textElement = $("<textarea class='ui-widget ui-widget-content' />").attr("name", propName)
.text((propValue == undefined || propValue == null) ? "" : propValue);
}
else
{
valuediv.addClass("text-value");
textinput = $("<input type='text' class='ui-widget ui-widget-content' />").attr("name", propName)
textElement = $("<input type='text' class='ui-widget ui-widget-content' />").attr("name", propName)
.val((propValue == undefined || propValue == null) ? "" : propValue);
}
if(options.readonly)
textinput.attr("readonly", true);
textElement.attr("readonly", true);
var dateFormat = "";
@ -832,20 +892,24 @@
dateFormat = options.timeFormat;
}
textinput.appendTo(valuediv);
textElement.appendTo(valuediv);
if(dateFormat)
textinput.after("<div class='input-desc input-desc-date ui-state-disabled'>"+dateFormat+"</div>");
textElement.after("<div class='input-desc input-desc-date ui-state-disabled'>"+dateFormat+"</div>");
propertyWidget.textinput = textinput[0];
propertyWidget.textElement = textElement[0];
propertyWidget.getValue = function()
{
return $(this.textinput).val();
return $(this.textElement).val();
};
propertyWidget.setValue = function(value)
{
$(this.textinput).val(value);
$(this.textElement).val(value);
};
propertyWidget.active = function()
{
$(this.textElement).focus();
};
this._addValidatorRequired(property, propName);
@ -868,18 +932,18 @@
var textinput=$("<input type='text' class='ui-widget ui-widget-content' />").attr("name", textinputName).attr("readonly", true)
.val($.model.tokenProperty(property, propValue)).appendTo(valuediv);
var button=$("<input type='button' />").attr("__propertyName", propName);
var buttonElement=$("<input type='button' />").attr("__propertyName", propName);
//只读
if(options.readonly)
{
button.attr("value", options.labels.view);
buttonElement.attr("value", options.labels.view);
if(!propValue)
button.attr("disabled", true);
buttonElement.attr("disabled", true);
else
{
button.click(function()
buttonElement.click(function()
{
var myPropertyName = $(this).attr("__propertyName");
var myPropertyInfo = _this._getPropertyInfo(myPropertyName);
@ -889,7 +953,7 @@
});
}
button.attr("value", _this.options.labels.view).appendTo(valuediv).button();
buttonElement.attr("value", _this.options.labels.view).appendTo(valuediv).button();
}
//可编辑
else
@ -908,13 +972,13 @@
});
var actionGroup = $("<div class='property-action-group' />");
button.appendTo(actionGroup);
buttonElement.appendTo(actionGroup);
var moreActionSelect = $("<select />").appendTo(actionGroup);
//私有属性
if($.model.isPrivatePropertyModel(model, property, property.model))
{
button.attr("value", options.labels.edit).click(function()
buttonElement.attr("value", options.labels.edit).click(function()
{
var myPropertyName = $(this).attr("__propertyName");
var myPropertyInfo = _this._getPropertyInfo(myPropertyName);
@ -935,7 +999,7 @@
//公有字段
else
{
button.attr("value", options.labels.select).click(function()
buttonElement.attr("value", options.labels.select).click(function()
{
var myPropertyName = $(this).attr("__propertyName");
var myPropertyInfo = _this._getPropertyInfo(myPropertyName);
@ -972,13 +1036,17 @@
}
propertyWidget.textinput = textinput[0];
propertyWidget.button = button[0];
propertyWidget.buttonElement = buttonElement[0];
propertyWidget.setValue = function(value)
{
$(this.textinput).val($.model.tokenProperty(this.property, value));
this.value = value;
}
};
propertyWidget.active = function()
{
$(this.buttonElement).focus().click();
};
this._addValidatorRequired(property, textinputName);
},

View File

@ -1360,6 +1360,23 @@
return propertyCount;
},
/**
* 如果对象仅包含一个属性返回属性名否则返回null
*/
getPropertyNameIfSingle : function(obj)
{
if(!obj)
return null;
var keys = Object.keys(obj);
var length = keys.length;
if(length != 1)
return null;
return keys[0];
},
/**
* 判断两个对象是否深度相等
*/