Skip to content

Instantly share code, notes, and snippets.

@igorblumberg
Created January 11, 2017 20:20
Show Gist options
  • Save igorblumberg/8bc29103594b8336ebabaa85ef0acbc9 to your computer and use it in GitHub Desktop.
Save igorblumberg/8bc29103594b8336ebabaa85ef0acbc9 to your computer and use it in GitHub Desktop.
(function () {
var SHOULD_SAVE = 0,
progress;
return {
events: {
'app.activated': 'init',
'ticket.save': 'saveHook',
'click .cancel_button': 'cancelButton',
'click .save_button': 'saveButton',
'hidden .my_modal': 'handleHidden',
},
init: function() {
var ticket = this.ticket();
var userId = this.currentUser().id();
var str ='a[href^="#/users/' + userId + '"] :visible';
var element = this.$("header").closest("body");
var count = element.find(str).size();
var telefone = ticket.customField("custom_field_22641183");
var txt = "Você já enviou "+count+" emails nesse ticket.\n\nJá ligou para o cliente?\nO telefone dele é "+telefone+".\n\nAperte SIM se você já ligou e quer mandar esse email.\nAperte não para não mandar o email e ligar para o cliente.";
this.switchTo('modal',{
header: "Você já ligou para o cliente???",
body: txt});
},
saveHook: function(){
var userId = this.currentUser().id();
var str ='a[href^="#/users/' + userId + '"] :visible';
var element = this.$("header").closest("body");
var count = element.find(str).size();
if(count<2)
return true;
return this.promise(function(done, fail) {
this.displayModal();
console.log("abre modal");
progress = setInterval(function(){
if(SHOULD_SAVE === -1)
{
clearInterval(progress);
SHOULD_SAVE = 0;
fail("Ótima ideia, ligue para o cliente!");
}
else if(SHOULD_SAVE === 1)
{
clearInterval(progress);
SHOULD_SAVE = 0;
done();
}
}, 100);
});
},
displayModal: function() {
this.$('.my_modal').modal({
backdrop: true,
keyboard: false,
});
},
cancelButton: function(){
SHOULD_SAVE = -1;
},
saveButton: function(){
SHOULD_SAVE = 1;
},
handleHidden: function(){
SHOULD_SAVE = -1;
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment