module_shop.go 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  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]) + `" onerror="fave.ShopProductsRetryImage(this);" /></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. if len(wrap.UrlArgs) >= 3 && utils.IsNumeric(wrap.UrlArgs[2]) {
  742. content += `<div class="product-copy"><a title="Duplicate product" href="javascript:fave.ShopProductsDuplicate(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconCopy + `</a></div>`
  743. }
  744. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  745. {Name: "Modify product"},
  746. })
  747. }
  748. data := utils.MySql_shop_product{
  749. A_id: 0,
  750. A_user: 0,
  751. A_currency: 0,
  752. A_price: 0,
  753. A_name: "",
  754. A_alias: "",
  755. A_vendor: "",
  756. A_quantity: 0,
  757. A_category: 0,
  758. A_briefly: "",
  759. A_content: "",
  760. A_datetime: 0,
  761. A_active: 0,
  762. }
  763. if wrap.CurrSubModule == "modify" {
  764. if len(wrap.UrlArgs) != 3 {
  765. return "", "", ""
  766. }
  767. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  768. return "", "", ""
  769. }
  770. err := wrap.DB.QueryRow(`
  771. SELECT
  772. id,
  773. user,
  774. currency,
  775. price,
  776. name,
  777. alias,
  778. vendor,
  779. quantity,
  780. category,
  781. briefly,
  782. content,
  783. active
  784. FROM
  785. shop_products
  786. WHERE
  787. id = ?
  788. LIMIT 1;`,
  789. utils.StrToInt(wrap.UrlArgs[2]),
  790. ).Scan(
  791. &data.A_id,
  792. &data.A_user,
  793. &data.A_currency,
  794. &data.A_price,
  795. &data.A_name,
  796. &data.A_alias,
  797. &data.A_vendor,
  798. &data.A_quantity,
  799. &data.A_category,
  800. &data.A_briefly,
  801. &data.A_content,
  802. &data.A_active,
  803. )
  804. if err != nil {
  805. return "", "", ""
  806. }
  807. }
  808. // All product current categories
  809. var selids []int
  810. if data.A_id > 0 {
  811. rows, err := wrap.DB.Query("SELECT category_id FROM shop_cat_product_rel WHERE product_id = ?;", data.A_id)
  812. if err == nil {
  813. defer rows.Close()
  814. values := make([]int, 1)
  815. scan := make([]interface{}, len(values))
  816. for i := range values {
  817. scan[i] = &values[i]
  818. }
  819. for rows.Next() {
  820. err = rows.Scan(scan...)
  821. if err == nil {
  822. selids = append(selids, int(values[0]))
  823. }
  824. }
  825. }
  826. }
  827. btn_caption := "Add"
  828. if wrap.CurrSubModule == "modify" {
  829. btn_caption = "Save"
  830. }
  831. content += builder.DataForm(wrap, []builder.DataFormField{
  832. {
  833. Kind: builder.DFKHidden,
  834. Name: "action",
  835. Value: "shop-modify",
  836. },
  837. {
  838. Kind: builder.DFKHidden,
  839. Name: "id",
  840. Value: utils.IntToStr(data.A_id),
  841. },
  842. {
  843. Kind: builder.DFKText,
  844. Caption: "Product name",
  845. Name: "name",
  846. Value: data.A_name,
  847. Required: true,
  848. Min: "1",
  849. Max: "255",
  850. },
  851. {
  852. Kind: builder.DFKText,
  853. Caption: "Product price",
  854. Name: "price",
  855. Value: "0",
  856. CallBack: func(field *builder.DataFormField) string {
  857. return `<div class="form-group n3">` +
  858. `<div class="row">` +
  859. `<div class="col-md-3">` +
  860. `<label for="lbl_price">Product price</label>` +
  861. `</div>` +
  862. `<div class="col-md-9">` +
  863. `<div>` +
  864. `<div class="row">` +
  865. `<div class="col-md-8">` +
  866. `<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>` +
  867. `<div class="d-md-none mb-3"></div>` +
  868. `</div>` +
  869. `<div class="col-md-4">` +
  870. `<select class="selectpicker form-control" id="lbl_currency" name="currency" data-live-search="true">` +
  871. this.shop_GetCurrencySelectOptions(wrap, data.A_currency) +
  872. `</select>` +
  873. `</div>` +
  874. `</div>` +
  875. `</div>` +
  876. `</div>` +
  877. `</div>` +
  878. `</div>`
  879. },
  880. },
  881. {
  882. Kind: builder.DFKText,
  883. Caption: "Product alias",
  884. Name: "alias",
  885. Value: data.A_alias,
  886. Hint: "Example: mobile-phone",
  887. Max: "255",
  888. },
  889. {
  890. Kind: builder.DFKText,
  891. Caption: "Vendor/Count",
  892. Name: "vendor",
  893. Value: "0",
  894. CallBack: func(field *builder.DataFormField) string {
  895. return `<div class="form-group n5">` +
  896. `<div class="row">` +
  897. `<div class="col-md-3">` +
  898. `<label for="lbl_vendor">Vendor/Count</label>` +
  899. `</div>` +
  900. `<div class="col-md-9">` +
  901. `<div>` +
  902. `<div class="row">` +
  903. `<div class="col-md-8">` +
  904. `<div><input class="form-control" type="text" id="lbl_vendor" name="vendor" value="` + html.EscapeString(data.A_vendor) + `" placeholder="" autocomplete="off"></div>` +
  905. `<div class="d-md-none mb-3"></div>` +
  906. `</div>` +
  907. `<div class="col-md-4">` +
  908. `<input class="form-control" type="number" step="1" id="lbl_quantity" name="quantity" value="` + utils.IntToStr(data.A_quantity) + `" placeholder="" autocomplete="off">` +
  909. `</div>` +
  910. `</div>` +
  911. `</div>` +
  912. `</div>` +
  913. `</div>` +
  914. `</div>`
  915. },
  916. },
  917. {
  918. Kind: builder.DFKText,
  919. Caption: "Category",
  920. Name: "category",
  921. Value: "0",
  922. CallBack: func(field *builder.DataFormField) string {
  923. return `<div class="form-group n6">` +
  924. `<div class="row">` +
  925. `<div class="col-md-3">` +
  926. `<label for="lbl_category">Category</label>` +
  927. `</div>` +
  928. `<div class="col-md-9">` +
  929. `<div>` +
  930. `<select class="selectpicker form-control" id="lbl_category" name="category" data-live-search="true">` +
  931. `<option title="Nothing selected" value="0">&mdash;</option>` +
  932. this.shop_GetCategorySelectOptions(wrap, 0, data.A_category, []int{}) +
  933. `</select>` +
  934. `</div>` +
  935. `</div>` +
  936. `</div>` +
  937. `</div>`
  938. },
  939. },
  940. {
  941. Kind: builder.DFKText,
  942. Caption: "Categories",
  943. Name: "cats",
  944. Value: "0",
  945. CallBack: func(field *builder.DataFormField) string {
  946. return `<div class="form-group n7">` +
  947. `<div class="row">` +
  948. `<div class="col-md-3">` +
  949. `<label for="lbl_cats">Categories</label>` +
  950. `</div>` +
  951. `<div class="col-md-9">` +
  952. `<div>` +
  953. `<select class="selectpicker form-control" id="lbl_cats" name="cats[]" data-live-search="true" multiple>` +
  954. this.shop_GetCategorySelectOptions(wrap, 0, 0, selids) +
  955. `</select>` +
  956. `</div>` +
  957. `</div>` +
  958. `</div>` +
  959. `</div>`
  960. },
  961. },
  962. {
  963. Kind: builder.DFKText,
  964. Caption: "Attributes",
  965. Name: "",
  966. Value: "",
  967. CallBack: func(field *builder.DataFormField) string {
  968. return `<div class="form-group n8">` +
  969. `<div class="row">` +
  970. `<div class="col-md-3">` +
  971. `<label>Attributes</label>` +
  972. `</div>` +
  973. `<div class="col-md-9">` +
  974. `<div class="list-wrapper">` +
  975. `<div id="list">` +
  976. this.shop_GetProductValuesInputs(wrap, data.A_id) +
  977. `</div>` +
  978. `<div class="list-button position-relative">` +
  979. `<select class="selectpicker form-control" id="lbl_attributes" data-live-search="true" onchange="fave.ShopProductsAdd();">` +
  980. this.shop_GetAllAttributesSelectOptions(wrap) +
  981. `</select>` +
  982. `</div>` +
  983. `</div>` +
  984. `</div>` +
  985. `</div>` +
  986. `</div>`
  987. },
  988. },
  989. {
  990. Kind: builder.DFKTextArea,
  991. Caption: "Briefly",
  992. Name: "briefly",
  993. Value: data.A_briefly,
  994. Classes: "briefly wysiwyg",
  995. },
  996. {
  997. Kind: builder.DFKTextArea,
  998. Caption: "Product content",
  999. Name: "content",
  1000. Value: data.A_content,
  1001. Classes: "wysiwyg",
  1002. },
  1003. {
  1004. Kind: builder.DFKText,
  1005. Caption: "Product images",
  1006. Name: "",
  1007. Value: "",
  1008. CallBack: func(field *builder.DataFormField) string {
  1009. if data.A_id == 0 {
  1010. return ``
  1011. }
  1012. return `<div class="form-group n11">` +
  1013. `<div class="row">` +
  1014. `<div class="col-md-3">` +
  1015. `<label>Product images</label>` +
  1016. `</div>` +
  1017. `<div class="col-md-9">` +
  1018. `<div class="list-wrapper">` +
  1019. `<div id="list-images">` +
  1020. this.shop_GetAllProductImages(wrap, data.A_id) +
  1021. `</div>` +
  1022. `<div id="img-upload-block" class="list-button position-relative">` +
  1023. `<div id="upload-msg">Uploading...</div>` +
  1024. `<input class="form-control ignore-lost-data" type="file" id="file" name="file" onchange="fave.ShopProductsUploadImage('shop-upload-image', ` + utils.IntToStr(data.A_id) + `, 'file');" style="font-size:13px;" multiple />` +
  1025. `</div>` +
  1026. `</div>` +
  1027. `</div>` +
  1028. `</div>` +
  1029. `</div>`
  1030. },
  1031. },
  1032. {
  1033. Kind: builder.DFKCheckBox,
  1034. Caption: "Active",
  1035. Name: "active",
  1036. Value: utils.IntToStr(data.A_active),
  1037. },
  1038. {
  1039. Kind: builder.DFKSubmit,
  1040. Value: btn_caption,
  1041. Target: "add-edit-button",
  1042. },
  1043. })
  1044. if wrap.CurrSubModule == "add" {
  1045. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1046. } else {
  1047. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1048. }
  1049. } else if wrap.CurrSubModule == "categories-add" || wrap.CurrSubModule == "categories-modify" {
  1050. if wrap.CurrSubModule == "categories-add" {
  1051. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1052. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1053. {Name: "Add new category"},
  1054. })
  1055. } else {
  1056. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1057. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1058. {Name: "Modify category"},
  1059. })
  1060. }
  1061. data := utils.MySql_shop_category{
  1062. A_id: 0,
  1063. A_user: 0,
  1064. A_name: "",
  1065. A_alias: "",
  1066. A_lft: 0,
  1067. A_rgt: 0,
  1068. }
  1069. if wrap.CurrSubModule == "categories-modify" {
  1070. if len(wrap.UrlArgs) != 3 {
  1071. return "", "", ""
  1072. }
  1073. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1074. return "", "", ""
  1075. }
  1076. err := wrap.DB.QueryRow(`
  1077. SELECT
  1078. id,
  1079. user,
  1080. name,
  1081. alias,
  1082. lft,
  1083. rgt
  1084. FROM
  1085. shop_cats
  1086. WHERE
  1087. id = ?
  1088. LIMIT 1;`,
  1089. utils.StrToInt(wrap.UrlArgs[2]),
  1090. ).Scan(
  1091. &data.A_id,
  1092. &data.A_user,
  1093. &data.A_name,
  1094. &data.A_alias,
  1095. &data.A_lft,
  1096. &data.A_rgt,
  1097. )
  1098. if err != nil {
  1099. return "", "", ""
  1100. }
  1101. }
  1102. btn_caption := "Add"
  1103. if wrap.CurrSubModule == "categories-modify" {
  1104. btn_caption = "Save"
  1105. }
  1106. parentId := 0
  1107. if wrap.CurrSubModule == "categories-modify" {
  1108. parentId = this.shop_GetCategoryParentId(wrap, data.A_id)
  1109. }
  1110. content += builder.DataForm(wrap, []builder.DataFormField{
  1111. {
  1112. Kind: builder.DFKHidden,
  1113. Name: "action",
  1114. Value: "shop-categories-modify",
  1115. },
  1116. {
  1117. Kind: builder.DFKHidden,
  1118. Name: "id",
  1119. Value: utils.IntToStr(data.A_id),
  1120. },
  1121. {
  1122. Kind: builder.DFKText,
  1123. Caption: "Parent",
  1124. Name: "parent",
  1125. Value: "0",
  1126. CallBack: func(field *builder.DataFormField) string {
  1127. return `<div class="form-group n2">` +
  1128. `<div class="row">` +
  1129. `<div class="col-md-3">` +
  1130. `<label for="lbl_parent">Parent</label>` +
  1131. `</div>` +
  1132. `<div class="col-md-9">` +
  1133. `<div>` +
  1134. `<select class="selectpicker form-control" id="lbl_parent" name="parent" data-live-search="true">` +
  1135. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1136. this.shop_GetCategorySelectOptions(wrap, data.A_id, parentId, []int{}) +
  1137. `</select>` +
  1138. `</div>` +
  1139. `</div>` +
  1140. `</div>` +
  1141. `</div>`
  1142. },
  1143. },
  1144. {
  1145. Kind: builder.DFKText,
  1146. Caption: "Name",
  1147. Name: "name",
  1148. Value: data.A_name,
  1149. Required: true,
  1150. Min: "1",
  1151. Max: "255",
  1152. },
  1153. {
  1154. Kind: builder.DFKText,
  1155. Caption: "Alias",
  1156. Name: "alias",
  1157. Value: data.A_alias,
  1158. Hint: "Example: popular-products",
  1159. Max: "255",
  1160. },
  1161. {
  1162. Kind: builder.DFKSubmit,
  1163. Value: btn_caption,
  1164. Target: "add-edit-button",
  1165. },
  1166. })
  1167. if wrap.CurrSubModule == "categories-add" {
  1168. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1169. } else {
  1170. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1171. }
  1172. } else if wrap.CurrSubModule == "attributes-add" || wrap.CurrSubModule == "attributes-modify" {
  1173. if wrap.CurrSubModule == "attributes-add" {
  1174. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1175. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1176. {Name: "Add new attribute"},
  1177. })
  1178. } else {
  1179. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1180. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1181. {Name: "Modify attribute"},
  1182. })
  1183. }
  1184. data := utils.MySql_shop_filter{
  1185. A_id: 0,
  1186. A_name: "",
  1187. A_filter: "",
  1188. }
  1189. if wrap.CurrSubModule == "attributes-modify" {
  1190. if len(wrap.UrlArgs) != 3 {
  1191. return "", "", ""
  1192. }
  1193. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1194. return "", "", ""
  1195. }
  1196. err := wrap.DB.QueryRow(`
  1197. SELECT
  1198. id,
  1199. name,
  1200. filter
  1201. FROM
  1202. shop_filters
  1203. WHERE
  1204. id = ?
  1205. LIMIT 1;`,
  1206. utils.StrToInt(wrap.UrlArgs[2]),
  1207. ).Scan(
  1208. &data.A_id,
  1209. &data.A_name,
  1210. &data.A_filter,
  1211. )
  1212. if err != nil {
  1213. return "", "", ""
  1214. }
  1215. }
  1216. btn_caption := "Add"
  1217. if wrap.CurrSubModule == "attributes-modify" {
  1218. btn_caption = "Save"
  1219. }
  1220. content += builder.DataForm(wrap, []builder.DataFormField{
  1221. {
  1222. Kind: builder.DFKHidden,
  1223. Name: "action",
  1224. Value: "shop-attributes-modify",
  1225. },
  1226. {
  1227. Kind: builder.DFKHidden,
  1228. Name: "id",
  1229. Value: utils.IntToStr(data.A_id),
  1230. },
  1231. {
  1232. Kind: builder.DFKText,
  1233. Caption: "Attribute name",
  1234. Name: "name",
  1235. Value: data.A_name,
  1236. Required: true,
  1237. Min: "1",
  1238. Max: "255",
  1239. },
  1240. {
  1241. Kind: builder.DFKText,
  1242. Caption: "Attribute in filter",
  1243. Name: "filter",
  1244. Value: data.A_filter,
  1245. Required: true,
  1246. Min: "1",
  1247. Max: "255",
  1248. },
  1249. {
  1250. Kind: builder.DFKText,
  1251. Caption: "Attribute values",
  1252. Name: "",
  1253. Value: "",
  1254. CallBack: func(field *builder.DataFormField) string {
  1255. return `<div class="form-group n4">` +
  1256. `<div class="row">` +
  1257. `<div class="col-md-3">` +
  1258. `<label>Attribute values</label>` +
  1259. `</div>` +
  1260. `<div class="col-md-9">` +
  1261. `<div class="list-wrapper">` +
  1262. `<div id="list">` +
  1263. this.shop_GetFilterValuesInputs(wrap, data.A_id) +
  1264. `</div>` +
  1265. `<div class="list-button"><button type="button" class="btn btn-success" onclick="fave.ShopAttributesAdd();">Add attribute value</button></div>` +
  1266. `</div>` +
  1267. `</div>` +
  1268. `</div>` +
  1269. `</div>`
  1270. },
  1271. },
  1272. {
  1273. Kind: builder.DFKSubmit,
  1274. Value: btn_caption,
  1275. Target: "add-edit-button",
  1276. },
  1277. })
  1278. if wrap.CurrSubModule == "attributes-add" {
  1279. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1280. } else {
  1281. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1282. }
  1283. } else if wrap.CurrSubModule == "currencies-add" || wrap.CurrSubModule == "currencies-modify" {
  1284. if wrap.CurrSubModule == "currencies-add" {
  1285. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1286. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1287. {Name: "Add new currency"},
  1288. })
  1289. } else {
  1290. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1291. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1292. {Name: "Modify currency"},
  1293. })
  1294. }
  1295. data := utils.MySql_shop_currency{
  1296. A_id: 0,
  1297. A_name: "",
  1298. A_coefficient: 0,
  1299. A_code: "",
  1300. A_symbol: "",
  1301. }
  1302. if wrap.CurrSubModule == "currencies-modify" {
  1303. if len(wrap.UrlArgs) != 3 {
  1304. return "", "", ""
  1305. }
  1306. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1307. return "", "", ""
  1308. }
  1309. err := wrap.DB.QueryRow(`
  1310. SELECT
  1311. id,
  1312. name,
  1313. coefficient,
  1314. code,
  1315. symbol
  1316. FROM
  1317. shop_currencies
  1318. WHERE
  1319. id = ?
  1320. LIMIT 1;`,
  1321. utils.StrToInt(wrap.UrlArgs[2]),
  1322. ).Scan(
  1323. &data.A_id,
  1324. &data.A_name,
  1325. &data.A_coefficient,
  1326. &data.A_code,
  1327. &data.A_symbol,
  1328. )
  1329. if err != nil {
  1330. return "", "", ""
  1331. }
  1332. }
  1333. btn_caption := "Add"
  1334. if wrap.CurrSubModule == "currencies-modify" {
  1335. btn_caption = "Save"
  1336. }
  1337. content += builder.DataForm(wrap, []builder.DataFormField{
  1338. {
  1339. Kind: builder.DFKHidden,
  1340. Name: "action",
  1341. Value: "shop-currencies-modify",
  1342. },
  1343. {
  1344. Kind: builder.DFKHidden,
  1345. Name: "id",
  1346. Value: utils.IntToStr(data.A_id),
  1347. },
  1348. {
  1349. Kind: builder.DFKText,
  1350. Caption: "Currency name",
  1351. Name: "name",
  1352. Value: data.A_name,
  1353. Required: true,
  1354. Min: "1",
  1355. Max: "255",
  1356. },
  1357. {
  1358. Kind: builder.DFKText,
  1359. Caption: "Currency coefficient",
  1360. Name: "coefficient",
  1361. Value: "0",
  1362. CallBack: func(field *builder.DataFormField) string {
  1363. return `<div class="form-group n3">` +
  1364. `<div class="row">` +
  1365. `<div class="col-md-3">` +
  1366. `<label for="lbl_coefficient">Currency coefficient</label>` +
  1367. `</div>` +
  1368. `<div class="col-md-9">` +
  1369. `<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>` +
  1370. `</div>` +
  1371. `</div>` +
  1372. `</div>`
  1373. },
  1374. },
  1375. {
  1376. Kind: builder.DFKText,
  1377. Caption: "Currency code",
  1378. Name: "code",
  1379. Value: data.A_code,
  1380. Required: true,
  1381. Min: "1",
  1382. Max: "10",
  1383. },
  1384. {
  1385. Kind: builder.DFKText,
  1386. Caption: "Currency symbol",
  1387. Name: "symbol",
  1388. Value: data.A_symbol,
  1389. Required: true,
  1390. Min: "1",
  1391. Max: "5",
  1392. },
  1393. {
  1394. Kind: builder.DFKSubmit,
  1395. Value: btn_caption,
  1396. Target: "add-edit-button",
  1397. },
  1398. })
  1399. if wrap.CurrSubModule == "currencies-add" {
  1400. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1401. } else {
  1402. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1403. }
  1404. }
  1405. return this.getSidebarModules(wrap), content, sidebar
  1406. })
  1407. }