You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

106 lines
2.0 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'html!ui/templates/mail/template',
  5. 'css!ui/templates/mail/styles'
  6. ], function (
  7. events,
  8. client,
  9. template,
  10. styles
  11. ) {
  12. return {
  13. tpl: template,
  14. centered: true,
  15. modal: true,
  16. item: null,
  17. postRender: function () {
  18. this.onEvent('onSetMailItem', this.onSetItem.bind(this));
  19. this.find('.btnSend').on('click', this.onSendClick.bind(this));
  20. },
  21. onSendClick: function () {
  22. if (!this.item)
  23. return;
  24. let recipient = this.find('.txtRecipient').val();
  25. if (recipient.length == 0)
  26. return;
  27. client.request({
  28. cpn: 'player',
  29. method: 'performAction',
  30. data: {
  31. cpn: 'inventory',
  32. method: 'mailItem',
  33. data: {
  34. itemId: this.item.id,
  35. recipient: recipient
  36. }
  37. },
  38. callback: this.onSend.bind(this)
  39. });
  40. },
  41. onSend: function (res) {
  42. if (res.length > 0) {
  43. events.emit('onGetAnnouncement', {
  44. msg: res,
  45. type: 'failure'
  46. });
  47. return;
  48. }
  49. this.hide();
  50. },
  51. onSetItem: function (msg) {
  52. this.toggle();
  53. this.item = msg.item;
  54. let item = msg.item;
  55. let imgX = -item.sprite[0] * 64;
  56. let imgY = -item.sprite[1] * 64;
  57. let spritesheet = item.spritesheet || '../../../images/items.png';
  58. if (item.material)
  59. spritesheet = '../../../images/materials.png';
  60. else if (item.quest)
  61. spritesheet = '../../../images/questItems.png';
  62. else if (item.type == 'consumable')
  63. spritesheet = '../../../images/consumables.png';
  64. let el = this.find('.item');
  65. el
  66. .data('item', item)
  67. .find('.icon')
  68. .css('background', 'url(' + spritesheet + ') ' + imgX + 'px ' + imgY + 'px');
  69. if (item.quantity) {
  70. let quantityText = item.quantity;
  71. el.find('.quantity').html(item.quantity);
  72. } else
  73. el.find('.quantity').html('');
  74. this.find('.txtRecipient').val('');
  75. },
  76. toggle: function () {
  77. this.shown = !this.el.is(':visible');
  78. if (this.shown) {
  79. this.show();
  80. this.find('input').focus();
  81. } else
  82. this.hide();
  83. }
  84. };
  85. });