module_shop.go 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
  1. package modules
  2. import (
  3. "html"
  4. "net/http"
  5. "strings"
  6. "time"
  7. "golang-fave/assets"
  8. "golang-fave/consts"
  9. "golang-fave/engine/basket"
  10. "golang-fave/engine/builder"
  11. "golang-fave/engine/fetdata"
  12. "golang-fave/engine/sqlw"
  13. "golang-fave/engine/wrapper"
  14. "golang-fave/utils"
  15. )
  16. func (this *Modules) shop_GetCurrencySelectOptions(wrap *wrapper.Wrapper, id int) string {
  17. result := ``
  18. rows, err := wrap.DB.Query(
  19. `SELECT
  20. id,
  21. code
  22. FROM
  23. shop_currencies
  24. ORDER BY
  25. id ASC
  26. ;`,
  27. )
  28. if err == nil {
  29. defer rows.Close()
  30. values := make([]string, 2)
  31. scan := make([]interface{}, len(values))
  32. for i := range values {
  33. scan[i] = &values[i]
  34. }
  35. idStr := utils.IntToStr(id)
  36. for rows.Next() {
  37. err = rows.Scan(scan...)
  38. if *wrap.LogCpError(&err) == nil {
  39. selected := ""
  40. if string(values[0]) == idStr {
  41. selected = " selected"
  42. }
  43. result += `<option title="` + html.EscapeString(string(values[1])) + `" value="` + html.EscapeString(string(values[0])) + `"` + selected + `>` + html.EscapeString(string(values[1])) + `</option>`
  44. }
  45. }
  46. }
  47. return result
  48. }
  49. func (this *Modules) shop_GetProductValuesInputs(wrap *wrapper.Wrapper, product_id int) string {
  50. result := ``
  51. rows, err := wrap.DB.Query(
  52. `SELECT
  53. shop_filters.id,
  54. shop_filters.name,
  55. shop_filters_values.id,
  56. shop_filters_values.name,
  57. IF(shop_filter_product_values.filter_value_id > 0, 1, 0) as selected
  58. FROM
  59. shop_filters_values
  60. LEFT JOIN shop_filters ON shop_filters.id = shop_filters_values.filter_id
  61. LEFT JOIN shop_filter_product_values ON
  62. shop_filter_product_values.filter_value_id = shop_filters_values.id AND
  63. shop_filter_product_values.product_id = ` + utils.IntToStr(product_id) + `
  64. LEFT JOIN (
  65. SELECT
  66. shop_filters_values.filter_id,
  67. shop_filter_product_values.product_id
  68. FROM
  69. shop_filter_product_values
  70. LEFT JOIN shop_filters_values ON shop_filters_values.id = shop_filter_product_values.filter_value_id
  71. WHERE
  72. shop_filter_product_values.product_id = ` + utils.IntToStr(product_id) + `
  73. GROUP BY
  74. shop_filters_values.filter_id
  75. ) as filter_used ON filter_used.filter_id = shop_filters.id
  76. WHERE
  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 *wrap.LogCpError(&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 *wrap.LogCpError(&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 *wrap.LogCpError(&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 *wrap.LogCpError(&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. id,
  216. product_id,
  217. filename
  218. FROM
  219. shop_product_images
  220. WHERE
  221. product_id = ?
  222. ORDER BY
  223. ord ASC
  224. ;`,
  225. product_id,
  226. )
  227. if err == nil {
  228. defer rows.Close()
  229. values := make([]string, 3)
  230. scan := make([]interface{}, len(values))
  231. for i := range values {
  232. scan[i] = &values[i]
  233. }
  234. for rows.Next() {
  235. err = rows.Scan(scan...)
  236. if *wrap.LogCpError(&err) == nil {
  237. result += `<div class="attached-img" data-id="` + html.EscapeString(string(values[0])) + `"><a href="/products/images/` + html.EscapeString(string(values[1])) + `/` + html.EscapeString(string(values[2])) + `" title="` + html.EscapeString(string(values[2])) + `" target="_blank"><img id="pimg_` + string(values[1]) + `_` + strings.Replace(string(values[2]), ".", "_", -1) + `" src="/products/images/` + string(values[1]) + `/thumb-0-` + string(values[2]) + `" onerror="WaitForFave(function(){fave.ShopProductsRetryImage(this, 'pimg_` + string(values[1]) + `_` + strings.Replace(string(values[2]), ".", "_", -1) + `');});" /></a><a class="remove" onclick="fave.ShopProductsDeleteImage(this, ` + html.EscapeString(string(values[1])) + `, '` + html.EscapeString(string(values[2])) + `');"><svg viewBox="1 1 11 14" width="10" height="12" class="sicon" version="1.1"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"></path></svg></a></div>`
  238. }
  239. }
  240. }
  241. return result
  242. }
  243. func (this *Modules) shop_GetSubProducts(wrap *wrapper.Wrapper, id int) string {
  244. result := ``
  245. rows, err := wrap.DB.Query(
  246. `SELECT
  247. id,
  248. name
  249. FROM
  250. shop_products
  251. WHERE
  252. parent_id = ?
  253. ORDER BY
  254. id DESC
  255. ;`,
  256. id,
  257. )
  258. if err == nil {
  259. defer rows.Close()
  260. values := make([]string, 2)
  261. scan := make([]interface{}, len(values))
  262. for i := range values {
  263. scan[i] = &values[i]
  264. }
  265. for rows.Next() {
  266. err = rows.Scan(scan...)
  267. if *wrap.LogCpError(&err) == nil {
  268. result += `<div><a href="/cp/` + wrap.CurrModule + `/modify/` + html.EscapeString(string(values[0])) + `/">` + html.EscapeString(string(values[1])) + ` ` + html.EscapeString(string(values[0])) + `</a> <a class="ico delete" title="Delete" href="javascript:fave.ActionDataTableDelete(this,'shop-detach','` + html.EscapeString(string(values[0])) + `','Are you sure want to detach product?');"><svg viewBox="0 0 16 16" width="16" height="16" class="sicon" version="1.1"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"></path></svg></a></div>`
  269. }
  270. }
  271. }
  272. return result
  273. }
  274. func (this *Modules) shop_GetParentProduct(wrap *wrapper.Wrapper, id int) string {
  275. result := ``
  276. rows, err := wrap.DB.Query(
  277. `SELECT
  278. id,
  279. name
  280. FROM
  281. shop_products
  282. WHERE
  283. id = ?
  284. ;`,
  285. id,
  286. )
  287. if err == nil {
  288. defer rows.Close()
  289. values := make([]string, 2)
  290. scan := make([]interface{}, len(values))
  291. for i := range values {
  292. scan[i] = &values[i]
  293. }
  294. for rows.Next() {
  295. err = rows.Scan(scan...)
  296. if *wrap.LogCpError(&err) == nil {
  297. result += `<div><a href="/cp/` + wrap.CurrModule + `/modify/` + html.EscapeString(string(values[0])) + `/">` + html.EscapeString(string(values[1])) + ` ` + html.EscapeString(string(values[0])) + `</a></div>`
  298. }
  299. }
  300. }
  301. return result
  302. }
  303. func (this *Modules) shop_GetOrderStatus(status int) string {
  304. if status == 0 {
  305. return `<span style="color:#f0ad4e;">New</span>`
  306. } else if status == 1 {
  307. return `<span style="color:#28a745;">Confirmed</span>`
  308. } else if status == 2 {
  309. return `<span style="color:#d9534f;">Canceled</span>`
  310. } else if status == 3 {
  311. return `<span style="color:#f0ad4e;">In progress</span>`
  312. } else if status == 4 {
  313. return `<span style="color:#6c757d;">Completed</span>`
  314. }
  315. return "Unknown"
  316. }
  317. func (this *Modules) RegisterModule_Shop() *Module {
  318. return this.newModule(MInfo{
  319. WantDB: true,
  320. Mount: "shop",
  321. Name: "Shop",
  322. Order: 2,
  323. System: false,
  324. Icon: assets.SysSvgIconShop,
  325. Sub: &[]MISub{
  326. {Mount: "default", Name: "List of products", Show: true, Icon: assets.SysSvgIconList},
  327. {Mount: "add", Name: "Add new product", Show: true, Icon: assets.SysSvgIconPlus},
  328. {Mount: "modify", Name: "Modify product", Show: false},
  329. {Sep: true, Show: true},
  330. {Mount: "categories", Name: "List of categories", Show: true, Icon: assets.SysSvgIconList},
  331. {Mount: "categories-add", Name: "Add new category", Show: true, Icon: assets.SysSvgIconPlus},
  332. {Mount: "categories-modify", Name: "Modify category", Show: false},
  333. {Sep: true, Show: true},
  334. {Mount: "attributes", Name: "List of attributes", Show: true, Icon: assets.SysSvgIconList},
  335. {Mount: "attributes-add", Name: "Add new attribute", Show: true, Icon: assets.SysSvgIconPlus},
  336. {Mount: "attributes-modify", Name: "Modify attribute", Show: false},
  337. {Sep: true, Show: true},
  338. {Mount: "currencies", Name: "List of currencies", Show: true, Icon: assets.SysSvgIconList},
  339. {Mount: "currencies-add", Name: "Add new currency", Show: true, Icon: assets.SysSvgIconPlus},
  340. {Mount: "currencies-modify", Name: "Modify currency", Show: false},
  341. {Sep: true, Show: true},
  342. {Mount: "orders", Name: "List of orders", Show: true, Icon: assets.SysSvgIconList},
  343. {Mount: "orders-modify", Name: "Viewing order", Show: false},
  344. },
  345. }, func(wrap *wrapper.Wrapper) {
  346. if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
  347. // Shop category
  348. row := &utils.MySql_shop_category{}
  349. rou := &utils.MySql_user{}
  350. err := wrap.DB.QueryRow(`
  351. SELECT
  352. main.id,
  353. main.user,
  354. main.name,
  355. main.alias,
  356. main.lft,
  357. main.rgt,
  358. main.depth,
  359. parent.id AS parent_id,
  360. users.id,
  361. users.first_name,
  362. users.last_name,
  363. users.email,
  364. users.admin,
  365. users.active
  366. FROM
  367. (
  368. SELECT
  369. node.id,
  370. node.user,
  371. node.name,
  372. node.alias,
  373. node.lft,
  374. node.rgt,
  375. (COUNT(parent.id) - 1) AS depth
  376. FROM
  377. shop_cats AS node,
  378. shop_cats AS parent
  379. WHERE
  380. node.lft BETWEEN parent.lft AND parent.rgt
  381. GROUP BY
  382. node.id
  383. ORDER BY
  384. node.lft ASC
  385. ) AS main
  386. LEFT JOIN (
  387. SELECT
  388. node.id,
  389. node.user,
  390. node.name,
  391. node.alias,
  392. node.lft,
  393. node.rgt,
  394. (COUNT(parent.id) - 0) AS depth
  395. FROM
  396. shop_cats AS node,
  397. shop_cats AS parent
  398. WHERE
  399. node.lft BETWEEN parent.lft AND parent.rgt
  400. GROUP BY
  401. node.id
  402. ORDER BY
  403. node.lft ASC
  404. ) AS parent ON
  405. parent.depth = main.depth AND
  406. main.lft > parent.lft AND
  407. main.rgt < parent.rgt
  408. LEFT JOIN users ON users.id = main.user
  409. WHERE
  410. main.id > 1 AND
  411. main.alias = ?
  412. ORDER BY
  413. main.lft ASC
  414. ;`,
  415. wrap.UrlArgs[2],
  416. ).Scan(
  417. &row.A_id,
  418. &row.A_user,
  419. &row.A_name,
  420. &row.A_alias,
  421. &row.A_lft,
  422. &row.A_rgt,
  423. &row.A_depth,
  424. &row.A_parent,
  425. &rou.A_id,
  426. &rou.A_first_name,
  427. &rou.A_last_name,
  428. &rou.A_email,
  429. &rou.A_admin,
  430. &rou.A_active,
  431. )
  432. if err != nil && err != wrapper.ErrNoRows {
  433. // System error 500
  434. wrap.LogCpError(&err)
  435. utils.SystemErrorPageEngine(wrap.W, err)
  436. return
  437. } else if err == wrapper.ErrNoRows {
  438. // User error 404 page
  439. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  440. return
  441. }
  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-category", fetdata.New(wrap, false, row, rou), http.StatusOK)
  449. return
  450. } else if len(wrap.UrlArgs) >= 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "basket" && (wrap.UrlArgs[2] == "info" || wrap.UrlArgs[2] == "plus" || wrap.UrlArgs[2] == "minus" || wrap.UrlArgs[2] == "remove" || wrap.UrlArgs[2] == "currency") {
  451. SBParam := basket.SBParam{
  452. R: wrap.R,
  453. DB: wrap.DB,
  454. Host: wrap.CurrHost,
  455. Config: wrap.Config,
  456. SessionId: wrap.GetSessionId(),
  457. }
  458. if wrap.UrlArgs[2] == "info" {
  459. wrap.W.WriteHeader(http.StatusOK)
  460. wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  461. wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
  462. wrap.W.Write([]byte(wrap.ShopBasket.Info(&SBParam)))
  463. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  464. return
  465. } else if wrap.UrlArgs[2] == "plus" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
  466. wrap.W.WriteHeader(http.StatusOK)
  467. wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  468. wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
  469. wrap.W.Write([]byte(wrap.ShopBasket.Plus(&SBParam, utils.StrToInt(wrap.UrlArgs[3]))))
  470. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  471. return
  472. } else if wrap.UrlArgs[2] == "minus" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
  473. wrap.W.WriteHeader(http.StatusOK)
  474. wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  475. wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
  476. wrap.W.Write([]byte(wrap.ShopBasket.Minus(&SBParam, utils.StrToInt(wrap.UrlArgs[3]))))
  477. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  478. return
  479. } else if wrap.UrlArgs[2] == "remove" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
  480. wrap.W.WriteHeader(http.StatusOK)
  481. wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  482. wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
  483. wrap.W.Write([]byte(wrap.ShopBasket.Remove(&SBParam, utils.StrToInt(wrap.UrlArgs[3]))))
  484. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  485. return
  486. } else if wrap.UrlArgs[2] == "currency" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
  487. http.SetCookie(wrap.W, &http.Cookie{
  488. Name: "currency",
  489. Value: wrap.UrlArgs[3],
  490. Path: "/",
  491. Expires: time.Now().Add(7 * 24 * time.Hour),
  492. HttpOnly: true,
  493. })
  494. redirectUrl := wrap.R.Referer()
  495. if redirectUrl == "" {
  496. redirectUrl = "/"
  497. }
  498. http.Redirect(wrap.W, wrap.R, redirectUrl, 302)
  499. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  500. return
  501. }
  502. } else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] != "" {
  503. // Shop product
  504. row := &utils.MySql_shop_product{}
  505. rou := &utils.MySql_user{}
  506. err := wrap.DB.QueryRow(`
  507. SELECT
  508. shop_products.id,
  509. shop_products.parent_id,
  510. shop_products.user,
  511. shop_products.currency,
  512. shop_products.price,
  513. shop_products.name,
  514. shop_products.alias,
  515. shop_products.vendor,
  516. shop_products.quantity,
  517. shop_products.category,
  518. shop_products.briefly,
  519. shop_products.content,
  520. UNIX_TIMESTAMP(shop_products.datetime) as datetime,
  521. shop_products.active,
  522. users.id,
  523. users.first_name,
  524. users.last_name,
  525. users.email,
  526. users.admin,
  527. users.active
  528. FROM
  529. shop_products
  530. LEFT JOIN users ON users.id = shop_products.user
  531. WHERE
  532. shop_products.active = 1 and
  533. shop_products.alias = ?
  534. LIMIT 1;`,
  535. wrap.UrlArgs[1],
  536. ).Scan(
  537. &row.A_id,
  538. &row.A_parent,
  539. &row.A_user,
  540. &row.A_currency,
  541. &row.A_price,
  542. &row.A_name,
  543. &row.A_alias,
  544. &row.A_vendor,
  545. &row.A_quantity,
  546. &row.A_category,
  547. &row.A_briefly,
  548. &row.A_content,
  549. &row.A_datetime,
  550. &row.A_active,
  551. &rou.A_id,
  552. &rou.A_first_name,
  553. &rou.A_last_name,
  554. &rou.A_email,
  555. &rou.A_admin,
  556. &rou.A_active,
  557. )
  558. if err != nil && err != wrapper.ErrNoRows {
  559. // System error 500
  560. wrap.LogCpError(&err)
  561. utils.SystemErrorPageEngine(wrap.W, err)
  562. return
  563. } else if err == wrapper.ErrNoRows {
  564. // User error 404 page
  565. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  566. return
  567. }
  568. // Fix url
  569. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  570. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  571. return
  572. }
  573. // Render template
  574. wrap.RenderFrontEnd("shop-product", fetdata.New(wrap, false, row, rou), http.StatusOK)
  575. return
  576. } else if len(wrap.UrlArgs) == 1 && wrap.UrlArgs[0] == "shop" {
  577. // Shop
  578. // Fix url
  579. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  580. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  581. return
  582. }
  583. // Render template
  584. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  585. return
  586. } else if (*wrap.Config).Engine.MainModule == 2 {
  587. // Render template
  588. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  589. return
  590. }
  591. // User error 404 page
  592. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  593. }, func(wrap *wrapper.Wrapper) (string, string, string) {
  594. content := ""
  595. sidebar := ""
  596. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
  597. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  598. {Name: "List of products"},
  599. })
  600. // Load currencies
  601. currencies := this.shop_GetAllCurrencies(wrap)
  602. content += builder.DataTable(
  603. wrap,
  604. "shop_products",
  605. "id",
  606. "DESC",
  607. &[]builder.DataTableRow{
  608. {
  609. DBField: "id",
  610. },
  611. {
  612. DBField: "name",
  613. NameInTable: "Product / URL",
  614. CallBack: func(values *[]string) string {
  615. name := `<a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` ` + html.EscapeString((*values)[0]) + `</a>`
  616. alias := html.EscapeString((*values)[2])
  617. parent := ``
  618. if (*values)[7] != "" {
  619. parent = `<div class="parent">&uarr;<small><a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[7] + `/">` + html.EscapeString((*values)[8]) + ` ` + (*values)[7] + `</a></small></div>`
  620. }
  621. return `<div>` + name + `</div><div><small>/shop/` + alias + `/</small></div>` + parent
  622. },
  623. },
  624. {
  625. DBField: "alias",
  626. },
  627. {
  628. DBField: "currency",
  629. },
  630. {
  631. DBField: "price",
  632. NameInTable: "Price",
  633. Classes: "d-none d-md-table-cell",
  634. CallBack: func(values *[]string) string {
  635. return `<div>` + utils.Float64ToStr(utils.StrToFloat64((*values)[4])) + `</div>` +
  636. `<div><small>` + currencies[utils.StrToInt((*values)[3])] + `</small></div>`
  637. },
  638. },
  639. {
  640. DBField: "datetime",
  641. DBExp: "UNIX_TIMESTAMP(`datetime`)",
  642. NameInTable: "Date / Time",
  643. Classes: "d-none d-lg-table-cell",
  644. CallBack: func(values *[]string) string {
  645. t := int64(utils.StrToInt((*values)[5]))
  646. return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
  647. `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
  648. },
  649. },
  650. {
  651. DBField: "active",
  652. NameInTable: "Active",
  653. Classes: "d-none d-sm-table-cell",
  654. CallBack: func(values *[]string) string {
  655. return builder.CheckBox(utils.StrToInt((*values)[6]))
  656. },
  657. },
  658. {
  659. DBField: "parent_id",
  660. },
  661. {
  662. DBField: "pname",
  663. DBExp: "spp.name",
  664. },
  665. },
  666. func(values *[]string) string {
  667. return builder.DataTableAction(&[]builder.DataTableActionRow{
  668. {
  669. Icon: assets.SysSvgIconView,
  670. Href: `/shop/` + (*values)[2] + `/`,
  671. Hint: "View",
  672. Target: "_blank",
  673. },
  674. {
  675. Icon: assets.SysSvgIconEdit,
  676. Href: "/cp/" + wrap.CurrModule + "/modify/" + (*values)[0] + "/",
  677. Hint: "Edit",
  678. },
  679. {
  680. Icon: assets.SysSvgIconRemove,
  681. Href: "javascript:fave.ActionDataTableDelete(this,'shop-delete','" +
  682. (*values)[0] + "','Are you sure want to delete product?');",
  683. Hint: "Delete",
  684. Classes: "delete",
  685. },
  686. })
  687. },
  688. "/cp/"+wrap.CurrModule+"/",
  689. func() (int, error) {
  690. var count int
  691. return count, wrap.DB.QueryRow(
  692. "SELECT COUNT(*) FROM `shop_products`;",
  693. ).Scan(&count)
  694. },
  695. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  696. return wrap.DB.Query(
  697. `SELECT
  698. shop_products.id,
  699. shop_products.name,
  700. shop_products.alias,
  701. shop_products.currency,
  702. shop_products.price,
  703. UNIX_TIMESTAMP(`+"`shop_products`.`datetime`"+`) AS datetime,
  704. shop_products.active,
  705. shop_products.parent_id,
  706. spp.name AS pname
  707. FROM
  708. shop_products
  709. LEFT JOIN shop_products AS spp ON spp.id = shop_products.parent_id
  710. ORDER BY
  711. shop_products.id DESC
  712. LIMIT ?, ?;`,
  713. limit_offset,
  714. pear_page,
  715. )
  716. },
  717. true,
  718. )
  719. } else if wrap.CurrSubModule == "categories" {
  720. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  721. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  722. {Name: "List of categories"},
  723. })
  724. content += builder.DataTable(
  725. wrap,
  726. "shop_cats",
  727. "id",
  728. "ASC",
  729. &[]builder.DataTableRow{
  730. {
  731. DBField: "id",
  732. },
  733. {
  734. DBField: "user",
  735. },
  736. {
  737. DBField: "name",
  738. NameInTable: "Category",
  739. CallBack: func(values *[]string) string {
  740. depth := utils.StrToInt((*values)[4]) - 1
  741. if depth < 0 {
  742. depth = 0
  743. }
  744. sub := strings.Repeat("&mdash; ", depth)
  745. name := `<a href="/cp/` + wrap.CurrModule + `/categories-modify/` + (*values)[0] + `/">` + sub + html.EscapeString((*values)[2]) + `</a>`
  746. return `<div>` + name + `</div>`
  747. },
  748. },
  749. {
  750. DBField: "alias",
  751. },
  752. {
  753. DBField: "depth",
  754. },
  755. },
  756. func(values *[]string) string {
  757. return builder.DataTableAction(&[]builder.DataTableActionRow{
  758. {
  759. Icon: assets.SysSvgIconView,
  760. Href: `/shop/category/` + (*values)[3] + `/`,
  761. Hint: "View",
  762. Target: "_blank",
  763. },
  764. {
  765. Icon: assets.SysSvgIconEdit,
  766. Href: "/cp/" + wrap.CurrModule + "/categories-modify/" + (*values)[0] + "/",
  767. Hint: "Edit",
  768. },
  769. {
  770. Icon: assets.SysSvgIconRemove,
  771. Href: "javascript:fave.ActionDataTableDelete(this,'shop-categories-delete','" +
  772. (*values)[0] + "','Are you sure want to delete category?');",
  773. Hint: "Delete",
  774. Classes: "delete",
  775. },
  776. })
  777. },
  778. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  779. nil,
  780. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  781. return wrap.DB.Query(
  782. `SELECT
  783. node.id,
  784. node.user,
  785. node.name,
  786. node.alias,
  787. (COUNT(parent.id) - 1) AS depth
  788. FROM
  789. shop_cats AS node,
  790. shop_cats AS parent
  791. WHERE
  792. node.lft BETWEEN parent.lft AND parent.rgt AND
  793. node.id > 1
  794. GROUP BY
  795. node.id
  796. ORDER BY
  797. node.lft ASC
  798. ;`,
  799. )
  800. },
  801. false,
  802. )
  803. } else if wrap.CurrSubModule == "attributes" {
  804. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  805. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  806. {Name: "List of attributes"},
  807. })
  808. content += builder.DataTable(
  809. wrap,
  810. "shop_filters",
  811. "id",
  812. "DESC",
  813. &[]builder.DataTableRow{
  814. {
  815. DBField: "id",
  816. },
  817. {
  818. DBField: "name",
  819. NameInTable: "Name",
  820. CallBack: func(values *[]string) string {
  821. name := `<a href="/cp/` + wrap.CurrModule + `/attributes-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  822. return `<div>` + name + `</div><div><small>` + html.EscapeString((*values)[2]) + `</small></div>`
  823. },
  824. },
  825. {
  826. DBField: "filter",
  827. },
  828. },
  829. func(values *[]string) string {
  830. return builder.DataTableAction(&[]builder.DataTableActionRow{
  831. {
  832. Icon: assets.SysSvgIconEdit,
  833. Href: "/cp/" + wrap.CurrModule + "/attributes-modify/" + (*values)[0] + "/",
  834. Hint: "Edit",
  835. },
  836. {
  837. Icon: assets.SysSvgIconRemove,
  838. Href: "javascript:fave.ActionDataTableDelete(this,'shop-attributes-delete','" +
  839. (*values)[0] + "','Are you sure want to delete attribute?');",
  840. Hint: "Delete",
  841. Classes: "delete",
  842. },
  843. })
  844. },
  845. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  846. nil,
  847. nil,
  848. true,
  849. )
  850. } else if wrap.CurrSubModule == "currencies" {
  851. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  852. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  853. {Name: "List of currencies"},
  854. })
  855. content += builder.DataTable(
  856. wrap,
  857. "shop_currencies",
  858. "id",
  859. "DESC",
  860. &[]builder.DataTableRow{
  861. {
  862. DBField: "id",
  863. },
  864. {
  865. DBField: "name",
  866. NameInTable: "Name",
  867. CallBack: func(values *[]string) string {
  868. name := `<a href="/cp/` + wrap.CurrModule + `/currencies-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` (` + (*values)[3] + `, ` + (*values)[4] + `)</a>`
  869. return `<div>` + name + `</div>`
  870. },
  871. },
  872. {
  873. DBField: "coefficient",
  874. NameInTable: "Coefficient",
  875. Classes: "d-none d-md-table-cell",
  876. CallBack: func(values *[]string) string {
  877. return utils.Float64ToStrF(utils.StrToFloat64((*values)[2]), "%.4f")
  878. },
  879. },
  880. {
  881. DBField: "code",
  882. },
  883. {
  884. DBField: "symbol",
  885. },
  886. },
  887. func(values *[]string) string {
  888. return builder.DataTableAction(&[]builder.DataTableActionRow{
  889. {
  890. Icon: assets.SysSvgIconEdit,
  891. Href: "/cp/" + wrap.CurrModule + "/currencies-modify/" + (*values)[0] + "/",
  892. Hint: "Edit",
  893. },
  894. {
  895. Icon: assets.SysSvgIconRemove,
  896. Href: "javascript:fave.ActionDataTableDelete(this,'shop-currencies-delete','" +
  897. (*values)[0] + "','Are you sure want to delete currency?');",
  898. Hint: "Delete",
  899. Classes: "delete",
  900. },
  901. })
  902. },
  903. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  904. nil,
  905. nil,
  906. true,
  907. )
  908. } else if wrap.CurrSubModule == "orders" {
  909. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  910. {Name: "Orders", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  911. {Name: "List of orders"},
  912. })
  913. content += builder.DataTable(
  914. wrap,
  915. "shop_orders",
  916. "id",
  917. "DESC",
  918. &[]builder.DataTableRow{
  919. {
  920. DBField: "id",
  921. NameInTable: "Order #",
  922. Classes: "d-none d-lg-table-cell",
  923. },
  924. {
  925. DBField: "client_phone",
  926. },
  927. {
  928. DBField: "update_datetime",
  929. },
  930. {
  931. DBField: "currency_id",
  932. },
  933. {
  934. DBField: "currency_name",
  935. },
  936. {
  937. DBField: "currency_coefficient",
  938. },
  939. {
  940. DBField: "currency_code",
  941. },
  942. {
  943. DBField: "currency_symbol",
  944. },
  945. {
  946. DBField: "client_last_name",
  947. NameInTable: "Client / Contact",
  948. CallBack: func(values *[]string) string {
  949. link := "/cp/" + wrap.CurrModule + "/orders-modify/" + (*values)[0] + "/"
  950. last_name := html.EscapeString((*values)[8])
  951. first_name := html.EscapeString((*values)[9])
  952. second_name := html.EscapeString((*values)[10])
  953. phone := html.EscapeString((*values)[1])
  954. email := html.EscapeString((*values)[12])
  955. order_id := `<span class="d-inline d-sm-none">#` + (*values)[0] + `. </span>`
  956. name := ""
  957. if last_name != "" {
  958. name += " " + last_name
  959. }
  960. if first_name != "" {
  961. name += " " + first_name
  962. }
  963. if second_name != "" {
  964. name += " " + second_name
  965. }
  966. name = `<a href="` + link + `">` + order_id + strings.TrimSpace(name) + `</a>`
  967. contact := ""
  968. if email != "" {
  969. contact += " " + email
  970. }
  971. if phone != "" {
  972. contact += " (" + phone + ")"
  973. }
  974. contact = `<a href="` + link + `">` + strings.TrimSpace(contact) + `</a>`
  975. return `<div>` + name + `</div><div><small>` + contact + `</small></div>`
  976. },
  977. },
  978. {
  979. DBField: "client_first_name",
  980. },
  981. {
  982. DBField: "client_second_name",
  983. },
  984. {
  985. DBField: "create_datetime",
  986. DBExp: "UNIX_TIMESTAMP(`create_datetime`)",
  987. NameInTable: "Date / Time",
  988. Classes: "d-none d-lg-table-cell",
  989. CallBack: func(values *[]string) string {
  990. t := int64(utils.StrToInt((*values)[11]))
  991. return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
  992. `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
  993. },
  994. },
  995. {
  996. DBField: "client_email",
  997. NameInTable: "Status / Total",
  998. CallBack: func(values *[]string) string {
  999. status := this.shop_GetOrderStatus(utils.StrToInt((*values)[15]))
  1000. total := utils.Float64ToStr(0) + " " + html.EscapeString((*values)[6])
  1001. return `<div>` + status + `</div><div><small>` + total + `</small></div>`
  1002. },
  1003. },
  1004. {
  1005. DBField: "client_delivery_comment",
  1006. },
  1007. {
  1008. DBField: "client_order_comment",
  1009. },
  1010. {
  1011. DBField: "status",
  1012. },
  1013. },
  1014. nil,
  1015. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  1016. nil,
  1017. nil,
  1018. true,
  1019. )
  1020. } else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
  1021. if wrap.CurrSubModule == "add" {
  1022. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1023. {Name: "Add new product"},
  1024. })
  1025. } else {
  1026. if len(wrap.UrlArgs) >= 3 && utils.IsNumeric(wrap.UrlArgs[2]) {
  1027. content += `<div class="product-copy"><a title="Duplicate product" href="javascript:fave.ShopProductsDuplicate(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconCopy + `</a></div>`
  1028. content += `<div class="product-another"><a title="Duplicate product and attach" href="javascript:fave.ShopProductsDuplicateWithAttach(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconPlus + `</a></div>`
  1029. }
  1030. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1031. {Name: "Modify product"},
  1032. })
  1033. }
  1034. data := utils.MySql_shop_product{
  1035. A_id: 0,
  1036. A_user: 0,
  1037. A_currency: 0,
  1038. A_price: 0,
  1039. A_gname: "",
  1040. A_name: "",
  1041. A_alias: "",
  1042. A_vendor: "",
  1043. A_quantity: 0,
  1044. A_category: 0,
  1045. A_briefly: "",
  1046. A_content: "",
  1047. A_datetime: 0,
  1048. A_active: 0,
  1049. }
  1050. if wrap.CurrSubModule == "modify" {
  1051. if len(wrap.UrlArgs) != 3 {
  1052. return "", "", ""
  1053. }
  1054. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1055. return "", "", ""
  1056. }
  1057. err := wrap.DB.QueryRow(`
  1058. SELECT
  1059. id,
  1060. parent_id,
  1061. user,
  1062. currency,
  1063. price,
  1064. gname,
  1065. name,
  1066. alias,
  1067. vendor,
  1068. quantity,
  1069. category,
  1070. briefly,
  1071. content,
  1072. active
  1073. FROM
  1074. shop_products
  1075. WHERE
  1076. id = ?
  1077. LIMIT 1;`,
  1078. utils.StrToInt(wrap.UrlArgs[2]),
  1079. ).Scan(
  1080. &data.A_id,
  1081. &data.A_parent,
  1082. &data.A_user,
  1083. &data.A_currency,
  1084. &data.A_price,
  1085. &data.A_gname,
  1086. &data.A_name,
  1087. &data.A_alias,
  1088. &data.A_vendor,
  1089. &data.A_quantity,
  1090. &data.A_category,
  1091. &data.A_briefly,
  1092. &data.A_content,
  1093. &data.A_active,
  1094. )
  1095. if *wrap.LogCpError(&err) != nil {
  1096. return "", "", ""
  1097. }
  1098. }
  1099. if data.A_parent_id() > 0 {
  1100. content += `<style>.product-another{display:none}</style>`
  1101. }
  1102. // All product current categories
  1103. var selids []int
  1104. if data.A_id > 0 {
  1105. rows, err := wrap.DB.Query("SELECT category_id FROM shop_cat_product_rel WHERE product_id = ?;", data.A_id)
  1106. if err == nil {
  1107. defer rows.Close()
  1108. values := make([]int, 1)
  1109. scan := make([]interface{}, len(values))
  1110. for i := range values {
  1111. scan[i] = &values[i]
  1112. }
  1113. for rows.Next() {
  1114. err = rows.Scan(scan...)
  1115. if *wrap.LogCpError(&err) == nil {
  1116. selids = append(selids, int(values[0]))
  1117. }
  1118. }
  1119. }
  1120. }
  1121. // Sub products
  1122. sub_products := ``
  1123. if data.A_id >= 1 && data.A_parent_id() <= 0 {
  1124. sub_products = this.shop_GetSubProducts(wrap, data.A_id)
  1125. }
  1126. btn_caption := "Add"
  1127. if wrap.CurrSubModule == "modify" {
  1128. btn_caption = "Save"
  1129. }
  1130. content += builder.DataForm(wrap, []builder.DataFormField{
  1131. {
  1132. Kind: builder.DFKHidden,
  1133. Name: "action",
  1134. Value: "shop-modify",
  1135. },
  1136. {
  1137. Kind: builder.DFKHidden,
  1138. Name: "id",
  1139. Value: utils.IntToStr(data.A_id),
  1140. },
  1141. {
  1142. Kind: builder.DFKText,
  1143. CallBack: func(field *builder.DataFormField) string {
  1144. if data.A_id >= 1 && data.A_parent_id() <= 0 {
  1145. return `<div class="form-group nf">` +
  1146. `<div class="row">` +
  1147. `<div class="col-md-3">` +
  1148. `<label>Sub products</label>` +
  1149. `</div>` +
  1150. `<div class="col-md-9">` +
  1151. `<div class="list-wrapper">` +
  1152. sub_products +
  1153. `<div><a href="javascript:fave.ShopAttachProduct(` + utils.IntToStr(data.A_id) + `);"><b>Attach product</b></a></div>` +
  1154. `</div>` +
  1155. `</div>` +
  1156. `</div>` +
  1157. `</div>`
  1158. }
  1159. return ""
  1160. },
  1161. },
  1162. {
  1163. Kind: builder.DFKText,
  1164. CallBack: func(field *builder.DataFormField) string {
  1165. if data.A_id >= 1 && data.A_parent_id() != 0 {
  1166. return `<div class="form-group nf">` +
  1167. `<div class="row">` +
  1168. `<div class="col-md-3">` +
  1169. `<label>Parent</label>` +
  1170. `</div>` +
  1171. `<div class="col-md-9">` +
  1172. `<div class="list-wrapper">` +
  1173. this.shop_GetParentProduct(wrap, data.A_parent_id()) +
  1174. `</div>` +
  1175. `</div>` +
  1176. `</div>` +
  1177. `</div>`
  1178. }
  1179. return ""
  1180. },
  1181. },
  1182. {
  1183. Kind: builder.DFKText,
  1184. CallBack: func(field *builder.DataFormField) string {
  1185. if data.A_id >= 1 && data.A_parent_id() <= 0 && sub_products != "" {
  1186. return `<div class="form-group nf">` +
  1187. `<div class="row">` +
  1188. `<div class="col-md-3">` +
  1189. `<label for="lbl_gname">Group name</label>` +
  1190. `</div>` +
  1191. `<div class="col-md-9">` +
  1192. `<div><input class="form-control" type="text" id="lbl_gname" name="gname" value="` + html.EscapeString(data.A_gname) + `" maxlength="255" autocomplete="off"></div>` +
  1193. `</div>` +
  1194. `</div>` +
  1195. `</div>`
  1196. }
  1197. return ""
  1198. },
  1199. },
  1200. {
  1201. Kind: builder.DFKText,
  1202. Caption: "Product name",
  1203. Name: "name",
  1204. Value: data.A_name,
  1205. Required: true,
  1206. Min: "1",
  1207. Max: "255",
  1208. },
  1209. {
  1210. Kind: builder.DFKText,
  1211. Caption: "Product price",
  1212. Name: "price",
  1213. Value: "0",
  1214. CallBack: func(field *builder.DataFormField) string {
  1215. return `<div class="form-group n6">` +
  1216. `<div class="row">` +
  1217. `<div class="col-md-3">` +
  1218. `<label for="lbl_price">Product price</label>` +
  1219. `</div>` +
  1220. `<div class="col-md-9">` +
  1221. `<div>` +
  1222. `<div class="row">` +
  1223. `<div class="col-md-8">` +
  1224. `<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>` +
  1225. `<div class="d-md-none mb-3"></div>` +
  1226. `</div>` +
  1227. `<div class="col-md-4">` +
  1228. `<select class="selectpicker form-control" id="lbl_currency" name="currency" data-live-search="true">` +
  1229. this.shop_GetCurrencySelectOptions(wrap, data.A_currency) +
  1230. `</select>` +
  1231. `</div>` +
  1232. `</div>` +
  1233. `</div>` +
  1234. `</div>` +
  1235. `</div>` +
  1236. `</div>`
  1237. },
  1238. },
  1239. {
  1240. Kind: builder.DFKText,
  1241. Caption: "Product alias",
  1242. Name: "alias",
  1243. Value: data.A_alias,
  1244. Hint: "Example: mobile-phone",
  1245. Max: "255",
  1246. },
  1247. {
  1248. Kind: builder.DFKText,
  1249. Caption: "Vendor/Count",
  1250. Name: "vendor",
  1251. Value: "0",
  1252. CallBack: func(field *builder.DataFormField) string {
  1253. return `<div class="form-group n8">` +
  1254. `<div class="row">` +
  1255. `<div class="col-md-3">` +
  1256. `<label for="lbl_vendor">Vendor/Count</label>` +
  1257. `</div>` +
  1258. `<div class="col-md-9">` +
  1259. `<div>` +
  1260. `<div class="row">` +
  1261. `<div class="col-md-8">` +
  1262. `<div><input class="form-control" type="text" id="lbl_vendor" name="vendor" value="` + html.EscapeString(data.A_vendor) + `" placeholder="" autocomplete="off"></div>` +
  1263. `<div class="d-md-none mb-3"></div>` +
  1264. `</div>` +
  1265. `<div class="col-md-4">` +
  1266. `<input class="form-control" type="number" step="1" id="lbl_quantity" name="quantity" value="` + utils.IntToStr(data.A_quantity) + `" placeholder="" autocomplete="off">` +
  1267. `</div>` +
  1268. `</div>` +
  1269. `</div>` +
  1270. `</div>` +
  1271. `</div>` +
  1272. `</div>`
  1273. },
  1274. },
  1275. {
  1276. Kind: builder.DFKText,
  1277. Caption: "Category",
  1278. Name: "category",
  1279. Value: "0",
  1280. CallBack: func(field *builder.DataFormField) string {
  1281. return `<div class="form-group n9">` +
  1282. `<div class="row">` +
  1283. `<div class="col-md-3">` +
  1284. `<label for="lbl_category">Category</label>` +
  1285. `</div>` +
  1286. `<div class="col-md-9">` +
  1287. `<div>` +
  1288. `<select class="selectpicker form-control" id="lbl_category" name="category" data-live-search="true">` +
  1289. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1290. this.shop_GetCategorySelectOptions(wrap, 0, data.A_category, []int{}) +
  1291. `</select>` +
  1292. `</div>` +
  1293. `</div>` +
  1294. `</div>` +
  1295. `</div>`
  1296. },
  1297. },
  1298. {
  1299. Kind: builder.DFKText,
  1300. Caption: "Categories",
  1301. Name: "cats",
  1302. Value: "0",
  1303. CallBack: func(field *builder.DataFormField) string {
  1304. return `<div class="form-group n10">` +
  1305. `<div class="row">` +
  1306. `<div class="col-md-3">` +
  1307. `<label for="lbl_cats">Categories</label>` +
  1308. `</div>` +
  1309. `<div class="col-md-9">` +
  1310. `<div>` +
  1311. `<select class="selectpicker form-control" id="lbl_cats" name="cats[]" data-live-search="true" multiple>` +
  1312. this.shop_GetCategorySelectOptions(wrap, 0, 0, selids) +
  1313. `</select>` +
  1314. `</div>` +
  1315. `</div>` +
  1316. `</div>` +
  1317. `</div>`
  1318. },
  1319. },
  1320. {
  1321. Kind: builder.DFKText,
  1322. Caption: "Attributes",
  1323. Name: "",
  1324. Value: "",
  1325. CallBack: func(field *builder.DataFormField) string {
  1326. return `<div class="form-group n11">` +
  1327. `<div class="row">` +
  1328. `<div class="col-md-3">` +
  1329. `<label>Attributes</label>` +
  1330. `</div>` +
  1331. `<div class="col-md-9">` +
  1332. `<div class="list-wrapper">` +
  1333. `<div id="list">` +
  1334. this.shop_GetProductValuesInputs(wrap, data.A_id) +
  1335. `</div>` +
  1336. `<div class="list-button position-relative">` +
  1337. `<select class="selectpicker form-control" id="lbl_attributes" data-live-search="true" onchange="fave.ShopProductsAdd();">` +
  1338. this.shop_GetAllAttributesSelectOptions(wrap) +
  1339. `</select>` +
  1340. `</div>` +
  1341. `</div>` +
  1342. `</div>` +
  1343. `</div>` +
  1344. `</div>`
  1345. },
  1346. },
  1347. {
  1348. Kind: builder.DFKTextArea,
  1349. Caption: "Briefly",
  1350. Name: "briefly",
  1351. Value: data.A_briefly,
  1352. Classes: "briefly wysiwyg",
  1353. },
  1354. {
  1355. Kind: builder.DFKTextArea,
  1356. Caption: "Product content",
  1357. Name: "content",
  1358. Value: data.A_content,
  1359. Classes: "wysiwyg",
  1360. },
  1361. {
  1362. Kind: builder.DFKText,
  1363. Caption: "Product images",
  1364. Name: "",
  1365. Value: "",
  1366. CallBack: func(field *builder.DataFormField) string {
  1367. if data.A_id == 0 {
  1368. return ``
  1369. }
  1370. return `<div class="form-group n14">` +
  1371. `<div class="row">` +
  1372. `<div class="col-md-3">` +
  1373. `<label>Product images</label>` +
  1374. `</div>` +
  1375. `<div class="col-md-9">` +
  1376. `<div class="list-wrapper">` +
  1377. `<div id="list-images">` +
  1378. this.shop_GetAllProductImages(wrap, data.A_id) +
  1379. `</div>` +
  1380. `<div id="img-upload-block" class="list-button position-relative">` +
  1381. `<div id="upload-msg">Uploading...</div>` +
  1382. `<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:12px;" multiple />` +
  1383. `</div>` +
  1384. `</div>` +
  1385. `</div>` +
  1386. `</div>` +
  1387. `</div>` +
  1388. `<script>WaitForFave(function(){Sortable.create(document.getElementById('list-images'),{animation:0,onEnd:function(evt){var orderData=[];$('#list-images div.attached-img').each(function(i,v){orderData.push({Id:$(v).data('id'),Order:i+1});});$('#list-images').addClass('loading');fave.ShopProductsImageReorder('shop-images-reorder',{Items:orderData});},});});</script>`
  1389. },
  1390. },
  1391. {
  1392. Kind: builder.DFKCheckBox,
  1393. Caption: "Active",
  1394. Name: "active",
  1395. Value: utils.IntToStr(data.A_active),
  1396. },
  1397. {
  1398. Kind: builder.DFKSubmit,
  1399. Value: btn_caption,
  1400. Target: "add-edit-button",
  1401. },
  1402. })
  1403. if wrap.CurrSubModule == "add" {
  1404. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1405. } else {
  1406. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1407. }
  1408. } else if wrap.CurrSubModule == "categories-add" || wrap.CurrSubModule == "categories-modify" {
  1409. if wrap.CurrSubModule == "categories-add" {
  1410. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1411. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1412. {Name: "Add new category"},
  1413. })
  1414. } else {
  1415. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1416. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1417. {Name: "Modify category"},
  1418. })
  1419. }
  1420. data := utils.MySql_shop_category{
  1421. A_id: 0,
  1422. A_user: 0,
  1423. A_name: "",
  1424. A_alias: "",
  1425. A_lft: 0,
  1426. A_rgt: 0,
  1427. }
  1428. if wrap.CurrSubModule == "categories-modify" {
  1429. if len(wrap.UrlArgs) != 3 {
  1430. return "", "", ""
  1431. }
  1432. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1433. return "", "", ""
  1434. }
  1435. err := wrap.DB.QueryRow(`
  1436. SELECT
  1437. id,
  1438. user,
  1439. name,
  1440. alias,
  1441. lft,
  1442. rgt
  1443. FROM
  1444. shop_cats
  1445. WHERE
  1446. id = ?
  1447. LIMIT 1;`,
  1448. utils.StrToInt(wrap.UrlArgs[2]),
  1449. ).Scan(
  1450. &data.A_id,
  1451. &data.A_user,
  1452. &data.A_name,
  1453. &data.A_alias,
  1454. &data.A_lft,
  1455. &data.A_rgt,
  1456. )
  1457. if *wrap.LogCpError(&err) != nil {
  1458. return "", "", ""
  1459. }
  1460. }
  1461. btn_caption := "Add"
  1462. if wrap.CurrSubModule == "categories-modify" {
  1463. btn_caption = "Save"
  1464. }
  1465. parentId := 0
  1466. if wrap.CurrSubModule == "categories-modify" {
  1467. parentId = this.shop_GetCategoryParentId(wrap, data.A_id)
  1468. }
  1469. content += builder.DataForm(wrap, []builder.DataFormField{
  1470. {
  1471. Kind: builder.DFKHidden,
  1472. Name: "action",
  1473. Value: "shop-categories-modify",
  1474. },
  1475. {
  1476. Kind: builder.DFKHidden,
  1477. Name: "id",
  1478. Value: utils.IntToStr(data.A_id),
  1479. },
  1480. {
  1481. Kind: builder.DFKText,
  1482. Caption: "Parent",
  1483. Name: "parent",
  1484. Value: "0",
  1485. CallBack: func(field *builder.DataFormField) string {
  1486. return `<div class="form-group n2">` +
  1487. `<div class="row">` +
  1488. `<div class="col-md-3">` +
  1489. `<label for="lbl_parent">Parent</label>` +
  1490. `</div>` +
  1491. `<div class="col-md-9">` +
  1492. `<div>` +
  1493. `<select class="selectpicker form-control" id="lbl_parent" name="parent" data-live-search="true">` +
  1494. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1495. this.shop_GetCategorySelectOptions(wrap, data.A_id, parentId, []int{}) +
  1496. `</select>` +
  1497. `</div>` +
  1498. `</div>` +
  1499. `</div>` +
  1500. `</div>`
  1501. },
  1502. },
  1503. {
  1504. Kind: builder.DFKText,
  1505. Caption: "Name",
  1506. Name: "name",
  1507. Value: data.A_name,
  1508. Required: true,
  1509. Min: "1",
  1510. Max: "255",
  1511. },
  1512. {
  1513. Kind: builder.DFKText,
  1514. Caption: "Alias",
  1515. Name: "alias",
  1516. Value: data.A_alias,
  1517. Hint: "Example: popular-products",
  1518. Max: "255",
  1519. },
  1520. {
  1521. Kind: builder.DFKSubmit,
  1522. Value: btn_caption,
  1523. Target: "add-edit-button",
  1524. },
  1525. })
  1526. if wrap.CurrSubModule == "categories-add" {
  1527. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1528. } else {
  1529. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1530. }
  1531. } else if wrap.CurrSubModule == "attributes-add" || wrap.CurrSubModule == "attributes-modify" {
  1532. if wrap.CurrSubModule == "attributes-add" {
  1533. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1534. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1535. {Name: "Add new attribute"},
  1536. })
  1537. } else {
  1538. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1539. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1540. {Name: "Modify attribute"},
  1541. })
  1542. }
  1543. data := utils.MySql_shop_filter{
  1544. A_id: 0,
  1545. A_name: "",
  1546. A_filter: "",
  1547. }
  1548. if wrap.CurrSubModule == "attributes-modify" {
  1549. if len(wrap.UrlArgs) != 3 {
  1550. return "", "", ""
  1551. }
  1552. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1553. return "", "", ""
  1554. }
  1555. err := wrap.DB.QueryRow(`
  1556. SELECT
  1557. id,
  1558. name,
  1559. filter
  1560. FROM
  1561. shop_filters
  1562. WHERE
  1563. id = ?
  1564. LIMIT 1;`,
  1565. utils.StrToInt(wrap.UrlArgs[2]),
  1566. ).Scan(
  1567. &data.A_id,
  1568. &data.A_name,
  1569. &data.A_filter,
  1570. )
  1571. if *wrap.LogCpError(&err) != nil {
  1572. return "", "", ""
  1573. }
  1574. }
  1575. btn_caption := "Add"
  1576. if wrap.CurrSubModule == "attributes-modify" {
  1577. btn_caption = "Save"
  1578. }
  1579. content += builder.DataForm(wrap, []builder.DataFormField{
  1580. {
  1581. Kind: builder.DFKHidden,
  1582. Name: "action",
  1583. Value: "shop-attributes-modify",
  1584. },
  1585. {
  1586. Kind: builder.DFKHidden,
  1587. Name: "id",
  1588. Value: utils.IntToStr(data.A_id),
  1589. },
  1590. {
  1591. Kind: builder.DFKText,
  1592. Caption: "Attribute name",
  1593. Name: "name",
  1594. Value: data.A_name,
  1595. Required: true,
  1596. Min: "1",
  1597. Max: "255",
  1598. },
  1599. {
  1600. Kind: builder.DFKText,
  1601. Caption: "Attribute in filter",
  1602. Name: "filter",
  1603. Value: data.A_filter,
  1604. Required: true,
  1605. Min: "1",
  1606. Max: "255",
  1607. },
  1608. {
  1609. Kind: builder.DFKText,
  1610. Caption: "Attribute values",
  1611. Name: "",
  1612. Value: "",
  1613. CallBack: func(field *builder.DataFormField) string {
  1614. return `<div class="form-group n4">` +
  1615. `<div class="row">` +
  1616. `<div class="col-md-3">` +
  1617. `<label>Attribute values</label>` +
  1618. `</div>` +
  1619. `<div class="col-md-9">` +
  1620. `<div class="list-wrapper">` +
  1621. `<div id="list">` +
  1622. this.shop_GetFilterValuesInputs(wrap, data.A_id) +
  1623. `</div>` +
  1624. `<div class="list-button"><button type="button" class="btn btn-success" onclick="fave.ShopAttributesAdd();">Add attribute value</button></div>` +
  1625. `</div>` +
  1626. `</div>` +
  1627. `</div>` +
  1628. `</div>`
  1629. },
  1630. },
  1631. {
  1632. Kind: builder.DFKSubmit,
  1633. Value: btn_caption,
  1634. Target: "add-edit-button",
  1635. },
  1636. })
  1637. if wrap.CurrSubModule == "attributes-add" {
  1638. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1639. } else {
  1640. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1641. }
  1642. } else if wrap.CurrSubModule == "currencies-add" || wrap.CurrSubModule == "currencies-modify" {
  1643. if wrap.CurrSubModule == "currencies-add" {
  1644. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1645. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1646. {Name: "Add new currency"},
  1647. })
  1648. } else {
  1649. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1650. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1651. {Name: "Modify currency"},
  1652. })
  1653. }
  1654. data := utils.MySql_shop_currency{
  1655. A_id: 0,
  1656. A_name: "",
  1657. A_coefficient: 0,
  1658. A_code: "",
  1659. A_symbol: "",
  1660. }
  1661. if wrap.CurrSubModule == "currencies-modify" {
  1662. if len(wrap.UrlArgs) != 3 {
  1663. return "", "", ""
  1664. }
  1665. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1666. return "", "", ""
  1667. }
  1668. err := wrap.DB.QueryRow(`
  1669. SELECT
  1670. id,
  1671. name,
  1672. coefficient,
  1673. code,
  1674. symbol
  1675. FROM
  1676. shop_currencies
  1677. WHERE
  1678. id = ?
  1679. LIMIT 1;`,
  1680. utils.StrToInt(wrap.UrlArgs[2]),
  1681. ).Scan(
  1682. &data.A_id,
  1683. &data.A_name,
  1684. &data.A_coefficient,
  1685. &data.A_code,
  1686. &data.A_symbol,
  1687. )
  1688. if *wrap.LogCpError(&err) != nil {
  1689. return "", "", ""
  1690. }
  1691. }
  1692. btn_caption := "Add"
  1693. if wrap.CurrSubModule == "currencies-modify" {
  1694. btn_caption = "Save"
  1695. }
  1696. content += builder.DataForm(wrap, []builder.DataFormField{
  1697. {
  1698. Kind: builder.DFKHidden,
  1699. Name: "action",
  1700. Value: "shop-currencies-modify",
  1701. },
  1702. {
  1703. Kind: builder.DFKHidden,
  1704. Name: "id",
  1705. Value: utils.IntToStr(data.A_id),
  1706. },
  1707. {
  1708. Kind: builder.DFKText,
  1709. Caption: "Currency name",
  1710. Name: "name",
  1711. Value: data.A_name,
  1712. Required: true,
  1713. Min: "1",
  1714. Max: "255",
  1715. },
  1716. {
  1717. Kind: builder.DFKText,
  1718. Caption: "Currency coefficient",
  1719. Name: "coefficient",
  1720. Value: "0",
  1721. CallBack: func(field *builder.DataFormField) string {
  1722. return `<div class="form-group n3">` +
  1723. `<div class="row">` +
  1724. `<div class="col-md-3">` +
  1725. `<label for="lbl_coefficient">Currency coefficient</label>` +
  1726. `</div>` +
  1727. `<div class="col-md-9">` +
  1728. `<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>` +
  1729. `</div>` +
  1730. `</div>` +
  1731. `</div>`
  1732. },
  1733. },
  1734. {
  1735. Kind: builder.DFKText,
  1736. Caption: "Currency code",
  1737. Name: "code",
  1738. Value: data.A_code,
  1739. Required: true,
  1740. Min: "1",
  1741. Max: "10",
  1742. },
  1743. {
  1744. Kind: builder.DFKText,
  1745. Caption: "Currency symbol",
  1746. Name: "symbol",
  1747. Value: data.A_symbol,
  1748. Required: true,
  1749. Min: "1",
  1750. Max: "5",
  1751. },
  1752. {
  1753. Kind: builder.DFKSubmit,
  1754. Value: btn_caption,
  1755. Target: "add-edit-button",
  1756. },
  1757. })
  1758. if wrap.CurrSubModule == "currencies-add" {
  1759. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1760. } else {
  1761. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1762. }
  1763. }
  1764. return this.getSidebarModules(wrap), content, sidebar
  1765. })
  1766. }