Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

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