Beispiel #1
0
func (this *BaseController) GetFormValues(itemD itemDef.ItemDef) map[string]interface{} {
	retMap := make(map[string]interface{})
	formValues := this.Input()
	beego.Debug("BaseController.GetFormValues from values: ", formValues)
	for k, _ := range formValues {
		if field, ok := itemD.GetField(k); ok {
			if v, fok := field.GetFormValue(this.GetString(field.Name)); fok {
				retMap[field.Name] = this.ReplaceSpecialValues(v)
			}
		}
	}
	return retMap
}
Beispiel #2
0
func ParseSqlError(err error, oEntityDef itemDef.ItemDef) (string, string) {
	errStr := err.Error()
	if strings.HasPrefix(errStr, SqlErrUniqueConstraint) {
		itemAndField := strings.TrimPrefix(errStr, SqlErrUniqueConstraint)
		lstStr := strings.Split(itemAndField, ".")
		if len(lstStr) < 2 {
			return stat.DuplicatedValue, itemAndField
		}
		field := strings.TrimSpace(lstStr[1])
		if v, ok := oEntityDef.GetField(field); ok {
			return stat.DuplicatedValue, v.Label
		}
		return stat.DuplicatedValue, itemAndField
	}
	beego.Error("ParseSqlError unknown error", errStr)
	return stat.UnKnownFailed, ""
}
Beispiel #3
0
func extendUserField(oItemDef itemDef.ItemDef, fieldName string) itemDef.ItemDef {
	userField, _ := oItemDef.GetField(fieldName)
	userField.Name = fieldName + s.Name
	userSnField, _ := oItemDef.GetField(fieldName)
	userSnField.Input = s.Hidden
	newFields := make([]itemDef.Field, 0)
	for _, field := range oItemDef.Fields {
		if field.Name == fieldName {
			newFields = append(newFields, userField)
			newFields = append(newFields, userSnField)
		} else {
			newFields = append(newFields, field)
		}
	}
	oItemDef.Fields = newFields
	return oItemDef
}
Beispiel #4
0
func (this *BaseController) GetExFormValues(itemD itemDef.ItemDef) (map[string]interface{}, map[string]interface{}) {
	retMap := make(map[string]interface{})
	exMap := make(map[string]interface{})
	formValues := this.Input()
	beego.Debug("BaseController.GetFormValues from values: ", formValues)
	for k, v := range formValues {
		if field, ok := itemD.GetField(k); ok {
			if fv, fok := field.GetFormValue(this.GetString(field.Name)); fok {
				retMap[field.Name] = this.ReplaceSpecialValues(fv)
			}
		} else {
			exMap[k] = v
		}
	}
	retMap[s.Creater] = this.GetCurUserSn()
	for _, field := range itemD.Fields {
		if strings.EqualFold(field.Model, s.Upload) {
			delete(retMap, field.Name)
		}
	}
	return retMap, exMap
}