module_shop.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  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])) + `" target="_blank">` + html.EscapeString(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. err := wrap.DB.QueryRow(`
  270. SELECT
  271. id,
  272. user,
  273. name,
  274. alias,
  275. lft,
  276. rgt
  277. FROM
  278. shop_cats
  279. WHERE
  280. alias = ? AND
  281. id > 1
  282. LIMIT 1;`,
  283. wrap.UrlArgs[2],
  284. ).Scan(
  285. &row.A_id,
  286. &row.A_user,
  287. &row.A_name,
  288. &row.A_alias,
  289. &row.A_lft,
  290. &row.A_rgt,
  291. )
  292. if err != nil && err != wrapper.ErrNoRows {
  293. // System error 500
  294. utils.SystemErrorPageEngine(wrap.W, err)
  295. return
  296. } else if err == wrapper.ErrNoRows {
  297. // User error 404 page
  298. wrap.RenderFrontEnd("404", fetdata.New(wrap, nil, true), http.StatusNotFound)
  299. return
  300. }
  301. // Fix url
  302. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  303. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  304. return
  305. }
  306. // Render template
  307. wrap.RenderFrontEnd("shop-category", fetdata.New(wrap, row, false), http.StatusOK)
  308. return
  309. } else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] != "" {
  310. // Shop product
  311. row := &utils.MySql_shop_product{}
  312. err := wrap.DB.QueryRow(`
  313. SELECT
  314. id,
  315. user,
  316. currency,
  317. price,
  318. name,
  319. alias,
  320. vendor,
  321. quantity,
  322. category,
  323. briefly,
  324. content,
  325. UNIX_TIMESTAMP(datetime) as datetime,
  326. active
  327. FROM
  328. shop_products
  329. WHERE
  330. active = 1 and
  331. alias = ?
  332. LIMIT 1;`,
  333. wrap.UrlArgs[1],
  334. ).Scan(
  335. &row.A_id,
  336. &row.A_user,
  337. &row.A_currency,
  338. &row.A_price,
  339. &row.A_name,
  340. &row.A_alias,
  341. &row.A_vendor,
  342. &row.A_quantity,
  343. &row.A_category,
  344. &row.A_briefly,
  345. &row.A_content,
  346. &row.A_datetime,
  347. &row.A_active,
  348. )
  349. if err != nil && err != wrapper.ErrNoRows {
  350. // System error 500
  351. utils.SystemErrorPageEngine(wrap.W, err)
  352. return
  353. } else if err == wrapper.ErrNoRows {
  354. // User error 404 page
  355. wrap.RenderFrontEnd("404", fetdata.New(wrap, nil, true), http.StatusNotFound)
  356. return
  357. }
  358. // Fix url
  359. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  360. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  361. return
  362. }
  363. // Render template
  364. wrap.RenderFrontEnd("shop-product", fetdata.New(wrap, row, false), http.StatusOK)
  365. return
  366. } else if len(wrap.UrlArgs) == 1 && wrap.UrlArgs[0] == "shop" {
  367. // Shop
  368. // Fix url
  369. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  370. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  371. return
  372. }
  373. // Render template
  374. wrap.RenderFrontEnd("shop", fetdata.New(wrap, nil, false), http.StatusOK)
  375. return
  376. }
  377. // User error 404 page
  378. wrap.RenderFrontEnd("404", fetdata.New(wrap, nil, true), http.StatusNotFound)
  379. }, func(wrap *wrapper.Wrapper) (string, string, string) {
  380. content := ""
  381. sidebar := ""
  382. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
  383. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  384. {Name: "List of products"},
  385. })
  386. // Load currencies
  387. currencies := this.shop_GetAllCurrencies(wrap)
  388. content += builder.DataTable(
  389. wrap,
  390. "shop_products",
  391. "id",
  392. "DESC",
  393. &[]builder.DataTableRow{
  394. {
  395. DBField: "id",
  396. },
  397. {
  398. DBField: "name",
  399. NameInTable: "Product / URL",
  400. CallBack: func(values *[]string) string {
  401. name := `<a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  402. alias := html.EscapeString((*values)[2])
  403. return `<div>` + name + `</div><div><small>/shop/` + alias + `/</small></div>`
  404. },
  405. },
  406. {
  407. DBField: "alias",
  408. },
  409. {
  410. DBField: "currency",
  411. },
  412. {
  413. DBField: "price",
  414. NameInTable: "Price",
  415. Classes: "d-none d-md-table-cell",
  416. CallBack: func(values *[]string) string {
  417. return `<div>` + utils.Float64ToStr(utils.StrToFloat64((*values)[4])) + `</div>` +
  418. `<div><small>` + currencies[utils.StrToInt((*values)[3])] + `</small></div>`
  419. },
  420. },
  421. {
  422. DBField: "datetime",
  423. DBExp: "UNIX_TIMESTAMP(`datetime`)",
  424. NameInTable: "Date / Time",
  425. Classes: "d-none d-lg-table-cell",
  426. CallBack: func(values *[]string) string {
  427. t := int64(utils.StrToInt((*values)[5]))
  428. return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
  429. `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
  430. },
  431. },
  432. {
  433. DBField: "active",
  434. NameInTable: "Active",
  435. Classes: "d-none d-sm-table-cell",
  436. CallBack: func(values *[]string) string {
  437. return builder.CheckBox(utils.StrToInt((*values)[6]))
  438. },
  439. },
  440. },
  441. func(values *[]string) string {
  442. return builder.DataTableAction(&[]builder.DataTableActionRow{
  443. {
  444. Icon: assets.SysSvgIconView,
  445. Href: `/shop/` + (*values)[2] + `/`,
  446. Hint: "View",
  447. Target: "_blank",
  448. },
  449. {
  450. Icon: assets.SysSvgIconEdit,
  451. Href: "/cp/" + wrap.CurrModule + "/modify/" + (*values)[0] + "/",
  452. Hint: "Edit",
  453. },
  454. {
  455. Icon: assets.SysSvgIconRemove,
  456. Href: "javascript:fave.ActionDataTableDelete(this,'shop-delete','" +
  457. (*values)[0] + "','Are you sure want to delete product?');",
  458. Hint: "Delete",
  459. Classes: "delete",
  460. },
  461. })
  462. },
  463. "/cp/"+wrap.CurrModule+"/",
  464. nil,
  465. nil,
  466. true,
  467. )
  468. } else if wrap.CurrSubModule == "categories" {
  469. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  470. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  471. {Name: "List of categories"},
  472. })
  473. content += builder.DataTable(
  474. wrap,
  475. "shop_cats",
  476. "id",
  477. "ASC",
  478. &[]builder.DataTableRow{
  479. {
  480. DBField: "id",
  481. },
  482. {
  483. DBField: "user",
  484. },
  485. {
  486. DBField: "name",
  487. NameInTable: "Category",
  488. CallBack: func(values *[]string) string {
  489. depth := utils.StrToInt((*values)[4]) - 1
  490. if depth < 0 {
  491. depth = 0
  492. }
  493. sub := strings.Repeat("&mdash; ", depth)
  494. name := `<a href="/cp/` + wrap.CurrModule + `/categories-modify/` + (*values)[0] + `/">` + sub + html.EscapeString((*values)[2]) + `</a>`
  495. return `<div>` + name + `</div>`
  496. },
  497. },
  498. {
  499. DBField: "alias",
  500. },
  501. {
  502. DBField: "depth",
  503. },
  504. },
  505. func(values *[]string) string {
  506. return builder.DataTableAction(&[]builder.DataTableActionRow{
  507. {
  508. Icon: assets.SysSvgIconView,
  509. Href: `/shop/category/` + (*values)[3] + `/`,
  510. Hint: "View",
  511. Target: "_blank",
  512. },
  513. {
  514. Icon: assets.SysSvgIconEdit,
  515. Href: "/cp/" + wrap.CurrModule + "/categories-modify/" + (*values)[0] + "/",
  516. Hint: "Edit",
  517. },
  518. {
  519. Icon: assets.SysSvgIconRemove,
  520. Href: "javascript:fave.ActionDataTableDelete(this,'shop-categories-delete','" +
  521. (*values)[0] + "','Are you sure want to delete category?');",
  522. Hint: "Delete",
  523. Classes: "delete",
  524. },
  525. })
  526. },
  527. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  528. nil,
  529. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  530. return wrap.DB.Query(
  531. `SELECT
  532. node.id,
  533. node.user,
  534. node.name,
  535. node.alias,
  536. (COUNT(parent.id) - 1) AS depth
  537. FROM
  538. shop_cats AS node,
  539. shop_cats AS parent
  540. WHERE
  541. node.lft BETWEEN parent.lft AND parent.rgt AND
  542. node.id > 1
  543. GROUP BY
  544. node.id
  545. ORDER BY
  546. node.lft ASC
  547. ;`,
  548. )
  549. },
  550. false,
  551. )
  552. } else if wrap.CurrSubModule == "attributes" {
  553. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  554. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  555. {Name: "List of attributes"},
  556. })
  557. content += builder.DataTable(
  558. wrap,
  559. "shop_filters",
  560. "id",
  561. "DESC",
  562. &[]builder.DataTableRow{
  563. {
  564. DBField: "id",
  565. },
  566. {
  567. DBField: "name",
  568. NameInTable: "Name",
  569. CallBack: func(values *[]string) string {
  570. name := `<a href="/cp/` + wrap.CurrModule + `/attributes-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  571. return `<div>` + name + `</div><div><small>` + html.EscapeString((*values)[2]) + `</small></div>`
  572. },
  573. },
  574. {
  575. DBField: "filter",
  576. },
  577. },
  578. func(values *[]string) string {
  579. return builder.DataTableAction(&[]builder.DataTableActionRow{
  580. {
  581. Icon: assets.SysSvgIconEdit,
  582. Href: "/cp/" + wrap.CurrModule + "/attributes-modify/" + (*values)[0] + "/",
  583. Hint: "Edit",
  584. },
  585. {
  586. Icon: assets.SysSvgIconRemove,
  587. Href: "javascript:fave.ActionDataTableDelete(this,'shop-attributes-delete','" +
  588. (*values)[0] + "','Are you sure want to delete attribute?');",
  589. Hint: "Delete",
  590. Classes: "delete",
  591. },
  592. })
  593. },
  594. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  595. nil,
  596. nil,
  597. true,
  598. )
  599. } else if wrap.CurrSubModule == "currencies" {
  600. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  601. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  602. {Name: "List of currencies"},
  603. })
  604. content += builder.DataTable(
  605. wrap,
  606. "shop_currencies",
  607. "id",
  608. "DESC",
  609. &[]builder.DataTableRow{
  610. {
  611. DBField: "id",
  612. },
  613. {
  614. DBField: "name",
  615. NameInTable: "Name",
  616. CallBack: func(values *[]string) string {
  617. name := `<a href="/cp/` + wrap.CurrModule + `/currencies-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` (` + (*values)[3] + `, ` + (*values)[4] + `)</a>`
  618. return `<div>` + name + `</div>`
  619. },
  620. },
  621. {
  622. DBField: "coefficient",
  623. NameInTable: "Coefficient",
  624. Classes: "d-none d-md-table-cell",
  625. CallBack: func(values *[]string) string {
  626. return utils.Float64ToStrF(utils.StrToFloat64((*values)[2]), "%.4f")
  627. },
  628. },
  629. {
  630. DBField: "code",
  631. },
  632. {
  633. DBField: "symbol",
  634. },
  635. },
  636. func(values *[]string) string {
  637. return builder.DataTableAction(&[]builder.DataTableActionRow{
  638. {
  639. Icon: assets.SysSvgIconEdit,
  640. Href: "/cp/" + wrap.CurrModule + "/currencies-modify/" + (*values)[0] + "/",
  641. Hint: "Edit",
  642. },
  643. {
  644. Icon: assets.SysSvgIconRemove,
  645. Href: "javascript:fave.ActionDataTableDelete(this,'shop-currencies-delete','" +
  646. (*values)[0] + "','Are you sure want to delete currency?');",
  647. Hint: "Delete",
  648. Classes: "delete",
  649. },
  650. })
  651. },
  652. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  653. nil,
  654. nil,
  655. true,
  656. )
  657. } else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
  658. if wrap.CurrSubModule == "add" {
  659. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  660. {Name: "Add new product"},
  661. })
  662. } else {
  663. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  664. {Name: "Modify product"},
  665. })
  666. }
  667. data := utils.MySql_shop_product{
  668. A_id: 0,
  669. A_user: 0,
  670. A_currency: 0,
  671. A_price: 0,
  672. A_name: "",
  673. A_alias: "",
  674. A_vendor: "",
  675. A_quantity: 0,
  676. A_category: 0,
  677. A_briefly: "",
  678. A_content: "",
  679. A_datetime: 0,
  680. A_active: 0,
  681. }
  682. if wrap.CurrSubModule == "modify" {
  683. if len(wrap.UrlArgs) != 3 {
  684. return "", "", ""
  685. }
  686. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  687. return "", "", ""
  688. }
  689. err := wrap.DB.QueryRow(`
  690. SELECT
  691. id,
  692. user,
  693. currency,
  694. price,
  695. name,
  696. alias,
  697. vendor,
  698. quantity,
  699. category,
  700. briefly,
  701. content,
  702. active
  703. FROM
  704. shop_products
  705. WHERE
  706. id = ?
  707. LIMIT 1;`,
  708. utils.StrToInt(wrap.UrlArgs[2]),
  709. ).Scan(
  710. &data.A_id,
  711. &data.A_user,
  712. &data.A_currency,
  713. &data.A_price,
  714. &data.A_name,
  715. &data.A_alias,
  716. &data.A_vendor,
  717. &data.A_quantity,
  718. &data.A_category,
  719. &data.A_briefly,
  720. &data.A_content,
  721. &data.A_active,
  722. )
  723. if err != nil {
  724. return "", "", ""
  725. }
  726. }
  727. // All product current categories
  728. var selids []int
  729. if data.A_id > 0 {
  730. rows, err := wrap.DB.Query("SELECT category_id FROM shop_cat_product_rel WHERE product_id = ?;", data.A_id)
  731. if err == nil {
  732. defer rows.Close()
  733. values := make([]int, 1)
  734. scan := make([]interface{}, len(values))
  735. for i := range values {
  736. scan[i] = &values[i]
  737. }
  738. for rows.Next() {
  739. err = rows.Scan(scan...)
  740. if err == nil {
  741. selids = append(selids, int(values[0]))
  742. }
  743. }
  744. }
  745. }
  746. btn_caption := "Add"
  747. if wrap.CurrSubModule == "modify" {
  748. btn_caption = "Save"
  749. }
  750. content += builder.DataForm(wrap, []builder.DataFormField{
  751. {
  752. Kind: builder.DFKHidden,
  753. Name: "action",
  754. Value: "shop-modify",
  755. },
  756. {
  757. Kind: builder.DFKHidden,
  758. Name: "id",
  759. Value: utils.IntToStr(data.A_id),
  760. },
  761. {
  762. Kind: builder.DFKText,
  763. Caption: "Product name",
  764. Name: "name",
  765. Value: data.A_name,
  766. Required: true,
  767. Min: "1",
  768. Max: "255",
  769. },
  770. {
  771. Kind: builder.DFKText,
  772. Caption: "Product price",
  773. Name: "price",
  774. Value: "0",
  775. CallBack: func(field *builder.DataFormField) string {
  776. return `<div class="form-group n3">` +
  777. `<div class="row">` +
  778. `<div class="col-md-3">` +
  779. `<label for="lbl_price">Product price</label>` +
  780. `</div>` +
  781. `<div class="col-md-9">` +
  782. `<div>` +
  783. `<div class="row">` +
  784. `<div class="col-md-8">` +
  785. `<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>` +
  786. `<div class="d-md-none mb-3"></div>` +
  787. `</div>` +
  788. `<div class="col-md-4">` +
  789. `<select class="selectpicker form-control" id="lbl_currency" name="currency" data-live-search="true">` +
  790. this.shop_GetCurrencySelectOptions(wrap, data.A_currency) +
  791. `</select>` +
  792. `</div>` +
  793. `</div>` +
  794. `</div>` +
  795. `</div>` +
  796. `</div>` +
  797. `</div>`
  798. },
  799. },
  800. {
  801. Kind: builder.DFKText,
  802. Caption: "Product alias",
  803. Name: "alias",
  804. Value: data.A_alias,
  805. Hint: "Example: mobile-phone",
  806. Max: "255",
  807. },
  808. {
  809. Kind: builder.DFKText,
  810. Caption: "Vendor/Count",
  811. Name: "vendor",
  812. Value: "0",
  813. CallBack: func(field *builder.DataFormField) string {
  814. return `<div class="form-group n3">` +
  815. `<div class="row">` +
  816. `<div class="col-md-3">` +
  817. `<label for="lbl_vendor">Vendor/Count</label>` +
  818. `</div>` +
  819. `<div class="col-md-9">` +
  820. `<div>` +
  821. `<div class="row">` +
  822. `<div class="col-md-8">` +
  823. `<div><input class="form-control" type="text" id="lbl_vendor" name="vendor" value="` + html.EscapeString(data.A_vendor) + `" placeholder="" autocomplete="off"></div>` +
  824. `<div class="d-md-none mb-3"></div>` +
  825. `</div>` +
  826. `<div class="col-md-4">` +
  827. `<input class="form-control" type="number" step="1" id="lbl_quantity" name="quantity" value="` + utils.IntToStr(data.A_quantity) + `" placeholder="" autocomplete="off">` +
  828. `</div>` +
  829. `</div>` +
  830. `</div>` +
  831. `</div>` +
  832. `</div>` +
  833. `</div>`
  834. },
  835. },
  836. {
  837. Kind: builder.DFKText,
  838. Caption: "Category",
  839. Name: "category",
  840. Value: "0",
  841. CallBack: func(field *builder.DataFormField) string {
  842. return `<div class="form-group n2">` +
  843. `<div class="row">` +
  844. `<div class="col-md-3">` +
  845. `<label for="lbl_category">Category</label>` +
  846. `</div>` +
  847. `<div class="col-md-9">` +
  848. `<div>` +
  849. `<select class="selectpicker form-control" id="lbl_category" name="category" data-live-search="true">` +
  850. `<option title="Nothing selected" value="0">&mdash;</option>` +
  851. this.shop_GetCategorySelectOptions(wrap, 0, data.A_category, []int{}) +
  852. `</select>` +
  853. `</div>` +
  854. `</div>` +
  855. `</div>` +
  856. `</div>`
  857. },
  858. },
  859. {
  860. Kind: builder.DFKText,
  861. Caption: "Categories",
  862. Name: "cats",
  863. Value: "0",
  864. CallBack: func(field *builder.DataFormField) string {
  865. return `<div class="form-group n5">` +
  866. `<div class="row">` +
  867. `<div class="col-md-3">` +
  868. `<label for="lbl_cats">Categories</label>` +
  869. `</div>` +
  870. `<div class="col-md-9">` +
  871. `<div>` +
  872. `<select class="selectpicker form-control" id="lbl_cats" name="cats[]" data-live-search="true" multiple>` +
  873. this.shop_GetCategorySelectOptions(wrap, 0, 0, selids) +
  874. `</select>` +
  875. `</div>` +
  876. `</div>` +
  877. `</div>` +
  878. `</div>`
  879. },
  880. },
  881. {
  882. Kind: builder.DFKText,
  883. Caption: "Attributes",
  884. Name: "",
  885. Value: "",
  886. CallBack: func(field *builder.DataFormField) string {
  887. return `<div class="form-group n6">` +
  888. `<div class="row">` +
  889. `<div class="col-md-3">` +
  890. `<label>Attributes</label>` +
  891. `</div>` +
  892. `<div class="col-md-9">` +
  893. `<div class="list-wrapper">` +
  894. `<div id="list">` +
  895. this.shop_GetProductValuesInputs(wrap, data.A_id) +
  896. `</div>` +
  897. `<div class="list-button position-relative">` +
  898. `<select class="selectpicker form-control" id="lbl_attributes" data-live-search="true">` +
  899. this.shop_GetAllAttributesSelectOptions(wrap) +
  900. `</select>` +
  901. `<button type="button" class="btn btn-success btn-dynamic-remove" onclick="fave.ShopProductsAdd();">Add attribute</button>` +
  902. `</div>` +
  903. `</div>` +
  904. `</div>` +
  905. `</div>` +
  906. `</div>`
  907. },
  908. },
  909. {
  910. Kind: builder.DFKTextArea,
  911. Caption: "Briefly",
  912. Name: "briefly",
  913. Value: data.A_briefly,
  914. Classes: "briefly wysiwyg",
  915. },
  916. {
  917. Kind: builder.DFKTextArea,
  918. Caption: "Product content",
  919. Name: "content",
  920. Value: data.A_content,
  921. Classes: "wysiwyg",
  922. },
  923. {
  924. Kind: builder.DFKText,
  925. Caption: "Product images",
  926. Name: "",
  927. Value: "",
  928. CallBack: func(field *builder.DataFormField) string {
  929. if data.A_id == 0 {
  930. return ``
  931. }
  932. return `<div class="form-group n6">` +
  933. `<div class="row">` +
  934. `<div class="col-md-3">` +
  935. `<label>Product images</label>` +
  936. `</div>` +
  937. `<div class="col-md-9">` +
  938. `<div class="list-wrapper">` +
  939. `<div id="list-images">` +
  940. this.shop_GetAllProductImages(wrap, data.A_id) +
  941. `</div>` +
  942. `<div class="list-button position-relative">` +
  943. `<input class="form-control" 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>` +
  944. `</div>` +
  945. `</div>` +
  946. `</div>` +
  947. `</div>` +
  948. `</div>`
  949. },
  950. },
  951. {
  952. Kind: builder.DFKCheckBox,
  953. Caption: "Active",
  954. Name: "active",
  955. Value: utils.IntToStr(data.A_active),
  956. },
  957. {
  958. Kind: builder.DFKSubmit,
  959. Value: btn_caption,
  960. Target: "add-edit-button",
  961. },
  962. })
  963. if wrap.CurrSubModule == "add" {
  964. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  965. } else {
  966. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  967. }
  968. } else if wrap.CurrSubModule == "categories-add" || wrap.CurrSubModule == "categories-modify" {
  969. if wrap.CurrSubModule == "categories-add" {
  970. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  971. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  972. {Name: "Add new category"},
  973. })
  974. } else {
  975. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  976. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  977. {Name: "Modify category"},
  978. })
  979. }
  980. data := utils.MySql_shop_category{
  981. A_id: 0,
  982. A_user: 0,
  983. A_name: "",
  984. A_alias: "",
  985. A_lft: 0,
  986. A_rgt: 0,
  987. }
  988. if wrap.CurrSubModule == "categories-modify" {
  989. if len(wrap.UrlArgs) != 3 {
  990. return "", "", ""
  991. }
  992. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  993. return "", "", ""
  994. }
  995. err := wrap.DB.QueryRow(`
  996. SELECT
  997. id,
  998. user,
  999. name,
  1000. alias,
  1001. lft,
  1002. rgt
  1003. FROM
  1004. shop_cats
  1005. WHERE
  1006. id = ?
  1007. LIMIT 1;`,
  1008. utils.StrToInt(wrap.UrlArgs[2]),
  1009. ).Scan(
  1010. &data.A_id,
  1011. &data.A_user,
  1012. &data.A_name,
  1013. &data.A_alias,
  1014. &data.A_lft,
  1015. &data.A_rgt,
  1016. )
  1017. if err != nil {
  1018. return "", "", ""
  1019. }
  1020. }
  1021. btn_caption := "Add"
  1022. if wrap.CurrSubModule == "categories-modify" {
  1023. btn_caption = "Save"
  1024. }
  1025. parentId := 0
  1026. if wrap.CurrSubModule == "categories-modify" {
  1027. parentId = this.shop_GetCategoryParentId(wrap, data.A_id)
  1028. }
  1029. content += builder.DataForm(wrap, []builder.DataFormField{
  1030. {
  1031. Kind: builder.DFKHidden,
  1032. Name: "action",
  1033. Value: "shop-categories-modify",
  1034. },
  1035. {
  1036. Kind: builder.DFKHidden,
  1037. Name: "id",
  1038. Value: utils.IntToStr(data.A_id),
  1039. },
  1040. {
  1041. Kind: builder.DFKText,
  1042. Caption: "Parent",
  1043. Name: "parent",
  1044. Value: "0",
  1045. CallBack: func(field *builder.DataFormField) string {
  1046. return `<div class="form-group n2">` +
  1047. `<div class="row">` +
  1048. `<div class="col-md-3">` +
  1049. `<label for="lbl_parent">Parent</label>` +
  1050. `</div>` +
  1051. `<div class="col-md-9">` +
  1052. `<div>` +
  1053. `<select class="selectpicker form-control" id="lbl_parent" name="parent" data-live-search="true">` +
  1054. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1055. this.shop_GetCategorySelectOptions(wrap, data.A_id, parentId, []int{}) +
  1056. `</select>` +
  1057. `</div>` +
  1058. `</div>` +
  1059. `</div>` +
  1060. `</div>`
  1061. },
  1062. },
  1063. {
  1064. Kind: builder.DFKText,
  1065. Caption: "Name",
  1066. Name: "name",
  1067. Value: data.A_name,
  1068. Required: true,
  1069. Min: "1",
  1070. Max: "255",
  1071. },
  1072. {
  1073. Kind: builder.DFKText,
  1074. Caption: "Alias",
  1075. Name: "alias",
  1076. Value: data.A_alias,
  1077. Hint: "Example: popular-products",
  1078. Max: "255",
  1079. },
  1080. {
  1081. Kind: builder.DFKSubmit,
  1082. Value: btn_caption,
  1083. Target: "add-edit-button",
  1084. },
  1085. })
  1086. if wrap.CurrSubModule == "categories-add" {
  1087. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1088. } else {
  1089. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1090. }
  1091. } else if wrap.CurrSubModule == "attributes-add" || wrap.CurrSubModule == "attributes-modify" {
  1092. if wrap.CurrSubModule == "attributes-add" {
  1093. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1094. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1095. {Name: "Add new attribute"},
  1096. })
  1097. } else {
  1098. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1099. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1100. {Name: "Modify attribute"},
  1101. })
  1102. }
  1103. data := utils.MySql_shop_filter{
  1104. A_id: 0,
  1105. A_name: "",
  1106. A_filter: "",
  1107. }
  1108. if wrap.CurrSubModule == "attributes-modify" {
  1109. if len(wrap.UrlArgs) != 3 {
  1110. return "", "", ""
  1111. }
  1112. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1113. return "", "", ""
  1114. }
  1115. err := wrap.DB.QueryRow(`
  1116. SELECT
  1117. id,
  1118. name,
  1119. filter
  1120. FROM
  1121. shop_filters
  1122. WHERE
  1123. id = ?
  1124. LIMIT 1;`,
  1125. utils.StrToInt(wrap.UrlArgs[2]),
  1126. ).Scan(
  1127. &data.A_id,
  1128. &data.A_name,
  1129. &data.A_filter,
  1130. )
  1131. if err != nil {
  1132. return "", "", ""
  1133. }
  1134. }
  1135. btn_caption := "Add"
  1136. if wrap.CurrSubModule == "attributes-modify" {
  1137. btn_caption = "Save"
  1138. }
  1139. content += builder.DataForm(wrap, []builder.DataFormField{
  1140. {
  1141. Kind: builder.DFKHidden,
  1142. Name: "action",
  1143. Value: "shop-attributes-modify",
  1144. },
  1145. {
  1146. Kind: builder.DFKHidden,
  1147. Name: "id",
  1148. Value: utils.IntToStr(data.A_id),
  1149. },
  1150. {
  1151. Kind: builder.DFKText,
  1152. Caption: "Attribute name",
  1153. Name: "name",
  1154. Value: data.A_name,
  1155. Required: true,
  1156. Min: "1",
  1157. Max: "255",
  1158. },
  1159. {
  1160. Kind: builder.DFKText,
  1161. Caption: "Attribute in filter",
  1162. Name: "filter",
  1163. Value: data.A_filter,
  1164. Required: true,
  1165. Min: "1",
  1166. Max: "255",
  1167. },
  1168. {
  1169. Kind: builder.DFKText,
  1170. Caption: "Attribute values",
  1171. Name: "",
  1172. Value: "",
  1173. CallBack: func(field *builder.DataFormField) string {
  1174. return `<div class="form-group n4">` +
  1175. `<div class="row">` +
  1176. `<div class="col-md-3">` +
  1177. `<label>Attribute values</label>` +
  1178. `</div>` +
  1179. `<div class="col-md-9">` +
  1180. `<div class="list-wrapper">` +
  1181. `<div id="list">` +
  1182. this.shop_GetFilterValuesInputs(wrap, data.A_id) +
  1183. `</div>` +
  1184. `<div class="list-button"><button type="button" class="btn btn-success" onclick="fave.ShopAttributesAdd();">Add attribute value</button></div>` +
  1185. `</div>` +
  1186. `</div>` +
  1187. `</div>` +
  1188. `</div>`
  1189. },
  1190. },
  1191. {
  1192. Kind: builder.DFKSubmit,
  1193. Value: btn_caption,
  1194. Target: "add-edit-button",
  1195. },
  1196. })
  1197. if wrap.CurrSubModule == "attributes-add" {
  1198. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1199. } else {
  1200. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1201. }
  1202. } else if wrap.CurrSubModule == "currencies-add" || wrap.CurrSubModule == "currencies-modify" {
  1203. if wrap.CurrSubModule == "currencies-add" {
  1204. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1205. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1206. {Name: "Add new currency"},
  1207. })
  1208. } else {
  1209. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1210. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1211. {Name: "Modify currency"},
  1212. })
  1213. }
  1214. data := utils.MySql_shop_currency{
  1215. A_id: 0,
  1216. A_name: "",
  1217. A_coefficient: 0,
  1218. A_code: "",
  1219. A_symbol: "",
  1220. }
  1221. if wrap.CurrSubModule == "currencies-modify" {
  1222. if len(wrap.UrlArgs) != 3 {
  1223. return "", "", ""
  1224. }
  1225. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1226. return "", "", ""
  1227. }
  1228. err := wrap.DB.QueryRow(`
  1229. SELECT
  1230. id,
  1231. name,
  1232. coefficient,
  1233. code,
  1234. symbol
  1235. FROM
  1236. shop_currencies
  1237. WHERE
  1238. id = ?
  1239. LIMIT 1;`,
  1240. utils.StrToInt(wrap.UrlArgs[2]),
  1241. ).Scan(
  1242. &data.A_id,
  1243. &data.A_name,
  1244. &data.A_coefficient,
  1245. &data.A_code,
  1246. &data.A_symbol,
  1247. )
  1248. if err != nil {
  1249. return "", "", ""
  1250. }
  1251. }
  1252. btn_caption := "Add"
  1253. if wrap.CurrSubModule == "currencies-modify" {
  1254. btn_caption = "Save"
  1255. }
  1256. content += builder.DataForm(wrap, []builder.DataFormField{
  1257. {
  1258. Kind: builder.DFKHidden,
  1259. Name: "action",
  1260. Value: "shop-currencies-modify",
  1261. },
  1262. {
  1263. Kind: builder.DFKHidden,
  1264. Name: "id",
  1265. Value: utils.IntToStr(data.A_id),
  1266. },
  1267. {
  1268. Kind: builder.DFKText,
  1269. Caption: "Currency name",
  1270. Name: "name",
  1271. Value: data.A_name,
  1272. Required: true,
  1273. Min: "1",
  1274. Max: "255",
  1275. },
  1276. {
  1277. Kind: builder.DFKText,
  1278. Caption: "Currency coefficient",
  1279. Name: "coefficient",
  1280. Value: "0",
  1281. CallBack: func(field *builder.DataFormField) string {
  1282. return `<div class="form-group n3">` +
  1283. `<div class="row">` +
  1284. `<div class="col-md-3">` +
  1285. `<label for="lbl_coefficient">Currency coefficient</label>` +
  1286. `</div>` +
  1287. `<div class="col-md-9">` +
  1288. `<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>` +
  1289. `</div>` +
  1290. `</div>` +
  1291. `</div>`
  1292. },
  1293. },
  1294. {
  1295. Kind: builder.DFKText,
  1296. Caption: "Currency code",
  1297. Name: "code",
  1298. Value: data.A_code,
  1299. Required: true,
  1300. Min: "1",
  1301. Max: "10",
  1302. },
  1303. {
  1304. Kind: builder.DFKText,
  1305. Caption: "Currency symbol",
  1306. Name: "symbol",
  1307. Value: data.A_symbol,
  1308. Required: true,
  1309. Min: "1",
  1310. Max: "5",
  1311. },
  1312. {
  1313. Kind: builder.DFKSubmit,
  1314. Value: btn_caption,
  1315. Target: "add-edit-button",
  1316. },
  1317. })
  1318. if wrap.CurrSubModule == "currencies-add" {
  1319. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1320. } else {
  1321. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1322. }
  1323. }
  1324. return this.getSidebarModules(wrap), content, sidebar
  1325. })
  1326. }