update api-client, add disable form
This commit is contained in:
parent
06279fb4b4
commit
73efd7209b
3
go.mod
3
go.mod
@ -30,6 +30,7 @@ require (
|
||||
github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a // indirect
|
||||
github.com/jinzhu/now v0.0.0-20180511015916-ed742868f2ae // indirect
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
|
||||
github.com/joho/godotenv v1.3.0 // indirect
|
||||
github.com/json-iterator/go v1.1.5 // indirect
|
||||
github.com/jtolds/gls v4.2.1+incompatible // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
@ -43,7 +44,7 @@ require (
|
||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
|
||||
github.com/pkg/errors v0.8.0
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/retailcrm/api-client-go v1.0.6
|
||||
github.com/retailcrm/api-client-go v1.0.7
|
||||
github.com/retailcrm/mg-transport-api-client-go v1.1.11
|
||||
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf // indirect
|
||||
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect
|
||||
|
6
go.sum
6
go.sum
@ -62,6 +62,8 @@ github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Ao
|
||||
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE=
|
||||
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
|
||||
@ -91,8 +93,8 @@ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/retailcrm/api-client-go v1.0.6 h1:4Q3e4ve8GOOHIQdq3/wTGqgWuWa1cKMKqmgrTv4FoDU=
|
||||
github.com/retailcrm/api-client-go v1.0.6/go.mod h1:QRoPE2SM6ST7i2g0yEdqm7Iw98y7cYuq3q14Ot+6N8c=
|
||||
github.com/retailcrm/api-client-go v1.0.7 h1:j4C2PvPUDP9nAuYWDvJPnYNpkj+LDBgn71kHvxJmSPg=
|
||||
github.com/retailcrm/api-client-go v1.0.7/go.mod h1:QRoPE2SM6ST7i2g0yEdqm7Iw98y7cYuq3q14Ot+6N8c=
|
||||
github.com/retailcrm/mg-transport-api-client-go v1.1.11 h1:jAIOKqkjA2r0v/V6lTHYQsD8q0lFpfpqzAffHAJlhCQ=
|
||||
github.com/retailcrm/mg-transport-api-client-go v1.1.11/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI=
|
||||
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf h1:6V1qxN6Usn4jy8unvggSJz/NC790tefw8Zdy6OZS5co=
|
||||
|
@ -60,6 +60,7 @@ func addBotHandler(c *gin.Context) {
|
||||
b.Name = bot.Self.UserName
|
||||
conn := getConnectionById(b.ConnectionID)
|
||||
client := v1.New(conn.MGURL, conn.MGToken)
|
||||
client.Debug = config.Debug
|
||||
|
||||
channelSettings := getChannelSettings()
|
||||
if b.Name != "" {
|
||||
@ -93,6 +94,7 @@ func deleteBotHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
var client = v1.New(conn.MGURL, conn.MGToken)
|
||||
client.Debug = config.Debug
|
||||
|
||||
data, status, err := client.DeactivateTransportChannel(getBotChannelByToken(b.Token))
|
||||
if status > http.StatusOK {
|
||||
@ -367,6 +369,7 @@ func updateBots(conn *Connection, hashSettings string) {
|
||||
bots := conn.getBotsByClientID()
|
||||
if len(bots) > 0 {
|
||||
client := v1.New(conn.MGURL, conn.MGToken)
|
||||
client.Debug = config.Debug
|
||||
for _, bot := range bots {
|
||||
if bot.ChannelSettingsHash == hashSettings {
|
||||
continue
|
||||
@ -432,6 +435,7 @@ func telegramWebhookHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
var client = v1.New(conn.MGURL, conn.MGToken)
|
||||
client.Debug = config.Debug
|
||||
|
||||
if update.Message != nil {
|
||||
if update.Message.Text == "" {
|
||||
@ -590,6 +594,7 @@ func mgWebhookHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
bot.Debug = config.Debug
|
||||
setLocale(b.Lang)
|
||||
|
||||
switch msg.Type {
|
||||
|
@ -59,8 +59,8 @@ func setup() *gin.Engine {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
r := gin.New()
|
||||
r.Use(gin.Recovery())
|
||||
if config.Debug {
|
||||
r.Use(gin.Logger())
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ func GenerateToken() string {
|
||||
|
||||
func getAPIClient(url, key string) (*v5.Client, error, int) {
|
||||
client := v5.New(url, key)
|
||||
client.Debug = config.Debug
|
||||
|
||||
cr, status, e := client.APICredentials()
|
||||
if e.RuntimeErr != nil {
|
||||
|
@ -13,9 +13,11 @@ $(document).on("change", "select", function(e) {
|
||||
|
||||
$('#save-crm').on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
let formData = formDataToObj($(this).serializeArray());
|
||||
disableForm($(this));
|
||||
send(
|
||||
$(this).attr('action'),
|
||||
formDataToObj($(this).serializeArray()),
|
||||
formData,
|
||||
function (data) {
|
||||
sessionStorage.setItem("createdMsg", data.message);
|
||||
|
||||
@ -28,17 +30,26 @@ $('#save-crm').on("submit", function(e) {
|
||||
|
||||
$("#save").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
let formData = formDataToObj($(this).serializeArray());
|
||||
disableForm($(this));
|
||||
send(
|
||||
$(this).attr('action'),
|
||||
formDataToObj($(this).serializeArray()),
|
||||
formData,
|
||||
function (data) {
|
||||
M.toast({html: data.message});
|
||||
M.toast({
|
||||
html: data.message,
|
||||
displayLength: 1000,
|
||||
completeCallback: function(){
|
||||
enableForm();
|
||||
}
|
||||
});
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
$("#add-bot").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
disableForm($(this));
|
||||
send(
|
||||
$(this).attr('action'),
|
||||
{
|
||||
@ -53,6 +64,7 @@ $("#add-bot").on("submit", function(e) {
|
||||
$("#bots tbody").append(getBotTemplate(data));
|
||||
$("#token").val("");
|
||||
$('select').formSelect();
|
||||
enableForm();
|
||||
}
|
||||
)
|
||||
});
|
||||
@ -61,6 +73,7 @@ $(document).on("click", ".delete-bot", function(e) {
|
||||
e.preventDefault();
|
||||
var but = $(this);
|
||||
var confirmText = JSON.parse(sessionStorage.getItem("confirmText"));
|
||||
but.addClass('disabled');
|
||||
|
||||
$.confirm({
|
||||
title: false,
|
||||
@ -90,6 +103,9 @@ $(document).on("click", ".delete-bot", function(e) {
|
||||
},
|
||||
cancel: {
|
||||
text: confirmText["cancel"],
|
||||
action: function () {
|
||||
but.removeClass('disabled');
|
||||
},
|
||||
},
|
||||
}
|
||||
});
|
||||
@ -103,14 +119,17 @@ function send(url, data, callback) {
|
||||
success: callback,
|
||||
error: function (res){
|
||||
if (res.status >= 400) {
|
||||
M.toast({html: res.responseJSON.error})
|
||||
M.toast({
|
||||
html: res.responseJSON.error,
|
||||
displayLength: 1000,
|
||||
completeCallback: enableForm()
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getBotTemplate(data) {
|
||||
// let bot = JSON.parse(data);
|
||||
tmpl =
|
||||
`<tr>
|
||||
<td>${data.name}</td>
|
||||
@ -180,3 +199,15 @@ $( document ).ready(function() {
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
function disableForm(elem) {
|
||||
$(document).find('button.btn').addClass('disabled');
|
||||
elem.find(".material-icons").addClass('animate');
|
||||
$("form :input").find(":input").prop("disabled", true);
|
||||
}
|
||||
|
||||
function enableForm() {
|
||||
$(document).find('button.btn').removeClass('disabled');
|
||||
$(document).find(".material-icons").removeClass('animate');
|
||||
$("form :input").prop("disabled", false);
|
||||
}
|
@ -137,3 +137,14 @@ main {
|
||||
.footer-copyright p {
|
||||
color: #9e9e9e;
|
||||
}
|
||||
|
||||
.animate {
|
||||
transition: all 0.5s ease;
|
||||
animation: rotate 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes rotate {
|
||||
from {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user