module_shop_act_get_attribute_values.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package modules
  2. import (
  3. "html"
  4. "golang-fave/engine/wrapper"
  5. "golang-fave/utils"
  6. )
  7. func (this *Modules) RegisterAction_ShopGetAttributeValues() *Action {
  8. return this.newAction(AInfo{
  9. WantDB: true,
  10. Mount: "shop-get-attribute-values",
  11. WantAdmin: true,
  12. }, func(wrap *wrapper.Wrapper) {
  13. pf_id := utils.Trim(wrap.R.FormValue("id"))
  14. if !utils.IsNumeric(pf_id) {
  15. wrap.MsgError(`Inner system error`)
  16. return
  17. }
  18. options := ``
  19. rows, err := wrap.DB.Query(
  20. `SELECT
  21. id,
  22. name
  23. FROM
  24. shop_filters_values
  25. WHERE
  26. filter_id = ?
  27. ORDER BY
  28. name ASC
  29. ;`,
  30. utils.StrToInt(pf_id),
  31. )
  32. if err == nil {
  33. defer rows.Close()
  34. values := make([]string, 2)
  35. scan := make([]interface{}, len(values))
  36. for i := range values {
  37. scan[i] = &values[i]
  38. }
  39. for rows.Next() {
  40. err = rows.Scan(scan...)
  41. if *wrap.LogCpError(&err) == nil {
  42. options += `<option value="` + html.EscapeString(string(values[0])) + `">` + html.EscapeString(utils.JavaScriptVarValue(string(values[1]))) + `</option>`
  43. }
  44. }
  45. }
  46. wrap.Write(`if($('#prod_attr_` + pf_id + `').length > 0) {`)
  47. wrap.Write(`$('#prod_attr_` + pf_id + ` select').prop('disabled', false).prop('multiple', true);`)
  48. wrap.Write(`$('#prod_attr_` + pf_id + ` select').html('` + options + `');`)
  49. wrap.Write(`$('#prod_attr_` + pf_id + ` select').selectpicker({});`)
  50. wrap.Write(`$('#prod_attr_` + pf_id + ` button').prop('disabled', false);`)
  51. wrap.Write(`}`)
  52. })
  53. }