module_shop.go 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. package modules
  2. import (
  3. "html"
  4. "net/http"
  5. "strings"
  6. "golang-fave/assets"
  7. "golang-fave/consts"
  8. "golang-fave/engine/builder"
  9. "golang-fave/engine/fetdata"
  10. "golang-fave/engine/sqlw"
  11. "golang-fave/engine/wrapper"
  12. "golang-fave/utils"
  13. )
  14. func (this *Modules) shop_GetCurrencySelectOptions(wrap *wrapper.Wrapper, id int) string {
  15. result := ``
  16. rows, err := wrap.DB.Query(
  17. `SELECT
  18. id,
  19. code
  20. FROM
  21. shop_currencies
  22. ORDER BY
  23. id ASC
  24. ;`,
  25. )
  26. if err == nil {
  27. defer rows.Close()
  28. values := make([]string, 2)
  29. scan := make([]interface{}, len(values))
  30. for i := range values {
  31. scan[i] = &values[i]
  32. }
  33. idStr := utils.IntToStr(id)
  34. for rows.Next() {
  35. err = rows.Scan(scan...)
  36. if err == nil {
  37. selected := ""
  38. if string(values[0]) == idStr {
  39. selected = " selected"
  40. }
  41. result += `<option title="` + html.EscapeString(string(values[1])) + `" value="` + html.EscapeString(string(values[0])) + `"` + selected + `>` + html.EscapeString(string(values[1])) + `</option>`
  42. }
  43. }
  44. }
  45. return result
  46. }
  47. func (this *Modules) shop_GetProductValuesInputs(wrap *wrapper.Wrapper, product_id int) string {
  48. result := ``
  49. rows, err := wrap.DB.Query(
  50. `SELECT
  51. shop_filters.id,
  52. shop_filters.name,
  53. shop_filters_values.id,
  54. shop_filters_values.name,
  55. IF(shop_filter_product_values.filter_value_id > 0, 1, 0) as selected
  56. FROM
  57. shop_filters
  58. LEFT JOIN shop_filters_values ON shop_filters_values.filter_id = shop_filters.id
  59. LEFT JOIN shop_filter_product_values ON shop_filter_product_values.filter_value_id = shop_filters_values.id
  60. LEFT JOIN (
  61. SELECT
  62. shop_filters_values.filter_id,
  63. shop_filter_product_values.product_id
  64. FROM
  65. shop_filter_product_values
  66. LEFT JOIN shop_filters_values ON shop_filters_values.id = shop_filter_product_values.filter_value_id
  67. WHERE
  68. shop_filter_product_values.product_id = ` + utils.IntToStr(product_id) + `
  69. GROUP BY
  70. shop_filters_values.filter_id
  71. ) as filter_used ON filter_used.filter_id = shop_filters.id
  72. WHERE
  73. (
  74. shop_filter_product_values.product_id = ` + utils.IntToStr(product_id) + ` OR
  75. shop_filter_product_values.product_id IS NULL
  76. ) AND
  77. filter_used.filter_id IS NOT NULL
  78. ORDER BY
  79. shop_filters.name ASC,
  80. shop_filters_values.name ASC
  81. ;`,
  82. )
  83. filter_ids := []int{}
  84. filter_names := map[int]string{}
  85. filter_values := map[int][]string{}
  86. if err == nil {
  87. defer rows.Close()
  88. values := make([]string, 5)
  89. scan := make([]interface{}, len(values))
  90. for i := range values {
  91. scan[i] = &values[i]
  92. }
  93. for rows.Next() {
  94. err = rows.Scan(scan...)
  95. if err == nil {
  96. filter_id := utils.StrToInt(string(values[0]))
  97. if !utils.InArrayInt(filter_ids, filter_id) {
  98. filter_ids = append(filter_ids, filter_id)
  99. }
  100. filter_names[filter_id] = html.EscapeString(string(values[1]))
  101. selected := ``
  102. if utils.StrToInt(string(values[4])) == 1 {
  103. selected = ` selected`
  104. }
  105. filter_values[filter_id] = append(filter_values[filter_id], `<option value="`+html.EscapeString(string(values[2]))+`"`+selected+`>`+html.EscapeString(string(values[3]))+`</option>`)
  106. }
  107. }
  108. }
  109. for _, filter_id := range filter_ids {
  110. result += `<div class="form-group" id="prod_attr_` + utils.IntToStr(filter_id) + `">` +
  111. `<div><b>` + filter_names[filter_id] + `</b></div>` +
  112. `<div class="position-relative">` +
  113. `<select class="selectpicker form-control" name="value.` + utils.IntToStr(filter_id) + `" autocomplete="off" required multiple>` +
  114. strings.Join(filter_values[filter_id], "") +
  115. `</select>` +
  116. `<button type="button" class="btn btn-danger btn-dynamic-remove" onclick="fave.ShopProductsRemove(this);">&times;</button>` +
  117. `</div>` +
  118. `</div>`
  119. }
  120. return result
  121. }
  122. func (this *Modules) shop_GetFilterValuesInputs(wrap *wrapper.Wrapper, filter_id int) string {
  123. result := ``
  124. rows, err := wrap.DB.Query(
  125. `SELECT
  126. id,
  127. name
  128. FROM
  129. shop_filters_values
  130. WHERE
  131. filter_id = ?
  132. ORDER BY
  133. name ASC
  134. ;`,
  135. filter_id,
  136. )
  137. if err == nil {
  138. defer rows.Close()
  139. values := make([]string, 2)
  140. scan := make([]interface{}, len(values))
  141. for i := range values {
  142. scan[i] = &values[i]
  143. }
  144. for rows.Next() {
  145. err = rows.Scan(scan...)
  146. if err == nil {
  147. result += `<div class="form-group position-relative"><input class="form-control" type="text" name="value.` + html.EscapeString(string(values[0])) + `" value="` + html.EscapeString(string(values[1])) + `" placeholder="" autocomplete="off" required><button type="button" class="btn btn-danger btn-dynamic-remove" onclick="fave.ShopAttributesRemove(this);">&times;</button></div>`
  148. }
  149. }
  150. }
  151. return result
  152. }
  153. func (this *Modules) shop_GetAllAttributesSelectOptions(wrap *wrapper.Wrapper) string {
  154. result := ``
  155. rows, err := wrap.DB.Query(
  156. `SELECT
  157. id,
  158. name,
  159. filter
  160. FROM
  161. shop_filters
  162. ORDER BY
  163. name ASC
  164. ;`,
  165. )
  166. result += `<option title="&mdash;" value="0">&mdash;</option>`
  167. if err == nil {
  168. defer rows.Close()
  169. values := make([]string, 3)
  170. scan := make([]interface{}, len(values))
  171. for i := range values {
  172. scan[i] = &values[i]
  173. }
  174. for rows.Next() {
  175. err = rows.Scan(scan...)
  176. if err == nil {
  177. result += `<option title="` + html.EscapeString(string(values[1])) + `" value="` + html.EscapeString(string(values[0])) + `">` + html.EscapeString(string(values[1])) + `</option>`
  178. }
  179. }
  180. }
  181. return result
  182. }
  183. func (this *Modules) shop_GetAllCurrencies(wrap *wrapper.Wrapper) map[int]string {
  184. result := map[int]string{}
  185. rows, err := wrap.DB.Query(
  186. `SELECT
  187. id,
  188. code
  189. FROM
  190. shop_currencies
  191. ORDER BY
  192. id ASC
  193. ;`,
  194. )
  195. if err == nil {
  196. defer rows.Close()
  197. values := make([]string, 2)
  198. scan := make([]interface{}, len(values))
  199. for i := range values {
  200. scan[i] = &values[i]
  201. }
  202. for rows.Next() {
  203. err = rows.Scan(scan...)
  204. if err == nil {
  205. result[utils.StrToInt(string(values[0]))] = html.EscapeString(string(values[1]))
  206. }
  207. }
  208. }
  209. return result
  210. }
  211. func (this *Modules) shop_GetAllProductImages(wrap *wrapper.Wrapper, product_id int) string {
  212. result := ``
  213. rows, err := wrap.DB.Query(
  214. `SELECT
  215. product_id,
  216. filename
  217. FROM
  218. shop_product_images
  219. WHERE
  220. product_id = ?
  221. ;`,
  222. product_id,
  223. )
  224. if err == nil {
  225. defer rows.Close()
  226. values := make([]string, 2)
  227. scan := make([]interface{}, len(values))
  228. for i := range values {
  229. scan[i] = &values[i]
  230. }
  231. for rows.Next() {
  232. err = rows.Scan(scan...)
  233. if err == nil {
  234. result += `<div class="attached-img"><a href="/products/images/` + html.EscapeString(string(values[0])) + `/` + html.EscapeString(string(values[1])) + `" title="` + html.EscapeString(string(values[1])) + `" target="_blank"><img src="/products/images/` + string(values[0]) + `/thumb-0-` + string(values[1]) + `" /></a>, <a href="javascript:fave.ShopProductsDeleteImage(this, ` + html.EscapeString(string(values[0])) + `, '` + html.EscapeString(string(values[1])) + `');">Delete</a></div>`
  235. }
  236. }
  237. }
  238. return result
  239. }
  240. func (this *Modules) RegisterModule_Shop() *Module {
  241. return this.newModule(MInfo{
  242. WantDB: true,
  243. Mount: "shop",
  244. Name: "Shop",
  245. Order: 2,
  246. System: false,
  247. Icon: assets.SysSvgIconList,
  248. Sub: &[]MISub{
  249. {Mount: "default", Name: "List of products", Show: true, Icon: assets.SysSvgIconList},
  250. {Mount: "add", Name: "Add new product", Show: true, Icon: assets.SysSvgIconPlus},
  251. {Mount: "modify", Name: "Modify product", Show: false},
  252. {Sep: true, Show: true},
  253. {Mount: "categories", Name: "List of categories", Show: true, Icon: assets.SysSvgIconList},
  254. {Mount: "categories-add", Name: "Add new category", Show: true, Icon: assets.SysSvgIconPlus},
  255. {Mount: "categories-modify", Name: "Modify category", Show: false},
  256. {Sep: true, Show: true},
  257. {Mount: "attributes", Name: "List of attributes", Show: true, Icon: assets.SysSvgIconList},
  258. {Mount: "attributes-add", Name: "Add new attribute", Show: true, Icon: assets.SysSvgIconPlus},
  259. {Mount: "attributes-modify", Name: "Modify attribute", Show: false},
  260. {Sep: true, Show: true},
  261. {Mount: "currencies", Name: "List of currencies", Show: true, Icon: assets.SysSvgIconList},
  262. {Mount: "currencies-add", Name: "Add new currency", Show: true, Icon: assets.SysSvgIconPlus},
  263. {Mount: "currencies-modify", Name: "Modify currency", Show: false},
  264. },
  265. }, func(wrap *wrapper.Wrapper) {
  266. if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
  267. // Shop category
  268. row := &utils.MySql_shop_category{}
  269. rou := &utils.MySql_user{}
  270. err := wrap.DB.QueryRow(`
  271. SELECT
  272. main.id,
  273. main.user,
  274. main.name,
  275. main.alias,
  276. main.lft,
  277. main.rgt,
  278. main.depth,
  279. parent.id AS parent_id,
  280. users.id,
  281. users.first_name,
  282. users.last_name,
  283. users.email,
  284. users.admin,
  285. users.active
  286. FROM
  287. (
  288. SELECT
  289. node.id,
  290. node.user,
  291. node.name,
  292. node.alias,
  293. node.lft,
  294. node.rgt,
  295. (COUNT(parent.id) - 1) AS depth
  296. FROM
  297. shop_cats AS node,
  298. shop_cats AS parent
  299. WHERE
  300. node.lft BETWEEN parent.lft AND parent.rgt
  301. GROUP BY
  302. node.id
  303. ORDER BY
  304. node.lft ASC
  305. ) AS main
  306. LEFT JOIN (
  307. SELECT
  308. node.id,
  309. node.user,
  310. node.name,
  311. node.alias,
  312. node.lft,
  313. node.rgt,
  314. (COUNT(parent.id) - 0) AS depth
  315. FROM
  316. shop_cats AS node,
  317. shop_cats AS parent
  318. WHERE
  319. node.lft BETWEEN parent.lft AND parent.rgt
  320. GROUP BY
  321. node.id
  322. ORDER BY
  323. node.lft ASC
  324. ) AS parent ON
  325. parent.depth = main.depth AND
  326. main.lft > parent.lft AND
  327. main.rgt < parent.rgt
  328. LEFT JOIN users ON users.id = main.user
  329. WHERE
  330. main.id > 1 AND
  331. main.alias = ?
  332. ORDER BY
  333. main.lft ASC
  334. ;`,
  335. wrap.UrlArgs[2],
  336. ).Scan(
  337. &row.A_id,
  338. &row.A_user,
  339. &row.A_name,
  340. &row.A_alias,
  341. &row.A_lft,
  342. &row.A_rgt,
  343. &row.A_depth,
  344. &row.A_parent,
  345. &rou.A_id,
  346. &rou.A_first_name,
  347. &rou.A_last_name,
  348. &rou.A_email,
  349. &rou.A_admin,
  350. &rou.A_active,
  351. )
  352. if err != nil && err != wrapper.ErrNoRows {
  353. // System error 500
  354. utils.SystemErrorPageEngine(wrap.W, err)
  355. return
  356. } else if err == wrapper.ErrNoRows {
  357. // User error 404 page
  358. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  359. return
  360. }
  361. // Fix url
  362. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  363. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  364. return
  365. }
  366. // Render template
  367. wrap.RenderFrontEnd("shop-category", fetdata.New(wrap, false, row, rou), http.StatusOK)
  368. return
  369. } else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] != "" {
  370. // Shop product
  371. row := &utils.MySql_shop_product{}
  372. rou := &utils.MySql_user{}
  373. err := wrap.DB.QueryRow(`
  374. SELECT
  375. shop_products.id,
  376. shop_products.user,
  377. shop_products.currency,
  378. shop_products.price,
  379. shop_products.name,
  380. shop_products.alias,
  381. shop_products.vendor,
  382. shop_products.quantity,
  383. shop_products.category,
  384. shop_products.briefly,
  385. shop_products.content,
  386. UNIX_TIMESTAMP(shop_products.datetime) as datetime,
  387. shop_products.active,
  388. users.id,
  389. users.first_name,
  390. users.last_name,
  391. users.email,
  392. users.admin,
  393. users.active
  394. FROM
  395. shop_products
  396. LEFT JOIN users ON users.id = shop_products.user
  397. WHERE
  398. shop_products.active = 1 and
  399. shop_products.alias = ?
  400. LIMIT 1;`,
  401. wrap.UrlArgs[1],
  402. ).Scan(
  403. &row.A_id,
  404. &row.A_user,
  405. &row.A_currency,
  406. &row.A_price,
  407. &row.A_name,
  408. &row.A_alias,
  409. &row.A_vendor,
  410. &row.A_quantity,
  411. &row.A_category,
  412. &row.A_briefly,
  413. &row.A_content,
  414. &row.A_datetime,
  415. &row.A_active,
  416. &rou.A_id,
  417. &rou.A_first_name,
  418. &rou.A_last_name,
  419. &rou.A_email,
  420. &rou.A_admin,
  421. &rou.A_active,
  422. )
  423. if err != nil && err != wrapper.ErrNoRows {
  424. // System error 500
  425. utils.SystemErrorPageEngine(wrap.W, err)
  426. return
  427. } else if err == wrapper.ErrNoRows {
  428. // User error 404 page
  429. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  430. return
  431. }
  432. // Fix url
  433. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  434. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  435. return
  436. }
  437. // Render template
  438. wrap.RenderFrontEnd("shop-product", fetdata.New(wrap, false, row, rou), http.StatusOK)
  439. return
  440. } else if len(wrap.UrlArgs) == 1 && wrap.UrlArgs[0] == "shop" {
  441. // Shop
  442. // Fix url
  443. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  444. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  445. return
  446. }
  447. // Render template
  448. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  449. return
  450. } else if (*wrap.Config).Engine.MainModule == 2 {
  451. // Render template
  452. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  453. return
  454. }
  455. // User error 404 page
  456. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  457. }, func(wrap *wrapper.Wrapper) (string, string, string) {
  458. content := ""
  459. sidebar := ""
  460. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
  461. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  462. {Name: "List of products"},
  463. })
  464. // Load currencies
  465. currencies := this.shop_GetAllCurrencies(wrap)
  466. content += builder.DataTable(
  467. wrap,
  468. "shop_products",
  469. "id",
  470. "DESC",
  471. &[]builder.DataTableRow{
  472. {
  473. DBField: "id",
  474. },
  475. {
  476. DBField: "name",
  477. NameInTable: "Product / URL",
  478. CallBack: func(values *[]string) string {
  479. name := `<a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  480. alias := html.EscapeString((*values)[2])
  481. return `<div>` + name + `</div><div><small>/shop/` + alias + `/</small></div>`
  482. },
  483. },
  484. {
  485. DBField: "alias",
  486. },
  487. {
  488. DBField: "currency",
  489. },
  490. {
  491. DBField: "price",
  492. NameInTable: "Price",
  493. Classes: "d-none d-md-table-cell",
  494. CallBack: func(values *[]string) string {
  495. return `<div>` + utils.Float64ToStr(utils.StrToFloat64((*values)[4])) + `</div>` +
  496. `<div><small>` + currencies[utils.StrToInt((*values)[3])] + `</small></div>`
  497. },
  498. },
  499. {
  500. DBField: "datetime",
  501. DBExp: "UNIX_TIMESTAMP(`datetime`)",
  502. NameInTable: "Date / Time",
  503. Classes: "d-none d-lg-table-cell",
  504. CallBack: func(values *[]string) string {
  505. t := int64(utils.StrToInt((*values)[5]))
  506. return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
  507. `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
  508. },
  509. },
  510. {
  511. DBField: "active",
  512. NameInTable: "Active",
  513. Classes: "d-none d-sm-table-cell",
  514. CallBack: func(values *[]string) string {
  515. return builder.CheckBox(utils.StrToInt((*values)[6]))
  516. },
  517. },
  518. },
  519. func(values *[]string) string {
  520. return builder.DataTableAction(&[]builder.DataTableActionRow{
  521. {
  522. Icon: assets.SysSvgIconView,
  523. Href: `/shop/` + (*values)[2] + `/`,
  524. Hint: "View",
  525. Target: "_blank",
  526. },
  527. {
  528. Icon: assets.SysSvgIconEdit,
  529. Href: "/cp/" + wrap.CurrModule + "/modify/" + (*values)[0] + "/",
  530. Hint: "Edit",
  531. },
  532. {
  533. Icon: assets.SysSvgIconRemove,
  534. Href: "javascript:fave.ActionDataTableDelete(this,'shop-delete','" +
  535. (*values)[0] + "','Are you sure want to delete product?');",
  536. Hint: "Delete",
  537. Classes: "delete",
  538. },
  539. })
  540. },
  541. "/cp/"+wrap.CurrModule+"/",
  542. nil,
  543. nil,
  544. true,
  545. )
  546. } else if wrap.CurrSubModule == "categories" {
  547. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  548. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  549. {Name: "List of categories"},
  550. })
  551. content += builder.DataTable(
  552. wrap,
  553. "shop_cats",
  554. "id",
  555. "ASC",
  556. &[]builder.DataTableRow{
  557. {
  558. DBField: "id",
  559. },
  560. {
  561. DBField: "user",
  562. },
  563. {
  564. DBField: "name",
  565. NameInTable: "Category",
  566. CallBack: func(values *[]string) string {
  567. depth := utils.StrToInt((*values)[4]) - 1
  568. if depth < 0 {
  569. depth = 0
  570. }
  571. sub := strings.Repeat("&mdash; ", depth)
  572. name := `<a href="/cp/` + wrap.CurrModule + `/categories-modify/` + (*values)[0] + `/">` + sub + html.EscapeString((*values)[2]) + `</a>`
  573. return `<div>` + name + `</div>`
  574. },
  575. },
  576. {
  577. DBField: "alias",
  578. },
  579. {
  580. DBField: "depth",
  581. },
  582. },
  583. func(values *[]string) string {
  584. return builder.DataTableAction(&[]builder.DataTableActionRow{
  585. {
  586. Icon: assets.SysSvgIconView,
  587. Href: `/shop/category/` + (*values)[3] + `/`,
  588. Hint: "View",
  589. Target: "_blank",
  590. },
  591. {
  592. Icon: assets.SysSvgIconEdit,
  593. Href: "/cp/" + wrap.CurrModule + "/categories-modify/" + (*values)[0] + "/",
  594. Hint: "Edit",
  595. },
  596. {
  597. Icon: assets.SysSvgIconRemove,
  598. Href: "javascript:fave.ActionDataTableDelete(this,'shop-categories-delete','" +
  599. (*values)[0] + "','Are you sure want to delete category?');",
  600. Hint: "Delete",
  601. Classes: "delete",
  602. },
  603. })
  604. },
  605. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  606. nil,
  607. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  608. return wrap.DB.Query(
  609. `SELECT
  610. node.id,
  611. node.user,
  612. node.name,
  613. node.alias,
  614. (COUNT(parent.id) - 1) AS depth
  615. FROM
  616. shop_cats AS node,
  617. shop_cats AS parent
  618. WHERE
  619. node.lft BETWEEN parent.lft AND parent.rgt AND
  620. node.id > 1
  621. GROUP BY
  622. node.id
  623. ORDER BY
  624. node.lft ASC
  625. ;`,
  626. )
  627. },
  628. false,
  629. )
  630. } else if wrap.CurrSubModule == "attributes" {
  631. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  632. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  633. {Name: "List of attributes"},
  634. })
  635. content += builder.DataTable(
  636. wrap,
  637. "shop_filters",
  638. "id",
  639. "DESC",
  640. &[]builder.DataTableRow{
  641. {
  642. DBField: "id",
  643. },
  644. {
  645. DBField: "name",
  646. NameInTable: "Name",
  647. CallBack: func(values *[]string) string {
  648. name := `<a href="/cp/` + wrap.CurrModule + `/attributes-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  649. return `<div>` + name + `</div><div><small>` + html.EscapeString((*values)[2]) + `</small></div>`
  650. },
  651. },
  652. {
  653. DBField: "filter",
  654. },
  655. },
  656. func(values *[]string) string {
  657. return builder.DataTableAction(&[]builder.DataTableActionRow{
  658. {
  659. Icon: assets.SysSvgIconEdit,
  660. Href: "/cp/" + wrap.CurrModule + "/attributes-modify/" + (*values)[0] + "/",
  661. Hint: "Edit",
  662. },
  663. {
  664. Icon: assets.SysSvgIconRemove,
  665. Href: "javascript:fave.ActionDataTableDelete(this,'shop-attributes-delete','" +
  666. (*values)[0] + "','Are you sure want to delete attribute?');",
  667. Hint: "Delete",
  668. Classes: "delete",
  669. },
  670. })
  671. },
  672. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  673. nil,
  674. nil,
  675. true,
  676. )
  677. } else if wrap.CurrSubModule == "currencies" {
  678. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  679. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  680. {Name: "List of currencies"},
  681. })
  682. content += builder.DataTable(
  683. wrap,
  684. "shop_currencies",
  685. "id",
  686. "DESC",
  687. &[]builder.DataTableRow{
  688. {
  689. DBField: "id",
  690. },
  691. {
  692. DBField: "name",
  693. NameInTable: "Name",
  694. CallBack: func(values *[]string) string {
  695. name := `<a href="/cp/` + wrap.CurrModule + `/currencies-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` (` + (*values)[3] + `, ` + (*values)[4] + `)</a>`
  696. return `<div>` + name + `</div>`
  697. },
  698. },
  699. {
  700. DBField: "coefficient",
  701. NameInTable: "Coefficient",
  702. Classes: "d-none d-md-table-cell",
  703. CallBack: func(values *[]string) string {
  704. return utils.Float64ToStrF(utils.StrToFloat64((*values)[2]), "%.4f")
  705. },
  706. },
  707. {
  708. DBField: "code",
  709. },
  710. {
  711. DBField: "symbol",
  712. },
  713. },
  714. func(values *[]string) string {
  715. return builder.DataTableAction(&[]builder.DataTableActionRow{
  716. {
  717. Icon: assets.SysSvgIconEdit,
  718. Href: "/cp/" + wrap.CurrModule + "/currencies-modify/" + (*values)[0] + "/",
  719. Hint: "Edit",
  720. },
  721. {
  722. Icon: assets.SysSvgIconRemove,
  723. Href: "javascript:fave.ActionDataTableDelete(this,'shop-currencies-delete','" +
  724. (*values)[0] + "','Are you sure want to delete currency?');",
  725. Hint: "Delete",
  726. Classes: "delete",
  727. },
  728. })
  729. },
  730. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  731. nil,
  732. nil,
  733. true,
  734. )
  735. } else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
  736. if wrap.CurrSubModule == "add" {
  737. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  738. {Name: "Add new product"},
  739. })
  740. } else {
  741. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  742. {Name: "Modify product"},
  743. })
  744. }
  745. data := utils.MySql_shop_product{
  746. A_id: 0,
  747. A_user: 0,
  748. A_currency: 0,
  749. A_price: 0,
  750. A_name: "",
  751. A_alias: "",
  752. A_vendor: "",
  753. A_quantity: 0,
  754. A_category: 0,
  755. A_briefly: "",
  756. A_content: "",
  757. A_datetime: 0,
  758. A_active: 0,
  759. }
  760. if wrap.CurrSubModule == "modify" {
  761. if len(wrap.UrlArgs) != 3 {
  762. return "", "", ""
  763. }
  764. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  765. return "", "", ""
  766. }
  767. err := wrap.DB.QueryRow(`
  768. SELECT
  769. id,
  770. user,
  771. currency,
  772. price,
  773. name,
  774. alias,
  775. vendor,
  776. quantity,
  777. category,
  778. briefly,
  779. content,
  780. active
  781. FROM
  782. shop_products
  783. WHERE
  784. id = ?
  785. LIMIT 1;`,
  786. utils.StrToInt(wrap.UrlArgs[2]),
  787. ).Scan(
  788. &data.A_id,
  789. &data.A_user,
  790. &data.A_currency,
  791. &data.A_price,
  792. &data.A_name,
  793. &data.A_alias,
  794. &data.A_vendor,
  795. &data.A_quantity,
  796. &data.A_category,
  797. &data.A_briefly,
  798. &data.A_content,
  799. &data.A_active,
  800. )
  801. if err != nil {
  802. return "", "", ""
  803. }
  804. }
  805. // All product current categories
  806. var selids []int
  807. if data.A_id > 0 {
  808. rows, err := wrap.DB.Query("SELECT category_id FROM shop_cat_product_rel WHERE product_id = ?;", data.A_id)
  809. if err == nil {
  810. defer rows.Close()
  811. values := make([]int, 1)
  812. scan := make([]interface{}, len(values))
  813. for i := range values {
  814. scan[i] = &values[i]
  815. }
  816. for rows.Next() {
  817. err = rows.Scan(scan...)
  818. if err == nil {
  819. selids = append(selids, int(values[0]))
  820. }
  821. }
  822. }
  823. }
  824. btn_caption := "Add"
  825. if wrap.CurrSubModule == "modify" {
  826. btn_caption = "Save"
  827. }
  828. content += builder.DataForm(wrap, []builder.DataFormField{
  829. {
  830. Kind: builder.DFKHidden,
  831. Name: "action",
  832. Value: "shop-modify",
  833. },
  834. {
  835. Kind: builder.DFKHidden,
  836. Name: "id",
  837. Value: utils.IntToStr(data.A_id),
  838. },
  839. {
  840. Kind: builder.DFKText,
  841. Caption: "Product name",
  842. Name: "name",
  843. Value: data.A_name,
  844. Required: true,
  845. Min: "1",
  846. Max: "255",
  847. },
  848. {
  849. Kind: builder.DFKText,
  850. Caption: "Product price",
  851. Name: "price",
  852. Value: "0",
  853. CallBack: func(field *builder.DataFormField) string {
  854. return `<div class="form-group n3">` +
  855. `<div class="row">` +
  856. `<div class="col-md-3">` +
  857. `<label for="lbl_price">Product price</label>` +
  858. `</div>` +
  859. `<div class="col-md-9">` +
  860. `<div>` +
  861. `<div class="row">` +
  862. `<div class="col-md-8">` +
  863. `<div><input class="form-control" type="number" step="0.01" id="lbl_price" name="price" value="` + utils.Float64ToStr(data.A_price) + `" placeholder="" autocomplete="off" required></div>` +
  864. `<div class="d-md-none mb-3"></div>` +
  865. `</div>` +
  866. `<div class="col-md-4">` +
  867. `<select class="selectpicker form-control" id="lbl_currency" name="currency" data-live-search="true">` +
  868. this.shop_GetCurrencySelectOptions(wrap, data.A_currency) +
  869. `</select>` +
  870. `</div>` +
  871. `</div>` +
  872. `</div>` +
  873. `</div>` +
  874. `</div>` +
  875. `</div>`
  876. },
  877. },
  878. {
  879. Kind: builder.DFKText,
  880. Caption: "Product alias",
  881. Name: "alias",
  882. Value: data.A_alias,
  883. Hint: "Example: mobile-phone",
  884. Max: "255",
  885. },
  886. {
  887. Kind: builder.DFKText,
  888. Caption: "Vendor/Count",
  889. Name: "vendor",
  890. Value: "0",
  891. CallBack: func(field *builder.DataFormField) string {
  892. return `<div class="form-group n5">` +
  893. `<div class="row">` +
  894. `<div class="col-md-3">` +
  895. `<label for="lbl_vendor">Vendor/Count</label>` +
  896. `</div>` +
  897. `<div class="col-md-9">` +
  898. `<div>` +
  899. `<div class="row">` +
  900. `<div class="col-md-8">` +
  901. `<div><input class="form-control" type="text" id="lbl_vendor" name="vendor" value="` + html.EscapeString(data.A_vendor) + `" placeholder="" autocomplete="off"></div>` +
  902. `<div class="d-md-none mb-3"></div>` +
  903. `</div>` +
  904. `<div class="col-md-4">` +
  905. `<input class="form-control" type="number" step="1" id="lbl_quantity" name="quantity" value="` + utils.IntToStr(data.A_quantity) + `" placeholder="" autocomplete="off">` +
  906. `</div>` +
  907. `</div>` +
  908. `</div>` +
  909. `</div>` +
  910. `</div>` +
  911. `</div>`
  912. },
  913. },
  914. {
  915. Kind: builder.DFKText,
  916. Caption: "Category",
  917. Name: "category",
  918. Value: "0",
  919. CallBack: func(field *builder.DataFormField) string {
  920. return `<div class="form-group n6">` +
  921. `<div class="row">` +
  922. `<div class="col-md-3">` +
  923. `<label for="lbl_category">Category</label>` +
  924. `</div>` +
  925. `<div class="col-md-9">` +
  926. `<div>` +
  927. `<select class="selectpicker form-control" id="lbl_category" name="category" data-live-search="true">` +
  928. `<option title="Nothing selected" value="0">&mdash;</option>` +
  929. this.shop_GetCategorySelectOptions(wrap, 0, data.A_category, []int{}) +
  930. `</select>` +
  931. `</div>` +
  932. `</div>` +
  933. `</div>` +
  934. `</div>`
  935. },
  936. },
  937. {
  938. Kind: builder.DFKText,
  939. Caption: "Categories",
  940. Name: "cats",
  941. Value: "0",
  942. CallBack: func(field *builder.DataFormField) string {
  943. return `<div class="form-group n7">` +
  944. `<div class="row">` +
  945. `<div class="col-md-3">` +
  946. `<label for="lbl_cats">Categories</label>` +
  947. `</div>` +
  948. `<div class="col-md-9">` +
  949. `<div>` +
  950. `<select class="selectpicker form-control" id="lbl_cats" name="cats[]" data-live-search="true" multiple>` +
  951. this.shop_GetCategorySelectOptions(wrap, 0, 0, selids) +
  952. `</select>` +
  953. `</div>` +
  954. `</div>` +
  955. `</div>` +
  956. `</div>`
  957. },
  958. },
  959. {
  960. Kind: builder.DFKText,
  961. Caption: "Attributes",
  962. Name: "",
  963. Value: "",
  964. CallBack: func(field *builder.DataFormField) string {
  965. return `<div class="form-group n8">` +
  966. `<div class="row">` +
  967. `<div class="col-md-3">` +
  968. `<label>Attributes</label>` +
  969. `</div>` +
  970. `<div class="col-md-9">` +
  971. `<div class="list-wrapper">` +
  972. `<div id="list">` +
  973. this.shop_GetProductValuesInputs(wrap, data.A_id) +
  974. `</div>` +
  975. `<div class="list-button position-relative">` +
  976. `<select class="selectpicker form-control" id="lbl_attributes" data-live-search="true" onchange="fave.ShopProductsAdd();">` +
  977. this.shop_GetAllAttributesSelectOptions(wrap) +
  978. `</select>` +
  979. `</div>` +
  980. `</div>` +
  981. `</div>` +
  982. `</div>` +
  983. `</div>`
  984. },
  985. },
  986. {
  987. Kind: builder.DFKTextArea,
  988. Caption: "Briefly",
  989. Name: "briefly",
  990. Value: data.A_briefly,
  991. Classes: "briefly wysiwyg",
  992. },
  993. {
  994. Kind: builder.DFKTextArea,
  995. Caption: "Product content",
  996. Name: "content",
  997. Value: data.A_content,
  998. Classes: "wysiwyg",
  999. },
  1000. {
  1001. Kind: builder.DFKText,
  1002. Caption: "Product images",
  1003. Name: "",
  1004. Value: "",
  1005. CallBack: func(field *builder.DataFormField) string {
  1006. if data.A_id == 0 {
  1007. return ``
  1008. }
  1009. return `<div class="form-group n11">` +
  1010. `<div class="row">` +
  1011. `<div class="col-md-3">` +
  1012. `<label>Product images</label>` +
  1013. `</div>` +
  1014. `<div class="col-md-9">` +
  1015. `<div class="list-wrapper">` +
  1016. `<div id="list-images">` +
  1017. this.shop_GetAllProductImages(wrap, data.A_id) +
  1018. `</div>` +
  1019. `<div class="list-button position-relative">` +
  1020. `<input class="form-control ignore-lost-data" type="file" id="file" name="file" style="font-size:13px;" /><button type="button" class="btn btn-success btn-dynamic-remove" onclick="fave.ShopProductsUploadImage('shop-upload-image', ` + utils.IntToStr(data.A_id) + `, 'file');">Upload</button>` +
  1021. `</div>` +
  1022. `</div>` +
  1023. `</div>` +
  1024. `</div>` +
  1025. `</div>`
  1026. },
  1027. },
  1028. {
  1029. Kind: builder.DFKCheckBox,
  1030. Caption: "Active",
  1031. Name: "active",
  1032. Value: utils.IntToStr(data.A_active),
  1033. },
  1034. {
  1035. Kind: builder.DFKSubmit,
  1036. Value: btn_caption,
  1037. Target: "add-edit-button",
  1038. },
  1039. })
  1040. if wrap.CurrSubModule == "add" {
  1041. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1042. } else {
  1043. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1044. }
  1045. } else if wrap.CurrSubModule == "categories-add" || wrap.CurrSubModule == "categories-modify" {
  1046. if wrap.CurrSubModule == "categories-add" {
  1047. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1048. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1049. {Name: "Add new category"},
  1050. })
  1051. } else {
  1052. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1053. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1054. {Name: "Modify category"},
  1055. })
  1056. }
  1057. data := utils.MySql_shop_category{
  1058. A_id: 0,
  1059. A_user: 0,
  1060. A_name: "",
  1061. A_alias: "",
  1062. A_lft: 0,
  1063. A_rgt: 0,
  1064. }
  1065. if wrap.CurrSubModule == "categories-modify" {
  1066. if len(wrap.UrlArgs) != 3 {
  1067. return "", "", ""
  1068. }
  1069. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1070. return "", "", ""
  1071. }
  1072. err := wrap.DB.QueryRow(`
  1073. SELECT
  1074. id,
  1075. user,
  1076. name,
  1077. alias,
  1078. lft,
  1079. rgt
  1080. FROM
  1081. shop_cats
  1082. WHERE
  1083. id = ?
  1084. LIMIT 1;`,
  1085. utils.StrToInt(wrap.UrlArgs[2]),
  1086. ).Scan(
  1087. &data.A_id,
  1088. &data.A_user,
  1089. &data.A_name,
  1090. &data.A_alias,
  1091. &data.A_lft,
  1092. &data.A_rgt,
  1093. )
  1094. if err != nil {
  1095. return "", "", ""
  1096. }
  1097. }
  1098. btn_caption := "Add"
  1099. if wrap.CurrSubModule == "categories-modify" {
  1100. btn_caption = "Save"
  1101. }
  1102. parentId := 0
  1103. if wrap.CurrSubModule == "categories-modify" {
  1104. parentId = this.shop_GetCategoryParentId(wrap, data.A_id)
  1105. }
  1106. content += builder.DataForm(wrap, []builder.DataFormField{
  1107. {
  1108. Kind: builder.DFKHidden,
  1109. Name: "action",
  1110. Value: "shop-categories-modify",
  1111. },
  1112. {
  1113. Kind: builder.DFKHidden,
  1114. Name: "id",
  1115. Value: utils.IntToStr(data.A_id),
  1116. },
  1117. {
  1118. Kind: builder.DFKText,
  1119. Caption: "Parent",
  1120. Name: "parent",
  1121. Value: "0",
  1122. CallBack: func(field *builder.DataFormField) string {
  1123. return `<div class="form-group n2">` +
  1124. `<div class="row">` +
  1125. `<div class="col-md-3">` +
  1126. `<label for="lbl_parent">Parent</label>` +
  1127. `</div>` +
  1128. `<div class="col-md-9">` +
  1129. `<div>` +
  1130. `<select class="selectpicker form-control" id="lbl_parent" name="parent" data-live-search="true">` +
  1131. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1132. this.shop_GetCategorySelectOptions(wrap, data.A_id, parentId, []int{}) +
  1133. `</select>` +
  1134. `</div>` +
  1135. `</div>` +
  1136. `</div>` +
  1137. `</div>`
  1138. },
  1139. },
  1140. {
  1141. Kind: builder.DFKText,
  1142. Caption: "Name",
  1143. Name: "name",
  1144. Value: data.A_name,
  1145. Required: true,
  1146. Min: "1",
  1147. Max: "255",
  1148. },
  1149. {
  1150. Kind: builder.DFKText,
  1151. Caption: "Alias",
  1152. Name: "alias",
  1153. Value: data.A_alias,
  1154. Hint: "Example: popular-products",
  1155. Max: "255",
  1156. },
  1157. {
  1158. Kind: builder.DFKSubmit,
  1159. Value: btn_caption,
  1160. Target: "add-edit-button",
  1161. },
  1162. })
  1163. if wrap.CurrSubModule == "categories-add" {
  1164. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1165. } else {
  1166. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1167. }
  1168. } else if wrap.CurrSubModule == "attributes-add" || wrap.CurrSubModule == "attributes-modify" {
  1169. if wrap.CurrSubModule == "attributes-add" {
  1170. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1171. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1172. {Name: "Add new attribute"},
  1173. })
  1174. } else {
  1175. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1176. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1177. {Name: "Modify attribute"},
  1178. })
  1179. }
  1180. data := utils.MySql_shop_filter{
  1181. A_id: 0,
  1182. A_name: "",
  1183. A_filter: "",
  1184. }
  1185. if wrap.CurrSubModule == "attributes-modify" {
  1186. if len(wrap.UrlArgs) != 3 {
  1187. return "", "", ""
  1188. }
  1189. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1190. return "", "", ""
  1191. }
  1192. err := wrap.DB.QueryRow(`
  1193. SELECT
  1194. id,
  1195. name,
  1196. filter
  1197. FROM
  1198. shop_filters
  1199. WHERE
  1200. id = ?
  1201. LIMIT 1;`,
  1202. utils.StrToInt(wrap.UrlArgs[2]),
  1203. ).Scan(
  1204. &data.A_id,
  1205. &data.A_name,
  1206. &data.A_filter,
  1207. )
  1208. if err != nil {
  1209. return "", "", ""
  1210. }
  1211. }
  1212. btn_caption := "Add"
  1213. if wrap.CurrSubModule == "attributes-modify" {
  1214. btn_caption = "Save"
  1215. }
  1216. content += builder.DataForm(wrap, []builder.DataFormField{
  1217. {
  1218. Kind: builder.DFKHidden,
  1219. Name: "action",
  1220. Value: "shop-attributes-modify",
  1221. },
  1222. {
  1223. Kind: builder.DFKHidden,
  1224. Name: "id",
  1225. Value: utils.IntToStr(data.A_id),
  1226. },
  1227. {
  1228. Kind: builder.DFKText,
  1229. Caption: "Attribute name",
  1230. Name: "name",
  1231. Value: data.A_name,
  1232. Required: true,
  1233. Min: "1",
  1234. Max: "255",
  1235. },
  1236. {
  1237. Kind: builder.DFKText,
  1238. Caption: "Attribute in filter",
  1239. Name: "filter",
  1240. Value: data.A_filter,
  1241. Required: true,
  1242. Min: "1",
  1243. Max: "255",
  1244. },
  1245. {
  1246. Kind: builder.DFKText,
  1247. Caption: "Attribute values",
  1248. Name: "",
  1249. Value: "",
  1250. CallBack: func(field *builder.DataFormField) string {
  1251. return `<div class="form-group n4">` +
  1252. `<div class="row">` +
  1253. `<div class="col-md-3">` +
  1254. `<label>Attribute values</label>` +
  1255. `</div>` +
  1256. `<div class="col-md-9">` +
  1257. `<div class="list-wrapper">` +
  1258. `<div id="list">` +
  1259. this.shop_GetFilterValuesInputs(wrap, data.A_id) +
  1260. `</div>` +
  1261. `<div class="list-button"><button type="button" class="btn btn-success" onclick="fave.ShopAttributesAdd();">Add attribute value</button></div>` +
  1262. `</div>` +
  1263. `</div>` +
  1264. `</div>` +
  1265. `</div>`
  1266. },
  1267. },
  1268. {
  1269. Kind: builder.DFKSubmit,
  1270. Value: btn_caption,
  1271. Target: "add-edit-button",
  1272. },
  1273. })
  1274. if wrap.CurrSubModule == "attributes-add" {
  1275. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1276. } else {
  1277. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1278. }
  1279. } else if wrap.CurrSubModule == "currencies-add" || wrap.CurrSubModule == "currencies-modify" {
  1280. if wrap.CurrSubModule == "currencies-add" {
  1281. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1282. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1283. {Name: "Add new currency"},
  1284. })
  1285. } else {
  1286. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1287. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1288. {Name: "Modify currency"},
  1289. })
  1290. }
  1291. data := utils.MySql_shop_currency{
  1292. A_id: 0,
  1293. A_name: "",
  1294. A_coefficient: 0,
  1295. A_code: "",
  1296. A_symbol: "",
  1297. }
  1298. if wrap.CurrSubModule == "currencies-modify" {
  1299. if len(wrap.UrlArgs) != 3 {
  1300. return "", "", ""
  1301. }
  1302. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1303. return "", "", ""
  1304. }
  1305. err := wrap.DB.QueryRow(`
  1306. SELECT
  1307. id,
  1308. name,
  1309. coefficient,
  1310. code,
  1311. symbol
  1312. FROM
  1313. shop_currencies
  1314. WHERE
  1315. id = ?
  1316. LIMIT 1;`,
  1317. utils.StrToInt(wrap.UrlArgs[2]),
  1318. ).Scan(
  1319. &data.A_id,
  1320. &data.A_name,
  1321. &data.A_coefficient,
  1322. &data.A_code,
  1323. &data.A_symbol,
  1324. )
  1325. if err != nil {
  1326. return "", "", ""
  1327. }
  1328. }
  1329. btn_caption := "Add"
  1330. if wrap.CurrSubModule == "currencies-modify" {
  1331. btn_caption = "Save"
  1332. }
  1333. content += builder.DataForm(wrap, []builder.DataFormField{
  1334. {
  1335. Kind: builder.DFKHidden,
  1336. Name: "action",
  1337. Value: "shop-currencies-modify",
  1338. },
  1339. {
  1340. Kind: builder.DFKHidden,
  1341. Name: "id",
  1342. Value: utils.IntToStr(data.A_id),
  1343. },
  1344. {
  1345. Kind: builder.DFKText,
  1346. Caption: "Currency name",
  1347. Name: "name",
  1348. Value: data.A_name,
  1349. Required: true,
  1350. Min: "1",
  1351. Max: "255",
  1352. },
  1353. {
  1354. Kind: builder.DFKText,
  1355. Caption: "Currency coefficient",
  1356. Name: "coefficient",
  1357. Value: "0",
  1358. CallBack: func(field *builder.DataFormField) string {
  1359. return `<div class="form-group n3">` +
  1360. `<div class="row">` +
  1361. `<div class="col-md-3">` +
  1362. `<label for="lbl_coefficient">Currency coefficient</label>` +
  1363. `</div>` +
  1364. `<div class="col-md-9">` +
  1365. `<div><input class="form-control" type="number" step="0.0001" id="lbl_coefficient" name="coefficient" value="` + utils.Float64ToStrF(data.A_coefficient, "%.4f") + `" placeholder="" autocomplete="off" required></div>` +
  1366. `</div>` +
  1367. `</div>` +
  1368. `</div>`
  1369. },
  1370. },
  1371. {
  1372. Kind: builder.DFKText,
  1373. Caption: "Currency code",
  1374. Name: "code",
  1375. Value: data.A_code,
  1376. Required: true,
  1377. Min: "1",
  1378. Max: "10",
  1379. },
  1380. {
  1381. Kind: builder.DFKText,
  1382. Caption: "Currency symbol",
  1383. Name: "symbol",
  1384. Value: data.A_symbol,
  1385. Required: true,
  1386. Min: "1",
  1387. Max: "5",
  1388. },
  1389. {
  1390. Kind: builder.DFKSubmit,
  1391. Value: btn_caption,
  1392. Target: "add-edit-button",
  1393. },
  1394. })
  1395. if wrap.CurrSubModule == "currencies-add" {
  1396. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1397. } else {
  1398. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1399. }
  1400. }
  1401. return this.getSidebarModules(wrap), content, sidebar
  1402. })
  1403. }