Example #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
}
Example #2
0
func makeFields(oItemDef itemDef.ItemDef, names []string) itemDef.ItemDef {
	fields := make([]itemDef.Field, len(names))

	fieldMap := oItemDef.GetFieldMap()
	for idx, name := range names {
		if field, ok := fieldMap[name]; ok {
			fields[idx] = field
		} else {
			beego.Error("Field not found", name, idx)
		}
	}
	oItemDef.Fields = fields
	return oItemDef
}
Example #3
0
func (this *BaseController) GetQueryParamFromJsonMap(requestMap map[string]interface{}, oItemDef itemDef.ItemDef) map[string]interface{} {
	queryParams := make(t.Params, 0)
	fieldMap := oItemDef.GetFieldMap()
	for k, v := range requestMap {
		if field, ok := fieldMap[k]; ok {
			if fv, fok := field.GetCheckedValue(v); fok {
				queryParams[k] = fv
			} else {
				beego.Error(fmt.Sprintf("Check param[%s]value %v error", k, v))
			}
		} else {
			beego.Error(fmt.Sprintf("Check param[%s]value %v error no such field", k, v))
		}
	}
	return queryParams
}
Example #4
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, ""
}
Example #5
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
}
Example #6
0
func transList(oItemDef itemDef.ItemDef, resultMaps []map[string]interface{}) []map[string]interface{} {
	if len(resultMaps) < 0 {
		return resultMaps
	}
	retList := make([]map[string]interface{}, len(resultMaps))
	neetTransMap := oItemDef.GetNeedTrans()
	for idx, oldMap := range resultMaps {
		var retMap = make(map[string]interface{}, len(oldMap))
		for key, value := range oldMap {
			if _, ok := neetTransMap[key]; ok {
				retMap[key] = lang.GetLabel(value.(string))
			} else {
				retMap[key] = value
			}
		}
		retList[idx] = retMap
	}
	return retList
}
Example #7
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
}