Toast.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. Ext.define('erp.view.core.window.Toast', {
  2. toastId: 'toast-div',
  3. initComponent: function() {
  4. var me = this;
  5. me.createEl();
  6. me.callParant();
  7. },
  8. createEl: function() {
  9. return Ext.DomHelper.insertFirst(document.body, {
  10. 'id': this.toastId,
  11. 'class': 'toast-div'
  12. }, true);
  13. },
  14. msg: function(type, title, delay, context) {
  15. var me = this, b = Ext.get(me.toastId);
  16. if(!b)
  17. b = me.createEl();
  18. var d = Ext.String.format.apply(String, Array.prototype.slice.call(arguments, 3));
  19. var c = Ext.DomHelper.append(b, me.getMsgContext((type || 'info'), title, d), true);
  20. c.hide();
  21. c.slideIn("t").ghost("t", {
  22. delay: delay || 1000,
  23. remove: true
  24. });
  25. },
  26. getMsgContext: function(type, title, context) {
  27. return '<div class="toast x-message-box-' + type + '"><h3>' + title + "</h3><p>" + context + "</p></div>";
  28. },
  29. info: function(title, context) {
  30. this.msg('info', title, 1000, context);
  31. },
  32. warning: function(title, context) {
  33. this.msg('warning', title, 4000, context);
  34. },
  35. error: function(title, context) {
  36. this.msg('error', title, 5000, context);
  37. }
  38. });