inbox.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. var Inbox = function () {
  2. var content = $('.inbox-content');
  3. var loading = $('.inbox-loading');
  4. var loadInbox = function (name) {
  5. var url = 'inbox_inbox.html';
  6. var title = $('.inbox-nav > li.' + name + ' a').attr('data-title');
  7. loading.show();
  8. content.html('');
  9. $.post(url, {}, function (res) {
  10. $('.inbox-nav > li.active').removeClass('active');
  11. $('.inbox-nav > li.' + name).addClass('active');
  12. $('.inbox-header > h1').text(title);
  13. loading.hide();
  14. content.html(res);
  15. App.fixContentHeight();
  16. App.initUniform();
  17. });
  18. }
  19. var loadMessage = function (name, resetMenu) {
  20. var url = 'inbox_view.html';
  21. loading.show();
  22. content.html('');
  23. $.post(url, {}, function (res) {
  24. if (resetMenu) {
  25. $('.inbox-nav > li.active').removeClass('active');
  26. }
  27. $('.inbox-header > h1').text('View Message');
  28. loading.hide();
  29. content.html(res);
  30. App.fixContentHeight();
  31. App.initUniform();
  32. });
  33. }
  34. var initTags = function (input) {
  35. input.tag({
  36. autosizedInput: true,
  37. containerClasses: 'span12',
  38. inputClasses: 'm-wrap',
  39. source: function (query, process) {
  40. return [
  41. 'Bob Nilson <bob.nilson@metronic.com>',
  42. 'Lisa Miller <lisa.miller@metronic.com>',
  43. 'Test <test@domain.com>',
  44. 'Dino <dino@demo.com>',
  45. 'Support <support@demo.com>']
  46. }
  47. });
  48. }
  49. var initWysihtml5 = function () {
  50. $('.inbox-wysihtml5').wysihtml5({
  51. "stylesheets": ["assets/plugins/bootstrap-wysihtml5/wysiwyg-color.css"]
  52. });
  53. }
  54. var initFileupload = function () {
  55. $('#fileupload').fileupload({
  56. // Uncomment the following to send cross-domain cookies:
  57. //xhrFields: {withCredentials: true},
  58. url: 'assets/plugins/jquery-file-upload/server/php/',
  59. autoUpload: true
  60. });
  61. // Upload server status check for browsers with CORS support:
  62. if ($.support.cors) {
  63. $.ajax({
  64. url: 'assets/plugins/jquery-file-upload/server/php/',
  65. type: 'HEAD'
  66. }).fail(function () {
  67. $('<span class="alert alert-error"/>')
  68. .text('Upload server currently unavailable - ' +
  69. new Date())
  70. .appendTo('#fileupload');
  71. });
  72. }
  73. }
  74. var loadCompose = function () {
  75. var url = 'inbox_compose.html';
  76. loading.show();
  77. content.html('');
  78. // load the form via ajax
  79. $.post(url, {}, function (res) {
  80. $('.inbox-nav > li.active').removeClass('active');
  81. $('.inbox-header > h1').text('Compose');
  82. loading.hide();
  83. content.html(res);
  84. initTags($('[name="to"]'));
  85. initFileupload();
  86. initWysihtml5();
  87. $('.inbox-wysihtml5').focus();
  88. App.fixContentHeight();
  89. App.initUniform();
  90. });
  91. }
  92. var loadReply = function () {
  93. var url = 'inbox_reply.html';
  94. loading.show();
  95. content.html('');
  96. // load the form via ajax
  97. $.post(url, {}, function (res) {
  98. $('.inbox-nav > li.active').removeClass('active');
  99. $('.inbox-header > h1').text('Reply');
  100. loading.hide();
  101. content.html(res);
  102. $('[name="message"]').val($('#reply_email_content_body').html());
  103. initTags($('[name="to"]')); // init "TO" input field
  104. handleCCInput(); // init "CC" input field
  105. initFileupload();
  106. initWysihtml5();
  107. App.fixContentHeight();
  108. App.initUniform();
  109. });
  110. }
  111. var loadSearchResults = function () {
  112. var url = 'inbox_search_result.html';
  113. loading.show();
  114. content.html('');
  115. $.post(url, {}, function (res) {
  116. $('.inbox-nav > li.active').removeClass('active');
  117. $('.inbox-header > h1').text('Search');
  118. loading.hide();
  119. content.html(res);
  120. App.fixContentHeight();
  121. App.initUniform();
  122. });
  123. }
  124. var handleCCInput = function () {
  125. var the = $('.inbox-compose .mail-to .inbox-cc');
  126. var input = $('.inbox-compose .input-cc');
  127. the.hide();
  128. input.show();
  129. initTags($('[name="cc"]'), -10);
  130. $('.close', input).click(function () {
  131. input.hide();
  132. the.show();
  133. });
  134. }
  135. var handleBCCInput = function () {
  136. var the = $('.inbox-compose .mail-to .inbox-bcc');
  137. var input = $('.inbox-compose .input-bcc');
  138. the.hide();
  139. input.show();
  140. initTags($('[name="bcc"]'), -10);
  141. $('.close', input).click(function () {
  142. input.hide();
  143. the.show();
  144. });
  145. }
  146. return {
  147. //main function to initiate the module
  148. init: function () {
  149. // handle compose btn click
  150. $('.inbox .compose-btn a').live('click', function () {
  151. loadCompose();
  152. });
  153. // handle reply and forward button click
  154. $('.inbox .reply-btn').live('click', function () {
  155. loadReply();
  156. });
  157. // handle view message
  158. $('.inbox-content .view-message').live('click', function () {
  159. loadMessage();
  160. });
  161. // handle inbox listing
  162. $('.inbox-nav > li.inbox > a').click(function () {
  163. loadInbox('inbox');
  164. });
  165. // handle sent listing
  166. $('.inbox-nav > li.sent > a').click(function () {
  167. loadInbox('sent');
  168. });
  169. // handle draft listing
  170. $('.inbox-nav > li.draft > a').click(function () {
  171. loadInbox('draft');
  172. });
  173. // handle trash listing
  174. $('.inbox-nav > li.trash > a').click(function () {
  175. loadInbox('trash');
  176. });
  177. //handle compose/reply cc input toggle
  178. $('.inbox-compose .mail-to .inbox-cc').live('click', function () {
  179. handleCCInput();
  180. });
  181. //handle compose/reply bcc input toggle
  182. $('.inbox-compose .mail-to .inbox-bcc').live('click', function () {
  183. handleBCCInput();
  184. });
  185. //handle loading content based on URL parameter
  186. if (App.getURLParameter("a") === "view") {
  187. loadMessage();
  188. } else if (App.getURLParameter("a") === "compose") {
  189. loadCompose();
  190. } else {
  191. loadInbox('inbox');
  192. }
  193. }
  194. };
  195. }();