From b75c725b3e1490f130b6927829d24270797c1cd3 Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Thu, 30 Aug 2018 15:07:20 +0300 Subject: [PATCH] add links to the documentation, confirmation of bot removal --- go.mod | 1 - go.sum | 4 +-- src/locale.go | 8 +++-- src/routing.go | 8 +++-- static/script.js | 69 +++++++++++++++++++++++++++++++------- static/style.css | 28 +++++++++++++++- templates/form.html | 3 ++ templates/layout.html | 26 +++++++++++--- translate/translate.en.yml | 3 ++ translate/translate.es.yml | 3 ++ translate/translate.ru.yml | 3 ++ 11 files changed, 130 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index ddf8911..2ff3f9d 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,6 @@ require ( github.com/json-iterator/go v0.0.0-20180806060727-1624edc4454b // indirect github.com/jtolds/gls v4.2.1+incompatible // indirect github.com/kr/pretty v0.1.0 // indirect - github.com/kr/pty v1.1.2 // indirect github.com/lib/pq v1.0.0 // indirect github.com/mattn/go-isatty v0.0.3 // indirect github.com/mattn/go-sqlite3 v1.9.0 // indirect diff --git a/go.sum b/go.sum index 9df65c5..5b51e88 100644 --- a/go.sum +++ b/go.sum @@ -69,7 +69,6 @@ github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVY github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.2/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= @@ -114,8 +113,7 @@ golang.org/x/net v0.0.0-20180821023952-922f4815f713 h1:rMJUcaDGbG+X967I4zGKCq5la golang.org/x/net v0.0.0-20180821023952-922f4815f713/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180821140842-3b58ed4ad339 h1:0w2EXzxbB03VAzqwe3csbadu4CPhMRtxCz/rjw9gkic= -golang.org/x/sys v0.0.0-20180821140842-3b58ed4ad339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc h1:MeuS1UDyZyFH++6vVy44PuufTeFF0d0nfI6XB87YGSk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.0.0-20171214130843-f21a4dfb5e38/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= diff --git a/src/locale.go b/src/locale.go index 40e7fe8..88301bb 100644 --- a/src/locale.go +++ b/src/locale.go @@ -1,6 +1,7 @@ package main import ( + "html/template" "io/ioutil" "github.com/nicksnyder/go-i18n/v2/i18n" @@ -40,8 +41,8 @@ func getLocalizedMessage(messageID string) string { return localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: messageID}) } -func getLocale() map[string]string { - return map[string]string{ +func getLocale() map[string]interface{} { + return map[string]interface{}{ "ButtonSave": getLocalizedMessage("button_save"), "ApiKey": getLocalizedMessage("api_key"), "TabSettings": getLocalizedMessage("tab_settings"), @@ -51,5 +52,8 @@ func getLocale() map[string]string { "AddBot": getLocalizedMessage("add_bot"), "TableDelete": getLocalizedMessage("table_delete"), "Title": getLocalizedMessage("title"), + "InfoBot": template.HTML(getLocalizedMessage("info_bot")), + "CRMLink": template.HTML(getLocalizedMessage("crm_link")), + "DocLink": template.HTML(getLocalizedMessage("doc_link")), } } diff --git a/src/routing.go b/src/routing.go index 379ee85..d54a1dd 100644 --- a/src/routing.go +++ b/src/routing.go @@ -15,10 +15,12 @@ import ( func connectHandler(c *gin.Context) { res := struct { Conn Connection - Locale map[string]string + Locale map[string]interface{} + Year int }{ c.MustGet("account").(Connection), getLocale(), + time.Now().Year(), } c.HTML(http.StatusOK, "home", &res) @@ -133,11 +135,13 @@ func settingsHandler(c *gin.Context) { res := struct { Conn *Connection Bots Bots - Locale map[string]string + Locale map[string]interface{} + Year int }{ p, bots, getLocale(), + time.Now().Year(), } c.HTML(http.StatusOK, "form", &res) diff --git a/static/script.js b/static/script.js index 2ebef7c..4acb1ea 100644 --- a/static/script.js +++ b/static/script.js @@ -44,19 +44,41 @@ $("#add-bot").on("submit", function(e) { }); $(document).on("click", ".delete-bot", function(e) { - let but = $(this); - send("/delete-bot/", - { - token: but.attr("data-token"), - connectionId: parseInt($('input[name=connectionId]').val()), - }, - function () { - but.parents("tr").remove(); - if ($("#bots tbody tr").length === 0) { - $("#bots").addClass("hide"); - } + e.preventDefault(); + var but = $(this); + var confirmText = JSON.parse(sessionStorage.getItem("confirmText")); + + $.confirm({ + title: false, + content: confirmText["text"], + useBootstrap: false, + boxWidth: '30%', + type: 'blue', + backgroundDismiss: false, + backgroundDismissAnimation: 'shake', + buttons: { + confirm: { + text: confirmText["confirm"], + action: function () { + send("/delete-bot/", + { + token: but.attr("data-token"), + connectionId: parseInt($('input[name=connectionId]').val()), + }, + function () { + but.parents("tr").remove(); + if ($("#bots tbody tr").length === 0) { + $("#bots").addClass("hide"); + } + } + ) + }, + }, + cancel: { + text: confirmText["cancel"], + }, } - ) + }); }); function send(url, data, callback) { @@ -103,6 +125,29 @@ $( document ).ready(function() { $("#bots").addClass("hide"); } + if (!sessionStorage.getItem("confirmText")) { + let confirmText = {}; + + switch (navigator.language.split('-')[0]) { + case "ru": + confirmText["text"] = "Вы уверены, что хотите удалить?"; + confirmText["confirm"] = "да"; + confirmText["cancel"] = "нет"; + break; + case "es": + confirmText["text"] = "¿Estás seguro que quieres borrar?"; + confirmText["confirm"] = "sí"; + confirmText["cancel"] = "no"; + break; + default: + confirmText["text"] = "Are you sure you want to delete?"; + confirmText["confirm"] = "yes"; + confirmText["cancel"] = "no"; + } + + sessionStorage.setItem("confirmText", JSON.stringify(confirmText)); + } + let createdMsg = sessionStorage.getItem("createdMsg"); if (createdMsg) { setTimeout(function() { diff --git a/static/style.css b/static/style.css index ce9aa32..51b9d62 100644 --- a/static/style.css +++ b/static/style.css @@ -1,3 +1,13 @@ +body { + display: flex; + min-height: 100vh; + flex-direction: column; +} + +main { + flex: 1 0 auto; +} + .indent-top { margin-top: 2%; } @@ -11,7 +21,9 @@ margin: 0 auto 23px; } -.tab-el-center{ +.docs, +.tab-el-center, +.footer-copyright{ width: 67%; margin: 0 auto; } @@ -102,3 +114,17 @@ background-color: #039be5; will-change: left, right; } + +.docs p { + text-align: center; + color: #9e9e9e; +} + +.footer-copyright { + border-top: 1px solid #9e9e9e; + margin-top: 10px; +} + +.footer-copyright p { + color: #9e9e9e; +} diff --git a/templates/form.html b/templates/form.html index 455882a..7a96a4e 100644 --- a/templates/form.html +++ b/templates/form.html @@ -32,6 +32,9 @@
+
+

{{.Locale.InfoBot}}

+
diff --git a/templates/layout.html b/templates/layout.html index 3fb2422..923dfdf 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -5,17 +5,33 @@ {{.Locale.Title}} + -
-
- +
+
+
+ +
+ {{template "body" .}}
- {{template "body" .}} -
+ +
+
+ +
+
+ diff --git a/translate/translate.en.yml b/translate/translate.en.yml index 8c41cc7..fcb6b33 100644 --- a/translate/translate.en.yml +++ b/translate/translate.en.yml @@ -28,6 +28,9 @@ error_adding_bot: Error when adding a bot error_save: Error while saving, contact technical support missing_credentials: "Required methods: {{.Credentials}}" error_activity_mg: Check if the integration with MessageGateway is enabled in retailCRM settings +info_bot: "If you have a problem with connecting a bot, please, refer to the documentation" +crm_link: "retailCRM" +doc_link: "документация" sticker: "[sticker]" audio: "[audio file]" diff --git a/translate/translate.es.yml b/translate/translate.es.yml index 956c7f9..9cb8efc 100644 --- a/translate/translate.es.yml +++ b/translate/translate.es.yml @@ -28,6 +28,9 @@ error_adding_bot: Error al añadir el bot error_save: Error al guardar, contacte con el soporte técnico missing_credentials: "Métodos requeridos: {{.Credenciales}}" error_activity_mg: Revisar si la integración con MessageGateway está habilitada en Ajustes de retailCRM +info_bot: "Si tiene dificultades para conectar el bot, por favor, consulte la documentación" +crm_link: "retailCRM" +doc_link: "documentación" sticker: "[etiqueta]" audio: "[archivo de audio]" diff --git a/translate/translate.ru.yml b/translate/translate.ru.yml index 46ca106..06201d1 100644 --- a/translate/translate.ru.yml +++ b/translate/translate.ru.yml @@ -28,6 +28,9 @@ error_adding_bot: Ошибка при добавлении бота error_save: Ошибка при сохранении, обратитесь в службу технической поддержки missing_credentials: "Необходимые методы: {{.Credentials}}" error_activity_mg: Проверьте активность интеграции с MessageGateway в настройках retailCRM +info_bot: "Если у вас возникли трудности при подключении бота, изучите, пожалуйста, документацию" +crm_link: "retailCRM" +doc_link: "документация" sticker: "[стикер]" audio: "[аудио файл]"