Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | var AppInbox = function () { |
| 2 | |||
| 3 | var content = $('.inbox-content'); |
||
| 4 | var loading = $('.inbox-loading'); |
||
| 5 | var listListing = ''; |
||
| 6 | |||
| 7 | var loadInbox = function (el, name) { |
||
| 8 | var url = 'app_inbox_inbox.html'; |
||
| 9 | var title = $('.inbox-nav > li.' + name + ' a').attr('data-title'); |
||
| 10 | listListing = name; |
||
| 11 | |||
| 12 | loading.show(); |
||
| 13 | content.html(''); |
||
| 14 | toggleButton(el); |
||
| 15 | |||
| 16 | $.ajax({ |
||
| 17 | type: "GET", |
||
| 18 | cache: false, |
||
| 19 | url: url, |
||
| 20 | dataType: "html", |
||
| 21 | success: function(res) |
||
| 22 | { |
||
| 23 | toggleButton(el); |
||
| 24 | |||
| 25 | $('.inbox-nav > li.active').removeClass('active'); |
||
| 26 | $('.inbox-nav > li.' + name).addClass('active'); |
||
| 27 | $('.inbox-header > h1').text(title); |
||
| 28 | |||
| 29 | loading.hide(); |
||
| 30 | content.html(res); |
||
| 31 | if (Layout.fixContentHeight) { |
||
| 32 | Layout.fixContentHeight(); |
||
| 33 | } |
||
| 34 | }, |
||
| 35 | error: function(xhr, ajaxOptions, thrownError) |
||
| 36 | { |
||
| 37 | toggleButton(el); |
||
| 38 | }, |
||
| 39 | async: false |
||
| 40 | }); |
||
| 41 | |||
| 42 | // handle group checkbox: |
||
| 43 | jQuery('body').on('change', '.mail-group-checkbox', function () { |
||
| 44 | var set = jQuery('.mail-checkbox'); |
||
| 45 | var checked = jQuery(this).is(":checked"); |
||
| 46 | jQuery(set).each(function () { |
||
| 47 | $(this).attr("checked", checked); |
||
| 48 | }); |
||
| 49 | }); |
||
| 50 | } |
||
| 51 | |||
| 52 | var loadMessage = function (el, name, resetMenu) { |
||
| 53 | var url = 'app_inbox_view.html'; |
||
| 54 | |||
| 55 | loading.show(); |
||
| 56 | content.html(''); |
||
| 57 | toggleButton(el); |
||
| 58 | |||
| 59 | var message_id = el.parent('tr').attr("data-messageid"); |
||
| 60 | |||
| 61 | $.ajax({ |
||
| 62 | type: "GET", |
||
| 63 | cache: false, |
||
| 64 | url: url, |
||
| 65 | dataType: "html", |
||
| 66 | data: {'message_id': message_id}, |
||
| 67 | success: function(res) |
||
| 68 | { |
||
| 69 | toggleButton(el); |
||
| 70 | |||
| 71 | if (resetMenu) { |
||
| 72 | $('.inbox-nav > li.active').removeClass('active'); |
||
| 73 | } |
||
| 74 | $('.inbox-header > h1').text('View Message'); |
||
| 75 | |||
| 76 | loading.hide(); |
||
| 77 | content.html(res); |
||
| 78 | Layout.fixContentHeight(); |
||
| 79 | }, |
||
| 80 | error: function(xhr, ajaxOptions, thrownError) |
||
| 81 | { |
||
| 82 | toggleButton(el); |
||
| 83 | }, |
||
| 84 | async: false |
||
| 85 | }); |
||
| 86 | } |
||
| 87 | |||
| 88 | var initWysihtml5 = function () { |
||
| 89 | $('.inbox-wysihtml5').wysihtml5({ |
||
| 90 | "stylesheets": ["../assets/global/plugins/bootstrap-wysihtml5/wysiwyg-color.css"] |
||
| 91 | }); |
||
| 92 | } |
||
| 93 | |||
| 94 | var initFileupload = function () { |
||
| 95 | |||
| 96 | $('#fileupload').fileupload({ |
||
| 97 | // Uncomment the following to send cross-domain cookies: |
||
| 98 | //xhrFields: {withCredentials: true}, |
||
| 99 | url: '../assets/global/plugins/jquery-file-upload/server/php/', |
||
| 100 | autoUpload: true |
||
| 101 | }); |
||
| 102 | |||
| 103 | // Upload server status check for browsers with CORS support: |
||
| 104 | if ($.support.cors) { |
||
| 105 | $.ajax({ |
||
| 106 | url: '../assets/global/plugins/jquery-file-upload/server/php/', |
||
| 107 | type: 'HEAD' |
||
| 108 | }).fail(function () { |
||
| 109 | $('<span class="alert alert-error"/>') |
||
| 110 | .text('Upload server currently unavailable - ' + |
||
| 111 | new Date()) |
||
| 112 | .appendTo('#fileupload'); |
||
| 113 | }); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | var loadCompose = function (el) { |
||
| 118 | var url = 'app_inbox_compose.html'; |
||
| 119 | |||
| 120 | loading.show(); |
||
| 121 | content.html(''); |
||
| 122 | toggleButton(el); |
||
| 123 | |||
| 124 | // load the form via ajax |
||
| 125 | $.ajax({ |
||
| 126 | type: "GET", |
||
| 127 | cache: false, |
||
| 128 | url: url, |
||
| 129 | dataType: "html", |
||
| 130 | success: function(res) |
||
| 131 | { |
||
| 132 | toggleButton(el); |
||
| 133 | |||
| 134 | $('.inbox-nav > li.active').removeClass('active'); |
||
| 135 | $('.inbox-header > h1').text('Compose'); |
||
| 136 | |||
| 137 | loading.hide(); |
||
| 138 | content.html(res); |
||
| 139 | |||
| 140 | initFileupload(); |
||
| 141 | initWysihtml5(); |
||
| 142 | |||
| 143 | $('.inbox-wysihtml5').focus(); |
||
| 144 | Layout.fixContentHeight(); |
||
| 145 | App.initUniform(); |
||
| 146 | }, |
||
| 147 | error: function(xhr, ajaxOptions, thrownError) |
||
| 148 | { |
||
| 149 | toggleButton(el); |
||
| 150 | }, |
||
| 151 | async: false |
||
| 152 | }); |
||
| 153 | } |
||
| 154 | |||
| 155 | var loadReply = function (el) { |
||
| 156 | var messageid = $(el).attr("data-messageid"); |
||
| 157 | var url = 'app_inbox_reply.html&messageid=' + messageid; |
||
| 158 | |||
| 159 | loading.show(); |
||
| 160 | content.html(''); |
||
| 161 | toggleButton(el); |
||
| 162 | |||
| 163 | // load the form via ajax |
||
| 164 | $.ajax({ |
||
| 165 | type: "GET", |
||
| 166 | cache: false, |
||
| 167 | url: url, |
||
| 168 | dataType: "html", |
||
| 169 | success: function(res) |
||
| 170 | { |
||
| 171 | toggleButton(el); |
||
| 172 | |||
| 173 | $('.inbox-nav > li.active').removeClass('active'); |
||
| 174 | $('.inbox-header > h1').text('Reply'); |
||
| 175 | |||
| 176 | loading.hide(); |
||
| 177 | content.html(res); |
||
| 178 | $('[name="message"]').val($('#reply_email_content_body').html()); |
||
| 179 | |||
| 180 | handleCCInput(); // init "CC" input field |
||
| 181 | |||
| 182 | initFileupload(); |
||
| 183 | initWysihtml5(); |
||
| 184 | Layout.fixContentHeight(); |
||
| 185 | App.initUniform(); |
||
| 186 | }, |
||
| 187 | error: function(xhr, ajaxOptions, thrownError) |
||
| 188 | { |
||
| 189 | toggleButton(el); |
||
| 190 | }, |
||
| 191 | async: false |
||
| 192 | }); |
||
| 193 | } |
||
| 194 | |||
| 195 | var loadSearchResults = function (el) { |
||
| 196 | var url = 'app_inbox_inbox.html'; |
||
| 197 | |||
| 198 | loading.show(); |
||
| 199 | content.html(''); |
||
| 200 | toggleButton(el); |
||
| 201 | |||
| 202 | $.ajax({ |
||
| 203 | type: "GET", |
||
| 204 | cache: false, |
||
| 205 | url: url, |
||
| 206 | dataType: "html", |
||
| 207 | success: function(res) |
||
| 208 | { |
||
| 209 | toggleButton(el); |
||
| 210 | |||
| 211 | $('.inbox-nav > li.active').removeClass('active'); |
||
| 212 | $('.inbox-header > h1').text('Search'); |
||
| 213 | |||
| 214 | loading.hide(); |
||
| 215 | content.html(res); |
||
| 216 | Layout.fixContentHeight(); |
||
| 217 | App.initUniform(); |
||
| 218 | }, |
||
| 219 | error: function(xhr, ajaxOptions, thrownError) |
||
| 220 | { |
||
| 221 | toggleButton(el); |
||
| 222 | }, |
||
| 223 | async: false |
||
| 224 | }); |
||
| 225 | } |
||
| 226 | |||
| 227 | var handleCCInput = function () { |
||
| 228 | var the = $('.inbox-compose .mail-to .inbox-cc'); |
||
| 229 | var input = $('.inbox-compose .input-cc'); |
||
| 230 | the.hide(); |
||
| 231 | input.show(); |
||
| 232 | $('.close', input).click(function () { |
||
| 233 | input.hide(); |
||
| 234 | the.show(); |
||
| 235 | }); |
||
| 236 | } |
||
| 237 | |||
| 238 | var handleBCCInput = function () { |
||
| 239 | |||
| 240 | var the = $('.inbox-compose .mail-to .inbox-bcc'); |
||
| 241 | var input = $('.inbox-compose .input-bcc'); |
||
| 242 | the.hide(); |
||
| 243 | input.show(); |
||
| 244 | $('.close', input).click(function () { |
||
| 245 | input.hide(); |
||
| 246 | the.show(); |
||
| 247 | }); |
||
| 248 | } |
||
| 249 | |||
| 250 | var toggleButton = function(el) { |
||
| 251 | if (typeof el == 'undefined') { |
||
| 252 | return; |
||
| 253 | } |
||
| 254 | if (el.attr("disabled")) { |
||
| 255 | el.attr("disabled", false); |
||
| 256 | } else { |
||
| 257 | el.attr("disabled", true); |
||
| 258 | } |
||
| 259 | } |
||
| 260 | |||
| 261 | return { |
||
| 262 | //main function to initiate the module |
||
| 263 | init: function () { |
||
| 264 | |||
| 265 | // handle compose btn click |
||
| 266 | $('.inbox').on('click', '.compose-btn a', function () { |
||
| 267 | loadCompose($(this)); |
||
| 268 | }); |
||
| 269 | |||
| 270 | // handle discard btn |
||
| 271 | $('.inbox').on('click', '.inbox-discard-btn', function(e) { |
||
| 272 | e.preventDefault(); |
||
| 273 | loadInbox($(this), listListing); |
||
| 274 | }); |
||
| 275 | |||
| 276 | // handle reply and forward button click |
||
| 277 | $('.inbox').on('click', '.reply-btn', function () { |
||
| 278 | loadReply($(this)); |
||
| 279 | }); |
||
| 280 | |||
| 281 | // handle view message |
||
| 282 | $('.inbox-content').on('click', '.view-message', function () { |
||
| 283 | loadMessage($(this)); |
||
| 284 | }); |
||
| 285 | |||
| 286 | // handle inbox listing |
||
| 287 | $('.inbox-nav > li.inbox > a').click(function () { |
||
| 288 | loadInbox($(this), 'inbox'); |
||
| 289 | }); |
||
| 290 | |||
| 291 | // handle sent listing |
||
| 292 | $('.inbox-nav > li.sent > a').click(function () { |
||
| 293 | loadInbox($(this), 'sent'); |
||
| 294 | }); |
||
| 295 | |||
| 296 | // handle draft listing |
||
| 297 | $('.inbox-nav > li.draft > a').click(function () { |
||
| 298 | loadInbox($(this), 'draft'); |
||
| 299 | }); |
||
| 300 | |||
| 301 | // handle trash listing |
||
| 302 | $('.inbox-nav > li.trash > a').click(function () { |
||
| 303 | loadInbox($(this), 'trash'); |
||
| 304 | }); |
||
| 305 | |||
| 306 | //handle compose/reply cc input toggle |
||
| 307 | $('.inbox-content').on('click', '.mail-to .inbox-cc', function () { |
||
| 308 | handleCCInput(); |
||
| 309 | }); |
||
| 310 | |||
| 311 | //handle compose/reply bcc input toggle |
||
| 312 | $('.inbox-content').on('click', '.mail-to .inbox-bcc', function () { |
||
| 313 | handleBCCInput(); |
||
| 314 | }); |
||
| 315 | |||
| 316 | //handle loading content based on URL parameter |
||
| 317 | if (App.getURLParameter("a") === "view") { |
||
| 318 | loadMessage(); |
||
| 319 | } else if (App.getURLParameter("a") === "compose") { |
||
| 320 | loadCompose(); |
||
| 321 | } else { |
||
| 322 | $('.inbox-nav > li.inbox > a').click(); |
||
| 323 | } |
||
| 324 | |||
| 325 | } |
||
| 326 | |||
| 327 | }; |
||
| 328 | |||
| 329 | }(); |
||
| 330 | |||
| 331 | jQuery(document).ready(function() { |
||
| 332 | AppInbox.init(); |
||
| 333 | }); |